From b315a2873b02e06e8a4dd60fbf2bb7728bcd43a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A1n=20Tomko?= Date: Thu, 24 Oct 2019 19:41:34 +0200 Subject: [PATCH] Remove all the uses that use subtraction in their length argument MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Ján Tomko Reviewed-by: Daniel Henrique Barboza Reviewed-by: Michal Privoznik --- 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 | 1 - src/util/virconf.c | 24 +++++++----------------- src/util/viriscsi.c | 3 +-- src/util/virkeyfile.c | 6 ++---- src/util/virstoragefile.c | 3 +-- src/util/virsysinfo.c | 3 +-- src/vmware/vmware_conf.c | 6 +----- 14 files changed, 25 insertions(+), 57 deletions(-) diff --git a/src/bhyve/bhyve_parse_command.c b/src/bhyve/bhyve_parse_command.c index 5eec05c7d4..e74c4c2d0c 100644 --- a/src/bhyve/bhyve_parse_command.c +++ b/src/bhyve/bhyve_parse_command.c @@ -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) { diff --git a/src/libxl/xen_common.c b/src/libxl/xen_common.c index 912dd8834a..89ced6ae2b 100644 --- a/src/libxl/xen_common.c +++ b/src/libxl/xen_common.c @@ -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) diff --git a/src/libxl/xen_xm.c b/src/libxl/xen_xm.c index 1b462d0487..a196912194 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 b40a96b4ce..fbf49ee957 100644 --- a/src/lxc/lxc_driver.c +++ b/src/lxc/lxc_driver.c @@ -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; diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 4d77fd6f6a..47665f4ea6 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -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; diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c index 8a8347924a..b2f695a70c 100644 --- a/src/qemu/qemu_monitor_json.c +++ b/src/qemu/qemu_monitor_json.c @@ -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; diff --git a/src/util/vircgroupv1.c b/src/util/vircgroupv1.c index 40eafd7552..4f6b89cf2e 100644 --- a/src/util/vircgroupv1.c +++ b/src/util/vircgroupv1.c @@ -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; } diff --git a/src/util/vircommand.c b/src/util/vircommand.c index e677b67b93..dd37b0b8dc 100644 --- a/src/util/vircommand.c +++ b/src/util/vircommand.c @@ -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) { diff --git a/src/util/virconf.c b/src/util/virconf.c index 3b45436499..dce84cabb7 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) && (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); diff --git a/src/util/viriscsi.c b/src/util/viriscsi.c index da27894b0b..ac48527dde 100644 --- a/src/util/viriscsi.c +++ b/src/util/viriscsi.c @@ -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; diff --git a/src/util/virkeyfile.c b/src/util/virkeyfile.c index a98d60cdb1..ece31667ce 100644 --- a/src/util/virkeyfile.c +++ b/src/util/virkeyfile.c @@ -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; diff --git a/src/util/virstoragefile.c b/src/util/virstoragefile.c index 5e371694d1..8918f905a2 100644 --- a/src/util/virstoragefile.c +++ b/src/util/virstoragefile.c @@ -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, diff --git a/src/util/virsysinfo.c b/src/util/virsysinfo.c index ebb329bb6f..8132ab7a07 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 9f7d874c12..290e0e898d 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 -- GitLab