libxl: handle null lists in libxl_string_list_length
authorMatthew Daley <mattjd@gmail.com>
Fri, 27 Sep 2013 11:29:10 +0000 (23:29 +1200)
committerIan Campbell <ian.campbell@citrix.com>
Thu, 3 Oct 2013 12:37:17 +0000 (13:37 +0100)
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>
Acked-by: Ian Campbell <ian.campbell@citrix.com>
tools/libxl/libxl.c

index ca24ca37cd4a1d242da106bf935f82c1860e7424..b6daceaf9bee2538bf2bfdabac13d80c57c4f89a 100644 (file)
@@ -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;
 }