xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] libxl: handle null lists in libxl_string_list_length
@ 2013-09-27 11:29 Matthew Daley
  2013-10-03 13:42 ` Ian Campbell
  0 siblings, 1 reply; 9+ messages in thread
From: Matthew Daley @ 2013-09-27 11:29 UTC (permalink / raw)
  To: xen-devel; +Cc: Andrew Cooper, Boris Ostrovsky, Matthew Daley, Ian Campbell

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
and tidy the layout of the function.

Reported-by: Boris Ostrovsky <boris.ostrovsky@oracle.com>
Signed-off-by: Matthew Daley <mattjd@gmail.com>
---
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

^ permalink raw reply related	[flat|nested] 9+ messages in thread
* Re: [PATCH] libxl: handle null lists in libxl_string_list_length
@ 2013-09-27 12:08 Boris Ostrovsky
  2013-09-27 12:20 ` Matthew Daley
  0 siblings, 1 reply; 9+ messages in thread
From: Boris Ostrovsky @ 2013-09-27 12:08 UTC (permalink / raw)
  To: mattjd; +Cc: andrew.cooper3, ian.campbell, xen-devel


----- 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 <boris.ostrovsky@oracle.com>
> Signed-off-by: Matthew Daley <mattjd@gmail.com>
> ---
> 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

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2013-10-03 13:42 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-09-27 11:29 [PATCH] libxl: handle null lists in libxl_string_list_length Matthew Daley
2013-10-03 13:42 ` Ian Campbell
  -- strict thread matches above, loose matches on Subject: below --
2013-09-27 12:08 Boris Ostrovsky
2013-09-27 12:20 ` Matthew Daley
2013-09-27 12:23   ` Andrew Cooper
2013-09-27 12:28   ` Ian Campbell
2013-09-27 13:14     ` Matthew Daley
2013-09-27 13:28       ` Boris Ostrovsky
2013-09-27 14:15         ` Ian Campbell

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).