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/util/virjson.c | 11 +++--------
src/util/virkeyfile.c | 3 +--
src/util/virsocketaddr.c | 5 +----
src/util/virstoragefile.c | 3 +--
src/util/virstring.c | 3 +--
13 files changed, 21 insertions(+), 47 deletions(-)
diff --git a/src/conf/nwfilter_conf.c b/src/conf/nwfilter_conf.c
index 5bcf52a84c..d071c398bc 100644
--- a/src/conf/nwfilter_conf.c
+++ b/src/conf/nwfilter_conf.c
@@ -400,8 +400,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 b1a2c50f27..4110169135 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 7df5cf2cc3..26b1045f8a 100644
--- a/src/interface/interface_backend_udev.c
+++ b/src/interface/interface_backend_udev.c
@@ -953,12 +953,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 89ced6ae2b..415549a42c 100644
--- a/src/libxl/xen_common.c
+++ b/src/libxl/xen_common.c
@@ -1153,8 +1153,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 cdff71f11b..8112214b5f 100644
--- a/src/libxl/xen_xl.c
+++ b/src/libxl/xen_xl.c
@@ -1104,13 +1104,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 a196912194..5d5d521c18 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 b2f695a70c..b4d103a37b 100644
--- a/src/qemu/qemu_monitor_json.c
+++ b/src/qemu/qemu_monitor_json.c
@@ -271,8 +271,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/util/virjson.c b/src/util/virjson.c
index c57dc11f78..988a09e956 100644
--- a/src/util/virjson.c
+++ b/src/util/virjson.c
@@ -462,10 +462,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;
}
@@ -1632,8 +1629,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);
@@ -1690,8 +1686,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 ece31667ce..84b1b0e55a 100644
--- a/src/util/virkeyfile.c
+++ b/src/util/virkeyfile.c
@@ -173,8 +173,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 8918f905a2..14e1efc9e8 100644
--- a/src/util/virstoragefile.c
+++ b/src/util/virstoragefile.c
@@ -420,8 +420,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 bd7c640042..7cf32fda3e 100644
--- a/src/util/virstring.c
+++ b/src/util/virstring.c
@@ -89,8 +89,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