From nobody Mon Apr 29 12:53:56 2024 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=1614878306; cv=none; d=zohomail.com; s=zohoarc; b=iRZIcYlCFtxxMwadI35awh3lVuqOUB3sYLkeFnWdwcVtVDU7CBUkPVSjKPjwMS4MrjYEOoVwIthf5DD7dhKzaTUFX7LS7jENsToJCrGoG+biYoJDQUHKn4pVghdKfmE3BZKmPEPu7emXO3KDIoXw2edGjMXxwvefqwwFyT28vUc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1614878306; 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=dUDpm+gRZNM/Irpgdda/93yE/5bnE9j9T7yAMa7LMVc=; b=BwLJgyDV0VnyeWpTtrjdkb3HNoGmEZ5Czi3JIQ7fsLomObiw57EBxHrg9aVasoAMS6v6iwOhs7G0mVeXpueoDTf1MlDbqQQtxxnl2451c0+G1W+S1mjLLlj2C8FDUZXF8mWs1hUvUIB53tWMqU4KOo03EewRJSZdu5euttCa5xI= 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 1614878306820710.1922600188956; Thu, 4 Mar 2021 09:18:26 -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-496-EoU0qCsiPYezfQyY_BFfng-1; Thu, 04 Mar 2021 12:18:23 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 011AC57; Thu, 4 Mar 2021 17:18:17 +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 E6AFB5D762; Thu, 4 Mar 2021 17:18:15 +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 7DE181809C86; Thu, 4 Mar 2021 17:18:14 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 124HICkR031926 for ; Thu, 4 Mar 2021 12:18:12 -0500 Received: by smtp.corp.redhat.com (Postfix) id 8A24960C66; Thu, 4 Mar 2021 17:18:12 +0000 (UTC) Received: from speedmetal.lan (unknown [10.40.208.53]) by smtp.corp.redhat.com (Postfix) with ESMTP id DAC8560C0F for ; Thu, 4 Mar 2021 17:18:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1614878305; 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=dUDpm+gRZNM/Irpgdda/93yE/5bnE9j9T7yAMa7LMVc=; b=UmjoPk+/iPXBcJxE/qlJ7hFp3PCK+bymjd6z4TUKUW0D3rxCzUgMM/gIfmHiUN2ux5Wenl IWnolkwRySW7bwkTTL45l6HYPErgMWWj8TGO49oC+WzkciJKmI8BM+o+NNxnuxDb6kmqCO QeWyAEI23xGxrJ1hgfqyI+lIj8X+VMo= X-MC-Unique: EoU0qCsiPYezfQyY_BFfng-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH] virBufferAdd: Ensure that the buffer is initialized also when len == 0 Date: Thu, 4 Mar 2021 18:18:07 +0100 Message-Id: <7e6a21580da7f00d5ccb81c694e52eea5a7d2d15.1614878287.git.pkrempa@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 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.15 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" There's an optimization in virBufferAdd which returns early when the length of the added string is 0 (given that auto-indent is disabled). The optimization causes inconsistent behaviour between these two cases: virBufferAdd(buf, "", 0); // this doesn't initialize the buffer and virBufferAdd(buf, "", -1); //this initializes the buffer Since using an empty string is used to prime the buffer to an empty string it can be confusing. Remove the optimization. This fixes such a wrong initialization done in x86FeatureNames. Note that our code in many places expects that if no virBuffer APIs are used on a buffer object, then NULL should be retured, so we can't always prime the buffer to an empty string. Signed-off-by: Peter Krempa --- src/util/virbuffer.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/util/virbuffer.c b/src/util/virbuffer.c index ebb4108b5d..b9ddf1f5c9 100644 --- a/src/util/virbuffer.c +++ b/src/util/virbuffer.c @@ -156,7 +156,7 @@ virBufferApplyIndent(virBufferPtr buf) void virBufferAdd(virBufferPtr buf, const char *str, int len) { - if (!str || !buf || (len =3D=3D 0 && buf->indent =3D=3D 0)) + if (!str || !buf) return; virBufferInitialize(buf); --=20 2.29.2