From nobody Mon Feb 9 03:46:38 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) client-ip=63.128.21.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 63.128.21.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=1614183472; cv=none; d=zohomail.com; s=zohoarc; b=A36Hn6++id1SQGY/aKkTyfXlqPhC7V6LVTkXSIsDFGJ3ZO9G6jhgTBF0h3Yur+GJFjNgTXWnnWvN/ZEnYrwAEJZk9F73pmbr6CLQAawCbn3+FgVN2XkBzM32DR5DURGDtU9kcDFAE9Yfv9k0HYwHrqSkjPpG8nWtzn87dblvhlI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1614183472; 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=4BOtAzYFXHWQHLnL8CS0i3b4JKqv9WWzdUidvh1n/iI=; b=RZeqqLID7+t7/4bmnfZwhzXlcyj6Sds34mXpUqmWVVRnhsx2DG1Q8uLlEHk2MQkreOa0gCX6EcLJC6w2HDrXsIVbZ64rKpOgHdoi+WWOdBWI5b+7ixz6Ne71hjlNEKFb7j/j755KjIQyg2GpfmHWp2PfjdrHldm18+K41eqfPVg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 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-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by mx.zohomail.com with SMTPS id 1614183472337330.05322754531915; Wed, 24 Feb 2021 08:17:52 -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-106-uEhDMoc_OWCi6PEOo5_Z4g-1; Wed, 24 Feb 2021 11:17:47 -0500 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id E4B5910B9CA3; Wed, 24 Feb 2021 16:17:38 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id C072A10016F9; Wed, 24 Feb 2021 16:17:38 +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 80D2218089C9; Wed, 24 Feb 2021 16:17:38 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 11OGHLfn015509 for ; Wed, 24 Feb 2021 11:17:21 -0500 Received: by smtp.corp.redhat.com (Postfix) id 1E03460C5B; Wed, 24 Feb 2021 16:17:21 +0000 (UTC) Received: from speedmetal.lan (unknown [10.40.208.53]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7435360862 for ; Wed, 24 Feb 2021 16:17:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1614183469; 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=4BOtAzYFXHWQHLnL8CS0i3b4JKqv9WWzdUidvh1n/iI=; b=QBgI/oom8ZbgyMKV+OHKrufO1sXEnPrmGAie0B9Svtkv824pl7u4QbZk65S3kK651YaynI eCjt2i6SJdiQJkUur/XxaX5azJ/TXHU26v/sU68Y+jf9TxjuEXpG87cjlsCSfkeUka+aG6 J/srz5IsXoX4K9anhStg0E/FGavqPsg= X-MC-Unique: uEhDMoc_OWCi6PEOo5_Z4g-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 05/33] virCommandAddArgBuffer: Simplify clearing of @buf Date: Wed, 24 Feb 2021 17:16:40 +0100 Message-Id: <52b31e32ead0db7353f5449edaafc6ca6c9be6af.1614182583.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 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.84 on 10.5.11.22 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com 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" Get the buffer contents into a temporary variable with automatic clearing so that the error branches don't have to reset the buffer. Additionally handle the NULL string case before assignment. Signed-off-by: Peter Krempa --- src/util/vircommand.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/util/vircommand.c b/src/util/vircommand.c index b94ab615d5..f11caf0d6e 100644 --- a/src/util/vircommand.c +++ b/src/util/vircommand.c @@ -1550,21 +1550,21 @@ virCommandAddArg(virCommandPtr cmd, const char *val) void virCommandAddArgBuffer(virCommandPtr cmd, virBufferPtr buf) { - if (!cmd || cmd->has_error) { - virBufferFreeAndReset(buf); + g_autofree char *str =3D virBufferContentAndReset(buf); + + if (!cmd || cmd->has_error) return; - } + + if (!str) + str =3D g_strdup(""); /* Arg plus trailing NULL. */ if (VIR_RESIZE_N(cmd->args, cmd->maxargs, cmd->nargs, 1 + 1) < 0) { cmd->has_error =3D ENOMEM; - virBufferFreeAndReset(buf); return; } - cmd->args[cmd->nargs] =3D virBufferContentAndReset(buf); - if (!cmd->args[cmd->nargs]) - cmd->args[cmd->nargs] =3D g_strdup(""); + cmd->args[cmd->nargs] =3D g_steal_pointer(&str); cmd->nargs++; } --=20 2.29.2