From: Boris Ostrovsky Subject: Re: [PATCH] libxl: handle null lists in libxl_string_list_length Date: Fri, 27 Sep 2013 05:08:48 -0700 (PDT) Message-ID: Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: Content-Disposition: inline List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: mattjd@gmail.com Cc: andrew.cooper3@citrix.com, ian.campbell@citrix.com, xen-devel@lists.xen.org List-Id: xen-devel@lists.xenproject.org ----- mattjd@gmail.com wrote: > After commit b0be2b12 ("libxl: fix libxl_string_list_length and its > only > caller") libxl_string_list_length no longer handles null (empty) > lists. Fix > so they are handled, returning length 0. > > While at it, remove the unneccessary undereferenced null pointer > check Are you sure this check should be removed? This routine can be called from anywhere (at least within libxl it seems) and one day someone will call it with NULL argument. I'd probably leave this check in. -boris > and tidy the layout of the function. > > Reported-by: Boris Ostrovsky > Signed-off-by: Matthew Daley > --- > I've verified that this fixes the no-bootloader-arguments case. > > tools/libxl/libxl.c | 7 +++++-- > 1 file changed, 5 insertions(+), 2 deletions(-) > > diff --git a/tools/libxl/libxl.c b/tools/libxl/libxl.c > index eeaaee8..058bef2 100644 > --- a/tools/libxl/libxl.c > +++ b/tools/libxl/libxl.c > @@ -200,9 +200,12 @@ void libxl_string_list_dispose(libxl_string_list > *psl) > > int libxl_string_list_length(const libxl_string_list *psl) > { > - if (!psl) return 0; > int i = 0; > - while ((*psl)[i]) i++; > + > + if (*psl) > + while ((*psl)[i]) > + i++; > + > return i; > } > > -- > 1.7.10.4