From nobody Wed Oct 30 19:56:11 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 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=1695029838; cv=none; d=zohomail.com; s=zohoarc; b=ZMCgPFUW804m0539Rynyz3NuyG6TN8S+lqKjYrDBaFngZZiqXwADzsy7j+LBdotrrKZngvR1sF8VQgsOClCS4JBlDWOEVvZC/Cjv6t274xGVKJ1uspixY70GFdEodOptcowF2AbP9iIhO1dLtWXjMpf+uX+iNyi9nlmXr8eeCxI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1695029838; h=Content-Type:Content-Transfer-Encoding:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To; bh=iYDiriBoC/jOvhHF/wxJejyzpnrp4hc2Y2q6s+Lt7eQ=; b=dq5CAETAZpRvepitNBJkq7RSiziRWQ+MeS+DCSOcSf4WVf+jamZMJqF8plmX5l24RTqdxAJnkqLwU3f1Z9TDvXgW4iUUnOB0qJNegxOZJbI6w7/IP8RD0AWXnRS2e4T0UGMJAcM+tLhONGGh3ELwjY9uPFcoBiw0VGjn9iTVMCM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.zohomail.com with SMTPS id 1695029838934620.4689440698223; Mon, 18 Sep 2023 02:37:18 -0700 (PDT) Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-654-T4EciKDOPuWGRrkUopTfOw-1; Mon, 18 Sep 2023 05:37:12 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 2419E85A5BE; Mon, 18 Sep 2023 09:37:10 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id 723BC1C554; Mon, 18 Sep 2023 09:37:09 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 34093194658D; Mon, 18 Sep 2023 09:36:59 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 64731194658C for ; Mon, 18 Sep 2023 09:36:58 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 5373D4011E4; Mon, 18 Sep 2023 09:36:58 +0000 (UTC) Received: from maggie.brq.redhat.com (unknown [10.43.2.46]) by smtp.corp.redhat.com (Postfix) with ESMTP id EF00B492B16 for ; Mon, 18 Sep 2023 09:36:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1695029838; 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:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=iYDiriBoC/jOvhHF/wxJejyzpnrp4hc2Y2q6s+Lt7eQ=; b=c8qsgCokBK5/fQYatNV/JDuNB51xn0gHX+3SNHLbaFvpK/CKDLD/UqVf18Zpi92/cKXJI2 A2vUj6EPcDFJ2xNmlXvBBgLaaXrfeF87UKc2M4A+o4+ojhOUBckuN10ENqwnEjxMX9kBax cHv0cI5mrkEZQttivXs6X3nJqRVuQSw= X-MC-Unique: T4EciKDOPuWGRrkUopTfOw-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH] src: Avoid needless checks before calling g_strdup() Date: Mon, 18 Sep 2023 11:36:40 +0200 Message-ID: <1a81790d809f6f0f0b808b3ec6a64eb1940829e7.1695029800.git.mprivozn@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.9 X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 3.1 on 10.11.54.5 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1695029839505100001 Content-Type: text/plain; charset="utf-8"; x-default="true" There are few places where the following pattern occurs: if (var) other =3D g_strdup(var); where @other wasn't initialized before g_strdup(). Checking for var !=3D NULL is useless in this case, as that's exactly what g_strdup() does (in which case it returns NULL). Signed-off-by: Michal Privoznik Reviewed-by: J=C3=A1n Tomko --- src/conf/domain_event.c | 3 +-- src/libxl/libxl_conf.c | 6 ++---- src/lxc/lxc_native.c | 3 +-- src/qemu/qemu_monitor_json.c | 3 +-- src/util/virconf.c | 3 +-- 5 files changed, 6 insertions(+), 12 deletions(-) diff --git a/src/conf/domain_event.c b/src/conf/domain_event.c index 75603a933a..09f3368064 100644 --- a/src/conf/domain_event.c +++ b/src/conf/domain_event.c @@ -1561,8 +1561,7 @@ virDomainEventMetadataChangeNew(int id, return NULL; =20 ev->type =3D type; - if (nsuri) - ev->nsuri =3D g_strdup(nsuri); + ev->nsuri =3D g_strdup(nsuri); =20 return (virObjectEvent *)ev; } diff --git a/src/libxl/libxl_conf.c b/src/libxl/libxl_conf.c index 3ffb46fddd..4582126d19 100644 --- a/src/libxl/libxl_conf.c +++ b/src/libxl/libxl_conf.c @@ -583,8 +583,7 @@ libxlMakeDomBuildInfo(virDomainDef *def, #endif =20 /* copy SLIC table path to acpi_firmware */ - if (def->os.slic_table) - b_info->u.hvm.acpi_firmware =3D g_strdup(def->os.slic_table); + b_info->u.hvm.acpi_firmware =3D g_strdup(def->os.slic_table); =20 if (def->nsounds > 0) { /* @@ -1198,8 +1197,7 @@ libxlMakeDisk(virDomainDiskDef *l_disk, libxl_device_= disk *x_disk) return -1; } =20 - if (l_disk->domain_name) - x_disk->backend_domname =3D g_strdup(l_disk->domain_name); + x_disk->backend_domname =3D g_strdup(l_disk->domain_name); =20 return 0; } diff --git a/src/lxc/lxc_native.c b/src/lxc/lxc_native.c index 5a63efc35f..c0011e0600 100644 --- a/src/lxc/lxc_native.c +++ b/src/lxc/lxc_native.c @@ -67,8 +67,7 @@ lxcCreateFSDef(int type, =20 def->type =3D type; def->accessmode =3D VIR_DOMAIN_FS_ACCESSMODE_PASSTHROUGH; - if (src) - def->src->path =3D g_strdup(src); + def->src->path =3D g_strdup(src); def->dst =3D g_strdup(dst); def->readonly =3D readonly; def->usage =3D usage; diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c index 137cb4e293..8152eea9a0 100644 --- a/src/qemu/qemu_monitor_json.c +++ b/src/qemu/qemu_monitor_json.c @@ -2960,8 +2960,7 @@ qemuMonitorJSONGetMigrationStatsReply(virJSONValue *r= eply, case QEMU_MONITOR_MIGRATION_STATUS_ERROR: if (error) { tmp =3D virJSONValueObjectGetString(ret, "error-desc"); - if (tmp) - *error =3D g_strdup(tmp); + *error =3D g_strdup(tmp); } break; =20 diff --git a/src/util/virconf.c b/src/util/virconf.c index 934632a35f..8fdf40e9d0 100644 --- a/src/util/virconf.c +++ b/src/util/virconf.c @@ -939,8 +939,7 @@ int virConfGetValueStringList(virConf *conf, case VIR_CONF_STRING: if (compatString) { *values =3D g_new0(char *, cval->str ? 2 : 1); - if (cval->str) - (*values)[0] =3D g_strdup(cval->str); + (*values)[0] =3D g_strdup(cval->str); break; } G_GNUC_FALLTHROUGH; --=20 2.41.0