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);
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++;
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;
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;
}
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;
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;
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;
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)