chiark / gitweb /
basic/strv: allow NULLs to be inserted into strv
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Sun, 22 Jan 2017 21:23:24 +0000 (16:23 -0500)
committerSven Eden <yamakuzure@gmx.net>
Mon, 17 Jul 2017 15:58:36 +0000 (17:58 +0200)
All callers of this function insert non-empty strings, so there's no functional
change.

src/basic/strv.c

index c98e956fd92ce7be1cfa5a8e55e0276f77f59163..4d3cce8260c3d78272f983fc9d61a2fc0c0af03d 100644 (file)
@@ -572,9 +572,6 @@ int strv_extend_front(char ***l, const char *value) {
 
         /* Like strv_extend(), but prepends rather than appends the new entry */
 
-        if (!value)
-                return 0;
-
         n = strv_length(*l);
 
         /* Increase and overflow check. */
@@ -582,9 +579,12 @@ int strv_extend_front(char ***l, const char *value) {
         if (m < n)
                 return -ENOMEM;
 
-        v = strdup(value);
-        if (!v)
-                return -ENOMEM;
+        if (value) {
+                v = strdup(value);
+                if (!v)
+                        return -ENOMEM;
+        } else
+                v = NULL;
 
         c = realloc_multiply(*l, sizeof(char*), m);
         if (!c) {