The function open-codes addition into an array. Use the helper instead. Signed-off-by: Peter Krempa <pkrempa@xxxxxxxxxx> --- src/util/virjson.c | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/src/util/virjson.c b/src/util/virjson.c index 1dceb746b9..7b874bf2ec 100644 --- a/src/util/virjson.c +++ b/src/util/virjson.c @@ -609,7 +609,8 @@ virJSONValueObjectAppend(virJSONValuePtr object, const char *key, virJSONValuePtr value) { - char *newkey; + virJSONObjectPair pair = { NULL, value }; + int ret = -1; if (object->type != VIR_JSON_TYPE_OBJECT) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", @@ -622,20 +623,14 @@ virJSONValueObjectAppend(virJSONValuePtr object, return -1; } - if (VIR_STRDUP(newkey, key) < 0) - return -1; - - if (VIR_REALLOC_N(object->data.object.pairs, - object->data.object.npairs + 1) < 0) { - VIR_FREE(newkey); + if (VIR_STRDUP(pair.key, key) < 0) return -1; - } - object->data.object.pairs[object->data.object.npairs].key = newkey; - object->data.object.pairs[object->data.object.npairs].value = value; - object->data.object.npairs++; + ret = VIR_APPEND_ELEMENT(object->data.object.pairs, + object->data.object.npairs, pair); - return 0; + VIR_FREE(pair.key); + return ret; } -- 2.20.1 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list