]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
Remove VIR_STRNDUP usage that passes -1
authorJán Tomko <jtomko@redhat.com>
Thu, 24 Oct 2019 22:05:28 +0000 (00:05 +0200)
committerJán Tomko <jtomko@redhat.com>
Wed, 13 Nov 2019 16:01:38 +0000 (17:01 +0100)
Replace all the usage of
  VIR_STRNDUP(dest, b, p ? p - b : -1)
with separate calls to g_strndup/g_strdup.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>
src/bhyve/bhyve_parse_command.c
src/libxl/xen_common.c
src/remote/remote_driver.c

index fa3b881f2177c13e43209505091bdcb0f2e6c03c..050a558cee4d6ddb85cf0e1d52aac622378fad1d 100644 (file)
@@ -150,8 +150,10 @@ bhyveCommandLineToArgv(const char *nativeConfig,
         start = curr;
         next = strchr(curr, '\n');
 
-        if (VIR_STRNDUP(line, curr, next ? next - curr : -1) < 0)
-            goto error;
+        if (next)
+            line = g_strndup(curr, next - curr);
+        else
+            line = g_strdup(curr);
 
         if (VIR_RESIZE_N(lines, lines_alloc, line_count, 2) < 0) {
             VIR_FREE(line);
@@ -194,8 +196,10 @@ bhyveCommandLineToArgv(const char *nativeConfig,
                 next = strchr(start, ' ');
             }
 
-            if (VIR_STRNDUP(arg, curr, next ? next - curr : -1) < 0)
-                goto error;
+            if (next)
+                arg = g_strndup(curr, next - curr);
+            else
+                arg = g_strdup(curr);
 
             if (next && (*next == '\'' || *next == '"'))
                 next++;
@@ -366,8 +370,10 @@ bhyveParsePCISlot(const char *slotdef,
 
        next = strchr(curr, ':');
 
-       if (VIR_STRNDUP(val, curr, next? next - curr : -1) < 0)
-           goto error;
+       if (next)
+           val = g_strndup(curr, next - curr);
+       else
+           val = g_strdup(curr);
 
        if (virStrToLong_ui(val, NULL, 10, &values[i]) < 0)
            goto error;
@@ -441,9 +447,10 @@ bhyveParsePCIDisk(virDomainDefPtr def,
         goto error;
 
     separator = strchr(config, ',');
-    if (VIR_STRNDUP(disk->src->path, config,
-                    separator? separator - config : -1) < 0)
-        goto error;
+    if (separator)
+        disk->src->path = g_strndup(config, separator - config);
+    else
+        disk->src->path = g_strdup(config);
 
     if (bus == VIR_DOMAIN_DISK_BUS_VIRTIO) {
         idx = *nvirtiodisk;
@@ -515,9 +522,10 @@ bhyveParsePCINet(virDomainDefPtr def,
     }
 
     separator = strchr(config, ',');
-    if (VIR_STRNDUP(net->ifname, config,
-                    separator? separator - config : -1) < 0)
-        goto error;
+    if (separator)
+        net->ifname = g_strndup(config, separator - config);
+    else
+        net->ifname = g_strdup(config);
 
     if (!separator)
         goto cleanup;
@@ -575,11 +583,12 @@ bhyveParseBhyvePCIArg(virDomainDefPtr def,
         goto error;
 
     conf = strchr(separator+1, ',');
-    if (conf)
+    if (conf) {
         conf++; /* Skip initial comma */
-
-    if (VIR_STRNDUP(emulation, separator, conf? conf - separator - 1 : -1) < 0)
-        goto error;
+        emulation = g_strndup(separator, conf - separator - 1);
+    } else {
+        emulation = g_strdup(separator);
+    }
 
     if (bhyveParsePCISlot(slotdef, &pcislot, &bus, &function) < 0)
         goto error;
index c31a5c952e789e561eaed4d4b208aff81ecf6916..a4a9ec59bf37a6aba41cefe5695f5d30542c5830 100644 (file)
@@ -823,9 +823,11 @@ xenParseSxprChar(const char *value,
 
         offset2 = strchr(offset, ',');
         offset++;
-        if (VIR_STRNDUP(def->source->data.tcp.service, offset,
-                        offset2 ? offset2 - offset : -1) < 0)
-            goto error;
+        if (offset2)
+            def->source->data.tcp.service = g_strndup(offset,
+                                                      offset2 - offset);
+        else
+            def->source->data.tcp.service = g_strdup(offset);
 
         if (offset2 && strstr(offset2, ",server"))
             def->source->data.tcp.listen = true;
@@ -875,9 +877,10 @@ xenParseSxprChar(const char *value,
     case VIR_DOMAIN_CHR_TYPE_UNIX:
     {
         const char *offset = strchr(value, ',');
-        if (VIR_STRNDUP(def->source->data.nix.path, value,
-                        offset ? offset - value : -1) < 0)
-            goto error;
+        if (offset)
+            def->source->data.nix.path = g_strndup(value, offset - value);
+        else
+            def->source->data.nix.path = g_strdup(value);
 
         if (offset != NULL &&
             strstr(offset, ",server") != NULL)
index 451a45f5907fd359b0c1dcb6220867750f9c3c8d..503f49a902f4714696ae6cac53cc414a4475559c 100644 (file)
@@ -215,8 +215,10 @@ static int remoteSplitURIScheme(virURIPtr uri,
 
     *driver = *transport = NULL;
 
-    if (VIR_STRNDUP(*driver, uri->scheme, p ? p - uri->scheme : -1) < 0)
-        return -1;
+    if (p)
+        *driver = g_strndup(uri->scheme, p - uri->scheme);
+    else
+        *driver = g_strdup(uri->scheme);
 
     if (p) {
         *transport = g_strdup(p + 1);