提交 b315a287 编写于 作者: J Ján Tomko

Remove all the uses that use subtraction in their length argument

Signed-off-by: NJán Tomko <jtomko@redhat.com>
Reviewed-by: NDaniel Henrique Barboza <danielhb413@gmail.com>
Reviewed-by: NMichal Privoznik <mprivozn@redhat.com>
上级 7318bff5
......@@ -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) {
......
......@@ -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)
......
......@@ -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);
......
......@@ -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;
......
......@@ -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;
......
......@@ -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;
......
......@@ -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;
}
......
......@@ -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) {
......
......@@ -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);
......
......@@ -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;
......
......@@ -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;
......
......@@ -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,
......
......@@ -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;
}
......
......@@ -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
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册