mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-23 06:05:27 +00:00
Remove VIR_STRNDUP usage that passes -1
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>
This commit is contained in:
parent
9985679c0a
commit
05e33d4f54
@ -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;
|
||||
|
@ -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)
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user