Replace all the uses passing a single parameter as the length.
Signed-off-by: Ján Tomko <jtomko(a)redhat.com>
---
src/conf/nwfilter_conf.c | 4 ++--
src/conf/nwfilter_params.c | 6 ++----
src/interface/interface_backend_udev.c | 8 ++------
src/libxl/xen_common.c | 3 +--
src/libxl/xen_xl.c | 6 ++----
src/libxl/xen_xm.c | 6 ++----
src/qemu/qemu_monitor_json.c | 3 +--
src/rpc/virnetlibsshsession.c | 7 ++-----
src/storage/storage_backend_logical.c | 7 ++-----
src/util/viriscsi.c | 3 +--
src/util/virjson.c | 11 +++--------
src/util/virkeyfile.c | 3 +--
src/util/virsocketaddr.c | 5 +----
src/util/virstoragefile.c | 3 +--
src/util/virstring.c | 3 +--
15 files changed, 24 insertions(+), 54 deletions(-)
diff --git a/src/conf/nwfilter_conf.c b/src/conf/nwfilter_conf.c
index 6c7b85d4c8..7a4be5d4ec 100644
--- a/src/conf/nwfilter_conf.c
+++ b/src/conf/nwfilter_conf.c
@@ -401,8 +401,8 @@ virNWFilterRuleDefAddString(virNWFilterRuleDefPtr nwf,
{
char *tmp;
- if (VIR_STRNDUP(tmp, string, maxstrlen) < 0 ||
- VIR_APPEND_ELEMENT_COPY(nwf->strings, nwf->nstrings, tmp) < 0)
+ tmp = g_strndup(string, maxstrlen);
+ if (VIR_APPEND_ELEMENT_COPY(nwf->strings, nwf->nstrings, tmp) < 0)
VIR_FREE(tmp);
return tmp;
diff --git a/src/conf/nwfilter_params.c b/src/conf/nwfilter_params.c
index 7608d4960e..4549b7a71c 100644
--- a/src/conf/nwfilter_params.c
+++ b/src/conf/nwfilter_params.c
@@ -884,8 +884,7 @@ virNWFilterVarAccessParse(const char *varAccess)
if (input[idx] == '\0') {
/* in the form 'IP', which is equivalent to IP[@0] */
- if (VIR_STRNDUP(dest->varName, input, idx) < 0)
- goto err_exit;
+ dest->varName = g_strndup(input, idx);
dest->accessType = VIR_NWFILTER_VAR_ACCESS_ITERATOR;
dest->u.iterId = 0;
return dest;
@@ -898,8 +897,7 @@ virNWFilterVarAccessParse(const char *varAccess)
varNameLen = idx;
- if (VIR_STRNDUP(dest->varName, input, varNameLen) < 0)
- goto err_exit;
+ dest->varName = g_strndup(input, varNameLen);
input += idx + 1;
virSkipSpaces(&input);
diff --git a/src/interface/interface_backend_udev.c
b/src/interface/interface_backend_udev.c
index b7b06ed67a..531f9e90e5 100644
--- a/src/interface/interface_backend_udev.c
+++ b/src/interface/interface_backend_udev.c
@@ -954,12 +954,8 @@ udevGetIfaceDefVlan(struct udev *udev G_GNUC_UNUSED,
goto cleanup;
}
- if (VIR_STRNDUP(ifacedef->data.vlan.tag, vid_pos, vid_len) < 0)
- goto cleanup;
- if (VIR_STRNDUP(ifacedef->data.vlan.dev_name, dev_pos, dev_len) < 0) {
- VIR_FREE(ifacedef->data.vlan.tag);
- goto cleanup;
- }
+ ifacedef->data.vlan.tag = g_strndup(vid_pos, vid_len);
+ ifacedef->data.vlan.dev_name = g_strndup(dev_pos, dev_len);
ret = 0;
diff --git a/src/libxl/xen_common.c b/src/libxl/xen_common.c
index e6d022f253..66e7850245 100644
--- a/src/libxl/xen_common.c
+++ b/src/libxl/xen_common.c
@@ -1164,8 +1164,7 @@ xenParseVif(char *entry, const char *vif_typename)
} else if (STRPREFIX(key, "script=")) {
int len = nextkey ? (nextkey - data) : strlen(data);
VIR_FREE(script);
- if (VIR_STRNDUP(script, data, len) < 0)
- return NULL;
+ script = g_strndup(data, len);
} else if (STRPREFIX(key, "model=")) {
int len = nextkey ? (nextkey - data) : strlen(data);
if (virStrncpy(model, data, len, sizeof(model)) < 0) {
diff --git a/src/libxl/xen_xl.c b/src/libxl/xen_xl.c
index 396adf6dac..4e2bdb2ed0 100644
--- a/src/libxl/xen_xl.c
+++ b/src/libxl/xen_xl.c
@@ -1109,13 +1109,11 @@ xenParseXLChannel(virConfPtr conf, virDomainDefPtr def)
} else if (STRPREFIX(key, "name=")) {
int len = nextkey ? (nextkey - data) : strlen(data);
VIR_FREE(name);
- if (VIR_STRNDUP(name, data, len) < 0)
- goto cleanup;
+ name = g_strndup(data, len);
} else if (STRPREFIX(key, "path=")) {
int len = nextkey ? (nextkey - data) : strlen(data);
VIR_FREE(path);
- if (VIR_STRNDUP(path, data, len) < 0)
- goto cleanup;
+ path = g_strndup(data, len);
}
while (nextkey && (nextkey[0] == ',' ||
diff --git a/src/libxl/xen_xm.c b/src/libxl/xen_xm.c
index a0e649f4ef..7dea2998f2 100644
--- a/src/libxl/xen_xm.c
+++ b/src/libxl/xen_xm.c
@@ -167,8 +167,7 @@ xenParseXMDisk(char *entry, int hvm)
/* The main type phy:, file:, tap: ... */
if ((tmp = strchr(src, ':')) != NULL) {
len = tmp - src;
- if (VIR_STRNDUP(tmp, src, len) < 0)
- goto error;
+ tmp = g_strndup(src, len);
if (virDomainDiskSetDriver(disk, tmp) < 0) {
VIR_FREE(tmp);
@@ -192,8 +191,7 @@ xenParseXMDisk(char *entry, int hvm)
goto error;
len = tmp - src;
- if (VIR_STRNDUP(driverType, src, len) < 0)
- goto error;
+ driverType = g_strndup(src, len);
if (STREQ(driverType, "aio"))
virDomainDiskSetFormat(disk, VIR_STORAGE_FILE_RAW);
diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c
index 963ca58f43..aa2598a85d 100644
--- a/src/qemu/qemu_monitor_json.c
+++ b/src/qemu/qemu_monitor_json.c
@@ -272,8 +272,7 @@ int qemuMonitorJSONIOProcess(qemuMonitorPtr mon,
if (nl) {
int got = nl - (data + used);
char *line;
- if (VIR_STRNDUP(line, data + used, got) < 0)
- return -1;
+ line = g_strndup(data + used, got);
used += got + strlen(LINE_ENDING);
line[got] = '\0'; /* kill \n */
if (qemuMonitorJSONIOProcessLine(mon, line, msg) < 0) {
diff --git a/src/rpc/virnetlibsshsession.c b/src/rpc/virnetlibsshsession.c
index 2312939cdc..e874929740 100644
--- a/src/rpc/virnetlibsshsession.c
+++ b/src/rpc/virnetlibsshsession.c
@@ -431,9 +431,7 @@ virNetLibsshAuthenticatePrivkeyCb(const char *prompt,
goto error;
}
- if (VIR_STRNDUP(actual_prompt, prompt,
- virLengthForPromptString(prompt)) < 0)
- goto error;
+ actual_prompt = g_strndup(prompt, virLengthForPromptString(prompt));
memset(&retr_passphrase, 0, sizeof(virConnectCredential));
retr_passphrase.type = cred_type;
@@ -716,8 +714,7 @@ virNetLibsshAuthenticateKeyboardInteractive(virNetLibsshSessionPtr
sess,
prompt = virBufferContentAndReset(&prompt_buff);
} else {
- if (VIR_STRNDUP(prompt, promptStr, promptStrLen) < 0)
- goto prompt_error;
+ prompt = g_strndup(promptStr, promptStrLen);
}
memset(&retr_passphrase, 0, sizeof(virConnectCredential));
diff --git a/src/storage/storage_backend_logical.c
b/src/storage/storage_backend_logical.c
index 48023abd1a..ba3c5ea70e 100644
--- a/src/storage/storage_backend_logical.c
+++ b/src/storage/storage_backend_logical.c
@@ -214,13 +214,10 @@ virStorageBackendLogicalParseVolExtents(virStorageVolDefPtr vol,
len = vars[j].rm_eo - vars[j].rm_so;
p[vars[j].rm_eo] = '\0';
- if (VIR_STRNDUP(extent.path,
- p + vars[j].rm_so, len) < 0)
- goto cleanup;
+ extent.path = g_strndup(p + vars[j].rm_so, len);
len = vars[j + 1].rm_eo - vars[j + 1].rm_so;
- if (VIR_STRNDUP(offset_str, p + vars[j + 1].rm_so, len) < 0)
- goto cleanup;
+ offset_str = g_strndup(p + vars[j + 1].rm_so, len);
if (virStrToLong_ull(offset_str, NULL, 10, &offset) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
diff --git a/src/util/viriscsi.c b/src/util/viriscsi.c
index 9f4c8f4e03..84fa542b7c 100644
--- a/src/util/viriscsi.c
+++ b/src/util/viriscsi.c
@@ -162,8 +162,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/virjson.c b/src/util/virjson.c
index 76efb17e24..184d082dc5 100644
--- a/src/util/virjson.c
+++ b/src/util/virjson.c
@@ -463,10 +463,7 @@ virJSONValueNewStringLen(const char *data,
return NULL;
val->type = VIR_JSON_TYPE_STRING;
- if (VIR_STRNDUP(val->data.string, data, length) < 0) {
- VIR_FREE(val);
- return NULL;
- }
+ val->data.string = g_strndup(data, length);
return val;
}
@@ -1633,8 +1630,7 @@ virJSONParserHandleNumber(void *ctx,
char *str;
virJSONValuePtr value;
- if (VIR_STRNDUP(str, s, l) < 0)
- return -1;
+ str = g_strndup(s, l);
value = virJSONValueNewNumber(str);
VIR_FREE(str);
@@ -1691,8 +1687,7 @@ virJSONParserHandleMapKey(void *ctx,
state = &parser->state[parser->nstate-1];
if (state->key)
return 0;
- if (VIR_STRNDUP(state->key, (const char *)stringVal, stringLen) < 0)
- return 0;
+ state->key = g_strndup((const char *)stringVal, stringLen);
return 1;
}
diff --git a/src/util/virkeyfile.c b/src/util/virkeyfile.c
index c5af85e72b..998ce9caf7 100644
--- a/src/util/virkeyfile.c
+++ b/src/util/virkeyfile.c
@@ -172,8 +172,7 @@ static int virKeyFileParseValue(virKeyFileParserCtxtPtr ctxt)
len = ctxt->cur - valuestart;
if (IS_EOF && !IS_EOL(CUR))
len++;
- if (VIR_STRNDUP(value, valuestart, len) < 0)
- goto cleanup;
+ value = g_strndup(valuestart, len);
if (virHashAddEntry(ctxt->group, key, value) < 0) {
VIR_FREE(value);
diff --git a/src/util/virsocketaddr.c b/src/util/virsocketaddr.c
index d7b0f12d96..ef51d3fa7d 100644
--- a/src/util/virsocketaddr.c
+++ b/src/util/virsocketaddr.c
@@ -593,10 +593,7 @@ virSocketAddrGetPath(virSocketAddrPtr addr G_GNUC_UNUSED)
return NULL;
}
- if (VIR_STRNDUP(path,
- addr->data.un.sun_path,
- sizeof(addr->data.un.sun_path)) < 0)
- return NULL;
+ path = g_strndup(addr->data.un.sun_path, sizeof(addr->data.un.sun_path));
return path;
#else
diff --git a/src/util/virstoragefile.c b/src/util/virstoragefile.c
index a6ef64f73d..8c99c349a6 100644
--- a/src/util/virstoragefile.c
+++ b/src/util/virstoragefile.c
@@ -421,8 +421,7 @@ cowGetBackingStore(char **res,
return BACKING_STORE_OK;
}
- if (VIR_STRNDUP(*res, (const char*)buf + 4 + 4, COW_FILENAME_MAXLEN) < 0)
- return BACKING_STORE_ERROR;
+ *res = g_strndup((const char *)buf + 4 + 4, COW_FILENAME_MAXLEN);
return BACKING_STORE_OK;
}
diff --git a/src/util/virstring.c b/src/util/virstring.c
index 1b0b5dae97..cd4418d144 100644
--- a/src/util/virstring.c
+++ b/src/util/virstring.c
@@ -91,8 +91,7 @@ virStringSplitCount(const char *string,
if (VIR_RESIZE_N(tokens, maxtokens, ntokens, 1) < 0)
goto error;
- if (VIR_STRNDUP(tokens[ntokens], remainder, len) < 0)
- goto error;
+ tokens[ntokens] = g_strndup(remainder, len);
ntokens++;
remainder = tmp + delimlen;
tmp = strstr(remainder, delim);
--
2.21.0