From nobody Sat Nov 23 14:19:05 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) client-ip=8.43.85.245; envelope-from=devel-bounces@lists.libvirt.org; helo=lists.libvirt.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [8.43.85.245]) by mx.zohomail.com with SMTPS id 1724064411307669.9160643595235; Mon, 19 Aug 2024 03:46:51 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 4635710B; Mon, 19 Aug 2024 06:46:50 -0400 (EDT) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 67A35156E; Mon, 19 Aug 2024 06:46:27 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 996) id A7B9513FE; Mon, 19 Aug 2024 06:46:24 -0400 (EDT) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by lists.libvirt.org (Postfix) with ESMTPS id 09FA613CC for ; Mon, 19 Aug 2024 06:46:24 -0400 (EDT) Received: from mx-prod-mc-02.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-688-7FgLD-VENUqsBH8sIRZChw-1; Mon, 19 Aug 2024 06:46:22 -0400 Received: from mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.15]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id B9AEE1954128 for ; Mon, 19 Aug 2024 10:46:21 +0000 (UTC) Received: from maggie.brq.redhat.com (unknown [10.43.3.102]) by mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id CEAC919773E0 for ; Mon, 19 Aug 2024 10:46:20 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-0.6 required=5.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1724064383; h=from:from: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; bh=SkhhpPEBbIRcM2bQ5WLWd9H1kSkfuqkq++POW7KNdEc=; b=Femg7aSIGOGAztgOUwXj84aExQUbq7OMZKuX+KKNrTc08jxz8W0Pb3dKHrIt1t81D+8+ad 6W70ubHTtUcGAxQ3mgMVishRKEvXczCm62APPOBOz79wfHfrXM0bHQf8LLQm22uEQMzBYh uEkEZAmEXvXwuUhsQ4UD1EcfCCQccRI= X-MC-Unique: 7FgLD-VENUqsBH8sIRZChw-1 From: Michal Privoznik To: devel@lists.libvirt.org Subject: [PATCH] lib: Use NULLSTR family of macros more Date: Mon, 19 Aug 2024 12:46:18 +0200 Message-ID: <5774060202925c23f1944ea0a007d1789ea97404.1724064378.git.mprivozn@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.15 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Message-ID-Hash: UHEMF6GU3MAB22WB44SAQKUTBTWZX2XV X-Message-ID-Hash: UHEMF6GU3MAB22WB44SAQKUTBTWZX2XV X-MailFrom: mprivozn@redhat.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-config-1; header-match-config-2; header-match-config-3; header-match-devel.lists.libvirt.org-0; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; suspicious-header X-Mailman-Version: 3.2.2 Precedence: list List-Id: Development discussions about the libvirt library & tools Archived-At: List-Archive: List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1724064412672116600 Content-Type: text/plain; charset="utf-8"; x-default="true" There is a family of convenient macros: NULLSTR, NULLSTR_EMPTY, NULLSTR_STAR, NULLSTR_MINUS which hides ternary operator. Generated using the following spatch (and its obvious variants): @@ expression s; @@ <+... - s ? s : "" + NULLSTR(s) ...+> Signed-off-by: Michal Privoznik Reviewed-by: Peter Krempa --- src/libvirt.c | 2 +- src/network/network_iptables.c | 4 ++-- src/network/network_nftables.c | 4 ++-- src/qemu/qemu_firmware.c | 2 +- src/util/virnetdevip.c | 8 ++++---- tools/virsh-checkpoint.c | 2 +- tools/virsh-domain-monitor.c | 8 ++++---- tools/virsh-nodedev.c | 2 +- 8 files changed, 16 insertions(+), 16 deletions(-) diff --git a/src/libvirt.c b/src/libvirt.c index 26c3fe454f..1d37696d6f 100644 --- a/src/libvirt.c +++ b/src/libvirt.c @@ -168,7 +168,7 @@ virConnectAuthCallbackDefault(virConnectCredentialPtr c= red, } =20 if (cred[i].type !=3D VIR_CRED_EXTERNAL) { - cred[i].result =3D bufptr ? bufptr : g_strdup(cred[i].defresul= t ? cred[i].defresult : ""); + cred[i].result =3D bufptr ? bufptr : g_strdup(NULLSTR_EMPTY(cr= ed[i].defresult)); cred[i].resultlen =3D strlen(cred[i].result); } } diff --git a/src/network/network_iptables.c b/src/network/network_iptables.c index f774176b3d..e8da15426e 100644 --- a/src/network/network_iptables.c +++ b/src/network/network_iptables.c @@ -867,10 +867,10 @@ iptablesForwardMasquerade(virFirewall *fw, if (addrStartStr && addrStartStr[0]) { if (addrEndStr && addrEndStr[0]) { natRangeStr =3D g_strdup_printf("%s-%s%s", addrStartStr, addrE= ndStr, - portRangeStr ? portRangeStr : ""= ); + NULLSTR_EMPTY(portRangeStr)); } else { natRangeStr =3D g_strdup_printf("%s%s", addrStartStr, - portRangeStr ? portRangeStr : ""= ); + NULLSTR_EMPTY(portRangeStr)); } =20 virFirewallCmdAddArgList(fw, fwCmd, diff --git a/src/network/network_nftables.c b/src/network/network_nftables.c index 268d1f12ca..f8b5ab665d 100644 --- a/src/network/network_nftables.c +++ b/src/network/network_nftables.c @@ -588,10 +588,10 @@ nftablesAddForwardMasquerade(virFirewall *fw, if (addrStartStr && addrStartStr[0]) { if (addrEndStr && addrEndStr[0]) { natRangeStr =3D g_strdup_printf("%s-%s%s", addrStartStr, addrE= ndStr, - portRangeStr ? portRangeStr : ""= ); + NULLSTR_EMPTY(portRangeStr)); } else { natRangeStr =3D g_strdup_printf("%s%s", addrStartStr, - portRangeStr ? portRangeStr : ""= ); + NULLSTR_EMPTY(portRangeStr)); } =20 virFirewallCmdAddArgList(fw, fwCmd, "counter", "snat", "to", natRa= ngeStr, NULL); diff --git a/src/qemu/qemu_firmware.c b/src/qemu/qemu_firmware.c index 08ca99e1ac..914f8596bd 100644 --- a/src/qemu/qemu_firmware.c +++ b/src/qemu/qemu_firmware.c @@ -1090,7 +1090,7 @@ qemuFirmwareEnsureNVRAM(virDomainDef *def, =20 loader->nvram->path =3D g_strdup_printf("%s/%s_VARS%s", cfg->nvramDir, def->name, - ext ? ext : ""); + NULLSTR_EMPTY(ext)); } =20 =20 diff --git a/src/util/virnetdevip.c b/src/util/virnetdevip.c index 3b02fe0cec..f365c1999c 100644 --- a/src/util/virnetdevip.c +++ b/src/util/virnetdevip.c @@ -188,8 +188,8 @@ virNetDevIPAddrAdd(const char *ifname, =20 VIR_DEBUG("Adding IP address %s/%d%s%s%s%s to %s", NULLSTR(ipStr), prefix, - peerStr ? " peer " : "", peerStr ? peerStr : "", - bcastStr ? " bcast " : "", bcastStr ? bcastStr : "", + peerStr ? " peer " : "", NULLSTR_EMPTY(peerStr), + bcastStr ? " bcast " : "", NULLSTR_EMPTY(bcastStr), ifname); =20 if (!(nlmsg =3D virNetDevCreateNetlinkAddressMessage(RTM_NEWADDR, ifna= me, @@ -206,8 +206,8 @@ virNetDevIPAddrAdd(const char *ifname, virReportError(VIR_ERR_SYSTEM_ERROR, _("Failed to add IP address %1$s/%2$d%3$s%4$s%5$s%6= $s to %7$s"), ipStr, prefix, - peerStr ? " peer " : "", peerStr ? peerStr : "", - bcastStr ? " bcast " : "", bcastStr ? bcastStr : "", + peerStr ? " peer " : "", NULLSTR_EMPTY(peerStr), + bcastStr ? " bcast " : "", NULLSTR_EMPTY(bcastStr), ifname); return -1; } diff --git a/tools/virsh-checkpoint.c b/tools/virsh-checkpoint.c index 972b2f979c..a0ac0d7f71 100644 --- a/tools/virsh-checkpoint.c +++ b/tools/virsh-checkpoint.c @@ -455,7 +455,7 @@ cmdCheckpointInfo(vshControl *ctl, _("unexpected problem querying checkpoint state")); return false; } - vshPrint(ctl, "%-15s %s\n", _("Parent:"), parent ? parent : "-"); + vshPrint(ctl, "%-15s %s\n", _("Parent:"), NULLSTR_MINUS(parent)); =20 /* Children, Descendants. */ flags =3D 0; diff --git a/tools/virsh-domain-monitor.c b/tools/virsh-domain-monitor.c index 74deca2f94..37184baa69 100644 --- a/tools/virsh-domain-monitor.c +++ b/tools/virsh-domain-monitor.c @@ -712,11 +712,11 @@ cmdDomiflist(vshControl *ctl, const vshCmd *cmd) mac =3D virXPathString("string(./mac/@address)", ctxt); =20 if (vshTableRowAppend(table, - target ? target : "-", + NULLSTR_MINUS(target), type, - source ? source : "-", - model ? model : "-", - mac ? mac : "-", + NULLSTR_MINUS(source), + NULLSTR_MINUS(model), + NULLSTR_MINUS(mac), NULL) < 0) return false; } diff --git a/tools/virsh-nodedev.c b/tools/virsh-nodedev.c index 910eaefc9e..145faff3e7 100644 --- a/tools/virsh-nodedev.c +++ b/tools/virsh-nodedev.c @@ -1233,7 +1233,7 @@ cmdNodeDeviceInfo(vshControl *ctl, const vshCmd *cmd) =20 parent =3D virNodeDeviceGetParent(device); vshPrint(ctl, "%-15s %s\n", _("Name:"), virNodeDeviceGetName(device)); - vshPrint(ctl, "%-15s %s\n", _("Parent:"), parent ? parent : ""); + vshPrint(ctl, "%-15s %s\n", _("Parent:"), NULLSTR_EMPTY(parent)); vshPrint(ctl, "%-15s %s\n", _("Active:"), virNodeDeviceIsActive(device= ) ? _("yes") : _("no")); vshPrint(ctl, "%-15s %s\n", _("Persistent:"), --=20 2.44.2