mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-22 04:25:18 +00:00
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:
parent
b315a2873b
commit
93de3025b4
@ -400,8 +400,8 @@ virNWFilterRuleDefAddString(virNWFilterRuleDefPtr nwf,
|
|||||||
{
|
{
|
||||||
char *tmp;
|
char *tmp;
|
||||||
|
|
||||||
if (VIR_STRNDUP(tmp, string, maxstrlen) < 0 ||
|
tmp = g_strndup(string, maxstrlen);
|
||||||
VIR_APPEND_ELEMENT_COPY(nwf->strings, nwf->nstrings, tmp) < 0)
|
if (VIR_APPEND_ELEMENT_COPY(nwf->strings, nwf->nstrings, tmp) < 0)
|
||||||
VIR_FREE(tmp);
|
VIR_FREE(tmp);
|
||||||
|
|
||||||
return tmp;
|
return tmp;
|
||||||
|
@ -884,8 +884,7 @@ virNWFilterVarAccessParse(const char *varAccess)
|
|||||||
|
|
||||||
if (input[idx] == '\0') {
|
if (input[idx] == '\0') {
|
||||||
/* in the form 'IP', which is equivalent to IP[@0] */
|
/* in the form 'IP', which is equivalent to IP[@0] */
|
||||||
if (VIR_STRNDUP(dest->varName, input, idx) < 0)
|
dest->varName = g_strndup(input, idx);
|
||||||
goto err_exit;
|
|
||||||
dest->accessType = VIR_NWFILTER_VAR_ACCESS_ITERATOR;
|
dest->accessType = VIR_NWFILTER_VAR_ACCESS_ITERATOR;
|
||||||
dest->u.iterId = 0;
|
dest->u.iterId = 0;
|
||||||
return dest;
|
return dest;
|
||||||
@ -898,8 +897,7 @@ virNWFilterVarAccessParse(const char *varAccess)
|
|||||||
|
|
||||||
varNameLen = idx;
|
varNameLen = idx;
|
||||||
|
|
||||||
if (VIR_STRNDUP(dest->varName, input, varNameLen) < 0)
|
dest->varName = g_strndup(input, varNameLen);
|
||||||
goto err_exit;
|
|
||||||
|
|
||||||
input += idx + 1;
|
input += idx + 1;
|
||||||
virSkipSpaces(&input);
|
virSkipSpaces(&input);
|
||||||
|
@ -953,12 +953,8 @@ udevGetIfaceDefVlan(struct udev *udev G_GNUC_UNUSED,
|
|||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (VIR_STRNDUP(ifacedef->data.vlan.tag, vid_pos, vid_len) < 0)
|
ifacedef->data.vlan.tag = g_strndup(vid_pos, vid_len);
|
||||||
goto cleanup;
|
ifacedef->data.vlan.dev_name = g_strndup(dev_pos, dev_len);
|
||||||
if (VIR_STRNDUP(ifacedef->data.vlan.dev_name, dev_pos, dev_len) < 0) {
|
|
||||||
VIR_FREE(ifacedef->data.vlan.tag);
|
|
||||||
goto cleanup;
|
|
||||||
}
|
|
||||||
|
|
||||||
ret = 0;
|
ret = 0;
|
||||||
|
|
||||||
|
@ -1153,8 +1153,7 @@ xenParseVif(char *entry, const char *vif_typename)
|
|||||||
} else if (STRPREFIX(key, "script=")) {
|
} else if (STRPREFIX(key, "script=")) {
|
||||||
int len = nextkey ? (nextkey - data) : strlen(data);
|
int len = nextkey ? (nextkey - data) : strlen(data);
|
||||||
VIR_FREE(script);
|
VIR_FREE(script);
|
||||||
if (VIR_STRNDUP(script, data, len) < 0)
|
script = g_strndup(data, len);
|
||||||
return NULL;
|
|
||||||
} else if (STRPREFIX(key, "model=")) {
|
} else if (STRPREFIX(key, "model=")) {
|
||||||
int len = nextkey ? (nextkey - data) : strlen(data);
|
int len = nextkey ? (nextkey - data) : strlen(data);
|
||||||
if (virStrncpy(model, data, len, sizeof(model)) < 0) {
|
if (virStrncpy(model, data, len, sizeof(model)) < 0) {
|
||||||
|
@ -1104,13 +1104,11 @@ xenParseXLChannel(virConfPtr conf, virDomainDefPtr def)
|
|||||||
} else if (STRPREFIX(key, "name=")) {
|
} else if (STRPREFIX(key, "name=")) {
|
||||||
int len = nextkey ? (nextkey - data) : strlen(data);
|
int len = nextkey ? (nextkey - data) : strlen(data);
|
||||||
VIR_FREE(name);
|
VIR_FREE(name);
|
||||||
if (VIR_STRNDUP(name, data, len) < 0)
|
name = g_strndup(data, len);
|
||||||
goto cleanup;
|
|
||||||
} else if (STRPREFIX(key, "path=")) {
|
} else if (STRPREFIX(key, "path=")) {
|
||||||
int len = nextkey ? (nextkey - data) : strlen(data);
|
int len = nextkey ? (nextkey - data) : strlen(data);
|
||||||
VIR_FREE(path);
|
VIR_FREE(path);
|
||||||
if (VIR_STRNDUP(path, data, len) < 0)
|
path = g_strndup(data, len);
|
||||||
goto cleanup;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
while (nextkey && (nextkey[0] == ',' ||
|
while (nextkey && (nextkey[0] == ',' ||
|
||||||
|
@ -167,8 +167,7 @@ xenParseXMDisk(char *entry, int hvm)
|
|||||||
/* The main type phy:, file:, tap: ... */
|
/* The main type phy:, file:, tap: ... */
|
||||||
if ((tmp = strchr(src, ':')) != NULL) {
|
if ((tmp = strchr(src, ':')) != NULL) {
|
||||||
len = tmp - src;
|
len = tmp - src;
|
||||||
if (VIR_STRNDUP(tmp, src, len) < 0)
|
tmp = g_strndup(src, len);
|
||||||
goto error;
|
|
||||||
|
|
||||||
if (virDomainDiskSetDriver(disk, tmp) < 0) {
|
if (virDomainDiskSetDriver(disk, tmp) < 0) {
|
||||||
VIR_FREE(tmp);
|
VIR_FREE(tmp);
|
||||||
@ -192,8 +191,7 @@ xenParseXMDisk(char *entry, int hvm)
|
|||||||
goto error;
|
goto error;
|
||||||
len = tmp - src;
|
len = tmp - src;
|
||||||
|
|
||||||
if (VIR_STRNDUP(driverType, src, len) < 0)
|
driverType = g_strndup(src, len);
|
||||||
goto error;
|
|
||||||
|
|
||||||
if (STREQ(driverType, "aio"))
|
if (STREQ(driverType, "aio"))
|
||||||
virDomainDiskSetFormat(disk, VIR_STORAGE_FILE_RAW);
|
virDomainDiskSetFormat(disk, VIR_STORAGE_FILE_RAW);
|
||||||
|
@ -271,8 +271,7 @@ int qemuMonitorJSONIOProcess(qemuMonitorPtr mon,
|
|||||||
if (nl) {
|
if (nl) {
|
||||||
int got = nl - (data + used);
|
int got = nl - (data + used);
|
||||||
char *line;
|
char *line;
|
||||||
if (VIR_STRNDUP(line, data + used, got) < 0)
|
line = g_strndup(data + used, got);
|
||||||
return -1;
|
|
||||||
used += got + strlen(LINE_ENDING);
|
used += got + strlen(LINE_ENDING);
|
||||||
line[got] = '\0'; /* kill \n */
|
line[got] = '\0'; /* kill \n */
|
||||||
if (qemuMonitorJSONIOProcessLine(mon, line, msg) < 0) {
|
if (qemuMonitorJSONIOProcessLine(mon, line, msg) < 0) {
|
||||||
|
@ -431,9 +431,7 @@ virNetLibsshAuthenticatePrivkeyCb(const char *prompt,
|
|||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (VIR_STRNDUP(actual_prompt, prompt,
|
actual_prompt = g_strndup(prompt, virLengthForPromptString(prompt));
|
||||||
virLengthForPromptString(prompt)) < 0)
|
|
||||||
goto error;
|
|
||||||
|
|
||||||
memset(&retr_passphrase, 0, sizeof(virConnectCredential));
|
memset(&retr_passphrase, 0, sizeof(virConnectCredential));
|
||||||
retr_passphrase.type = cred_type;
|
retr_passphrase.type = cred_type;
|
||||||
@ -716,8 +714,7 @@ virNetLibsshAuthenticateKeyboardInteractive(virNetLibsshSessionPtr sess,
|
|||||||
|
|
||||||
prompt = virBufferContentAndReset(&prompt_buff);
|
prompt = virBufferContentAndReset(&prompt_buff);
|
||||||
} else {
|
} else {
|
||||||
if (VIR_STRNDUP(prompt, promptStr, promptStrLen) < 0)
|
prompt = g_strndup(promptStr, promptStrLen);
|
||||||
goto prompt_error;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
memset(&retr_passphrase, 0, sizeof(virConnectCredential));
|
memset(&retr_passphrase, 0, sizeof(virConnectCredential));
|
||||||
|
@ -462,10 +462,7 @@ virJSONValueNewStringLen(const char *data,
|
|||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
val->type = VIR_JSON_TYPE_STRING;
|
val->type = VIR_JSON_TYPE_STRING;
|
||||||
if (VIR_STRNDUP(val->data.string, data, length) < 0) {
|
val->data.string = g_strndup(data, length);
|
||||||
VIR_FREE(val);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
return val;
|
return val;
|
||||||
}
|
}
|
||||||
@ -1632,8 +1629,7 @@ virJSONParserHandleNumber(void *ctx,
|
|||||||
char *str;
|
char *str;
|
||||||
virJSONValuePtr value;
|
virJSONValuePtr value;
|
||||||
|
|
||||||
if (VIR_STRNDUP(str, s, l) < 0)
|
str = g_strndup(s, l);
|
||||||
return -1;
|
|
||||||
value = virJSONValueNewNumber(str);
|
value = virJSONValueNewNumber(str);
|
||||||
VIR_FREE(str);
|
VIR_FREE(str);
|
||||||
|
|
||||||
@ -1690,8 +1686,7 @@ virJSONParserHandleMapKey(void *ctx,
|
|||||||
state = &parser->state[parser->nstate-1];
|
state = &parser->state[parser->nstate-1];
|
||||||
if (state->key)
|
if (state->key)
|
||||||
return 0;
|
return 0;
|
||||||
if (VIR_STRNDUP(state->key, (const char *)stringVal, stringLen) < 0)
|
state->key = g_strndup((const char *)stringVal, stringLen);
|
||||||
return 0;
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -173,8 +173,7 @@ static int virKeyFileParseValue(virKeyFileParserCtxtPtr ctxt)
|
|||||||
len = ctxt->cur - valuestart;
|
len = ctxt->cur - valuestart;
|
||||||
if (IS_EOF && !IS_EOL(CUR))
|
if (IS_EOF && !IS_EOL(CUR))
|
||||||
len++;
|
len++;
|
||||||
if (VIR_STRNDUP(value, valuestart, len) < 0)
|
value = g_strndup(valuestart, len);
|
||||||
goto cleanup;
|
|
||||||
|
|
||||||
if (virHashAddEntry(ctxt->group, key, value) < 0) {
|
if (virHashAddEntry(ctxt->group, key, value) < 0) {
|
||||||
VIR_FREE(value);
|
VIR_FREE(value);
|
||||||
|
@ -593,10 +593,7 @@ virSocketAddrGetPath(virSocketAddrPtr addr G_GNUC_UNUSED)
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (VIR_STRNDUP(path,
|
path = g_strndup(addr->data.un.sun_path, sizeof(addr->data.un.sun_path));
|
||||||
addr->data.un.sun_path,
|
|
||||||
sizeof(addr->data.un.sun_path)) < 0)
|
|
||||||
return NULL;
|
|
||||||
|
|
||||||
return path;
|
return path;
|
||||||
#else
|
#else
|
||||||
|
@ -420,8 +420,7 @@ cowGetBackingStore(char **res,
|
|||||||
return BACKING_STORE_OK;
|
return BACKING_STORE_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (VIR_STRNDUP(*res, (const char*)buf + 4 + 4, COW_FILENAME_MAXLEN) < 0)
|
*res = g_strndup((const char *)buf + 4 + 4, COW_FILENAME_MAXLEN);
|
||||||
return BACKING_STORE_ERROR;
|
|
||||||
return BACKING_STORE_OK;
|
return BACKING_STORE_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -89,8 +89,7 @@ virStringSplitCount(const char *string,
|
|||||||
if (VIR_RESIZE_N(tokens, maxtokens, ntokens, 1) < 0)
|
if (VIR_RESIZE_N(tokens, maxtokens, ntokens, 1) < 0)
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
if (VIR_STRNDUP(tokens[ntokens], remainder, len) < 0)
|
tokens[ntokens] = g_strndup(remainder, len);
|
||||||
goto error;
|
|
||||||
ntokens++;
|
ntokens++;
|
||||||
remainder = tmp + delimlen;
|
remainder = tmp + delimlen;
|
||||||
tmp = strstr(remainder, delim);
|
tmp = strstr(remainder, delim);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user