chiark / gitweb /
strv: handle empty lists in strv_copy() properly
authorLennart Poettering <lennart@poettering.net>
Fri, 15 Apr 2011 23:49:20 +0000 (01:49 +0200)
committerLennart Poettering <lennart@poettering.net>
Sat, 16 Apr 2011 00:03:34 +0000 (02:03 +0200)
src/strv.c

index c5f8df0..c8ebb64 100644 (file)
@@ -70,9 +70,10 @@ char **strv_copy(char **l) {
         if (!(r = new(char*, strv_length(l)+1)))
                 return NULL;
 
-        for (k = r; *l; k++, l++)
-                if (!(*k = strdup(*l)))
-                        goto fail;
+        if (l)
+                for (k = r; *l; k++, l++)
+                        if (!(*k = strdup(*l)))
+                                goto fail;
 
         *k = NULL;
         return r;