From nobody Sun Feb 8 18:44:49 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 207.211.31.81 as permitted sender) client-ip=207.211.31.81; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.81 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1583331384; cv=none; d=zohomail.com; s=zohoarc; b=TPmHAub84BXPcbmIwJQ0nGHrNPvCCJ0gD6fFlU3NEtjNgma2depEJVpv4NmZ/kaN+uaBhFbpHetrMDcCjX+ERsB30NLwzrEK7GwbE5lApzYPkzmKSwUjn6LWv2aHULd91wknizpNngACPenDqvol72RjXBwF9/93Me8fvg6E9Q4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1583331384; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=Y/e4jytnM4Avs2/OWe3v2apP5ob3qcjrHrYPrh3VRnk=; b=TLwpZd0SRUkaUIzW7HaZdScRkvczET58IhXuLxpnDpG8qvTwyXw6RA4kOORIkE6YBqnaTBkoXE5BMcizulGqLp8Gs4ZqLUlGKWROBgwuAV3lyxGrKEpccuFqwPjx0cLWZIHFlriSK/eetAeiDe2HMngcQG7tcGaqqJTkGVacEuQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.81 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-1.mimecast.com (us-smtp-1.mimecast.com [207.211.31.81]) by mx.zohomail.com with SMTPS id 1583331384409389.74581625644885; Wed, 4 Mar 2020 06:16:24 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-279-2qaeM7xDPL-ww0F6buKLVg-1; Wed, 04 Mar 2020 09:16:21 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id B85E6800D4E; Wed, 4 Mar 2020 14:16:14 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 8D1465C1D4; Wed, 4 Mar 2020 14:16:14 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 2ABC086A06; Wed, 4 Mar 2020 14:16:14 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 024EGCbP012730 for ; Wed, 4 Mar 2020 09:16:12 -0500 Received: by smtp.corp.redhat.com (Postfix) id C5B8D5DA7D; Wed, 4 Mar 2020 14:16:12 +0000 (UTC) Received: from angien.redhat.com (unknown [10.43.2.48]) by smtp.corp.redhat.com (Postfix) with ESMTP id 245345DA7B for ; Wed, 4 Mar 2020 14:16:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1583331383; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=Y/e4jytnM4Avs2/OWe3v2apP5ob3qcjrHrYPrh3VRnk=; b=gs8bMfxTf1xRRdgwLXY0wPCkIQiNCrIlv54hiMPUBEoC+QZv/kv5s+tDxtSvKbI5i/y7jJ v1tHGDZCOljiYfRGvVq3p7LC5+7ug9+Mrf030v3OWEmhp65nazhBE4GHhCTeXNFIXID5xL djg49QWPLLwlcQKteE4i5StKWPqVAtg= X-MC-Unique: 2qaeM7xDPL-ww0F6buKLVg-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 1/3] util: json: Convert virJSONValueNewObject() to g_new0 Date: Wed, 4 Mar 2020 15:16:05 +0100 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" Make it obvious that the function always returns a valid pointer and fix all callers. Signed-off-by: Peter Krempa --- src/admin/admin_server_dispatch.c | 3 --- src/locking/lock_daemon.c | 8 +------- src/logging/log_daemon.c | 8 +------- src/logging/log_handler.c | 5 ----- src/qemu/qemu_agent.c | 8 ++------ src/qemu/qemu_command.c | 3 +-- src/qemu/qemu_firmware.c | 20 ++++---------------- src/qemu/qemu_migration_params.c | 8 ++------ src/qemu/qemu_monitor_json.c | 30 +++++++----------------------- src/qemu/qemu_vhost_user.c | 3 +-- src/rpc/virnetdaemon.c | 10 ++-------- src/rpc/virnetserver.c | 5 +---- src/rpc/virnetserverclient.c | 3 --- src/rpc/virnetserverservice.c | 3 --- src/rpc/virnetsocket.c | 3 +-- src/util/virjson.c | 21 ++++----------------- src/util/virlease.c | 6 +----- src/util/virlockspace.c | 6 ------ src/util/virmacmap.c | 5 +---- src/util/virnetdev.c | 3 +-- tests/qemumonitortestutils.c | 8 ++------ 21 files changed, 32 insertions(+), 137 deletions(-) diff --git a/src/admin/admin_server_dispatch.c b/src/admin/admin_server_dis= patch.c index 7b3bd697f3..b3da577995 100644 --- a/src/admin/admin_server_dispatch.c +++ b/src/admin/admin_server_dispatch.c @@ -119,9 +119,6 @@ virJSONValuePtr remoteAdmClientPreExecRestart(virNetSer= verClientPtr client G_GNU { virJSONValuePtr object =3D virJSONValueNewObject(); - if (!object) - return NULL; - /* No content to add at this time - just need empty object */ return object; diff --git a/src/locking/lock_daemon.c b/src/locking/lock_daemon.c index 5e5a0c1089..245155206a 100644 --- a/src/locking/lock_daemon.c +++ b/src/locking/lock_daemon.c @@ -774,9 +774,6 @@ virLockDaemonClientPreExecRestart(virNetServerClientPtr= client G_GNUC_UNUSED, virJSONValuePtr object =3D virJSONValueNewObject(); char uuidstr[VIR_UUID_STRING_BUFLEN]; - if (!object) - return NULL; - if (virJSONValueObjectAppendBoolean(object, "restricted", priv->restri= cted) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Cannot set restricted data in JSON document")); @@ -923,16 +920,13 @@ virLockDaemonPreExecRestart(const char *state_file, virJSONValuePtr child; char *state =3D NULL; int ret =3D -1; - virJSONValuePtr object; + virJSONValuePtr object =3D virJSONValueNewObject(); char *magic; virHashKeyValuePairPtr pairs =3D NULL, tmp; virJSONValuePtr lockspaces; VIR_DEBUG("Running pre-restart exec"); - if (!(object =3D virJSONValueNewObject())) - goto cleanup; - if (!(child =3D virNetDaemonPreExecRestart(dmn))) goto cleanup; diff --git a/src/logging/log_daemon.c b/src/logging/log_daemon.c index 772bbb805b..47377deb4f 100644 --- a/src/logging/log_daemon.c +++ b/src/logging/log_daemon.c @@ -597,9 +597,6 @@ virLogDaemonClientPreExecRestart(virNetServerClientPtr = client G_GNUC_UNUSED, { virJSONValuePtr object =3D virJSONValueNewObject(); - if (!object) - return NULL; - return object; } @@ -718,15 +715,12 @@ virLogDaemonPreExecRestart(const char *state_file, virJSONValuePtr child; char *state =3D NULL; int ret =3D -1; - virJSONValuePtr object; + virJSONValuePtr object =3D virJSONValueNewObject(); char *magic; virHashKeyValuePairPtr pairs =3D NULL; VIR_DEBUG("Running pre-restart exec"); - if (!(object =3D virJSONValueNewObject())) - goto cleanup; - if (!(child =3D virNetDaemonPreExecRestart(dmn))) goto cleanup; diff --git a/src/logging/log_handler.c b/src/logging/log_handler.c index 576d0d6921..87748d96d1 100644 --- a/src/logging/log_handler.c +++ b/src/logging/log_handler.c @@ -615,9 +615,6 @@ virLogHandlerPreExecRestart(virLogHandlerPtr handler) size_t i; char domuuid[VIR_UUID_STRING_BUFLEN]; - if (!ret) - return NULL; - files =3D virJSONValueNewArray(); if (virJSONValueObjectAppend(ret, "files", files) < 0) { @@ -627,8 +624,6 @@ virLogHandlerPreExecRestart(virLogHandlerPtr handler) for (i =3D 0; i < handler->nfiles; i++) { virJSONValuePtr file =3D virJSONValueNewObject(); - if (!file) - goto error; if (virJSONValueArrayAppend(files, file) < 0) { virJSONValueFree(file); diff --git a/src/qemu/qemu_agent.c b/src/qemu/qemu_agent.c index 23a775034f..cd25ef6cd3 100644 --- a/src/qemu/qemu_agent.c +++ b/src/qemu/qemu_agent.c @@ -1166,15 +1166,12 @@ static virJSONValuePtr G_GNUC_NULL_TERMINATED qemuAgentMakeCommand(const char *cmdname, ...) { - virJSONValuePtr obj; + virJSONValuePtr obj =3D virJSONValueNewObject(); virJSONValuePtr jargs =3D NULL; va_list args; va_start(args, cmdname); - if (!(obj =3D virJSONValueNewObject())) - goto error; - if (virJSONValueObjectAppendString(obj, "execute", cmdname) < 0) goto error; @@ -1544,8 +1541,7 @@ qemuAgentSetVCPUsCommand(qemuAgentPtr mon, (*nmodified)++; /* create single cpu object */ - if (!(cpu =3D virJSONValueNewObject())) - goto cleanup; + cpu =3D virJSONValueNewObject(); if (virJSONValueObjectAppendNumberInt(cpu, "logical-id", in->id) <= 0) goto cleanup; diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index 9d215e5e06..9e0334a3e7 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -3442,8 +3442,7 @@ qemuBuildMemoryBackendProps(virJSONValuePtr *backendP= rops, return -1; } - if (!(props =3D virJSONValueNewObject())) - return -1; + props =3D virJSONValueNewObject(); if (def->mem.source =3D=3D VIR_DOMAIN_MEMORY_SOURCE_MEMFD) { backendType =3D "memory-backend-memfd"; diff --git a/src/qemu/qemu_firmware.c b/src/qemu/qemu_firmware.c index 68e2c6b40f..bd251c05fc 100644 --- a/src/qemu/qemu_firmware.c +++ b/src/qemu/qemu_firmware.c @@ -672,12 +672,9 @@ qemuFirmwareInterfaceFormat(virJSONValuePtr doc, static virJSONValuePtr qemuFirmwareFlashFileFormat(qemuFirmwareFlashFile flash) { - g_autoptr(virJSONValue) json =3D NULL; + g_autoptr(virJSONValue) json =3D virJSONValueNewObject(); virJSONValuePtr ret; - if (!(json =3D virJSONValueNewObject())) - return NULL; - if (virJSONValueObjectAppendString(json, "filename", flash.filename) < 0) @@ -754,10 +751,7 @@ static int qemuFirmwareMappingFormat(virJSONValuePtr doc, qemuFirmwarePtr fw) { - g_autoptr(virJSONValue) mapping =3D NULL; - - if (!(mapping =3D virJSONValueNewObject())) - return -1; + g_autoptr(virJSONValue) mapping =3D virJSONValueNewObject(); if (virJSONValueObjectAppendString(mapping, "device", @@ -802,13 +796,10 @@ qemuFirmwareTargetFormat(virJSONValuePtr doc, for (i =3D 0; i < fw->ntargets; i++) { qemuFirmwareTargetPtr t =3D fw->targets[i]; - g_autoptr(virJSONValue) target =3D NULL; + g_autoptr(virJSONValue) target =3D virJSONValueNewObject(); g_autoptr(virJSONValue) machines =3D NULL; size_t j; - if (!(target =3D virJSONValueNewObject())) - return -1; - if (virJSONValueObjectAppendString(target, "architecture", virQEMUCapsArchToString(t->arch= itecture)) < 0) @@ -869,14 +860,11 @@ qemuFirmwareFeatureFormat(virJSONValuePtr doc, char * qemuFirmwareFormat(qemuFirmwarePtr fw) { - g_autoptr(virJSONValue) doc =3D NULL; + g_autoptr(virJSONValue) doc =3D virJSONValueNewObject(); if (!fw) return NULL; - if (!(doc =3D virJSONValueNewObject())) - return NULL; - if (qemuFirmwareInterfaceFormat(doc, fw) < 0) return NULL; diff --git a/src/qemu/qemu_migration_params.c b/src/qemu/qemu_migration_par= ams.c index dd1ad9349b..a92bb2fa2b 100644 --- a/src/qemu/qemu_migration_params.c +++ b/src/qemu/qemu_migration_params.c @@ -729,15 +729,12 @@ qemuMigrationParamsFromJSON(virJSONValuePtr params) virJSONValuePtr qemuMigrationParamsToJSON(qemuMigrationParamsPtr migParams) { - virJSONValuePtr params =3D NULL; + virJSONValuePtr params =3D virJSONValueNewObject(); qemuMigrationParamValuePtr pv; const char *name; size_t i; int rc; - if (!(params =3D virJSONValueNewObject())) - return NULL; - for (i =3D 0; i < QEMU_MIGRATION_PARAM_LAST; i++) { name =3D qemuMigrationParamTypeToString(i); pv =3D &migParams->params[i]; @@ -797,8 +794,7 @@ qemuMigrationCapsToJSON(virBitmapPtr caps, ignore_value(virBitmapGetBit(states, bit, &state)); - if (!(cap =3D virJSONValueNewObject())) - goto error; + cap =3D virJSONValueNewObject(); name =3D qemuMigrationCapabilityTypeToString(bit); if (virJSONValueObjectAppendString(cap, "capability", name) < 0) diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c index 451e1afef5..5f0185d10b 100644 --- a/src/qemu/qemu_monitor_json.c +++ b/src/qemu/qemu_monitor_json.c @@ -690,15 +690,12 @@ qemuMonitorJSONParseKeywords(const char *str, static virJSONValuePtr qemuMonitorJSONKeywordStringToJSON(const char *str, const char *firstkeywo= rd) { - virJSONValuePtr ret =3D NULL; + virJSONValuePtr ret =3D virJSONValueNewObject(); char **keywords =3D NULL; char **values =3D NULL; int nkeywords =3D 0; size_t i; - if (!(ret =3D virJSONValueNewObject())) - return NULL; - if (qemuMonitorJSONParseKeywords(str, &keywords, &values, &nkeywords, = 1) < 0) goto error; @@ -3444,12 +3441,9 @@ qemuMonitorJSONSetMigrationParams(qemuMonitorPtr mon, virJSONValuePtr params) { int ret =3D -1; - virJSONValuePtr cmd =3D NULL; + virJSONValuePtr cmd =3D virJSONValueNewObject(); virJSONValuePtr reply =3D NULL; - if (!(cmd =3D virJSONValueNewObject())) - goto cleanup; - if (virJSONValueObjectAppendString(cmd, "execute", "migrate-set-parameters") < 0) goto cleanup; @@ -4823,8 +4817,7 @@ int qemuMonitorJSONSendKey(qemuMonitorPtr mon, } /* create single key object */ - if (!(key =3D virJSONValueNewObject())) - goto cleanup; + key =3D virJSONValueNewObject(); /* Union KeyValue has two types, use the generic one */ if (virJSONValueObjectAppendString(key, "type", "number") < 0) @@ -5817,19 +5810,15 @@ static virJSONValuePtr qemuMonitorJSONMakeCPUModel(virCPUDefPtr cpu, bool migratable) { - virJSONValuePtr model =3D NULL; + virJSONValuePtr model =3D virJSONValueNewObject(); virJSONValuePtr props =3D NULL; size_t i; - if (!(model =3D virJSONValueNewObject())) - goto error; - if (virJSONValueObjectAppendString(model, "name", cpu->model) < 0) goto error; if (cpu->nfeatures || !migratable) { - if (!(props =3D virJSONValueNewObject())) - goto error; + props =3D virJSONValueNewObject(); for (i =3D 0; i < cpu->nfeatures; i++) { char *name =3D cpu->features[i].name; @@ -7382,8 +7371,8 @@ qemuMonitorJSONAttachCharDevCommand(const char *chrID, const virDomainChrSourceDef *chr) { virJSONValuePtr ret =3D NULL; - virJSONValuePtr backend =3D NULL; - virJSONValuePtr data =3D NULL; + virJSONValuePtr backend =3D virJSONValueNewObject(); + virJSONValuePtr data =3D virJSONValueNewObject(); virJSONValuePtr addr =3D NULL; const char *backend_type =3D NULL; const char *host; @@ -7391,11 +7380,6 @@ qemuMonitorJSONAttachCharDevCommand(const char *chrI= D, char *tlsalias =3D NULL; bool telnet; - if (!(backend =3D virJSONValueNewObject()) || - !(data =3D virJSONValueNewObject())) { - goto cleanup; - } - switch ((virDomainChrType)chr->type) { case VIR_DOMAIN_CHR_TYPE_NULL: case VIR_DOMAIN_CHR_TYPE_VC: diff --git a/src/qemu/qemu_vhost_user.c b/src/qemu/qemu_vhost_user.c index aee18c9670..be7c3dd5b8 100644 --- a/src/qemu/qemu_vhost_user.c +++ b/src/qemu/qemu_vhost_user.c @@ -217,8 +217,7 @@ qemuVhostUserFormat(qemuVhostUserPtr vu) if (!vu) return NULL; - if (!(doc =3D virJSONValueNewObject())) - return NULL; + doc =3D virJSONValueNewObject(); if (virJSONValueObjectAppendString(doc, "type", qemuVhostUserTypeTypeToString(vu->t= ype)) < 0) diff --git a/src/rpc/virnetdaemon.c b/src/rpc/virnetdaemon.c index 7f2226b086..bb81a43d43 100644 --- a/src/rpc/virnetdaemon.c +++ b/src/rpc/virnetdaemon.c @@ -382,18 +382,12 @@ virJSONValuePtr virNetDaemonPreExecRestart(virNetDaemonPtr dmn) { size_t i =3D 0; - virJSONValuePtr object =3D NULL; - virJSONValuePtr srvObj =3D NULL; + virJSONValuePtr object =3D virJSONValueNewObject(); + virJSONValuePtr srvObj =3D virJSONValueNewObject(); virHashKeyValuePairPtr srvArray =3D NULL; virObjectLock(dmn); - if (!(object =3D virJSONValueNewObject())) - goto error; - - if (!(srvObj =3D virJSONValueNewObject())) - goto error; - if (virJSONValueObjectAppend(object, "servers", srvObj) < 0) { virJSONValueFree(srvObj); goto error; diff --git a/src/rpc/virnetserver.c b/src/rpc/virnetserver.c index c87dade1a8..a5998801de 100644 --- a/src/rpc/virnetserver.c +++ b/src/rpc/virnetserver.c @@ -546,16 +546,13 @@ virNetServerPtr virNetServerNewPostExecRestart(virJSO= NValuePtr object, virJSONValuePtr virNetServerPreExecRestart(virNetServerPtr srv) { - virJSONValuePtr object; + virJSONValuePtr object =3D virJSONValueNewObject(); virJSONValuePtr clients; virJSONValuePtr services; size_t i; virObjectLock(srv); - if (!(object =3D virJSONValueNewObject())) - goto error; - if (virJSONValueObjectAppendNumberUint(object, "min_workers", virThreadPoolGetMinWorkers(srv-= >workers)) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", diff --git a/src/rpc/virnetserverclient.c b/src/rpc/virnetserverclient.c index 67b3bf9531..4d85ee25d7 100644 --- a/src/rpc/virnetserverclient.c +++ b/src/rpc/virnetserverclient.c @@ -593,9 +593,6 @@ virJSONValuePtr virNetServerClientPreExecRestart(virNet= ServerClientPtr client) virJSONValuePtr object =3D virJSONValueNewObject(); virJSONValuePtr child; - if (!object) - return NULL; - virObjectLock(client); if (virJSONValueObjectAppendNumberUlong(object, "id", diff --git a/src/rpc/virnetserverservice.c b/src/rpc/virnetserverservice.c index 0a003e5814..9d5df456a8 100644 --- a/src/rpc/virnetserverservice.c +++ b/src/rpc/virnetserverservice.c @@ -343,9 +343,6 @@ virJSONValuePtr virNetServerServicePreExecRestart(virNe= tServerServicePtr svc) virJSONValuePtr socks; size_t i; - if (!object) - return NULL; - if (virJSONValueObjectAppendNumberInt(object, "auth", svc->auth) < 0) goto error; if (virJSONValueObjectAppendBoolean(object, "readonly", svc->readonly)= < 0) diff --git a/src/rpc/virnetsocket.c b/src/rpc/virnetsocket.c index a217404fa6..360711acb6 100644 --- a/src/rpc/virnetsocket.c +++ b/src/rpc/virnetsocket.c @@ -1283,8 +1283,7 @@ virJSONValuePtr virNetSocketPreExecRestart(virNetSock= etPtr sock) goto error; } - if (!(object =3D virJSONValueNewObject())) - goto error; + object =3D virJSONValueNewObject(); if (virJSONValueObjectAppendNumberInt(object, "fd", sock->fd) < 0) goto error; diff --git a/src/util/virjson.c b/src/util/virjson.c index ca57df816f..2d7368b0b6 100644 --- a/src/util/virjson.c +++ b/src/util/virjson.c @@ -362,8 +362,7 @@ virJSONValueObjectCreateVArgs(virJSONValuePtr *obj, { int ret; - if (!(*obj =3D virJSONValueNewObject())) - return -1; + *obj =3D virJSONValueNewObject(); /* free the object on error, or if no value objects were added */ if ((ret =3D virJSONValueObjectAddVArgs(*obj, args)) <=3D 0) { @@ -572,10 +571,7 @@ virJSONValueNewArray(void) virJSONValuePtr virJSONValueNewObject(void) { - virJSONValuePtr val; - - if (VIR_ALLOC(val) < 0) - return NULL; + virJSONValuePtr val =3D g_new0(virJSONValue, 1); val->type =3D VIR_JSON_TYPE_OBJECT; @@ -1503,8 +1499,6 @@ virJSONValueCopy(const virJSONValue *in) switch ((virJSONType) in->type) { case VIR_JSON_TYPE_OBJECT: out =3D virJSONValueNewObject(); - if (!out) - return NULL; for (i =3D 0; i < in->data.object.npairs; i++) { virJSONValuePtr val =3D NULL; if (!(val =3D virJSONValueCopy(in->data.object.pairs[i].value)= )) @@ -1724,9 +1718,6 @@ virJSONParserHandleStartMap(void *ctx) VIR_DEBUG("parser=3D%p", parser); - if (!value) - return 0; - if (virJSONParserInsertValue(parser, value) < 0) { virJSONValueFree(value); return 0; @@ -2103,8 +2094,7 @@ virJSONValueObjectDeflattenWorker(const char *key, } if (!(existobj =3D virJSONValueObjectGet(retobj, tokens[0]))) { - if (!(existobj =3D virJSONValueNewObject())) - goto cleanup; + existobj =3D virJSONValueNewObject(); if (virJSONValueObjectAppend(retobj, tokens[0], existobj) < 0) goto cleanup; @@ -2143,10 +2133,7 @@ virJSONValueObjectDeflattenWorker(const char *key, virJSONValuePtr virJSONValueObjectDeflatten(virJSONValuePtr json) { - g_autoptr(virJSONValue) deflattened =3D NULL; - - if (!(deflattened =3D virJSONValueNewObject())) - return NULL; + g_autoptr(virJSONValue) deflattened =3D virJSONValueNewObject(); if (virJSONValueObjectForeachKeyValue(json, virJSONValueObjectDeflattenWorke= r, diff --git a/src/util/virlease.c b/src/util/virlease.c index e0f81539be..1cb9540d80 100644 --- a/src/util/virlease.c +++ b/src/util/virlease.c @@ -238,11 +238,7 @@ virLeaseNew(virJSONValuePtr *lease_ret, } /* Create new lease */ - if (!(lease_new =3D virJSONValueNewObject())) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("failed to create json")); - return -1; - } + lease_new =3D virJSONValueNewObject(); if (iaid && virJSONValueObjectAppendString(lease_new, "iaid", iaid) < = 0) return -1; diff --git a/src/util/virlockspace.c b/src/util/virlockspace.c index a44377f89e..05517f8b40 100644 --- a/src/util/virlockspace.c +++ b/src/util/virlockspace.c @@ -434,9 +434,6 @@ virJSONValuePtr virLockSpacePreExecRestart(virLockSpace= Ptr lockspace) virJSONValuePtr resources; virHashKeyValuePairPtr pairs =3D NULL, tmp; - if (!object) - return NULL; - virMutexLock(&lockspace->lock); if (lockspace->dir && @@ -457,9 +454,6 @@ virJSONValuePtr virLockSpacePreExecRestart(virLockSpace= Ptr lockspace) virJSONValuePtr owners =3D NULL; size_t i; - if (!child) - goto error; - if (virJSONValueArrayAppend(resources, child) < 0) { virJSONValueFree(child); goto error; diff --git a/src/util/virmacmap.c b/src/util/virmacmap.c index ec589334ea..0c0ba90def 100644 --- a/src/util/virmacmap.c +++ b/src/util/virmacmap.c @@ -200,15 +200,12 @@ virMACMapHashDumper(void *payload, const void *name, void *data) { - virJSONValuePtr obj =3D NULL; + virJSONValuePtr obj =3D virJSONValueNewObject(); virJSONValuePtr arr =3D NULL; const char **macs =3D payload; size_t i; int ret =3D -1; - if (!(obj =3D virJSONValueNewObject())) - goto cleanup; - arr =3D virJSONValueNewArray(); for (i =3D 0; macs[i]; i++) { diff --git a/src/util/virnetdev.c b/src/util/virnetdev.c index 094d1ac09b..b465bdac2e 100644 --- a/src/util/virnetdev.c +++ b/src/util/virnetdev.c @@ -1874,8 +1874,7 @@ virNetDevSaveNetConfig(const char *linkdev, int vf, } } - if (!(configJSON =3D virJSONValueNewObject())) - goto cleanup; + configJSON =3D virJSONValueNewObject(); /* if there is a PF, it's now in pfDevName, and linkdev is either * the VF's name, or NULL (if the VF isn't bound to a net driver diff --git a/tests/qemumonitortestutils.c b/tests/qemumonitortestutils.c index b29e5d8cd2..00f5b49439 100644 --- a/tests/qemumonitortestutils.c +++ b/tests/qemumonitortestutils.c @@ -529,12 +529,8 @@ qemuMonitorTestProcessCommandDefaultValidate(qemuMonit= orTestPtr test, return -1; } - if (!args) { - if (!(emptyargs =3D virJSONValueNewObject())) - return -1; - - args =3D emptyargs; - } + if (!args) + args =3D emptyargs =3D virJSONValueNewObject(); if (testQEMUSchemaValidate(args, schemaroot, test->qapischema, &debug)= < 0) { if (qemuMonitorReportError(test, --=20 2.24.1