Remove the rest of VIR_STRNDUP

Replace all the uses passing a single parameter as the length.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
This commit is contained in:
Ján Tomko 2019-10-24 23:34:40 +02:00
parent b315a2873b
commit 93de3025b4
13 changed files with 21 additions and 47 deletions

View File

@ -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;

View File

@ -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);

View File

@ -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;

View File

@ -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) {

View File

@ -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] == ',' ||

View File

@ -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);

View File

@ -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) {

View File

@ -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));

View File

@ -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;
}

View File

@ -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);

View File

@ -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

View File

@ -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;
}

View File

@ -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);