util: json: Open-code only call of virJSONValueNewStringLen

Replace the function by a call to virJSONValueNewString, when we copy
the string using g_strndup. Remove the unused helper.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Tim Wiederhake <twiederh@redhat.com>
This commit is contained in:
Peter Krempa 2021-12-20 14:56:13 +01:00
parent a8b4a41731
commit 36d6c3bb67
3 changed files with 1 additions and 22 deletions

View File

@ -2536,7 +2536,6 @@ virJSONValueNewNumberUint;
virJSONValueNewNumberUlong;
virJSONValueNewObject;
virJSONValueNewString;
virJSONValueNewStringLen;
virJSONValueObjectAdd;
virJSONValueObjectAddVArgs;
virJSONValueObjectAppend;

View File

@ -428,24 +428,6 @@ virJSONValueNewString(char *data)
}
virJSONValue *
virJSONValueNewStringLen(const char *data,
size_t length)
{
virJSONValue *val;
if (!data)
return virJSONValueNewNull();
val = g_new0(virJSONValue, 1);
val->type = VIR_JSON_TYPE_STRING;
val->data.string = g_strndup(data, length);
return val;
}
/**
* virJSONValueNewNumber:
* @data: string representing the number
@ -1558,8 +1540,7 @@ virJSONParserHandleString(void *ctx,
size_t stringLen)
{
virJSONParser *parser = ctx;
g_autoptr(virJSONValue) value = virJSONValueNewStringLen((const char *)stringVal,
stringLen);
g_autoptr(virJSONValue) value = virJSONValueNewString(g_strndup((const char *)stringVal, stringLen));
VIR_DEBUG("parser=%p str=%p", parser, (const char *)stringVal);

View File

@ -51,7 +51,6 @@ int virJSONValueObjectAddVArgs(virJSONValue **objptr, va_list args)
virJSONValue *virJSONValueNewString(char *data);
virJSONValue *virJSONValueNewStringLen(const char *data, size_t length);
virJSONValue *virJSONValueNewNumberInt(int data);
virJSONValue *virJSONValueNewNumberUint(unsigned int data);
virJSONValue *virJSONValueNewNumberLong(long long data);