Remove all the uses that use subtraction in their length argument. Signed-off-by: Ján Tomko <jtomko@xxxxxxxxxx> --- src/bhyve/bhyve_parse_command.c | 6 ++---- src/libxl/xen_common.c | 8 +++----- src/libxl/xen_xm.c | 3 +-- src/lxc/lxc_driver.c | 3 +-- src/qemu/qemu_driver.c | 3 +-- src/qemu/qemu_monitor_json.c | 8 ++------ src/util/vircgroupv1.c | 5 ++--- src/util/vircommand.c | 5 ++--- src/util/virconf.c | 24 +++++++----------------- src/util/virkeyfile.c | 6 ++---- src/util/virstoragefile.c | 3 +-- src/util/virstring.c | 4 +--- src/util/virsysinfo.c | 3 +-- src/vmware/vmware_conf.c | 6 +----- 14 files changed, 27 insertions(+), 60 deletions(-) diff --git a/src/bhyve/bhyve_parse_command.c b/src/bhyve/bhyve_parse_command.c index 5c5dfae4a9..93c9c10b39 100644 --- a/src/bhyve/bhyve_parse_command.c +++ b/src/bhyve/bhyve_parse_command.c @@ -283,8 +283,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) { @@ -579,8 +578,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) diff --git a/src/libxl/xen_common.c b/src/libxl/xen_common.c index 7ac24fb606..e6d022f253 100644 --- a/src/libxl/xen_common.c +++ b/src/libxl/xen_common.c @@ -850,9 +850,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) { @@ -994,8 +993,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) diff --git a/src/libxl/xen_xm.c b/src/libxl/xen_xm.c index 88cf9ac5b0..a0e649f4ef 100644 --- a/src/libxl/xen_xm.c +++ b/src/libxl/xen_xm.c @@ -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); diff --git a/src/lxc/lxc_driver.c b/src/lxc/lxc_driver.c index ea86451b09..ef3649800b 100644 --- a/src/lxc/lxc_driver.c +++ b/src/lxc/lxc_driver.c @@ -2150,8 +2150,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; diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index f4ff2ba292..9e26af8af7 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -9289,8 +9289,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; diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c index 10f6a4cadc..963ca58f43 100644 --- a/src/qemu/qemu_monitor_json.c +++ b/src/qemu/qemu_monitor_json.c @@ -644,15 +644,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; diff --git a/src/util/vircgroupv1.c b/src/util/vircgroupv1.c index c1083b6d18..c0b6aa8204 100644 --- a/src/util/vircgroupv1.c +++ b/src/util/vircgroupv1.c @@ -769,9 +769,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; } diff --git a/src/util/vircommand.c b/src/util/vircommand.c index 49432ddfcb..0993d3e168 100644 --- a/src/util/vircommand.c +++ b/src/util/vircommand.c @@ -3145,9 +3145,8 @@ virCommandRunRegex(virCommandPtr cmd, /* NB vars[0] is the full pattern, so we offset j by 1 */ for (j = 1; j <= nvars[i]; j++) { - if (VIR_STRNDUP(groups[ngroup++], p + vars[j].rm_so, - vars[j].rm_eo - vars[j].rm_so) < 0) - goto cleanup; + groups[ngroup++] = g_strndup(p + vars[j].rm_so, + vars[j].rm_eo - vars[j].rm_so); } } diff --git a/src/util/virconf.c b/src/util/virconf.c index cc88000387..4a16037284 100644 --- a/src/util/virconf.c +++ b/src/util/virconf.c @@ -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) && (c_isblank(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); diff --git a/src/util/virkeyfile.c b/src/util/virkeyfile.c index c7e756d26a..c5af85e72b 100644 --- a/src/util/virkeyfile.c +++ b/src/util/virkeyfile.c @@ -116,8 +116,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; @@ -160,8 +159,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; diff --git a/src/util/virstoragefile.c b/src/util/virstoragefile.c index 77f885ef1d..a6ef64f73d 100644 --- a/src/util/virstoragefile.c +++ b/src/util/virstoragefile.c @@ -2946,8 +2946,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, diff --git a/src/util/virstring.c b/src/util/virstring.c index 283cf8c8d8..1b0b5dae97 100644 --- a/src/util/virstring.c +++ b/src/util/virstring.c @@ -1058,9 +1058,7 @@ virStringSearch(const char *str, if (VIR_EXPAND_N(*matches, nmatches, 1) < 0) goto cleanup; - if (VIR_STRNDUP(match, str + rem.rm_so, - rem.rm_eo - rem.rm_so) < 0) - goto cleanup; + match = g_strndup(str + rem.rm_so, rem.rm_eo - rem.rm_so); VIR_DEBUG("Got '%s'", match); diff --git a/src/util/virsysinfo.c b/src/util/virsysinfo.c index 635e4c4bfb..fe43dfdd75 100644 --- a/src/util/virsysinfo.c +++ b/src/util/virsysinfo.c @@ -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; } diff --git a/src/vmware/vmware_conf.c b/src/vmware/vmware_conf.c index ef7696a496..6b2c8888ab 100644 --- a/src/vmware/vmware_conf.c +++ b/src/vmware/vmware_conf.c @@ -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 -- 2.21.0 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list