Skip to contentSkip to conversation

libxl: handle null lists in libxl_string_list_length

PATCH In review Matthew Daley 2 participants 2 messages Sep 27, 2013 – Oct 3, 2013

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 libxl: handle null lists in libxl_string_list_length

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.

---
I've verified that this fixes the no-bootloader-arguments case.

 tools/libxl/libxl.c |    7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
tools/libxl/libxl.c +5 -2
index eeaaee8..058bef2 100644
@@ -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;
 }
 
Signature · 1 line
1.7.10.4
#1 lore raw
Quoted 9 lines · Matthew Daley

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.

acked + applied, thanks.

Ian.