From nobody Mon Feb 9 00:38:51 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1553866470894978.3209783636254; Fri, 29 Mar 2019 06:34:30 -0700 (PDT) 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 mx1.redhat.com (Postfix) with ESMTPS id 5AF7D308339F; Fri, 29 Mar 2019 13:34:29 +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 2723561B80; Fri, 29 Mar 2019 13:34:28 +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 27F83180338C; Fri, 29 Mar 2019 13:34:28 +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 x2TDXnLt026953 for ; Fri, 29 Mar 2019 09:33:49 -0400 Received: by smtp.corp.redhat.com (Postfix) id 2D81118E3E; Fri, 29 Mar 2019 13:33:49 +0000 (UTC) Received: from angien.brq.redhat.com (unknown [10.43.2.229]) by smtp.corp.redhat.com (Postfix) with ESMTP id AAB7C17C69 for ; Fri, 29 Mar 2019 13:33:48 +0000 (UTC) From: Peter Krempa To: libvir-list@redhat.com Date: Fri, 29 Mar 2019 14:33:39 +0100 Message-Id: <7ae0b96a9e38043e459823ef36ab1249254ffcd7.1553866155.git.pkrempa@redhat.com> 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 Subject: [libvirt] [PATCH 2/7] util: buffer: Use 'size_t' for buffer size variables 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: , Content-Transfer-Encoding: quoted-printable 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-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.44]); Fri, 29 Mar 2019 13:34:30 +0000 (UTC) Content-Type: text/plain; charset="utf-8" Use size_t for all sizes. The '*' modifier unfortunately does require an int so a temporary variable is necessary in the tests. Signed-off-by: Peter Krempa Reviewed-by: Laine Stump --- src/util/virbuffer.c | 2 +- src/util/virbuffer.h | 6 +++--- tests/virbuftest.c | 4 +++- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/util/virbuffer.c b/src/util/virbuffer.c index 8bb9c8e1fa..2e1e4abead 100644 --- a/src/util/virbuffer.c +++ b/src/util/virbuffer.c @@ -339,7 +339,7 @@ virBufferCheckErrorInternal(const virBuffer *buf, * * Return the string usage in bytes */ -unsigned int +size_t virBufferUse(const virBuffer *buf) { if (buf =3D=3D NULL) diff --git a/src/util/virbuffer.h b/src/util/virbuffer.h index 16cd8515d6..18957ae02c 100644 --- a/src/util/virbuffer.h +++ b/src/util/virbuffer.h @@ -38,8 +38,8 @@ typedef virBuffer *virBufferPtr; # define VIR_BUFFER_INITIALIZER { 0, 0, 0, 0, NULL } struct _virBuffer { - unsigned int size; - unsigned int use; + size_t size; + size_t use; unsigned int error; /* errno value, or -1 for usage error */ int indent; char *content; @@ -69,7 +69,7 @@ VIR_DEFINE_AUTOCLEAN_FUNC(virBuffer, virBufferFreeAndRese= t); # define virBufferCheckError(buf) \ virBufferCheckErrorInternal(buf, VIR_FROM_THIS, __FILE__, __FUNCTION__= , \ __LINE__) -unsigned int virBufferUse(const virBuffer *buf); +size_t virBufferUse(const virBuffer *buf); void virBufferAdd(virBufferPtr buf, const char *str, int len); void virBufferAddBuffer(virBufferPtr buf, virBufferPtr toadd); void virBufferAddChar(virBufferPtr buf, char c); diff --git a/tests/virbuftest.c b/tests/virbuftest.c index b608da94d4..778754d7c1 100644 --- a/tests/virbuftest.c +++ b/tests/virbuftest.c @@ -20,6 +20,7 @@ static int testBufInfiniteLoop(const void *data) char *addstr =3D NULL, *bufret =3D NULL; int ret =3D -1; const struct testInfo *info =3D data; + int len; virBufferAddChar(buf, 'a'); @@ -29,7 +30,8 @@ static int testBufInfiniteLoop(const void *data) * which was the case after the above addchar at the time of the bug. * This test is a bit fragile, since it relies on virBuffer internals. */ - if (virAsprintf(&addstr, "%*s", buf->size - buf->use - 1, "a") < 0) + len =3D buf->size - buf->use - 1; + if (virAsprintf(&addstr, "%*s", len, "a") < 0) goto out; if (info->doEscape) --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list