]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
Remove all the uses that use subtraction in their length argument
authorJán Tomko <jtomko@redhat.com>
Thu, 24 Oct 2019 17:41:34 +0000 (19:41 +0200)
committerJán Tomko <jtomko@redhat.com>
Thu, 12 Dec 2019 13:24:35 +0000 (14:24 +0100)
Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
14 files changed:
src/bhyve/bhyve_parse_command.c
src/libxl/xen_common.c
src/libxl/xen_xm.c
src/lxc/lxc_driver.c
src/qemu/qemu_driver.c
src/qemu/qemu_monitor_json.c
src/util/vircgroupv1.c
src/util/vircommand.c
src/util/virconf.c
src/util/viriscsi.c
src/util/virkeyfile.c
src/util/virstoragefile.c
src/util/virsysinfo.c
src/vmware/vmware_conf.c

index 5eec05c7d40242e413a4c7ef23b1239c94fa7fbf..e74c4c2d0c49a8efedf16c2d6426034fd4a6b80c 100644 (file)
@@ -282,8 +282,7 @@ bhyveParseBhyveLPCArg(virDomainDefPtr def,
     if (!separator)
         goto error;
 
-    if (VIR_STRNDUP(type, arg, separator - arg) < 0)
-        goto error;
+    type = g_strndup(arg, separator - arg);
 
     /* Only support com%d */
     if (STRPREFIX(type, "com") && type[4] == 0) {
@@ -578,8 +577,7 @@ bhyveParseBhyvePCIArg(virDomainDefPtr def,
     else
         separator++; /* Skip comma */
 
-    if (VIR_STRNDUP(slotdef, arg, separator - arg - 1) < 0)
-        goto error;
+    slotdef = g_strndup(arg, separator - arg - 1);
 
     conf = strchr(separator+1, ',');
     if (conf) {
index 912dd8834aef4475c177e827c8ae7f3cf72f69b7..89ced6ae2ba1dfc9e0d9dcee474f25db42415fea 100644 (file)
@@ -848,9 +848,8 @@ xenParseSxprChar(const char *value,
 
         offset2 = strchr(offset, '@');
         if (offset2 != NULL) {
-            if (VIR_STRNDUP(def->source->data.udp.connectService,
-                            offset + 1, offset2 - offset - 1) < 0)
-                goto error;
+            def->source->data.udp.connectService = g_strndup(offset + 1,
+                                                             offset2 - offset - 1);
 
             offset3 = strchr(offset2, ':');
             if (offset3 == NULL) {
@@ -992,8 +991,7 @@ xenParseVifBridge(virDomainNetDefPtr net, char *bridge)
 
     if ((vlanstr = strchr(bridge, '.'))) {
         /* 'bridge' string contains a bridge name and single vlan tag */
-        if (VIR_STRNDUP(net->data.bridge.brname, bridge, vlanstr - bridge) < 0)
-            return -1;
+        net->data.bridge.brname = g_strndup(bridge, vlanstr - bridge);
 
         vlanstr++;
         if (virStrToLong_ui(vlanstr, NULL, 10, &tag) < 0)
index 1b462d04874f72c209ccc9eecb6e09567c1c68d5..a196912194a079a18d18f65b95d4bac4ef2357b2 100644 (file)
@@ -131,8 +131,7 @@ xenParseXMDisk(char *entry, int hvm)
         /* No source file given, eg CDROM with no media */
         ignore_value(virDomainDiskSetSource(disk, NULL));
     } else {
-        if (VIR_STRNDUP(tmp, head, offset - head) < 0)
-            goto error;
+        tmp = g_strndup(head, offset - head);
 
         if (virDomainDiskSetSource(disk, tmp) < 0) {
             VIR_FREE(tmp);
index b40a96b4cebe2230fe8cd3a4c4ef0611212268c3..fbf49ee95723dbbee97f02daf8e3cea075872345 100644 (file)
@@ -2137,8 +2137,7 @@ lxcDomainParseBlkioDeviceStr(char *blkioDeviceStr, const char *type,
         if (!p)
             goto parse_error;
 
-        if (VIR_STRNDUP(result[i].path, temp, p - temp) < 0)
-            goto cleanup;
+        result[i].path = g_strndup(temp, p - temp);
 
         /* value */
         temp = p + 1;
index 4d77fd6f6a696149c980bdaa22c083b5357e43e2..47665f4ea662239c55760a513748c1be409ff12f 100644 (file)
@@ -9251,8 +9251,7 @@ qemuDomainParseBlkioDeviceStr(char *blkioDeviceStr, const char *type,
         if (!p)
             goto parse_error;
 
-        if (VIR_STRNDUP(result[i].path, temp, p - temp) < 0)
-            goto cleanup;
+        result[i].path = g_strndup(temp, p - temp);
 
         /* value */
         temp = p + 1;
index 8a8347924a51c30d9885b002cef1e7d10c9f3af0..b2f695a70c3c0e2679c8b00432caa18cdd413b4a 100644 (file)
@@ -643,15 +643,11 @@ qemuMonitorJSONParseKeywords(const char *str,
             separator = endmark;
         }
 
-        if (VIR_STRNDUP(keyword, start, separator - start) < 0)
-            goto error;
+        keyword = g_strndup(start, separator - start);
 
         if (separator < endmark) {
             separator++;
-            if (VIR_STRNDUP(value, separator, endmark - separator) < 0) {
-                VIR_FREE(keyword);
-                goto error;
-            }
+            value = g_strndup(separator, endmark - separator);
             if (strchr(value, ',')) {
                 char *p = strchr(value, ',') + 1;
                 char *q = p + 1;
index 40eafd75521f065db485e8dbeb3f3a70509bd31b..4f6b89cf2ee7802361c5bb7e6137e6ed0e0ee573 100644 (file)
@@ -780,9 +780,8 @@ virCgroupV1IdentifyRoot(virCgroupPtr group)
             return NULL;
         }
 
-        if (VIR_STRNDUP(ret, group->legacy[i].mountPoint,
-                        tmp - group->legacy[i].mountPoint) < 0)
-            return NULL;
+        ret = g_strndup(group->legacy[i].mountPoint,
+                        tmp - group->legacy[i].mountPoint);
         return ret;
     }
 
index e677b67b931ee771538633ac0cf98942f064e18f..dd37b0b8dc6d93bbb89810803ebf50f5db6fd1b6 100644 (file)
@@ -3138,7 +3138,6 @@ virCommandRunRegex(virCommandPtr cmd,
             /* NB match #0 is the full pattern, so we offset j by 1 */
             for (j = 1; j <= nvars[i]; j++)
                 groups[ngroup++] = g_match_info_fetch(info, j);
-
         }
         /* We've matched on the last regex, so callback time */
         if (i == nregex) {
index 3b454364995e3dcd9eff8949724237df2a1dea36..dce84cabb73a3888d7b00de29e992f214154afdd 100644 (file)
@@ -386,8 +386,7 @@ virConfParseString(virConfParserCtxtPtr ctxt)
             virConfError(ctxt, VIR_ERR_CONF_SYNTAX, _("unterminated string"));
             return NULL;
         }
-        if (VIR_STRNDUP(ret, base, ctxt->cur - base) < 0)
-            return NULL;
+        ret = g_strndup(base, ctxt->cur - base);
         NEXT;
     } else if ((ctxt->cur + 6 < ctxt->end) &&
                (STRPREFIX(ctxt->cur, "\"\"\""))) {
@@ -407,8 +406,7 @@ virConfParseString(virConfParserCtxtPtr ctxt)
             virConfError(ctxt, VIR_ERR_CONF_SYNTAX, _("unterminated string"));
             return NULL;
         }
-        if (VIR_STRNDUP(ret, base, ctxt->cur - base) < 0)
-            return NULL;
+        ret = g_strndup(base, ctxt->cur - base);
         ctxt->cur += 3;
     } else if (CUR == '"') {
         NEXT;
@@ -419,8 +417,7 @@ virConfParseString(virConfParserCtxtPtr ctxt)
             virConfError(ctxt, VIR_ERR_CONF_SYNTAX, _("unterminated string"));
             return NULL;
         }
-        if (VIR_STRNDUP(ret, base, ctxt->cur - base) < 0)
-            return NULL;
+        ret = g_strndup(base, ctxt->cur - base);
         NEXT;
     } else if (ctxt->conf->flags & VIR_CONF_FLAG_LXC_FORMAT) {
         base = ctxt->cur;
@@ -430,8 +427,7 @@ virConfParseString(virConfParserCtxtPtr ctxt)
         /* Reverse to exclude the trailing blanks from the value */
         while ((ctxt->cur > base) && (IS_BLANK(CUR)))
             ctxt->cur--;
-        if (VIR_STRNDUP(ret, base, ctxt->cur - base) < 0)
-            return NULL;
+        ret = g_strndup(base, ctxt->cur - base);
     }
     return ret;
 }
@@ -567,8 +563,7 @@ virConfParseName(virConfParserCtxtPtr ctxt)
             ((ctxt->conf->flags & VIR_CONF_FLAG_LXC_FORMAT) &&
              (CUR == '.'))))
         NEXT;
-    if (VIR_STRNDUP(ret, base, ctxt->cur - base) < 0)
-        return NULL;
+    ret = g_strndup(base, ctxt->cur - base);
     return ret;
 }
 
@@ -591,8 +586,7 @@ virConfParseComment(virConfParserCtxtPtr ctxt)
     NEXT;
     base = ctxt->cur;
     while ((ctxt->cur < ctxt->end) && (!IS_EOL(CUR))) NEXT;
-    if (VIR_STRNDUP(comm, base, ctxt->cur - base) < 0)
-        return -1;
+    comm = g_strndup(base, ctxt->cur - base);
     if (virConfAddEntry(ctxt->conf, NULL, NULL, comm) == NULL) {
         VIR_FREE(comm);
         return -1;
@@ -666,11 +660,7 @@ virConfParseStatement(virConfParserCtxtPtr ctxt)
         NEXT;
         base = ctxt->cur;
         while ((ctxt->cur < ctxt->end) && (!IS_EOL(CUR))) NEXT;
-        if (VIR_STRNDUP(comm, base, ctxt->cur - base) < 0) {
-            VIR_FREE(name);
-            virConfFreeValue(value);
-            return -1;
-        }
+        comm = g_strndup(base, ctxt->cur - base);
     }
     if (virConfAddEntry(ctxt->conf, name, value, comm) == NULL) {
         VIR_FREE(name);
index da27894b0b8181595bafc470708ee2fee4606ee9..ac48527dde8be89d249cafcbe9226f019405d871 100644 (file)
@@ -160,8 +160,7 @@ virStorageBackendIQNFound(const char *initiatoriqn,
         if (!(next = strchr(current, ' ')))
             goto error;
 
-        if (VIR_STRNDUP(iface, current, (next - current)) < 0)
-            goto cleanup;
+        iface = g_strndup(current, next - current);
 
         current = next + 1;
 
index a98d60cdb188fa151599f1641d0276327bf7698e..ece31667ceb51cff2e3b5ebe944bac8c9da5b7fe 100644 (file)
@@ -117,8 +117,7 @@ static int virKeyFileParseGroup(virKeyFileParserCtxtPtr ctxt)
         return -1;
     }
 
-    if (VIR_STRNDUP(ctxt->groupname, name, ctxt->cur - name) < 0)
-        return -1;
+    ctxt->groupname = g_strndup(name, ctxt->cur - name);
 
     NEXT;
 
@@ -161,8 +160,7 @@ static int virKeyFileParseValue(virKeyFileParserCtxtPtr ctxt)
         return -1;
     }
 
-    if (VIR_STRNDUP(key, keystart, ctxt->cur - keystart) < 0)
-        return -1;
+    key = g_strndup(keystart, ctxt->cur - keystart);
 
     NEXT;
     valuestart = ctxt->cur;
index 5e371694d1ea7a9adae743331e099cd96dda49a6..8918f905a2187b47d5b27dc11a552214ee2a803c 100644 (file)
@@ -2945,8 +2945,7 @@ virStorageSourceParseBackingColon(virStorageSourcePtr src,
         return -1;
     }
 
-    if (VIR_STRNDUP(protocol, path, p - path) < 0)
-        return -1;
+    protocol = g_strndup(path, p - path);
 
     if ((src->protocol = virStorageNetProtocolTypeFromString(protocol)) < 0) {
         virReportError(VIR_ERR_INTERNAL_ERROR,
index ebb329bb6f1eaa38b61b7f52029bd0542193881e..8132ab7a07d01cca525fac6563731a57613feaca 100644 (file)
@@ -485,8 +485,7 @@ virSysinfoParseS390Delimited(const char *base, const char *name, char **value,
         start += 1;
         end = strchrnul(start, delim2);
         virSkipSpaces(&start);
-        if (VIR_STRNDUP(*value, start, end - start) < 0)
-            return NULL;
+        *value = g_strndup(start, end - start);
         virTrimSpaces(*value, NULL);
         return end;
     }
index 9f7d874c12f59453700b45a06ae21262abcbd7ce..290e0e898d5a26230f639ed69020b4754775d379 100644 (file)
@@ -348,8 +348,7 @@ vmwareParsePath(const char *path, char **directory, char **filename)
             return -1;
         }
 
-        if (VIR_STRNDUP(*directory, path, separator - path - 1) < 0)
-            goto error;
+        *directory = g_strndup(path, separator - path - 1);
         *filename = g_strdup(separator);
 
     } else {
@@ -357,9 +356,6 @@ vmwareParsePath(const char *path, char **directory, char **filename)
     }
 
     return 0;
-
- error:
-    return -1;
 }
 
 void