From nobody Fri Apr 26 20:39:30 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 205.139.110.61 as permitted sender) client-ip=205.139.110.61; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zoho.com: domain of redhat.com designates 205.139.110.61 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=1571925415; cv=none; d=zoho.com; s=zohoarc; b=a73sWOtbGJfpqFIkX80xjKMdmRSM91fYXg7DoJoSyAX/6wcHVu46qc1zFjfcABMz4FZxJBZ25REhE24DQwX/FahM2kg5OO4nvVboPdDYTe+7lASVwfFyg0k8oowDm+aDhU+koMdLeUJiJAkMGLATdmxrboxvMH89AJHV2azJyq0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1571925415; 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=WAKgKh6RoFMVtSa4SprlTAcybrJ2JkGrQAHDkObBn60=; b=KaolQIvm1nNgH94iKBJdg3t8isFg/4TlLbOf19MuJKbbQ/XYwVBI6nFV85UMGdILzAQ7Pq0r6HxxSD91Gs0/znFPDtg27y3h2TjZtQbzKdrZ1firXtBVmyNu3a/tX9C05cfVqi87BXkDFAgWw6JAlBrrC+VG4OS3bJIEs0+cLBc= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=pass; spf=pass (zoho.com: domain of redhat.com designates 205.139.110.61 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-1.mimecast.com (us-smtp-2.mimecast.com [205.139.110.61]) by mx.zohomail.com with SMTPS id 1571925415697972.767683947799; Thu, 24 Oct 2019 06:56:55 -0700 (PDT) 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-138-wyjlGcClM6myWuPiThj2oA-1; Thu, 24 Oct 2019 09:56:51 -0400 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 C4354107AD31; Thu, 24 Oct 2019 13:56:46 +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 728F95B681; Thu, 24 Oct 2019 13:56:46 +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 531A4180B536; Thu, 24 Oct 2019 13:56:44 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x9ODufN5026277 for ; Thu, 24 Oct 2019 09:56:41 -0400 Received: by smtp.corp.redhat.com (Postfix) id EAEED10027C4; Thu, 24 Oct 2019 13:56:41 +0000 (UTC) Received: from angien.redhat.com (unknown [10.43.2.229]) by smtp.corp.redhat.com (Postfix) with ESMTP id 748FD100164D for ; Thu, 24 Oct 2019 13:56:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1571925414; 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=WAKgKh6RoFMVtSa4SprlTAcybrJ2JkGrQAHDkObBn60=; b=Cb4NweZIaZjE4jT810XUs+y20DVn85OCyW/Qj/2z0+A12Rc6QmyOywTwpoCEXA2uPRj56A P1rq6GQmCVurqi1MxJn6mOtzRGdV+TKwxu8y6fm1/CEwCz/V9xWAhtxBYn2t+LLAgvR4Jz gldt4W//uRySi1oNfBUNJFJ1FcxpxKk= From: Peter Krempa To: libvir-list@redhat.com Date: Thu, 24 Oct 2019 15:56:19 +0200 Message-Id: <3fef25159f64ee83ca5bcfd89044d68de01027a4.1571925291.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 01/19] util: buffer: Simplify convoluted condition 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 X-MC-Unique: wyjlGcClM6myWuPiThj2oA-1 X-Mimecast-Spam-Score: 0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" Spare a few more lines rather than having a condition with a nested ternary. Signed-off-by: Peter Krempa Reviewed-by: Jonathon Jongsma Reviewed-by: J=C3=A1n Tomko --- src/util/virbuffer.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/util/virbuffer.c b/src/util/virbuffer.c index 04c8fd7291..a58481430a 100644 --- a/src/util/virbuffer.c +++ b/src/util/virbuffer.c @@ -64,11 +64,19 @@ virBufferAdjustIndent(virBufferPtr buf, int indent) { if (!buf || buf->error) return; - if (indent > 0 ? INT_MAX - indent < buf->indent - : buf->indent < -indent) { - virBufferSetError(buf, -1); - return; + + if (indent > 0) { + if (INT_MAX - indent < buf->indent) { + virBufferSetError(buf, -1); + return; + } + } else { + if (buf->indent < -indent) { + virBufferSetError(buf, -1); + return; + } } + buf->indent +=3D indent; } --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri Apr 26 20:39:30 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 205.139.110.61 as permitted sender) client-ip=205.139.110.61; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zoho.com: domain of redhat.com designates 205.139.110.61 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=1571925430; cv=none; d=zoho.com; s=zohoarc; b=AQDJIC0bhoNiGiUZFQjTzLdI3rnidvYVuo9dxO6H7ijxZoIsRozrGMDyshILvUBJ8ulS5WEz871rqiAWBU6lxJQbM70ZKjAc/n2UX4uFIXXmCazwLm4wSrv2q0sp9MiQQwhkvVQ8TVnr40s/e+o91V00f3E+/HZV2xWPiGN2ecg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1571925430; 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=rmmldVrFJs8n1qQ9wNXySVcvwjpaQjvdlf2OO+uLD6Q=; b=eyL3JzNNYtN3qkZr1LdqRxb22nHwUH0N6FtpPA0DGxdhuLUHh6YIAmu/S256S1M327BYtlc+DLAuK00sy0HH/+5lqaN1n7lU3RTM8keM4cjIBelVnuFHqDrQzwK26p8LSY8kKImlxtebj46RXqWhNKhxYvv6+bSZZfmNeI7MiCc= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=pass; spf=pass (zoho.com: domain of redhat.com designates 205.139.110.61 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-1.mimecast.com (us-smtp-2.mimecast.com [205.139.110.61]) by mx.zohomail.com with SMTPS id 1571925430168841.3228926448631; Thu, 24 Oct 2019 06:57:10 -0700 (PDT) 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-138-4M3usMnFOhe5EhG720yvFg-1; Thu, 24 Oct 2019 09:57:04 -0400 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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id D715C107AD33; Thu, 24 Oct 2019 13:56:57 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id B058F5C1D4; Thu, 24 Oct 2019 13:56:57 +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 6ED5E4E9F5; Thu, 24 Oct 2019 13:56:57 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x9ODug05026288 for ; Thu, 24 Oct 2019 09:56:42 -0400 Received: by smtp.corp.redhat.com (Postfix) id BC1491000232; Thu, 24 Oct 2019 13:56:42 +0000 (UTC) Received: from angien.redhat.com (unknown [10.43.2.229]) by smtp.corp.redhat.com (Postfix) with ESMTP id 45BCE10027A9 for ; Thu, 24 Oct 2019 13:56:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1571925428; 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=rmmldVrFJs8n1qQ9wNXySVcvwjpaQjvdlf2OO+uLD6Q=; b=gjqo/s11Y6Mbd67P6mMsbFtvpSowd/GOptyoo9gL+RwNi17wsGt24K8q5snHblIa8WWiJt wFakmBkWC7lwXZwPedoK+LvollKN5rczi4Tiq0eUOwZNu4KBklOkX350znDWYh8gklFH8O pNJI3asGptD0noa6kt2ucCKv4PHnPwk= From: Peter Krempa To: libvir-list@redhat.com Date: Thu, 24 Oct 2019 15:56:20 +0200 Message-Id: <1cc6a0370d383ae133558c0034545a1adb07c08f.1571925291.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 02/19] util: buffer: Use 'cleanup' as label name in virBufferAddBuffer 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.16 X-MC-Unique: 4M3usMnFOhe5EhG720yvFg-1 X-Mimecast-Spam-Score: 0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- src/util/virbuffer.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/util/virbuffer.c b/src/util/virbuffer.c index a58481430a..a2b5aa8508 100644 --- a/src/util/virbuffer.c +++ b/src/util/virbuffer.c @@ -201,22 +201,22 @@ virBufferAddBuffer(virBufferPtr buf, virBufferPtr toa= dd) return; if (!buf) - goto done; + goto cleanup; if (buf->error || toadd->error) { if (!buf->error) virBufferSetError(buf, toadd->error); - goto done; + goto cleanup; } if (virBufferGrow(buf, toadd->use) < 0) - goto done; + goto cleanup; memcpy(&buf->content[buf->use], toadd->content, toadd->use); buf->use +=3D toadd->use; buf->content[buf->use] =3D '\0'; - done: + cleanup: virBufferFreeAndReset(toadd); } --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri Apr 26 20:39:30 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 205.139.110.120 as permitted sender) client-ip=205.139.110.120; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zoho.com: domain of redhat.com designates 205.139.110.120 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=1571925431; cv=none; d=zoho.com; s=zohoarc; b=K31ufFMB5kz26cJm65UWp7cKZt4UtsQ6XRuOvyeKQBSnmremQZJYRZuNfVF2VG4d9jEiSYKGPo6s8nSkL7WOJOJ+DNVFjkhKF2T0ne8tC7YkbfGbkLKZEu+c3nRZjzcmMheKz/TvNJEfht05ntFzJG7zfQHY6qxjwMARTF+TFIA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1571925431; 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=pI8qYbs+wpdDlYVMoHvkhQLlleiFwuqmxf/ENmYDnC4=; b=Pt81lDsFQpequfgVTic9liv4OwL4tdCEKD0239QMw/cSFOQ/SBAwEKYc5XUoaEkAgO6nwZafHU4mob9rKqr6NPgLpOH5buCMYBH3ZeFjZ+sab6+CQL948Lq1WEQgH5PqSdlpkHnN6Ya/dm2XY3qf7HzOKPHpVgfA4uFOONk50cQ= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=pass; spf=pass (zoho.com: domain of redhat.com designates 205.139.110.120 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-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) by mx.zohomail.com with SMTPS id 1571925431018219.51789714420215; Thu, 24 Oct 2019 06:57:11 -0700 (PDT) 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-332-Her3YigiPEKXnZRxn1a5Jg-1; Thu, 24 Oct 2019 09:57:04 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id DCB831005500; Thu, 24 Oct 2019 13:56:57 +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 AB33C60166; Thu, 24 Oct 2019 13:56:57 +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 6CA2A180B76F; Thu, 24 Oct 2019 13:56:57 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x9ODuhWo026295 for ; Thu, 24 Oct 2019 09:56:43 -0400 Received: by smtp.corp.redhat.com (Postfix) id 8CE35100164D; Thu, 24 Oct 2019 13:56:43 +0000 (UTC) Received: from angien.redhat.com (unknown [10.43.2.229]) by smtp.corp.redhat.com (Postfix) with ESMTP id 153221000232 for ; Thu, 24 Oct 2019 13:56:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1571925429; 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=pI8qYbs+wpdDlYVMoHvkhQLlleiFwuqmxf/ENmYDnC4=; b=iyyRtn9vDJ1gVLrbotbSJXquqoGH0mEd2TaToTY5mm7E+55ai3n/6jQOfathgNjoQMEpD7 vVC2pMeCCJ1jvyrGLgz3C89Jh7yrd4QdE85RsaCC3x8+9NeIVllaowJEegBTlhleq46kNU Dx05oEZ47ZYkKsiSBNu4kB7JFLQy49I= From: Peter Krempa To: libvir-list@redhat.com Date: Thu, 24 Oct 2019 15:56:21 +0200 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 03/19] util: buffer: Simplify escape buffer allocations 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.11 X-MC-Unique: Her3YigiPEKXnZRxn1a5Jg-1 X-Mimecast-Spam-Score: 0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" Replace combinations of xalloc_oversized and VIR_ALLOC_N_QUIET by using g_malloc0_n which does the checking internally. This conversion is done with a semantic difference and slightly higher memory requirements as I've opted to allocate one chunk more than necessary rather than trying to accomodate the NUL byte separately. Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- src/util/virbuffer.c | 19 ++++--------------- 1 file changed, 4 insertions(+), 15 deletions(-) diff --git a/src/util/virbuffer.c b/src/util/virbuffer.c index a2b5aa8508..bcf9042573 100644 --- a/src/util/virbuffer.c +++ b/src/util/virbuffer.c @@ -467,11 +467,7 @@ virBufferEscapeString(virBufferPtr buf, const char *fo= rmat, const char *str) return; } - if (xalloc_oversized(6, len) || - VIR_ALLOC_N_QUIET(escaped, 6 * len + 1) < 0) { - virBufferSetError(buf, errno); - return; - } + escaped =3D g_malloc0_n(len + 1, 6); cur =3D str; out =3D escaped; @@ -616,11 +612,7 @@ virBufferEscape(virBufferPtr buf, char escape, const c= har *toescape, return; } - if (xalloc_oversized(2, len) || - VIR_ALLOC_N_QUIET(escaped, 2 * len + 1) < 0) { - virBufferSetError(buf, errno); - return; - } + escaped =3D g_malloc0_n(len + 1, 2); cur =3D str; out =3D escaped; @@ -715,11 +707,8 @@ virBufferEscapeShell(virBufferPtr buf, const char *str) if (*str) { len =3D strlen(str); - if (xalloc_oversized(4, len) || - VIR_ALLOC_N_QUIET(escaped, 4 * len + 3) < 0) { - virBufferSetError(buf, errno); - return; - } + + escaped =3D g_malloc0_n(len + 1, 4); } else { virBufferAddLit(buf, "''"); return; --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri Apr 26 20:39:30 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 207.211.31.81 as permitted sender) client-ip=207.211.31.81; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zoho.com: domain of redhat.com designates 207.211.31.81 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=1571925484; cv=none; d=zoho.com; s=zohoarc; b=d90WKcj7JyfqQjZuoHc5M6pdpc+saM14JPT0h//5bIM6X4AXcIvJCZsnlKTgAvKR/X8OtiFqqQQPB95j5Sk2dhqrm8GkjZm9TJtjjuPvfdLLMrP4EAqpEuZMd+qw0bDPuvPBPpqeKyV7AdYg5Xgb9uL1QuSBB9ggCVI4DvPoQZc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1571925484; 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=v9bg8+qDpldwtAhXHCUEVGT4qndnN61/R5HOW6SJK0U=; b=g243o40xUzqYN/HaHBsAGcVbqmUwHlD3UcbDsRqhlseZqfvyEjqZ/tGws4cyVfmiFh1/Cr8L2bIG+z4JliuTUABO2UDpEVt9BD9rKRfeVrh/4/9ybAyoeqbvGQrQcL6qUsj2TM3tfJpNIEKBf09w5Ar0KSALEnudY+MfRAdAYgY= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=pass; spf=pass (zoho.com: domain of redhat.com designates 207.211.31.81 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-1.mimecast.com (207.211.31.81 [207.211.31.81]) by mx.zohomail.com with SMTPS id 1571925484169932.6361849333862; Thu, 24 Oct 2019 06:58:04 -0700 (PDT) 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-90-9o_csn4zPLiGyfoCOo96KQ-1; Thu, 24 Oct 2019 09:57:08 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id B2E451800E06; Thu, 24 Oct 2019 13:57:02 +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 8E7A35DA8D; Thu, 24 Oct 2019 13:57:02 +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 34BDF180BAA1; Thu, 24 Oct 2019 13:57:02 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x9ODukT0026308 for ; Thu, 24 Oct 2019 09:56:46 -0400 Received: by smtp.corp.redhat.com (Postfix) id 8E81A100164D; Thu, 24 Oct 2019 13:56:46 +0000 (UTC) Received: from angien.redhat.com (unknown [10.43.2.229]) by smtp.corp.redhat.com (Postfix) with ESMTP id 17E3F1001B33 for ; Thu, 24 Oct 2019 13:56:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1571925483; 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=v9bg8+qDpldwtAhXHCUEVGT4qndnN61/R5HOW6SJK0U=; b=MhYvWwm9YetAfItWizjjKMrVquJDrOxqYOoUNYf44xtkgwX7TZA4gayqbymcKWKV7D0Wqz +igw/nT+XQw3h1TQtgRUvgMYmYG5syDBtJWrO+bma25jWPJRk3kpKqw2AShLaQY8ivJrJh H5RIvl+tUNpW8Rv/VFfQaBtmgScwnRk= From: Peter Krempa To: libvir-list@redhat.com Date: Thu, 24 Oct 2019 15:56:22 +0200 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 04/19] virsh: Reimplement _vshCalloc using g_malloc0_n 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.14 X-MC-Unique: 9o_csn4zPLiGyfoCOo96KQ-1 X-Mimecast-Spam-Score: 0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" Drop the dead code by using glib's allocator. Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- tools/vsh.c | 12 ++---------- tools/vsh.h | 5 +---- 2 files changed, 3 insertions(+), 14 deletions(-) diff --git a/tools/vsh.c b/tools/vsh.c index 3f8b7f2186..58ee94b52f 100644 --- a/tools/vsh.c +++ b/tools/vsh.c @@ -129,17 +129,9 @@ _vshMalloc(vshControl *ctl, size_t size, const char *f= ilename, int line) } void * -_vshCalloc(vshControl *ctl, size_t nmemb, size_t size, const char *filenam= e, - int line) +vshCalloc(vshControl *ctl G_GNUC_UNUSED, size_t nmemb, size_t size) { - char *x; - - if (!xalloc_oversized(nmemb, size) && - VIR_ALLOC_N(x, nmemb * size) =3D=3D 0) - return x; - vshError(ctl, _("%s: %d: failed to allocate %d bytes"), - filename, line, (int) (size*nmemb)); - exit(EXIT_FAILURE); + return g_malloc0_n(nmemb, size); } int diff --git a/tools/vsh.h b/tools/vsh.h index ad783e24b7..b6ac070f10 100644 --- a/tools/vsh.h +++ b/tools/vsh.h @@ -468,10 +468,7 @@ char * vshReadline(vshControl *ctl, const char *prompt= ); void *_vshMalloc(vshControl *ctl, size_t sz, const char *filename, int lin= e); #define vshMalloc(_ctl, _sz) _vshMalloc(_ctl, _sz, __FILE__, __LINE__) -void *_vshCalloc(vshControl *ctl, size_t nmemb, size_t sz, - const char *filename, int line); -#define vshCalloc(_ctl, _nmemb, _sz) \ - _vshCalloc(_ctl, _nmemb, _sz, __FILE__, __LINE__) +void *vshCalloc(vshControl *ctl, size_t nmemb, size_t sz); /* Macros to help dealing with mutually exclusive options. */ --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri Apr 26 20:39:30 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 205.139.110.61 as permitted sender) client-ip=205.139.110.61; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zoho.com: domain of redhat.com designates 205.139.110.61 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=1571925434; cv=none; d=zoho.com; s=zohoarc; b=mdJAIhQmCi6ieB2YVUAKVz8NOs15kJm7zvodF2sfWRz0Pg1dn+rnaMXW2lsFVS4E3nNYRQfzNKcq9Awm2lgAO8x6n/u9PWWK26njyGFBokNfdPTQHbUWgfgJTVSTZvR0ls0lK/nZRzVIGtcguGFRC//9E8QQ9VALLUtZ1bmUiE0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1571925434; 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=EJTu1ED0TjwbC0OVJLK1p+urpPicv1k1awqhewFPPyQ=; b=eF/Q0XK6QPQWuCjbAL+Nfb6vzWriMBL8YQKnLDKEsBVegvF/WG4UY2OrJbjs/mBBDpKt0I3E+G+QQtJUmS37JAgl/TBz2vyjrWsGDEaJqvxbsTUFAqD6A3YzmvKtlNX4RJs7u17KD8E1XMM9+Fz3AqykFfgJ4a4TvCDGK5m6vUo= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=pass; spf=pass (zoho.com: domain of redhat.com designates 205.139.110.61 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-1.mimecast.com (us-smtp-1.mimecast.com [205.139.110.61]) by mx.zohomail.com with SMTPS id 1571925434192601.1165783736006; Thu, 24 Oct 2019 06:57:14 -0700 (PDT) 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-38-7ABBenSzOFyy6cONCV2img-1; Thu, 24 Oct 2019 09:57:11 -0400 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 409B2107AD31; Thu, 24 Oct 2019 13:57:06 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 1AB1210027C4; Thu, 24 Oct 2019 13:57:06 +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 CDA914EE69; Thu, 24 Oct 2019 13:57:05 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x9ODuniB026326 for ; Thu, 24 Oct 2019 09:56:49 -0400 Received: by smtp.corp.redhat.com (Postfix) id 4DD721001B33; Thu, 24 Oct 2019 13:56:49 +0000 (UTC) Received: from angien.redhat.com (unknown [10.43.2.229]) by smtp.corp.redhat.com (Postfix) with ESMTP id CAEA910027AB for ; Thu, 24 Oct 2019 13:56:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1571925433; 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=EJTu1ED0TjwbC0OVJLK1p+urpPicv1k1awqhewFPPyQ=; b=ALpfCqZf3fKPHDQ22bY6FZXIB4NqdyaR/7gr2QnUh/O9ojDbCezwZbpipxbCGuVvoal0rv +7/D3/bjvxW4y+afm53pIjpD/CyoaDdz/wd+VpwS9XZt5JtXU129bow71lt+4n29PKbYJu 0KsKGpY7+zDHVXowk2+YBMPbbZ+UU+E= From: Peter Krempa To: libvir-list@redhat.com Date: Thu, 24 Oct 2019 15:56:23 +0200 Message-Id: <9ff5a630ca0a92f2ac88cf4f0349e1f67942f986.1571925291.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 05/19] util: alloc: drop xalloc_oversized macro 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 X-MC-Unique: 7ABBenSzOFyy6cONCV2img-1 X-Mimecast-Spam-Score: 0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" We'we now got rid of all the uses. Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- src/util/viralloc.h | 19 ------------------- 1 file changed, 19 deletions(-) diff --git a/src/util/viralloc.h b/src/util/viralloc.h index d7862d6127..e6ad9984b7 100644 --- a/src/util/viralloc.h +++ b/src/util/viralloc.h @@ -33,25 +33,6 @@ * GLib array data types. See the hacking file for more guidance. */ -/* Return 1 if an array of N objects, each of size S, cannot exist due - to size arithmetic overflow. S must be positive and N must be - nonnegative. This is a macro, not an inline function, so that it - works correctly even when SIZE_MAX < N. - - By gnulib convention, SIZE_MAX represents overflow in size - calculations, so the conservative dividend to use here is - SIZE_MAX - 1, since SIZE_MAX might represent an overflowed value. - However, malloc (SIZE_MAX) fails on all known hosts where - sizeof(ptrdiff_t) <=3D sizeof(size_t), so do not bother to test for - exactly-SIZE_MAX allocations on such hosts; this avoids a test and - branch when S is known to be 1. */ -#ifndef xalloc_oversized -# define xalloc_oversized(n, s) \ - ((size_t) (sizeof(ptrdiff_t) <=3D sizeof(size_t) ? -1 : -2) / (s) < (n= )) -#endif - - - /* Don't call these directly - use the macros below */ int virAlloc(void *ptrptr, size_t size) G_GNUC_WARN_UNUSED_RESULT ATTRIBUTE_NONNULL(1); --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri Apr 26 20:39:30 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 205.139.110.61 as permitted sender) client-ip=205.139.110.61; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zoho.com: domain of redhat.com designates 205.139.110.61 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=1571925439; cv=none; d=zoho.com; s=zohoarc; b=dUGbKxeBpBIvaQ9QB7Uhq8UzoGQahT7RPwATURuOjnh2h84LQ5lS8yOgdJf95FCARMIJ+UBw3vvTRsUTTwbIHu9sqm9Op1wNa8P/Km682PqEXflGzjFTHRY3TnIciE/WI3vGvn8/imOpqV7IOGNr5/vlzOZvyhjfpj8CIMsIwsk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1571925439; 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=vyDHHU5l5ZXwY6azBcZ7OCuSqLuAsgmmYAUcGvACP20=; b=WzsIge9rJZZyN4Asfw05JFZYLiNKsV73T0HEF/b9Dohyx259DO2B1rbnNNH2GacsJAEfMgKgO27IyFMBjBJchBhoPxIsuG0QNUapYhX7+i06Qyd6HPYGa8hwIomCVBfyaOpxMuO0XtfkZVnEN4TXNBVdNqgwXKpKeYpWEUiv7Ew= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=pass; spf=pass (zoho.com: domain of redhat.com designates 205.139.110.61 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-1.mimecast.com (us-smtp-1.mimecast.com [205.139.110.61]) by mx.zohomail.com with SMTPS id 1571925439348613.4107359182598; Thu, 24 Oct 2019 06:57:19 -0700 (PDT) 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-62-uGAu-YYFO9SsDJ7AWoraIA-1; Thu, 24 Oct 2019 09:57:16 -0400 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 C7464107AD38; Thu, 24 Oct 2019 13:57:09 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 9FA55100EBA2; Thu, 24 Oct 2019 13:57:09 +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 611574EE7E; Thu, 24 Oct 2019 13:57:09 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x9ODuoWZ026335 for ; Thu, 24 Oct 2019 09:56:50 -0400 Received: by smtp.corp.redhat.com (Postfix) id 2107910027A9; Thu, 24 Oct 2019 13:56:50 +0000 (UTC) Received: from angien.redhat.com (unknown [10.43.2.229]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9EE201000232 for ; Thu, 24 Oct 2019 13:56:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1571925438; 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=vyDHHU5l5ZXwY6azBcZ7OCuSqLuAsgmmYAUcGvACP20=; b=ilgAJfIZ8+JCggGgY+NQJtmerHP8KiW2ICFMhH6aIyyYLqD9GZbFPsAqXYwQOY/+F43Tf5 ovhxJ+FkrTRe2SFiXkXZOZBJ8wPUyr/gWj37YSnXQEYV3+OMSOLuHzxXXzklCVWLMNoAo7 6ZzognDDBBgRLoe2iotbD4o2J28TDxA= From: Peter Krempa To: libvir-list@redhat.com Date: Thu, 24 Oct 2019 15:56:24 +0200 Message-Id: <807b4a22306400657bac09af186e3045b2cf4098.1571925291.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 06/19] util: buffer: Don't treat missing truncation in virBufferTrim as usage error 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 X-MC-Unique: uGAu-YYFO9SsDJ7AWoraIA-1 X-Mimecast-Spam-Score: 0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" Usage errors in the virBuffer are hard to track anyways. Just trim noting if the user requests the trimming string to be used without providing it. The change in the test proves that it's a noop now. Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- src/util/virbuffer.c | 6 +----- tests/virbuftest.c | 7 +------ 2 files changed, 2 insertions(+), 11 deletions(-) diff --git a/src/util/virbuffer.c b/src/util/virbuffer.c index bcf9042573..9a74ca78bb 100644 --- a/src/util/virbuffer.c +++ b/src/util/virbuffer.c @@ -784,8 +784,6 @@ virBufferStrcat(virBufferPtr buf, ...) * if the current tail of the buffer matches @str; a non-negative @len * further limits how much of the tail is trimmed. If @str is NULL, then * @len must be non-negative. - * - * Sets error to -1 (usage) if str is NULL and len is less than zero. */ void virBufferTrim(virBufferPtr buf, const char *str, int len) @@ -794,10 +792,8 @@ virBufferTrim(virBufferPtr buf, const char *str, int l= en) if (!buf || buf->error) return; - if (!str && len < 0) { - virBufferSetError(buf, -1); + if (!str && len < 0) return; - } if (len > 0 && len > buf->use) return; diff --git a/tests/virbuftest.c b/tests/virbuftest.c index 385f016174..8b8754adfa 100644 --- a/tests/virbuftest.c +++ b/tests/virbuftest.c @@ -163,6 +163,7 @@ static int testBufTrim(const void *data G_GNUC_UNUSED) virBufferTrim(buf, "a", 2); virBufferAddLit(buf, ",b,,"); + virBufferTrim(buf, NULL, -1); virBufferTrim(buf, "b", -1); virBufferTrim(buf, "b,,", 1); virBufferTrim(buf, ",", -1); @@ -178,12 +179,6 @@ static int testBufTrim(const void *data G_GNUC_UNUSED) goto cleanup; } - virBufferTrim(buf, NULL, -1); - if (virBufferError(buf) !=3D -1) { - VIR_TEST_DEBUG("Usage error not flagged"); - goto cleanup; - } - ret =3D 0; cleanup: --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri Apr 26 20:39:30 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 205.139.110.120 as permitted sender) client-ip=205.139.110.120; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zoho.com: domain of redhat.com designates 205.139.110.120 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=1571925441; cv=none; d=zoho.com; s=zohoarc; b=K+L0HKzhsnnLRBvbm2TJU+D8E0zCU4keOg6udhgvlL/aBnka+rAa0hM6vDd2OTdDdtdwQzH31xMsMSasqIb13F4PhT1P26qDjfAMdVn7zMGC1jrhi0Gf/z93EBvaZDxFbGHun85MMfBkyg0+5DcfN6Of2U2lc5hICuDLrtep6gs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1571925441; 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=p8DbW9llQSduA/OLHTT7BFTFr4IGvePk3EI/A5it0pA=; b=amCzqHSJnNEIXrki8Kyk22okigtnZ1TTPQjVQmq0B5vEc0cg1CfA2WoQbrc8d97Kdm+NwKJsrrFMutla9GVM4bshNIdA6kN1tCvTE7KytJvXfHKTsMYbA6pC2D8NcqcVjbX98igB+Dn9BLamdSoI6fju6jzX06U1bFnYG22UYSk= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=pass; spf=pass (zoho.com: domain of redhat.com designates 205.139.110.120 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-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) by mx.zohomail.com with SMTPS id 157192544182041.648890016310474; Thu, 24 Oct 2019 06:57:21 -0700 (PDT) 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-358-pgCjU0WJNUuEur285upgbg-1; Thu, 24 Oct 2019 09:57:19 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 6C4CA100551D; Thu, 24 Oct 2019 13:57:13 +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 4441260C80; Thu, 24 Oct 2019 13:57:13 +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 01FCF1803B4C; Thu, 24 Oct 2019 13:57:12 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x9ODuohK026345 for ; Thu, 24 Oct 2019 09:56:50 -0400 Received: by smtp.corp.redhat.com (Postfix) id E53811000232; Thu, 24 Oct 2019 13:56:50 +0000 (UTC) Received: from angien.redhat.com (unknown [10.43.2.229]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6F2BB10027A9 for ; Thu, 24 Oct 2019 13:56:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1571925440; 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=p8DbW9llQSduA/OLHTT7BFTFr4IGvePk3EI/A5it0pA=; b=iIIkapBAmmRzCLZKaoNiulh2Bq+BZ6YXTDu6DUUyxyJNlaf6GvuLVbty53XEBtDDbJ4xk5 gjtuuFC69eFZkUBH+xrpKt6eEx7RzjxtdZ3hEqBOyBP1wT60Q4PX3YOz5VjNOkiVfwVOpZ V2I/V14iKtaK/tC/2+z7pwuW9e9Sewc= From: Peter Krempa To: libvir-list@redhat.com Date: Thu, 24 Oct 2019 15:56:25 +0200 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 07/19] util: buffer: Simplify handling of indent overflows 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.12 X-MC-Unique: pgCjU0WJNUuEur285upgbg-1 X-Mimecast-Spam-Score: 0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" Rather than setting usage error truncate the indentation level. Having the output string misformated is way more useful to figure out where the error lies rather than reporting an error after a giant formatter function. In testBufAutoIndent we now validate that the indentation is truncated and testBufAddBuffer2 is removed since it became bogus. Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- src/util/virbuffer.c | 8 ++++---- tests/virbuftest.c | 35 ++++------------------------------- 2 files changed, 8 insertions(+), 35 deletions(-) diff --git a/src/util/virbuffer.c b/src/util/virbuffer.c index 9a74ca78bb..69fcf946f5 100644 --- a/src/util/virbuffer.c +++ b/src/util/virbuffer.c @@ -56,8 +56,8 @@ virBufferSetError(virBufferPtr buf, int error) * negative to decrease). Automatic indentation is performed by all * additive functions when the existing buffer is empty or ends with a * newline (however, note that no indentation is added after newlines - * embedded in an appended string). If @indent would cause overflow, - * the buffer error indicator is set. + * embedded in an appended string). If @indent would cause overflow, the + * indentation level is truncated. */ void virBufferAdjustIndent(virBufferPtr buf, int indent) @@ -67,12 +67,12 @@ virBufferAdjustIndent(virBufferPtr buf, int indent) if (indent > 0) { if (INT_MAX - indent < buf->indent) { - virBufferSetError(buf, -1); + buf->indent =3D INT_MAX; return; } } else { if (buf->indent < -indent) { - virBufferSetError(buf, -1); + buf->indent =3D 0; return; } } diff --git a/tests/virbuftest.c b/tests/virbuftest.c index 8b8754adfa..246c572bd2 100644 --- a/tests/virbuftest.c +++ b/tests/virbuftest.c @@ -85,12 +85,12 @@ static int testBufAutoIndent(const void *data G_GNUC_UN= USED) ret =3D -1; } virBufferAdjustIndent(buf, -3); - if (virBufferGetIndent(buf, false) !=3D -1 || - virBufferGetIndent(buf, true) !=3D -1 || - virBufferError(buf) !=3D -1) { - VIR_TEST_DEBUG("Usage error not flagged"); + if (virBufferGetIndent(buf, false) !=3D 0 || + virBufferGetIndent(buf, true) !=3D 0) { + VIR_TEST_DEBUG("Indentation level not truncated"); ret =3D -1; } + virBufferAdjustIndent(buf, 3); virBufferFreeAndReset(buf); if (virBufferGetIndent(buf, false) !=3D 0 || virBufferGetIndent(buf, true) !=3D 0 || @@ -298,32 +298,6 @@ static int testBufAddBuffer(const void *data G_GNUC_UN= USED) return ret; } -static int -testBufAddBuffer2(const void *opaque G_GNUC_UNUSED) -{ - g_auto(virBuffer) buf1 =3D VIR_BUFFER_INITIALIZER; - g_auto(virBuffer) buf2 =3D VIR_BUFFER_INITIALIZER; - - /* Intent of this test is to demonstrate a memleak that happen with - * virBufferAddBuffer */ - - virBufferAddLit(&buf1, "Hello world!\n"); - virBufferAddLit(&buf2, "Hello world!\n"); - - /* Intentional usage error */ - virBufferAdjustIndent(&buf2, -2); - - virBufferAddBuffer(&buf1, &buf2); - - if (virBufferCurrentContent(&buf1) || - !virBufferCurrentContent(&buf2)) { - VIR_TEST_DEBUG("Unexpected buffer content"); - return -1; - } - - return 0; -} - struct testBufAddStrData { const char *data; const char *expect; @@ -481,7 +455,6 @@ mymain(void) DO_TEST("Auto-indentation", testBufAutoIndent, 0); DO_TEST("Trim", testBufTrim, 0); DO_TEST("AddBuffer", testBufAddBuffer, 0); - DO_TEST("AddBuffer2", testBufAddBuffer2, 0); DO_TEST("set indent", testBufSetIndent, 0); DO_TEST("autoclean", testBufferAutoclean, 0); --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri Apr 26 20:39:30 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 205.139.110.120 as permitted sender) client-ip=205.139.110.120; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zoho.com: domain of redhat.com designates 205.139.110.120 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=1571925427; cv=none; d=zoho.com; s=zohoarc; b=IrU5cx9hnmdthzd+qmk/hHcg5jeovvxc+Ue65vk9ous9EBMsxZMPcXMama91qtKTwfLHPXQPdNWleMH4QyM3iI6CJqH7G3hFuWKoy1Sdrr5p2ZA21Uscpdu7wEb9a1NzmdHN/TtrCW9P9xnvbmrudR4//ZbhXJtVERAT9oF15+s= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1571925427; 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=HiY3pK72Ny+ntUyLJ5JlHNOfs3jVw19aovt3Lq0/AR0=; b=l6/Dykp9/a4ISPPRfqg7Cojxv/RgSfT1s1PSr0eJesbSwLgbTy4UFpHYjqgir1zWq+9zzIB2Yg6jiW7emcox9QI15KI60phk/NFKxKF9mYDlndBA0pjlCckcisNWQ1MuD3OmkMr5p/fxjxfxHNOhcuwsZLcIjlkM58MKsEObmZ8= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=pass; spf=pass (zoho.com: domain of redhat.com designates 205.139.110.120 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-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) by mx.zohomail.com with SMTPS id 1571925427318308.0491710046455; Thu, 24 Oct 2019 06:57:07 -0700 (PDT) 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-194-u-jzUtWCMoW1Pi9jK7D7Ig-1; Thu, 24 Oct 2019 09:57:02 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 59FA7100551E; Thu, 24 Oct 2019 13:56:56 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 341695DA8D; Thu, 24 Oct 2019 13:56:56 +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 EC69C4E58C; Thu, 24 Oct 2019 13:56:55 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x9ODus1L026364 for ; Thu, 24 Oct 2019 09:56:54 -0400 Received: by smtp.corp.redhat.com (Postfix) id 06FB010098FB; Thu, 24 Oct 2019 13:56:54 +0000 (UTC) Received: from angien.redhat.com (unknown [10.43.2.229]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8411110027A9 for ; Thu, 24 Oct 2019 13:56:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1571925426; 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=HiY3pK72Ny+ntUyLJ5JlHNOfs3jVw19aovt3Lq0/AR0=; b=hcyZInx/c3XCLkZQqooAqUgvhZ2n9OzsK4AEspsYZgE6uIqAwMQmVXzbXPN+ZXqT1zNIUv F4u1RKNJL8TA2oLX0eJOhKgocrwvOL8CHkqmD9uOOcKd1eyLpx86l4sQInTw4IZ+2LdQ+2 xLMX6ch8OPllTxoPS4smHy9PEP1ZYkI= From: Peter Krempa To: libvir-list@redhat.com Date: Thu, 24 Oct 2019 15:56:26 +0200 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 08/19] tests: virbuffer: Drop 'infinite loop' tests 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.14 X-MC-Unique: u-jzUtWCMoW1Pi9jK7D7Ig-1 X-Mimecast-Spam-Score: 0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" The tests are deeply based on internals of virBuffer which will be replaced in an upcoming patch with glib's GString. Remove the tests. Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- tests/virbuftest.c | 41 ----------------------------------------- 1 file changed, 41 deletions(-) diff --git a/tests/virbuftest.c b/tests/virbuftest.c index 246c572bd2..21b6295bb3 100644 --- a/tests/virbuftest.c +++ b/tests/virbuftest.c @@ -13,45 +13,6 @@ struct testInfo { int doEscape; }; -static int testBufInfiniteLoop(const void *data) -{ - virBuffer bufinit =3D VIR_BUFFER_INITIALIZER; - virBufferPtr buf =3D &bufinit; - char *addstr =3D NULL, *bufret =3D NULL; - int ret =3D -1; - const struct testInfo *info =3D data; - int len; - - virBufferAddChar(buf, 'a'); - - /* - * Infinite loop used to trigger if: - * (strlen + 1 > 1000) && (strlen =3D=3D buf-size - buf-use - 1) - * 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. - */ - len =3D buf->size - buf->use - 1; - if (virAsprintf(&addstr, "%*s", len, "a") < 0) - goto out; - - if (info->doEscape) - virBufferEscapeString(buf, "%s", addstr); - else - virBufferAsprintf(buf, "%s", addstr); - - ret =3D 0; - out: - bufret =3D virBufferContentAndReset(buf); - if (!bufret) { - VIR_TEST_DEBUG("Buffer had error set"); - ret =3D -1; - } - - VIR_FREE(addstr); - VIR_FREE(bufret); - return ret; -} - static int testBufAutoIndent(const void *data G_GNUC_UNUSED) { virBuffer bufinit =3D VIR_BUFFER_INITIALIZER; @@ -450,8 +411,6 @@ mymain(void) ret =3D -1; \ } while (0) - DO_TEST("EscapeString infinite loop", testBufInfiniteLoop, 1); - DO_TEST("VSprintf infinite loop", testBufInfiniteLoop, 0); DO_TEST("Auto-indentation", testBufAutoIndent, 0); DO_TEST("Trim", testBufTrim, 0); DO_TEST("AddBuffer", testBufAddBuffer, 0); --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri Apr 26 20:39:30 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 205.139.110.61 as permitted sender) client-ip=205.139.110.61; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zoho.com: domain of redhat.com designates 205.139.110.61 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=1571925485; cv=none; d=zoho.com; s=zohoarc; b=GCxGlXQxn5MnKx8gQtAlR/Fnx2yzdkyAcek9dUVFAqG1f5GxwM9JpdNEPzV84hrK5k15PSR0fZQRP1mVHW8JQ50xknaQnZh1f6CgUQX0M11W766lcPGEQFgjSDKXFBQbhUYy1sEsg/N7t7cpDRN70pVTUVLs6X3XDx2UnwkbRmM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1571925485; 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=4rGKeXDcjRY85+qMie0IncVil8h8qwvCLtnRvhHdas0=; b=ljUDNoob3KOeGUs9GIu+wBN4vTl2MOuIOL6URaKoZU1rmfNDEhiHwmbJtsev1twGPd1UjP7mmsYhi3Jp2wh1IxQS5Vdy8PR6EWdRIvuVAM7QQM87t5eWUCYPccRLUZGols6OIgrQ9JoN4FQy1gfvleJLbmfF1jOgnw/5wKEzTlI= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=pass; spf=pass (zoho.com: domain of redhat.com designates 205.139.110.61 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-1.mimecast.com (us-smtp-1.mimecast.com [205.139.110.61]) by mx.zohomail.com with SMTPS id 1571925485773676.6329256529227; Thu, 24 Oct 2019 06:58:05 -0700 (PDT) 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-166-s4uz5CxNPjq6MbqW7VHzwg-1; Thu, 24 Oct 2019 09:57:10 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 5C261800D5A; Thu, 24 Oct 2019 13:57:04 +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 36C805DD7A; Thu, 24 Oct 2019 13:57:04 +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 E1AAB180BAA2; Thu, 24 Oct 2019 13:57:03 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x9ODv2dK026383 for ; Thu, 24 Oct 2019 09:57:02 -0400 Received: by smtp.corp.redhat.com (Postfix) id E171110027A9; Thu, 24 Oct 2019 13:57:02 +0000 (UTC) Received: from angien.redhat.com (unknown [10.43.2.229]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6AB8C1001B33 for ; Thu, 24 Oct 2019 13:56:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1571925484; 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=4rGKeXDcjRY85+qMie0IncVil8h8qwvCLtnRvhHdas0=; b=dEUB6Gboo1odGKBp8M+gNHYBqIYUsxszA8Eeq0zP0F8SH0z/OTEMI5l7iTcQG1A3AAkl6M RAhtlOCT1ndNXeDKH3LxCDQWKdHVMYXcKqVq4myD+CEhR0cmsKBhFwX9DyoIb339l3atDy xogSblUGVGL08xhPCc/4FBQeK3UKb4U= From: Peter Krempa To: libvir-list@redhat.com Date: Thu, 24 Oct 2019 15:56:27 +0200 Message-Id: <588b8e2ff4e271cd16f6ed01d39a89152e8bf9f7.1571925291.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 09/19] tests: virbuffer: Remove unused test data struct 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.14 X-MC-Unique: s4uz5CxNPjq6MbqW7VHzwg-1 X-Mimecast-Spam-Score: 0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" The DO_TEST macro initializes 'struct testInfo' but it's not used by any of the tests. Remove it. Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- tests/virbuftest.c | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/tests/virbuftest.c b/tests/virbuftest.c index 21b6295bb3..064b3e96b4 100644 --- a/tests/virbuftest.c +++ b/tests/virbuftest.c @@ -9,10 +9,6 @@ #define VIR_FROM_THIS VIR_FROM_NONE -struct testInfo { - int doEscape; -}; - static int testBufAutoIndent(const void *data G_GNUC_UNUSED) { virBuffer bufinit =3D VIR_BUFFER_INITIALIZER; @@ -404,18 +400,17 @@ mymain(void) int ret =3D 0; -#define DO_TEST(msg, cb, data) \ +#define DO_TEST(msg, cb) \ do { \ - struct testInfo info =3D { data }; \ - if (virTestRun("Buf: " msg, cb, &info) < 0) \ + if (virTestRun("Buf: " msg, cb, NULL) < 0) \ ret =3D -1; \ } while (0) - DO_TEST("Auto-indentation", testBufAutoIndent, 0); - DO_TEST("Trim", testBufTrim, 0); - DO_TEST("AddBuffer", testBufAddBuffer, 0); - DO_TEST("set indent", testBufSetIndent, 0); - DO_TEST("autoclean", testBufferAutoclean, 0); + DO_TEST("Auto-indentation", testBufAutoIndent); + DO_TEST("Trim", testBufTrim); + DO_TEST("AddBuffer", testBufAddBuffer); + DO_TEST("set indent", testBufSetIndent); + DO_TEST("autoclean", testBufferAutoclean); #define DO_TEST_ADD_STR(DATA, EXPECT) \ do { \ --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri Apr 26 20:39:30 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 205.139.110.61 as permitted sender) client-ip=205.139.110.61; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zoho.com: domain of redhat.com designates 205.139.110.61 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=1571925487; cv=none; d=zoho.com; s=zohoarc; b=dRFvhxFkUpqrm4bGCwcSBbhmi9h022l/Fs3UlmaGL2jopud/yjUoA8LXXFl8YpGJcekc0twAsuTKDyo+LMi8rBuN7sI/zWK2ajtMSkie3AMeU5gfTgwFgCUSUZoIXx5aQGH2GciSVPghFsmQ/Lb9gNovaJSKMgyWwtlkjha8Qwk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1571925487; 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=gn3oZZ6D0RWe7ZLU9tWbgfUxaJsiepbchx7OG0+t6/I=; b=MGJQr9BF0mvuTNrvk051d+jSWLvsh+KkXCUPhJAolkusJ8nPwIQJp9IbWug09fRkAYDdqG2mv1WJ6MaXWO8BtoyXaDoQ7FDqcJLbkokufrhNhANi5eZqVoDR846TeJHa4zePKQfOV+PjitkwcVc3OLRBaGBtbOP+72A9l+Pzork= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=pass; spf=pass (zoho.com: domain of redhat.com designates 205.139.110.61 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-1.mimecast.com (us-smtp-1.mimecast.com [205.139.110.61]) by mx.zohomail.com with SMTPS id 1571925487227423.17467990541206; Thu, 24 Oct 2019 06:58:07 -0700 (PDT) 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-386-5EBW2fmKNUmiOceuxZzmzw-1; Thu, 24 Oct 2019 09:57:13 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 5EF561005500; Thu, 24 Oct 2019 13:57:08 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 38B7B1F3; Thu, 24 Oct 2019 13:57:08 +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 EE3694EE71; Thu, 24 Oct 2019 13:57:07 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x9ODv3Uv026392 for ; Thu, 24 Oct 2019 09:57:03 -0400 Received: by smtp.corp.redhat.com (Postfix) id B11BB100164D; Thu, 24 Oct 2019 13:57:03 +0000 (UTC) Received: from angien.redhat.com (unknown [10.43.2.229]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3A787100EBA5 for ; Thu, 24 Oct 2019 13:57:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1571925486; 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=gn3oZZ6D0RWe7ZLU9tWbgfUxaJsiepbchx7OG0+t6/I=; b=IFtVnt+kO2Pp0j7BEF66Ew0qd48OlRY+bs/twXhTTecGyO7Kt2wNdH7fjOmnlnutkS60HG Qvx/iRxPSPLHqGtqUWCQqKsqq2NbHTZUf0A/xLvp182RHw+XERPBERmXTPtuO+v0mDaZrK N3O/vE8iNdGUpDauEfWerb0N2YenTog= From: Peter Krempa To: libvir-list@redhat.com Date: Thu, 24 Oct 2019 15:56:28 +0200 Message-Id: <681a5d74e2be15254f27bd28eb6664454cd235b1.1571925291.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 10/19] util: buffer: Split getting of effective indent out of virBufferGetIndent 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.14 X-MC-Unique: 5EBW2fmKNUmiOceuxZzmzw-1 X-Mimecast-Spam-Score: 0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" The function basically does two very distinct things depending on a bool. As a first step of conversion split out the case when @dynamic is true and implement it as a new function and convert all callers. Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- src/libvirt_private.syms | 1 + src/util/virbuffer.c | 26 +++++++++++++++++++++----- src/util/virbuffer.h | 1 + tests/virbuftest.c | 12 ++++++------ 4 files changed, 29 insertions(+), 11 deletions(-) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 12cb3b5bf7..94c2e4ef6a 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -1600,6 +1600,7 @@ virBufferEscapeShell; virBufferEscapeSQL; virBufferEscapeString; virBufferFreeAndReset; +virBufferGetEffectiveIndent; virBufferGetIndent; virBufferSetIndent; virBufferStrcat; diff --git a/src/util/virbuffer.c b/src/util/virbuffer.c index 69fcf946f5..0d2721b118 100644 --- a/src/util/virbuffer.c +++ b/src/util/virbuffer.c @@ -117,6 +117,24 @@ virBufferGetIndent(const virBuffer *buf, bool dynamic) return buf->indent; } + +/** + * virBufferGetEffectiveIndent: + * @buf: the buffer + * + * Returns the number of spaces that need to be appended to @buf to honour + * auto-indentation. + */ +size_t +virBufferGetEffectiveIndent(const virBuffer *buf) +{ + if (buf->use && buf->content[buf->use - 1] !=3D '\n') + return 0; + + return buf->indent; +} + + /** * virBufferGrow: * @buf: the buffer @@ -161,14 +179,12 @@ void virBufferAdd(virBufferPtr buf, const char *str, int len) { unsigned int needSize; - int indent; + size_t indent; - if (!str || !buf || (len =3D=3D 0 && buf->indent =3D=3D 0)) + if (!str || !buf || buf->error || (len =3D=3D 0 && buf->indent =3D=3D = 0)) return; - indent =3D virBufferGetIndent(buf, true); - if (indent < 0) - return; + indent =3D virBufferGetEffectiveIndent(buf); if (len < 0) len =3D strlen(str); diff --git a/src/util/virbuffer.h b/src/util/virbuffer.h index ff24ab1019..7156d9d0d8 100644 --- a/src/util/virbuffer.h +++ b/src/util/virbuffer.h @@ -110,6 +110,7 @@ void virBufferSetIndent(virBufferPtr, int indent); virBufferSetIndent(childBuf_, virBufferGetIndent(parentBuf_, false) + = 2) int virBufferGetIndent(const virBuffer *buf, bool dynamic); +size_t virBufferGetEffectiveIndent(const virBuffer *buf); void virBufferTrim(virBufferPtr buf, const char *trim, int len); void virBufferAddStr(virBufferPtr buf, const char *str); diff --git a/tests/virbuftest.c b/tests/virbuftest.c index 064b3e96b4..0c806908e1 100644 --- a/tests/virbuftest.c +++ b/tests/virbuftest.c @@ -19,7 +19,7 @@ static int testBufAutoIndent(const void *data G_GNUC_UNUS= ED) int ret =3D 0; if (virBufferGetIndent(buf, false) !=3D 0 || - virBufferGetIndent(buf, true) !=3D 0) { + virBufferGetEffectiveIndent(buf) !=3D 0) { VIR_TEST_DEBUG("Wrong indentation"); ret =3D -1; } @@ -29,28 +29,28 @@ static int testBufAutoIndent(const void *data G_GNUC_UN= USED) ret =3D -1; } if (virBufferGetIndent(buf, false) !=3D 3 || - virBufferGetIndent(buf, true) !=3D 3 || + virBufferGetEffectiveIndent(buf) !=3D 3 || virBufferError(buf)) { VIR_TEST_DEBUG("Wrong indentation"); ret =3D -1; } virBufferAdjustIndent(buf, -2); if (virBufferGetIndent(buf, false) !=3D 1 || - virBufferGetIndent(buf, true) !=3D 1 || + virBufferGetEffectiveIndent(buf) !=3D 1 || virBufferError(buf)) { VIR_TEST_DEBUG("Wrong indentation"); ret =3D -1; } virBufferAdjustIndent(buf, -3); if (virBufferGetIndent(buf, false) !=3D 0 || - virBufferGetIndent(buf, true) !=3D 0) { + virBufferGetEffectiveIndent(buf) !=3D 0) { VIR_TEST_DEBUG("Indentation level not truncated"); ret =3D -1; } virBufferAdjustIndent(buf, 3); virBufferFreeAndReset(buf); if (virBufferGetIndent(buf, false) !=3D 0 || - virBufferGetIndent(buf, true) !=3D 0 || + virBufferGetEffectiveIndent(buf) !=3D 0 || virBufferError(buf)) { VIR_TEST_DEBUG("Reset didn't clear indentation"); ret =3D -1; @@ -66,7 +66,7 @@ static int testBufAutoIndent(const void *data G_GNUC_UNUS= ED) ret =3D -1; } if (virBufferGetIndent(buf, false) !=3D 2 || - virBufferGetIndent(buf, true) !=3D 0) { + virBufferGetEffectiveIndent(buf) !=3D 0) { VIR_TEST_DEBUG("Wrong indentation"); ret =3D -1; } --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri Apr 26 20:39:30 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 205.139.110.120 as permitted sender) client-ip=205.139.110.120; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zoho.com: domain of redhat.com designates 205.139.110.120 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=1571925440; cv=none; d=zoho.com; s=zohoarc; b=YuP8VHzC9dVCVm2nUSk2CDY29NiOf4gHoRLMMf0li5667610Id1IkxUnfVZsZ9+Cui3XoiDi/whbNsCYHXMJo21bwyTRuRbeUdn7vrmoxJTLQp/+L+wogl5bLpt5Df/vHw572qdHkVfNhHaL7s/ryrEws3Rm5R6Ib7VV+A5RcMA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1571925440; 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=UOdScD7rrFQqgNIZxE3VjD7L9EBDpJtkCGKnPHuEXFY=; b=hCx38snpsqWKwJs2Qf10BaEQC3oUb2i93vX9qfb3nTGO4OYzHwgw0g9/U4Yi2S2fvOkjg3MhcbPQJ1rkdFa8wlF58K5A/DCGhpk81UQCoyejFb3TIossMhzb9xsAKd6sW1DI6FoSUhkB6HOquOHndL77zTDWxHAL7h9SJhPuaKE= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=pass; spf=pass (zoho.com: domain of redhat.com designates 205.139.110.120 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-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) by mx.zohomail.com with SMTPS id 1571925440294308.4389540347846; Thu, 24 Oct 2019 06:57:20 -0700 (PDT) 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-48-KbU5bS8iMaa8NmBArBORjg-1; Thu, 24 Oct 2019 09:57:17 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id D6A5B801E78; Thu, 24 Oct 2019 13:57:11 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id A5EC5194B6; Thu, 24 Oct 2019 13:57:11 +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 5F8724EE97; Thu, 24 Oct 2019 13:57:11 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x9ODv420026400 for ; Thu, 24 Oct 2019 09:57:04 -0400 Received: by smtp.corp.redhat.com (Postfix) id 8129610027AB; Thu, 24 Oct 2019 13:57:04 +0000 (UTC) Received: from angien.redhat.com (unknown [10.43.2.229]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0B0A7100164D for ; Thu, 24 Oct 2019 13:57:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1571925439; 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=UOdScD7rrFQqgNIZxE3VjD7L9EBDpJtkCGKnPHuEXFY=; b=SigDNJ/U9oMGicrm94+43MSmt1zCWrgMjCsaL7waLRy6A9hBeifdgq7VsTFPPf7VcZ150u j5X/aIcOoZ2wfSFrQ063XbSVBB/Zn3v9WVBQLTHW5Hj/nRbyAwsiJ7EDrRt6Nzpu3f/JJT Udksh+nuNQujsf3jVT3k46P16ZANbps= From: Peter Krempa To: libvir-list@redhat.com Date: Thu, 24 Oct 2019 15:56:29 +0200 Message-Id: <638f873f1aab3de23ec5169b65d598ad0a6427b3.1571925291.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 11/19] util: sysinfo: Use virXMLFormatElement and infrastructure in virSysinfoFormat 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.23 X-MC-Unique: KbU5bS8iMaa8NmBArBORjg-1 X-Mimecast-Spam-Score: 0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" It basically implements almost the same thing, so we can replace it with existing helpers with a few tweaks. Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- src/util/virsysinfo.c | 26 ++++++++++---------------- 1 file changed, 10 insertions(+), 16 deletions(-) diff --git a/src/util/virsysinfo.c b/src/util/virsysinfo.c index 0a622dbbf9..6e7e221f00 100644 --- a/src/util/virsysinfo.c +++ b/src/util/virsysinfo.c @@ -1481,20 +1481,19 @@ virSysinfoOEMStringsFormat(virBufferPtr buf, virSys= infoOEMStringsDefPtr def) int virSysinfoFormat(virBufferPtr buf, virSysinfoDefPtr def) { + virBuffer attrBuf =3D VIR_BUFFER_INITIALIZER; virBuffer childrenBuf =3D VIR_BUFFER_INITIALIZER; const char *type =3D virSysinfoTypeToString(def->type); - int indent =3D virBufferGetIndent(buf, false); - int ret =3D -1; if (!type) { virReportError(VIR_ERR_INTERNAL_ERROR, _("unexpected sysinfo type model %d"), def->type); virBufferFreeAndReset(buf); - goto cleanup; + return -1; } - virBufferAdjustIndent(&childrenBuf, indent + 2); + virBufferSetChildIndent(&childrenBuf, buf); virSysinfoBIOSFormat(&childrenBuf, def->bios); virSysinfoSystemFormat(&childrenBuf, def->system); @@ -1504,22 +1503,17 @@ virSysinfoFormat(virBufferPtr buf, virSysinfoDefPtr= def) virSysinfoMemoryFormat(&childrenBuf, def); virSysinfoOEMStringsFormat(&childrenBuf, def->oemStrings); - virBufferAsprintf(buf, "\n"); - virBufferAddBuffer(buf, &childrenBuf); - virBufferAddLit(buf, "\n"); - } else { - virBufferAddLit(buf, "/>\n"); + virBufferAsprintf(&attrBuf, " type=3D'%s'", type); + + if (virXMLFormatElement(buf, "sysinfo", &attrBuf, &childrenBuf) < 0) { + virBufferFreeAndReset(buf); + return -1; } if (virBufferCheckError(buf) < 0) - goto cleanup; + return -1; - ret =3D 0; - cleanup: - virBufferFreeAndReset(&childrenBuf); - return ret; + return 0; } #define CHECK_FIELD(name, desc) \ --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri Apr 26 20:39:30 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 205.139.110.120 as permitted sender) client-ip=205.139.110.120; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zoho.com: domain of redhat.com designates 205.139.110.120 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=1571925442; cv=none; d=zoho.com; s=zohoarc; b=C4tdp6D4JFvp+zrLb7Bhj95oCIpuOhh0LZFYEPL+Qyfn/KaTseJOa8t57v+zKCbELunU7T2XSmzNy8JoSunU1xpRmasZtGc/W5EriVgPoO/32+xOo2LHmGCAU1m96zYdJp21cZioDfbj0ieaiJf3c2S61lnepACsdF8mfbI7WRQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1571925442; 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=qvoM+M4wbpZJ3hh6kcaOU1V5e8te3m+N8yCpHMEbXJ4=; b=BY3NFQPzMpo0/df9yXoSQ9VTsuxCxwiL0xqCmEg7Oy2spyqjq2eEVQOGTUViHJQriNEZkDp1blu9ezDDglfrnT0BL+/B1PPOx8D/Seslio33oPNaDjkvJ8Kqgr9ryhWENGh4G729dqZ+Sy6y8/kTqO9nP4QauMakoCENawHViT4= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=pass; spf=pass (zoho.com: domain of redhat.com designates 205.139.110.120 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-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) by mx.zohomail.com with SMTPS id 1571925442406931.2941037059843; Thu, 24 Oct 2019 06:57:22 -0700 (PDT) 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-56-9PMie75TP5O8OIyO0BUp2A-1; Thu, 24 Oct 2019 09:57:13 -0400 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 A0BD7800D4C; Thu, 24 Oct 2019 13:57:07 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 7773E61F2D; Thu, 24 Oct 2019 13:57:07 +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 2900A4EE6E; Thu, 24 Oct 2019 13:57:07 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x9ODv5c8026405 for ; Thu, 24 Oct 2019 09:57:05 -0400 Received: by smtp.corp.redhat.com (Postfix) id 52716100164D; Thu, 24 Oct 2019 13:57:05 +0000 (UTC) Received: from angien.redhat.com (unknown [10.43.2.229]) by smtp.corp.redhat.com (Postfix) with ESMTP id CF9C810027C4 for ; Thu, 24 Oct 2019 13:57:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1571925441; 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=qvoM+M4wbpZJ3hh6kcaOU1V5e8te3m+N8yCpHMEbXJ4=; b=g/2WvB1Qt9Dt9WxJ0AiBzgnO6oUK0NtvDkMucbBaro2+WHKFrhDu45X89wMv3KUxDlpsgF xOQ2J/m0RsFoH1+GvAioGViNFg00tU+WaXpa6fQV1ZexgjhJWRlR5MqrCYhaWsU3CUA3O5 NWevUva/ypuXAjCUdwMHUCpUNl7JRss= From: Peter Krempa To: libvir-list@redhat.com Date: Thu, 24 Oct 2019 15:56:30 +0200 Message-Id: <2dabf9694f1e19b272f7c8ea6f787bb127dd2e7a.1571925291.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 12/19] util: virbuffer: Remove @dynamic from virBufferGetIndent 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 X-MC-Unique: 9PMie75TP5O8OIyO0BUp2A-1 X-Mimecast-Spam-Score: 0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" After the conversion of all callers that would pass true as @dynamic to a different function we can remove the unused argument now. Additionally modify the return type to 'size_t' as indentation can't be negative and remove checks whether @buf is passed as it's caller's duty to do so. Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- src/conf/domain_conf.c | 2 +- src/conf/network_conf.c | 2 +- src/util/virbuffer.c | 12 +++--------- src/util/virbuffer.h | 4 ++-- tests/testutilsqemuschema.c | 2 +- tests/virbuftest.c | 12 ++++++------ 6 files changed, 14 insertions(+), 20 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 9ee9b44a5e..81006119aa 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -28493,7 +28493,7 @@ virDomainDefFormatInternalSetRootName(virDomainDefP= tr def, xmlIndentTreeOutput =3D 1; xmlbuf =3D xmlBufferCreate(); if (xmlNodeDump(xmlbuf, def->metadata->doc, def->metadata, - virBufferGetIndent(buf, false) / 2, 1) < 0) { + virBufferGetIndent(buf) / 2, 1) < 0) { xmlBufferFree(xmlbuf); xmlIndentTreeOutput =3D oldIndentTreeOutput; goto error; diff --git a/src/conf/network_conf.c b/src/conf/network_conf.c index 7f8e43b25c..1d20d28f46 100644 --- a/src/conf/network_conf.c +++ b/src/conf/network_conf.c @@ -2458,7 +2458,7 @@ virNetworkDefFormatBuf(virBufferPtr buf, xmlIndentTreeOutput =3D 1; xmlbuf =3D xmlBufferCreate(); if (xmlNodeDump(xmlbuf, def->metadata->doc, def->metadata, - virBufferGetIndent(buf, false) / 2, 1) < 0) { + virBufferGetIndent(buf) / 2, 1) < 0) { xmlBufferFree(xmlbuf); xmlIndentTreeOutput =3D oldIndentTreeOutput; goto error; diff --git a/src/util/virbuffer.c b/src/util/virbuffer.c index 0d2721b118..bf703fe7a5 100644 --- a/src/util/virbuffer.c +++ b/src/util/virbuffer.c @@ -102,18 +102,12 @@ virBufferSetIndent(virBufferPtr buf, int indent) /** * virBufferGetIndent: * @buf: the buffer - * @dynamic: if false, return set value; if true, return 0 unless next - * append would be affected by auto-indent * - * Return the current auto-indent value, or -1 if there has been an error. + * Return the current auto-indent setting of @buf. */ -int -virBufferGetIndent(const virBuffer *buf, bool dynamic) +size_t +virBufferGetIndent(const virBuffer *buf) { - if (!buf || buf->error) - return -1; - if (dynamic && buf->use && buf->content[buf->use - 1] !=3D '\n') - return 0; return buf->indent; } diff --git a/src/util/virbuffer.h b/src/util/virbuffer.h index 7156d9d0d8..6c41a7ea20 100644 --- a/src/util/virbuffer.h +++ b/src/util/virbuffer.h @@ -107,9 +107,9 @@ void virBufferSetIndent(virBufferPtr, int indent); * child buffer. */ #define virBufferSetChildIndent(childBuf_, parentBuf_) \ - virBufferSetIndent(childBuf_, virBufferGetIndent(parentBuf_, false) + = 2) + virBufferSetIndent(childBuf_, virBufferGetIndent(parentBuf_) + 2) -int virBufferGetIndent(const virBuffer *buf, bool dynamic); +size_t virBufferGetIndent(const virBuffer *buf); size_t virBufferGetEffectiveIndent(const virBuffer *buf); void virBufferTrim(virBufferPtr buf, const char *trim, int len); diff --git a/tests/testutilsqemuschema.c b/tests/testutilsqemuschema.c index 42b2550a03..9a1b1fea07 100644 --- a/tests/testutilsqemuschema.c +++ b/tests/testutilsqemuschema.c @@ -430,7 +430,7 @@ testQEMUSchemaValidateAlternate(virJSONValuePtr obj, virBufferAddLit(debug, "(\n"); virBufferAdjustIndent(debug, 3); - indent =3D virBufferGetIndent(debug, false); + indent =3D virBufferGetIndent(debug); n =3D virJSONValueArraySize(members); for (i =3D 0; i < n; i++) { diff --git a/tests/virbuftest.c b/tests/virbuftest.c index 0c806908e1..34aa8b678b 100644 --- a/tests/virbuftest.c +++ b/tests/virbuftest.c @@ -18,7 +18,7 @@ static int testBufAutoIndent(const void *data G_GNUC_UNUS= ED) char *result =3D NULL; int ret =3D 0; - if (virBufferGetIndent(buf, false) !=3D 0 || + if (virBufferGetIndent(buf) !=3D 0 || virBufferGetEffectiveIndent(buf) !=3D 0) { VIR_TEST_DEBUG("Wrong indentation"); ret =3D -1; @@ -28,28 +28,28 @@ static int testBufAutoIndent(const void *data G_GNUC_UN= USED) VIR_TEST_DEBUG("Wrong content"); ret =3D -1; } - if (virBufferGetIndent(buf, false) !=3D 3 || + if (virBufferGetIndent(buf) !=3D 3 || virBufferGetEffectiveIndent(buf) !=3D 3 || virBufferError(buf)) { VIR_TEST_DEBUG("Wrong indentation"); ret =3D -1; } virBufferAdjustIndent(buf, -2); - if (virBufferGetIndent(buf, false) !=3D 1 || + if (virBufferGetIndent(buf) !=3D 1 || virBufferGetEffectiveIndent(buf) !=3D 1 || virBufferError(buf)) { VIR_TEST_DEBUG("Wrong indentation"); ret =3D -1; } virBufferAdjustIndent(buf, -3); - if (virBufferGetIndent(buf, false) !=3D 0 || + if (virBufferGetIndent(buf) !=3D 0 || virBufferGetEffectiveIndent(buf) !=3D 0) { VIR_TEST_DEBUG("Indentation level not truncated"); ret =3D -1; } virBufferAdjustIndent(buf, 3); virBufferFreeAndReset(buf); - if (virBufferGetIndent(buf, false) !=3D 0 || + if (virBufferGetIndent(buf) !=3D 0 || virBufferGetEffectiveIndent(buf) !=3D 0 || virBufferError(buf)) { VIR_TEST_DEBUG("Reset didn't clear indentation"); @@ -65,7 +65,7 @@ static int testBufAutoIndent(const void *data G_GNUC_UNUS= ED) VIR_TEST_DEBUG("Wrong content"); ret =3D -1; } - if (virBufferGetIndent(buf, false) !=3D 2 || + if (virBufferGetIndent(buf) !=3D 2 || virBufferGetEffectiveIndent(buf) !=3D 0) { VIR_TEST_DEBUG("Wrong indentation"); ret =3D -1; --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri Apr 26 20:39:30 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 207.211.31.81 as permitted sender) client-ip=207.211.31.81; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zoho.com: domain of redhat.com designates 207.211.31.81 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=1571925487; cv=none; d=zoho.com; s=zohoarc; b=LPItkpI6KPa7P3FFdMqKUYUYCb0mWOJtvJdRJG2ERxnF0CoVKdAr1I5tgQ95wjx+3W2puTxWWzKfo8V14JMkoKELzSpF7BrCD2mMrdwQ5rsC/zS7/X7F0HGwYEbFuEsUr/Xb9/vhPHpuYr9OtaEdpK3/1aEGBINMXZ7Us/AwzU4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1571925487; 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=1PceDF0Cuomw0E1dUVWGuV+fdfXscj2pM6I5rvdDdq4=; b=atvKN7cr2ilJvx/PtBamL3HkdLVORTyOFDuq+EW1rTrRAzfOdrKbYC5CIjyxuXmr+4zrBrTZqqCg5AlVZKR/1/ixs20EcvDQyKPLnWAba8F/gL8743i/17+LxTr1ycx0ZODVGKxpiU/YocqXeg1TzMrQctTEnJADlcgbXTveda4= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=pass; spf=pass (zoho.com: domain of redhat.com designates 207.211.31.81 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-1.mimecast.com (207.211.31.81 [207.211.31.81]) by mx.zohomail.com with SMTPS id 15719254874671002.628336586974; Thu, 24 Oct 2019 06:58:07 -0700 (PDT) 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-274-jyHu2_5FORCFulsJbKG2qw-1; Thu, 24 Oct 2019 09:57:16 -0400 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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id 06C255E4; Thu, 24 Oct 2019 13:57:11 +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 D2DDF5C219; Thu, 24 Oct 2019 13:57:10 +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 9334B180BA9E; Thu, 24 Oct 2019 13:57:10 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x9ODv6xB026412 for ; Thu, 24 Oct 2019 09:57:06 -0400 Received: by smtp.corp.redhat.com (Postfix) id 2216D10098FB; Thu, 24 Oct 2019 13:57:06 +0000 (UTC) Received: from angien.redhat.com (unknown [10.43.2.229]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9FABC10027AB for ; Thu, 24 Oct 2019 13:57:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1571925486; 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=1PceDF0Cuomw0E1dUVWGuV+fdfXscj2pM6I5rvdDdq4=; b=G1MAiuRxMAAvQbVO0zVmLDxcei2sMNCqadMo3xCjMzIXitOuddjb5Ql73As9R9dBzMQIXK ZxUmw9VIqoIaKmfX1Qph/WmtRiDRDsKMMz1uHPxJy0feQOo7fUafyYhqBjz9lXfUUiihZ2 OOwRBPlDkPYT+cXcY0kfQ04CiVse/dY= From: Peter Krempa To: libvir-list@redhat.com Date: Thu, 24 Oct 2019 15:56:31 +0200 Message-Id: <3826fc4af4ce8dd2164bbc70c176e1b18b578869.1571925291.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 13/19] util: buffer: Properly URLencode strings 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.16 X-MC-Unique: jyHu2_5FORCFulsJbKG2qw-1 X-Mimecast-Spam-Score: 0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" According to rfc3986: 2.3. Unreserved Characters Characters that are allowed in a URI but do not have a reserved purpose are called unreserved. These include uppercase and lowercase letters, decimal digits, hyphen, period, underscore, and tilde. unreserved =3D ALPHA / DIGIT / "-" / "." / "_" / "~" URIs that differ in the replacement of an unreserved character with its corresponding percent-encoded US-ASCII octet are equivalent: they identify the same resource. However, URI comparison implementations do not always perform normalization prior to comparison (see Section 6). For consistency, percent-encoded octets in the ranges of ALPHA (%41-%5A and %61-%7A), DIGIT (%30-%39), hyphen (%2D), period (%2E), underscore (%5F), or tilde (%7E) should not be created by URI producers and, when found in a URI, should be decoded to their corresponding unreserved characters by URI normalizers. Thus we must not include few other characters which don't match c_isalpha to conform to the rules. Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- src/util/virbuffer.c | 14 ++++++++++++-- tests/viruritest.c | 2 +- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/util/virbuffer.c b/src/util/virbuffer.c index bf703fe7a5..bde118a248 100644 --- a/src/util/virbuffer.c +++ b/src/util/virbuffer.c @@ -638,6 +638,16 @@ virBufferEscape(virBufferPtr buf, char escape, const c= har *toescape, } +static bool +virBufferURIEncodeCharIsUnencoded(char c) +{ + if (c =3D=3D '-' || c =3D=3D '.' || c =3D=3D '_' || c =3D=3D '~') + return true; + + return c_isalnum(c); +} + + /** * virBufferURIEncodeString: * @buf: the buffer to append to @@ -664,7 +674,7 @@ virBufferURIEncodeString(virBufferPtr buf, const char *= str) virBufferAddLit(buf, ""); /* auto-indent */ for (p =3D str; *p; ++p) { - if (c_isalnum(*p)) + if (virBufferURIEncodeCharIsUnencoded(*p)) grow_size++; else grow_size +=3D 3; /* %ab */ @@ -674,7 +684,7 @@ virBufferURIEncodeString(virBufferPtr buf, const char *= str) return; for (p =3D str; *p; ++p) { - if (c_isalnum(*p)) { + if (virBufferURIEncodeCharIsUnencoded(*p)) { buf->content[buf->use++] =3D *p; } else { uc =3D (unsigned char) *p; diff --git a/tests/viruritest.c b/tests/viruritest.c index 3255e2333a..a11587e52b 100644 --- a/tests/viruritest.c +++ b/tests/viruritest.c @@ -184,7 +184,7 @@ mymain(void) { NULL, NULL, false }, }; TEST_FULL("spice://[3ffe::104]:5900/?tlsSubject=3DC=3DXX,L=3DTesttown,= O=3DTest%20Company,CN=3Dtester.test", - "spice://[3ffe::104]:5900/?tlsSubject=3DC%3dXX%2cL%3dTesttow= n%2cO%3dTest%20Company%2cCN%3dtester%2etest", + "spice://[3ffe::104]:5900/?tlsSubject=3DC%3dXX%2cL%3dTesttow= n%2cO%3dTest%20Company%2cCN%3dtester.test", "spice", "3ffe::104", 5900, "/", "tlsSubject=3DC=3DXX,L=3DTe= sttown,O=3DTest%20Company,CN=3Dtester.test", NULL, NULL, spiceparams); virURIParam params1[] =3D { --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri Apr 26 20:39:31 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 207.211.31.81 as permitted sender) client-ip=207.211.31.81; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zoho.com: domain of redhat.com designates 207.211.31.81 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=1571925495; cv=none; d=zoho.com; s=zohoarc; b=VnNsn++S3y/qsJc9QSkUvjPIFfSs2EW9h1lCaBYYCImcJGeNndz4lVupFpxHcqpWunoTW55++4pq7AO7/jaIJF7jIsx4sWBwmQ15wm8uX/WkFYPdMrBoq3Pj883rxiOnYql43cOh9dizy8heNkLFqsNB/2zAEzQYLMTNCQrYutA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1571925495; 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=kWuemfUjK6XCvLlrd0kpCQWLjvbAjm60WrhLkrfkO+0=; b=WpSmMHyLf/aQCGMcPZDFkAmgbAGrqfKHAKPakzSydU4rNDallLSEw3HClknuwOlEcX8It4deFLBc4bCcf3x6QdcGJmhUNgudy1VQDyhxwSj4RcxN6+DQddY+cOtQvyQr0qwqi1fAnpniq14VF/zBJl7J3RhfoU03wJ+AtV4/qPY= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=pass; spf=pass (zoho.com: domain of redhat.com designates 207.211.31.81 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-1.mimecast.com (207.211.31.81 [207.211.31.81]) by mx.zohomail.com with SMTPS id 1571925495967717.4856870598328; Thu, 24 Oct 2019 06:58:15 -0700 (PDT) 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-196-JxzgA_0FNXq95i4iX4JEAA-1; Thu, 24 Oct 2019 09:57:20 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 8E577801E66; Thu, 24 Oct 2019 13:57:15 +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 60B5A60A97; Thu, 24 Oct 2019 13:57: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 25936180BA9A; Thu, 24 Oct 2019 13:57:15 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x9ODv6aH026420 for ; Thu, 24 Oct 2019 09:57:06 -0400 Received: by smtp.corp.redhat.com (Postfix) id E707C10027A9; Thu, 24 Oct 2019 13:57:06 +0000 (UTC) Received: from angien.redhat.com (unknown [10.43.2.229]) by smtp.corp.redhat.com (Postfix) with ESMTP id 706CD100164D for ; Thu, 24 Oct 2019 13:57:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1571925494; 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=kWuemfUjK6XCvLlrd0kpCQWLjvbAjm60WrhLkrfkO+0=; b=fJpM79wLr03dRqOYqgxNxKf7n5SLyv+uN8rtt//ZjdETlFs+4X/+P19/QOOHGBQ3zOIol7 yBFjlblKhZGeH0TmM5z3UE602myZSR4kFvGvEEQ4SBvKSMKpmTOazJX0G4s/r0u37Tlkj3 XVCm549yUTroie+i6lTsHcUN4Yhvi2o= From: Peter Krempa To: libvir-list@redhat.com Date: Thu, 24 Oct 2019 15:56:32 +0200 Message-Id: <9561863b11b83575d9f584c4c17e57f73df6adf5.1571925291.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 14/19] util: buffer: Encode URIs with upper case hex characters 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.13 X-MC-Unique: JxzgA_0FNXq95i4iX4JEAA-1 X-Mimecast-Spam-Score: 0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" rfc3986 uses uppercase characters so switch to using them as well. Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- src/util/virbuffer.c | 2 +- tests/viruritest.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/util/virbuffer.c b/src/util/virbuffer.c index bde118a248..2256bd5de5 100644 --- a/src/util/virbuffer.c +++ b/src/util/virbuffer.c @@ -663,7 +663,7 @@ virBufferURIEncodeString(virBufferPtr buf, const char *= str) int grow_size =3D 0; const char *p; unsigned char uc; - const char *hex =3D "0123456789abcdef"; + const char *hex =3D "0123456789ABCDEF"; if ((buf =3D=3D NULL) || (str =3D=3D NULL)) return; diff --git a/tests/viruritest.c b/tests/viruritest.c index a11587e52b..07cf7261d1 100644 --- a/tests/viruritest.c +++ b/tests/viruritest.c @@ -184,7 +184,7 @@ mymain(void) { NULL, NULL, false }, }; TEST_FULL("spice://[3ffe::104]:5900/?tlsSubject=3DC=3DXX,L=3DTesttown,= O=3DTest%20Company,CN=3Dtester.test", - "spice://[3ffe::104]:5900/?tlsSubject=3DC%3dXX%2cL%3dTesttow= n%2cO%3dTest%20Company%2cCN%3dtester.test", + "spice://[3ffe::104]:5900/?tlsSubject=3DC%3DXX%2CL%3DTesttow= n%2CO%3DTest%20Company%2CCN%3Dtester.test", "spice", "3ffe::104", 5900, "/", "tlsSubject=3DC=3DXX,L=3DTe= sttown,O=3DTest%20Company,CN=3Dtester.test", NULL, NULL, spiceparams); virURIParam params1[] =3D { --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri Apr 26 20:39:31 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 205.139.110.120 as permitted sender) client-ip=205.139.110.120; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zoho.com: domain of redhat.com designates 205.139.110.120 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=1571925489; cv=none; d=zoho.com; s=zohoarc; b=HB+0Tn12TT7CXbyGR8pAOl+R8gcgDnhCKVjoD/SelSRfoQFBGsGeUh4LdRTP5dTpr7pGPjJLAeK6yt3f2AbGzBCiK3bZsgk8rPoivpnz30itF+LSnrIu7GgnXDSxrsCkZdzFMaQSJSxRGChD9KQidwSjL0yiZ7q9REAknnmwSjM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1571925489; 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=TEb9TNVcGBUfHQHl0KJGZjrKtJOwiOXleqdJNMab6dU=; b=QeSANf60MthiFYvZfREk3XtpVb0w7RKJqahYWBbX6r9NcSTmYE8Qp+PA5Hks4CAzLN2Pkvy3xY8o/konpJ1ChA/eDcZOD4uOnE7QLWmKbXVIp981xizmjyRV6OZr50enqMp3JTG0MGu2xtSI3opAy8kKa5cv13HF6SvSYA5+Hs0= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=pass; spf=pass (zoho.com: domain of redhat.com designates 205.139.110.120 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-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) by mx.zohomail.com with SMTPS id 1571925489119211.80370156225172; Thu, 24 Oct 2019 06:58:09 -0700 (PDT) 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-316-wh5_qaODPPKIPoBKBOkiHw-1; Thu, 24 Oct 2019 09:57:22 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id BADC0107AD3E; Thu, 24 Oct 2019 13:57:17 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 91D39194B6; Thu, 24 Oct 2019 13:57:17 +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 4F42E4EEBD; Thu, 24 Oct 2019 13:57:17 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x9ODv7BY026428 for ; Thu, 24 Oct 2019 09:57:07 -0400 Received: by smtp.corp.redhat.com (Postfix) id B6736100164D; Thu, 24 Oct 2019 13:57:07 +0000 (UTC) Received: from angien.redhat.com (unknown [10.43.2.229]) by smtp.corp.redhat.com (Postfix) with ESMTP id 404B710027AB for ; Thu, 24 Oct 2019 13:57:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1571925487; 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=TEb9TNVcGBUfHQHl0KJGZjrKtJOwiOXleqdJNMab6dU=; b=AVNApn4mIz/YjSRSXNhk3cHUlLRdPLvwaUsyO0ecAEkxslD1E8jyUdl/u9sVEs62zPPv6t aeuVL3u18sEX2E3zA8NiRty8oBiPchwm+Vl/wv5CJ2MXzESOnFZY02xQOhULXBxBV2q/XH MR7QkZPCXHrKhFZ/KBf0nLfQh6bFH1s= From: Peter Krempa To: libvir-list@redhat.com Date: Thu, 24 Oct 2019 15:56:33 +0200 Message-Id: <0f49f04549b07e3c9ac822dee50e9e96361a6ccc.1571925291.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 15/19] util: buffer: Reimplement virBuffer internals using glib's GString 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.23 X-MC-Unique: wh5_qaODPPKIPoBKBOkiHw-1 X-Mimecast-Spam-Score: 0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" GString is surprisingly similar to what libvirt was doing painstaikingly manually. Yet it doesn't support the automatic indentation features we use for XML so we rather keep those in form of virBuffer using GString internally. Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- src/util/virbuffer.c | 205 +++++++++++++++---------------------------- src/util/virbuffer.h | 6 +- 2 files changed, 71 insertions(+), 140 deletions(-) diff --git a/src/util/virbuffer.c b/src/util/virbuffer.c index 2256bd5de5..9306b79703 100644 --- a/src/util/virbuffer.c +++ b/src/util/virbuffer.c @@ -21,7 +21,6 @@ #include #include -#include "c-ctype.h" #include "virbuffer.h" #include "virerror.h" @@ -40,10 +39,7 @@ static void virBufferSetError(virBufferPtr buf, int error) { - VIR_FREE(buf->content); - buf->size =3D 0; - buf->use =3D 0; - buf->indent =3D 0; + virBufferFreeAndReset(buf); buf->error =3D error; } @@ -122,7 +118,7 @@ virBufferGetIndent(const virBuffer *buf) size_t virBufferGetEffectiveIndent(const virBuffer *buf) { - if (buf->use && buf->content[buf->use - 1] !=3D '\n') + if (buf->str && buf->str->len && buf->str->str[buf->str->len - 1] !=3D= '\n') return 0; return buf->indent; @@ -130,35 +126,38 @@ virBufferGetEffectiveIndent(const virBuffer *buf) /** - * virBufferGrow: + * virBufferInitialize * @buf: the buffer - * @len: the minimum free size to allocate on top of existing used space * - * Grow the available space of a buffer to at least @len bytes. - * - * Returns zero on success or -1 on error + * Ensures that the internal GString container is allocated. */ -static int -virBufferGrow(virBufferPtr buf, unsigned int len) +static void +virBufferInitialize(virBufferPtr buf) { - int size; + if (!buf->str) + buf->str =3D g_string_new(NULL); +} - if (buf->error) - return -1; - if ((len + buf->use) < buf->size) - return 0; +static void +virBufferApplyIndent(virBufferPtr buf) +{ + const char space[] =3D " "; + size_t spacesz =3D sizeof(space) - 1; + size_t toindent =3D virBufferGetEffectiveIndent(buf); - size =3D buf->use + len + 1000; + if (toindent =3D=3D 0) + return; - if (VIR_REALLOC_N_QUIET(buf->content, size) < 0) { - virBufferSetError(buf, errno); - return -1; + while (toindent > spacesz) { + g_string_append_len(buf->str, space, spacesz); + toindent -=3D spacesz; } - buf->size =3D size; - return 0; + + g_string_append_len(buf->str, space, toindent); } + /** * virBufferAdd: * @buf: the buffer to append to @@ -172,25 +171,16 @@ virBufferGrow(virBufferPtr buf, unsigned int len) void virBufferAdd(virBufferPtr buf, const char *str, int len) { - unsigned int needSize; - size_t indent; - if (!str || !buf || buf->error || (len =3D=3D 0 && buf->indent =3D=3D = 0)) return; - indent =3D virBufferGetEffectiveIndent(buf); + virBufferInitialize(buf); + virBufferApplyIndent(buf); if (len < 0) - len =3D strlen(str); - - needSize =3D buf->use + indent + len + 2; - if (virBufferGrow(buf, needSize - buf->use) < 0) - return; - - memset(&buf->content[buf->use], ' ', indent); - memcpy(&buf->content[buf->use + indent], str, len); - buf->use +=3D indent + len; - buf->content[buf->use] =3D '\0'; + g_string_append(buf->str, str); + else + g_string_append_len(buf->str, str, len); } /** @@ -207,7 +197,7 @@ virBufferAdd(virBufferPtr buf, const char *str, int len) void virBufferAddBuffer(virBufferPtr buf, virBufferPtr toadd) { - if (!toadd) + if (!toadd || !toadd->str) return; if (!buf) @@ -219,12 +209,8 @@ virBufferAddBuffer(virBufferPtr buf, virBufferPtr toad= d) goto cleanup; } - if (virBufferGrow(buf, toadd->use) < 0) - goto cleanup; - - memcpy(&buf->content[buf->use], toadd->content, toadd->use); - buf->use +=3D toadd->use; - buf->content[buf->use] =3D '\0'; + virBufferInitialize(buf); + g_string_append_len(buf->str, toadd->str->str, toadd->str->len); cleanup: virBufferFreeAndReset(toadd); @@ -259,7 +245,12 @@ virBufferCurrentContent(virBufferPtr buf) { if (!buf || buf->error) return NULL; - return buf->use ? buf->content : ""; + + if (!buf->str || + buf->str->len =3D=3D 0) + return ""; + + return buf->str->str; } /** @@ -277,16 +268,14 @@ virBufferCurrentContent(virBufferPtr buf) char * virBufferContentAndReset(virBufferPtr buf) { - char *str; - if (buf =3D=3D NULL) - return NULL; + char *str =3D NULL; - if (buf->error) { - memset(buf, 0, sizeof(*buf)); + if (!buf) return NULL; - } - str =3D buf->content; + if (buf->str) + str =3D g_string_free(buf->str, false); + memset(buf, 0, sizeof(*buf)); return str; } @@ -299,8 +288,13 @@ virBufferContentAndReset(virBufferPtr buf) */ void virBufferFreeAndReset(virBufferPtr buf) { - if (buf) - virBufferSetError(buf, 0); + if (!buf) + return; + + if (buf->str) + g_string_free(buf->str, true); + + memset(buf, 0, sizeof(*buf)); } /** @@ -360,10 +354,10 @@ virBufferCheckErrorInternal(const virBuffer *buf, size_t virBufferUse(const virBuffer *buf) { - if (buf =3D=3D NULL) + if (!buf || !buf->str) return 0; - return buf->use; + return buf->str->len; } /** @@ -394,48 +388,16 @@ virBufferAsprintf(virBufferPtr buf, const char *forma= t, ...) void virBufferVasprintf(virBufferPtr buf, const char *format, va_list argptr) { - int size, count, grow_size; - va_list copy; - if ((format =3D=3D NULL) || (buf =3D=3D NULL)) return; if (buf->error) return; - virBufferAddLit(buf, ""); /* auto-indent */ + virBufferInitialize(buf); + virBufferApplyIndent(buf); - if (buf->size =3D=3D 0 && - virBufferGrow(buf, 100) < 0) - return; - - va_copy(copy, argptr); - - size =3D buf->size - buf->use; - if ((count =3D vsnprintf(&buf->content[buf->use], - size, format, copy)) < 0) { - virBufferSetError(buf, errno); - va_end(copy); - return; - } - va_end(copy); - - /* Grow buffer if necessary and retry */ - if (count >=3D size) { - buf->content[buf->use] =3D 0; - - grow_size =3D (count + 1 > 1000) ? count + 1 : 1000; - if (virBufferGrow(buf, grow_size) < 0) - return; - - size =3D buf->size - buf->use; - if ((count =3D vsnprintf(&buf->content[buf->use], - size, format, argptr)) < 0) { - virBufferSetError(buf, errno); - return; - } - } - buf->use +=3D count; + g_string_append_vprintf(buf->str, format, argptr); } @@ -638,16 +600,6 @@ virBufferEscape(virBufferPtr buf, char escape, const c= har *toescape, } -static bool -virBufferURIEncodeCharIsUnencoded(char c) -{ - if (c =3D=3D '-' || c =3D=3D '.' || c =3D=3D '_' || c =3D=3D '~') - return true; - - return c_isalnum(c); -} - - /** * virBufferURIEncodeString: * @buf: the buffer to append to @@ -660,41 +612,16 @@ virBufferURIEncodeCharIsUnencoded(char c) void virBufferURIEncodeString(virBufferPtr buf, const char *str) { - int grow_size =3D 0; - const char *p; - unsigned char uc; - const char *hex =3D "0123456789ABCDEF"; - if ((buf =3D=3D NULL) || (str =3D=3D NULL)) return; if (buf->error) return; - virBufferAddLit(buf, ""); /* auto-indent */ - - for (p =3D str; *p; ++p) { - if (virBufferURIEncodeCharIsUnencoded(*p)) - grow_size++; - else - grow_size +=3D 3; /* %ab */ - } - - if (virBufferGrow(buf, grow_size) < 0) - return; - - for (p =3D str; *p; ++p) { - if (virBufferURIEncodeCharIsUnencoded(*p)) { - buf->content[buf->use++] =3D *p; - } else { - uc =3D (unsigned char) *p; - buf->content[buf->use++] =3D '%'; - buf->content[buf->use++] =3D hex[uc >> 4]; - buf->content[buf->use++] =3D hex[uc & 0xf]; - } - } + virBufferInitialize(buf); + virBufferApplyIndent(buf); - buf->content[buf->use] =3D '\0'; + g_string_append_uri_escaped(buf->str, str, NULL, false); } /** @@ -810,21 +737,27 @@ virBufferTrim(virBufferPtr buf, const char *str, int = len) { size_t len2 =3D 0; - if (!buf || buf->error) + if (!buf || buf->error || !buf->str) return; + if (!str && len < 0) return; - if (len > 0 && len > buf->use) + + if (len > 0 && len > buf->str->len) return; + if (str) { len2 =3D strlen(str); - if (len2 > buf->use || - memcmp(&buf->content[buf->use - len2], str, len2) !=3D 0) + if (len2 > buf->str->len || + memcmp(&buf->str->str[buf->str->len - len2], str, len2) !=3D 0) return; } - buf->use -=3D len < 0 ? len2 : len; - buf->content[buf->use] =3D '\0'; + + if (len < 0) + len =3D len2; + + g_string_truncate(buf->str, buf->str->len - len); } diff --git a/src/util/virbuffer.h b/src/util/virbuffer.h index 6c41a7ea20..f5b3961f9b 100644 --- a/src/util/virbuffer.h +++ b/src/util/virbuffer.h @@ -33,14 +33,12 @@ typedef struct _virBuffer virBuffer; typedef virBuffer *virBufferPtr; -#define VIR_BUFFER_INITIALIZER { 0, 0, 0, 0, NULL } +#define VIR_BUFFER_INITIALIZER { NULL, 0, 0 } struct _virBuffer { - size_t size; - size_t use; + GString *str; int error; /* errno value, or -1 for usage error */ int indent; - char *content; }; const char *virBufferCurrentContent(virBufferPtr buf); --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri Apr 26 20:39:31 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 205.139.110.61 as permitted sender) client-ip=205.139.110.61; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zoho.com: domain of redhat.com designates 205.139.110.61 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=1571925442; cv=none; d=zoho.com; s=zohoarc; b=d3KCR8ElMoBYH8kpR/0bFl5hWKjy9KqUpLp6MNHYDPCHXHbjDsj1VYXM0u2cgYQWnYlgg85f12QMzeHc41/YWV0Uf/hcdeKNDp4O1RL24R1H3Je+lpIehBDg8wEezkL8kEkROoZTW+scSR2kKzshF64Ekcj3czWDZjeN1Lhw4fo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1571925442; 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=kBJviRanzZA6QoQvv5i7PURQoxeAZTr7qf7yDJ1bvUc=; b=WaMYzq/ktCB7NtzclEJrlr1+bHmtwMxxdKfO5a95WoLaEBaMhn3DLD5M2Q0MMT0dVNUQnHt7lAv9J+7BA57GZwuGMZ0k+twLR/Qu0haii1brJYz+HWVptR2ba/lCfJXjlheHx76a7pwshAxNR65H2+FmOWMOHtAlZGlerBipJFY= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=pass; spf=pass (zoho.com: domain of redhat.com designates 205.139.110.61 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-1.mimecast.com (us-smtp-2.mimecast.com [205.139.110.61]) by mx.zohomail.com with SMTPS id 1571925442764759.6143950439712; Thu, 24 Oct 2019 06:57:22 -0700 (PDT) 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-138-XMWZc-I6OMOjZmjGXt-VJQ-1; Thu, 24 Oct 2019 09:57:19 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id BFEAC800D4C; Thu, 24 Oct 2019 13:57:14 +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 96222614CE; Thu, 24 Oct 2019 13:57:14 +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 5313B1803B4E; Thu, 24 Oct 2019 13:57:14 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x9ODv8SK026439 for ; Thu, 24 Oct 2019 09:57:08 -0400 Received: by smtp.corp.redhat.com (Postfix) id 860BC100164D; Thu, 24 Oct 2019 13:57:08 +0000 (UTC) Received: from angien.redhat.com (unknown [10.43.2.229]) by smtp.corp.redhat.com (Postfix) with ESMTP id 100B210027A9 for ; Thu, 24 Oct 2019 13:57:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1571925441; 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=kBJviRanzZA6QoQvv5i7PURQoxeAZTr7qf7yDJ1bvUc=; b=QaNJN3YkMd5a8JgiPkAYWrhYs9q4YCtb9gls6BCGjDCcyI+3UpBbX0nQc5b+VzsBXaQFQh A+nDQ7yXY5rY79l8v0H2xYVclRKKfeEiW4tgkJriekZGeAX3eERcXEEDhXPUo0G7tsP+AS 4EiMIRRSe51jqgRuhGKWl4viVuaLYTI= From: Peter Krempa To: libvir-list@redhat.com Date: Thu, 24 Oct 2019 15:56:34 +0200 Message-Id: <0d92261f20e6a28234bac1b10d3665800daa259f.1571925291.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 16/19] util: buffer: Remove error handling internals 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.13 X-MC-Unique: XMWZc-I6OMOjZmjGXt-VJQ-1 X-Mimecast-Spam-Score: 0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" Now that there are no errors reported and tracked in virBuffer, remove all the internals which were used to track them. Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- src/util/virbuffer.c | 78 ++++++-------------------------------------- src/util/virbuffer.h | 13 +++----- 2 files changed, 14 insertions(+), 77 deletions(-) diff --git a/src/util/virbuffer.c b/src/util/virbuffer.c index 9306b79703..e6480ca4ef 100644 --- a/src/util/virbuffer.c +++ b/src/util/virbuffer.c @@ -23,26 +23,11 @@ #include #include "virbuffer.h" -#include "virerror.h" #include "virstring.h" #include "viralloc.h" #define VIR_FROM_THIS VIR_FROM_NONE -/** - * virBufferFail - * @buf: the buffer - * @error: which error occurred (errno value, or -1 for usage) - * - * Mark the buffer as failed, free the content and set the error flag. - */ -static void -virBufferSetError(virBufferPtr buf, int error) -{ - virBufferFreeAndReset(buf); - buf->error =3D error; -} - /** * virBufferAdjustIndent: * @buf: the buffer @@ -58,7 +43,7 @@ virBufferSetError(virBufferPtr buf, int error) void virBufferAdjustIndent(virBufferPtr buf, int indent) { - if (!buf || buf->error) + if (!buf) return; if (indent > 0) { @@ -88,7 +73,7 @@ virBufferAdjustIndent(virBufferPtr buf, int indent) void virBufferSetIndent(virBufferPtr buf, int indent) { - if (!buf || buf->error) + if (!buf) return; buf->indent =3D indent; @@ -171,7 +156,7 @@ virBufferApplyIndent(virBufferPtr buf) void virBufferAdd(virBufferPtr buf, const char *str, int len) { - if (!str || !buf || buf->error || (len =3D=3D 0 && buf->indent =3D=3D = 0)) + if (!str || !buf || (len =3D=3D 0 && buf->indent =3D=3D 0)) return; virBufferInitialize(buf); @@ -203,12 +188,6 @@ virBufferAddBuffer(virBufferPtr buf, virBufferPtr toad= d) if (!buf) goto cleanup; - if (buf->error || toadd->error) { - if (!buf->error) - virBufferSetError(buf, toadd->error); - goto cleanup; - } - virBufferInitialize(buf); g_string_append_len(buf->str, toadd->str->str, toadd->str->len); @@ -243,7 +222,7 @@ virBufferAddChar(virBufferPtr buf, char c) const char * virBufferCurrentContent(virBufferPtr buf) { - if (!buf || buf->error) + if (!buf) return NULL; if (!buf->str || @@ -307,12 +286,9 @@ void virBufferFreeAndReset(virBufferPtr buf) * Return positive errno value or -1 on usage error, 0 if normal */ int -virBufferError(const virBuffer *buf) +virBufferError(const virBuffer *buf G_GNUC_UNUSED) { - if (buf =3D=3D NULL) - return -1; - - return buf->error; + return 0; } /** @@ -324,25 +300,9 @@ virBufferError(const virBuffer *buf) * Return -1 if an error has been reported, 0 otherwise. */ int -virBufferCheckErrorInternal(const virBuffer *buf, - int domcode, - const char *filename, - const char *funcname, - size_t linenr) +virBufferCheckErrorInternal(const virBuffer *buf G_GNUC_UNUSED) { - if (buf->error =3D=3D 0) - return 0; - - if (buf->error =3D=3D ENOMEM) { - virReportOOMErrorFull(domcode, filename, funcname, linenr); - errno =3D ENOMEM; - } else { - virReportErrorHelper(domcode, VIR_ERR_INTERNAL_ERROR, filename, - funcname, linenr, "%s", - _("Invalid buffer API usage")); - errno =3D EINVAL; - } - return -1; + return 0; } /** @@ -391,9 +351,6 @@ virBufferVasprintf(virBufferPtr buf, const char *format= , va_list argptr) if ((format =3D=3D NULL) || (buf =3D=3D NULL)) return; - if (buf->error) - return; - virBufferInitialize(buf); virBufferApplyIndent(buf); @@ -430,9 +387,6 @@ virBufferEscapeString(virBufferPtr buf, const char *for= mat, const char *str) if ((format =3D=3D NULL) || (buf =3D=3D NULL) || (str =3D=3D NULL)) return; - if (buf->error) - return; - len =3D strlen(str); if (strcspn(str, forbidden_characters) =3D=3D len) { virBufferAsprintf(buf, format, str); @@ -575,9 +529,6 @@ virBufferEscape(virBufferPtr buf, char escape, const ch= ar *toescape, if ((format =3D=3D NULL) || (buf =3D=3D NULL) || (str =3D=3D NULL)) return; - if (buf->error) - return; - len =3D strlen(str); if (strcspn(str, toescape) =3D=3D len) { virBufferAsprintf(buf, format, str); @@ -615,9 +566,6 @@ virBufferURIEncodeString(virBufferPtr buf, const char *= str) if ((buf =3D=3D NULL) || (str =3D=3D NULL)) return; - if (buf->error) - return; - virBufferInitialize(buf); virBufferApplyIndent(buf); @@ -643,9 +591,6 @@ virBufferEscapeShell(virBufferPtr buf, const char *str) if ((buf =3D=3D NULL) || (str =3D=3D NULL)) return; - if (buf->error) - return; - /* Only quote if str includes shell metacharacters. */ if (*str && !strpbrk(str, "\r\t\n !\"#$&'()*;<>?[\\]^`{|}~")) { virBufferAdd(buf, str, -1); @@ -693,9 +638,6 @@ virBufferStrcatVArgs(virBufferPtr buf, { char *str; - if (buf->error) - return; - while ((str =3D va_arg(ap, char *)) !=3D NULL) virBufferAdd(buf, str, -1); } @@ -737,7 +679,7 @@ virBufferTrim(virBufferPtr buf, const char *str, int le= n) { size_t len2 =3D 0; - if (!buf || buf->error || !buf->str) + if (!buf || !buf->str) return; if (!str && len < 0) @@ -775,7 +717,7 @@ virBufferAddStr(virBufferPtr buf, { const char *end; - if (!buf || !str || buf->error) + if (!buf || !str) return; while (*str) { diff --git a/src/util/virbuffer.h b/src/util/virbuffer.h index f5b3961f9b..9adec89f57 100644 --- a/src/util/virbuffer.h +++ b/src/util/virbuffer.h @@ -33,11 +33,10 @@ typedef struct _virBuffer virBuffer; typedef virBuffer *virBufferPtr; -#define VIR_BUFFER_INITIALIZER { NULL, 0, 0 } +#define VIR_BUFFER_INITIALIZER { NULL, 0 } struct _virBuffer { GString *str; - int error; /* errno value, or -1 for usage error */ int indent; }; @@ -45,11 +44,7 @@ const char *virBufferCurrentContent(virBufferPtr buf); char *virBufferContentAndReset(virBufferPtr buf); void virBufferFreeAndReset(virBufferPtr buf); int virBufferError(const virBuffer *buf); -int virBufferCheckErrorInternal(const virBuffer *buf, - int domcode, - const char *filename, - const char *funcname, - size_t linenr) +int virBufferCheckErrorInternal(const virBuffer *buf) ATTRIBUTE_NONNULL(1); G_DEFINE_AUTO_CLEANUP_CLEAR_FUNC(virBuffer, virBufferFreeAndReset); @@ -63,8 +58,8 @@ G_DEFINE_AUTO_CLEANUP_CLEAR_FUNC(virBuffer, virBufferFree= AndReset); * and -1 is returned. */ #define virBufferCheckError(buf) \ - virBufferCheckErrorInternal(buf, VIR_FROM_THIS, __FILE__, __FUNCTION__= , \ - __LINE__) + virBufferCheckErrorInternal(buf) + size_t virBufferUse(const virBuffer *buf); void virBufferAdd(virBufferPtr buf, const char *str, int len); void virBufferAddBuffer(virBufferPtr buf, virBufferPtr toadd); --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri Apr 26 20:39:31 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 205.139.110.120 as permitted sender) client-ip=205.139.110.120; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zoho.com: domain of redhat.com designates 205.139.110.120 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=1571925639; cv=none; d=zoho.com; s=zohoarc; b=n1nqPh4KwFI5DudlbgALVANiuN/yZIjCsNyf+94WSAnRtk+nf5bO5k1nKHS2bxBeAHkWS8yipCGRn5j36SciZhQDq2iGlcdCBelP2lcCYCPVc1FXdpW9o4dx3wII6f0Aww98GE0AXgvhUsHOr3PXHwzgn5GapePi0QJXJwXkDbE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1571925639; 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=V6CEochf8ofR/Ee4qCAbjOPQL8Si50a2ftS2LFzvweU=; b=TAagT25kQpGL9OiP9CAy/c8zkmtf5N+QanOW8ArHMY1rNZH8LJJaizELvsmdsssR+RvBx0V5C2o6qdwVZXXI2jXKjNVYWMCE7Ou6LvEgS5rqdnCNSLyAU90dMmBQGCRF8OpsfY4jlJNx/HCC6uVU6ZTnQveQXGeUZYeppnxvWAs= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=pass; spf=pass (zoho.com: domain of redhat.com designates 205.139.110.120 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-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) by mx.zohomail.com with SMTPS id 15719256398961003.9074470425238; Thu, 24 Oct 2019 07:00:39 -0700 (PDT) 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-276-EXQOJheDM5SSNBjl7Pi0WA-1; Thu, 24 Oct 2019 09:57:25 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 192DC107AD41; Thu, 24 Oct 2019 13:57:19 +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 EA92F60466; Thu, 24 Oct 2019 13:57:18 +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 AA110180BAA3; Thu, 24 Oct 2019 13:57:18 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x9ODv9Wq026447 for ; Thu, 24 Oct 2019 09:57:09 -0400 Received: by smtp.corp.redhat.com (Postfix) id 7D59B100164D; Thu, 24 Oct 2019 13:57:09 +0000 (UTC) Received: from angien.redhat.com (unknown [10.43.2.229]) by smtp.corp.redhat.com (Postfix) with ESMTP id D4BAF10098FB for ; Thu, 24 Oct 2019 13:57:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1571925638; 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=V6CEochf8ofR/Ee4qCAbjOPQL8Si50a2ftS2LFzvweU=; b=Nq070N8m2KhqHMedvbE6W9XjvufEusjKxU12BWsNqCCo+vqCwJ/03IexxjOqa0if2+tAEs rmN6PbqZmTdHmHLg4Q4ueMczALOgf6BA2WBUE9FVikFs7KiH0hmvz6OUP2+cPAKpgzDqei bmyzCTFNBZLJ3etdWM3GKq6uc9CWkDA= From: Peter Krempa To: libvir-list@redhat.com Date: Thu, 24 Oct 2019 15:56:35 +0200 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 17/19] util: buffer: Remove virBufferError 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.11 X-MC-Unique: EXQOJheDM5SSNBjl7Pi0WA-1 X-Mimecast-Spam-Score: 0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" The function now never returned an error so we can drop it fully. Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- src/conf/domain_conf.c | 2 -- src/libvirt_private.syms | 1 - src/nwfilter/nwfilter_gentech_driver.c | 4 ---- src/nwfilter/nwfilter_learnipaddr.c | 5 ----- src/security/virt-aa-helper.c | 11 ---------- src/util/virbitmap.c | 6 ------ src/util/virbuffer.c | 15 ------------- src/util/virbuffer.h | 1 - src/util/vircommand.c | 8 +------ src/util/virlog.c | 8 ------- tests/cputest.c | 4 ---- tests/networkxml2firewalltest.c | 3 --- tests/nwfilterebiptablestest.c | 21 ------------------ tests/nwfilterxml2firewalltest.c | 3 --- tests/testutils.c | 2 -- tests/vboxsnapshotxmltest.c | 5 ----- tests/virbuftest.c | 23 +++----------------- tests/virfirewalltest.c | 30 -------------------------- tests/virkmodtest.c | 6 +----- tests/virnetdevbandwidthtest.c | 5 ----- tests/virsystemdtest.c | 3 --- tools/virsh-checkpoint.c | 5 ----- tools/virsh-domain-monitor.c | 6 ------ tools/virsh-domain.c | 28 ------------------------ tools/virsh-pool.c | 9 -------- tools/virsh-snapshot.c | 5 ----- tools/virsh-volume.c | 4 ---- tools/vsh.c | 18 ---------------- 28 files changed, 5 insertions(+), 236 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 81006119aa..1fb538b9a8 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -30527,8 +30527,6 @@ virDomainMachineNameAppendValid(virBufferPtr buf, bool skip_dot =3D false; for (; *name; name++) { - if (virBufferError(buf)) - break; if (strlen(virBufferCurrentContent(buf)) >=3D 64) break; diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 94c2e4ef6a..089b28f85b 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -1592,7 +1592,6 @@ virBufferAsprintf; virBufferCheckErrorInternal; virBufferContentAndReset; virBufferCurrentContent; -virBufferError; virBufferEscape; virBufferEscapeRegex; virBufferEscapeSexpr; diff --git a/src/nwfilter/nwfilter_gentech_driver.c b/src/nwfilter/nwfilter= _gentech_driver.c index d39f1ecb6d..0366deaf8b 100644 --- a/src/nwfilter/nwfilter_gentech_driver.c +++ b/src/nwfilter/nwfilter_gentech_driver.c @@ -431,10 +431,6 @@ virNWFilterDetermineMissingVarsRec(virNWFilterDefPtr f= ilter, virBuffer buf =3D VIR_BUFFER_INITIALIZER; virNWFilterVarAccessPrint(rule->varAccess[j], &buf); - if (virBufferError(&buf)) { - virReportOOMError(); - return -1; - } val =3D virNWFilterVarValueCreateSimpleCopyValue("1"); if (!val) { diff --git a/src/nwfilter/nwfilter_learnipaddr.c b/src/nwfilter/nwfilter_le= arnipaddr.c index d7754c0c7a..293007300a 100644 --- a/src/nwfilter/nwfilter_learnipaddr.c +++ b/src/nwfilter/nwfilter_learnipaddr.c @@ -456,11 +456,6 @@ learnIPAddressThread(void *arg) macaddr); } - if (virBufferError(&buf)) { - req->status =3D ENOMEM; - goto done; - } - filter =3D virBufferContentAndReset(&buf); if (pcap_compile(handle, &fp, filter, 1, 0) !=3D 0) { diff --git a/src/security/virt-aa-helper.c b/src/security/virt-aa-helper.c index 7d7262ca39..54c07894c8 100644 --- a/src/security/virt-aa-helper.c +++ b/src/security/virt-aa-helper.c @@ -1314,12 +1314,6 @@ get_files(vahControl * ctl) if (vah_add_file(&buf, ctl->newfile, "rwk") !=3D 0) goto cleanup; - if (virBufferError(&buf)) { - virBufferFreeAndReset(&buf); - vah_error(NULL, 0, _("failed to allocate file buffer")); - goto cleanup; - } - rc =3D 0; ctl->files =3D virBufferContentAndReset(&buf); @@ -1507,11 +1501,6 @@ main(int argc, char **argv) virBufferAdd(&buf, ctl->files, -1); } - if (virBufferError(&buf)) { - virBufferFreeAndReset(&buf); - vah_error(ctl, 1, _("failed to allocate buffer")); - } - included_files =3D virBufferContentAndReset(&buf); /* (re)create the include file using included_files */ diff --git a/src/util/virbitmap.c b/src/util/virbitmap.c index a9d8e6c3d5..80eccaadce 100644 --- a/src/util/virbitmap.c +++ b/src/util/virbitmap.c @@ -446,12 +446,6 @@ virBitmapFormat(virBitmapPtr bitmap) start =3D prev =3D cur; } - if (virBufferError(&buf)) { - virBufferFreeAndReset(&buf); - virReportOOMError(); - return NULL; - } - return virBufferContentAndReset(&buf); } diff --git a/src/util/virbuffer.c b/src/util/virbuffer.c index e6480ca4ef..b513c59268 100644 --- a/src/util/virbuffer.c +++ b/src/util/virbuffer.c @@ -276,21 +276,6 @@ void virBufferFreeAndReset(virBufferPtr buf) memset(buf, 0, sizeof(*buf)); } -/** - * virBufferError: - * @buf: the buffer - * - * Check to see if the buffer is in an error state due - * to failed memory allocation or usage error - * - * Return positive errno value or -1 on usage error, 0 if normal - */ -int -virBufferError(const virBuffer *buf G_GNUC_UNUSED) -{ - return 0; -} - /** * virBufferCheckErrorInternal: * @buf: the buffer diff --git a/src/util/virbuffer.h b/src/util/virbuffer.h index 9adec89f57..c7f0568067 100644 --- a/src/util/virbuffer.h +++ b/src/util/virbuffer.h @@ -43,7 +43,6 @@ struct _virBuffer { const char *virBufferCurrentContent(virBufferPtr buf); char *virBufferContentAndReset(virBufferPtr buf); void virBufferFreeAndReset(virBufferPtr buf); -int virBufferError(const virBuffer *buf); int virBufferCheckErrorInternal(const virBuffer *buf) ATTRIBUTE_NONNULL(1); diff --git a/src/util/vircommand.c b/src/util/vircommand.c index 223a2a824e..6baa0b251f 100644 --- a/src/util/vircommand.c +++ b/src/util/vircommand.c @@ -1389,11 +1389,6 @@ virCommandAddEnvBuffer(virCommandPtr cmd, virBufferP= tr buf) return; } - if (virBufferError(buf)) { - cmd->has_error =3D ENOMEM; - virBufferFreeAndReset(buf); - return; - } if (!virBufferUse(buf)) { cmd->has_error =3D EINVAL; return; @@ -1525,8 +1520,7 @@ virCommandAddArgBuffer(virCommandPtr cmd, virBufferPt= r buf) } /* Arg plus trailing NULL. */ - if (virBufferError(buf) || - VIR_RESIZE_N(cmd->args, cmd->maxargs, cmd->nargs, 1 + 1) < 0) { + if (VIR_RESIZE_N(cmd->args, cmd->maxargs, cmd->nargs, 1 + 1) < 0) { cmd->has_error =3D ENOMEM; virBufferFreeAndReset(buf); return; diff --git a/src/util/virlog.c b/src/util/virlog.c index 27843363e7..cf0599c880 100644 --- a/src/util/virlog.c +++ b/src/util/virlog.c @@ -1137,11 +1137,6 @@ virLogGetFilters(void) } virLogUnlock(); - if (virBufferError(&filterbuf)) { - virBufferFreeAndReset(&filterbuf); - return NULL; - } - return virBufferContentAndReset(&filterbuf); } @@ -1185,9 +1180,6 @@ virLogGetOutputs(void) } } - if (virBufferError(&outputbuf)) - goto error; - virLogUnlock(); return virBufferContentAndReset(&outputbuf); diff --git a/tests/cputest.c b/tests/cputest.c index 83b494857f..a277224918 100644 --- a/tests/cputest.c +++ b/tests/cputest.c @@ -268,10 +268,6 @@ cpuTestGuestCPU(const void *arg) virBufferAsprintf(&buf, ",%s", data->modelsName); virBufferAddLit(&buf, "-result"); - if (virBufferError(&buf)) { - virBufferFreeAndReset(&buf); - goto cleanup; - } result =3D virBufferContentAndReset(&buf); if (cpuTestCompareXML(data->arch, cpu, result) < 0) diff --git a/tests/networkxml2firewalltest.c b/tests/networkxml2firewalltes= t.c index b8e974971a..6822a4f4c2 100644 --- a/tests/networkxml2firewalltest.c +++ b/tests/networkxml2firewalltest.c @@ -76,9 +76,6 @@ static int testCompareXMLToArgvFiles(const char *xml, if (networkAddFirewallRules(def) < 0) goto cleanup; - if (virBufferError(&buf)) - goto cleanup; - actual =3D actualargv =3D virBufferContentAndReset(&buf); virTestClearCommandPath(actualargv); virCommandSetDryRun(NULL, NULL, NULL); diff --git a/tests/nwfilterebiptablestest.c b/tests/nwfilterebiptablestest.c index 61b3284397..f7fb03396d 100644 --- a/tests/nwfilterebiptablestest.c +++ b/tests/nwfilterebiptablestest.c @@ -109,9 +109,6 @@ testNWFilterEBIPTablesAllTeardown(const void *opaque G_= GNUC_UNUSED) if (ebiptables_driver.allTeardown("vnet0") < 0) goto cleanup; - if (virBufferError(&buf)) - goto cleanup; - actual =3D virBufferContentAndReset(&buf); virTestClearCommandPath(actual); @@ -180,9 +177,6 @@ testNWFilterEBIPTablesTearOldRules(const void *opaque G= _GNUC_UNUSED) if (ebiptables_driver.tearOldRules("vnet0") < 0) goto cleanup; - if (virBufferError(&buf)) - goto cleanup; - actual =3D virBufferContentAndReset(&buf); virTestClearCommandPath(actual); @@ -229,9 +223,6 @@ testNWFilterEBIPTablesRemoveBasicRules(const void *opaq= ue G_GNUC_UNUSED) if (ebiptables_driver.removeBasicRules("vnet0") < 0) goto cleanup; - if (virBufferError(&buf)) - goto cleanup; - actual =3D virBufferContentAndReset(&buf); virTestClearCommandPath(actual); @@ -263,9 +254,6 @@ testNWFilterEBIPTablesTearNewRules(const void *opaque G= _GNUC_UNUSED) if (ebiptables_driver.tearNewRules("vnet0") < 0) goto cleanup; - if (virBufferError(&buf)) - goto cleanup; - actual =3D virBufferContentAndReset(&buf); virTestClearCommandPath(actual); @@ -335,9 +323,6 @@ testNWFilterEBIPTablesApplyBasicRules(const void *opaqu= e G_GNUC_UNUSED) if (ebiptables_driver.applyBasicRules("vnet0", &mac) < 0) goto cleanup; - if (virBufferError(&buf)) - goto cleanup; - actual =3D virBufferContentAndReset(&buf); virTestClearCommandPath(actual); @@ -425,9 +410,6 @@ testNWFilterEBIPTablesApplyDHCPOnlyRules(const void *op= aque G_GNUC_UNUSED) if (ebiptables_driver.applyDHCPOnlyRules("vnet0", &mac, &val, false) <= 0) goto cleanup; - if (virBufferError(&buf)) - goto cleanup; - actual =3D virBufferContentAndReset(&buf); virTestClearCommandPath(actual); @@ -498,9 +480,6 @@ testNWFilterEBIPTablesApplyDropAllRules(const void *opa= que G_GNUC_UNUSED) if (ebiptables_driver.applyDropAllRules("vnet0") < 0) goto cleanup; - if (virBufferError(&buf)) - goto cleanup; - actual =3D virBufferContentAndReset(&buf); virTestClearCommandPath(actual); diff --git a/tests/nwfilterxml2firewalltest.c b/tests/nwfilterxml2firewallt= est.c index bef3790da2..6b17a33953 100644 --- a/tests/nwfilterxml2firewalltest.c +++ b/tests/nwfilterxml2firewalltest.c @@ -394,9 +394,6 @@ static int testCompareXMLToArgvFiles(const char *xml, if (ebiptables_driver.applyNewRules("vnet0", inst.rules, inst.nrules) = < 0) goto cleanup; - if (virBufferError(&buf)) - goto cleanup; - actualargv =3D virBufferContentAndReset(&buf); virTestClearCommandPath(actualargv); virCommandSetDryRun(NULL, NULL, NULL); diff --git a/tests/testutils.c b/tests/testutils.c index a141abc91b..da236c74a1 100644 --- a/tests/testutils.c +++ b/tests/testutils.c @@ -763,8 +763,6 @@ virTestLogContentAndReset(void) { char *ret; - if (virBufferError(&testLog.buf)) - return NULL; ret =3D virBufferContentAndReset(&testLog.buf); if (!ret) ret =3D g_strdup(""); diff --git a/tests/vboxsnapshotxmltest.c b/tests/vboxsnapshotxmltest.c index 3d6171e266..38dbba9eff 100644 --- a/tests/vboxsnapshotxmltest.c +++ b/tests/vboxsnapshotxmltest.c @@ -36,11 +36,6 @@ testFilterXML(char *xml) virBufferStrcat(&buf, *xmlLine, "\n", NULL); } - if (virBufferError(&buf)) { - virReportOOMError(); - goto cleanup; - } - ret =3D virBufferContentAndReset(&buf); cleanup: diff --git a/tests/virbuftest.c b/tests/virbuftest.c index 34aa8b678b..56a6ece8f6 100644 --- a/tests/virbuftest.c +++ b/tests/virbuftest.c @@ -29,15 +29,13 @@ static int testBufAutoIndent(const void *data G_GNUC_UN= USED) ret =3D -1; } if (virBufferGetIndent(buf) !=3D 3 || - virBufferGetEffectiveIndent(buf) !=3D 3 || - virBufferError(buf)) { + virBufferGetEffectiveIndent(buf) !=3D 3) { VIR_TEST_DEBUG("Wrong indentation"); ret =3D -1; } virBufferAdjustIndent(buf, -2); if (virBufferGetIndent(buf) !=3D 1 || - virBufferGetEffectiveIndent(buf) !=3D 1 || - virBufferError(buf)) { + virBufferGetEffectiveIndent(buf) !=3D 1) { VIR_TEST_DEBUG("Wrong indentation"); ret =3D -1; } @@ -50,17 +48,12 @@ static int testBufAutoIndent(const void *data G_GNUC_UN= USED) virBufferAdjustIndent(buf, 3); virBufferFreeAndReset(buf); if (virBufferGetIndent(buf) !=3D 0 || - virBufferGetEffectiveIndent(buf) !=3D 0 || - virBufferError(buf)) { + virBufferGetEffectiveIndent(buf) !=3D 0) { VIR_TEST_DEBUG("Reset didn't clear indentation"); ret =3D -1; } virBufferAdjustIndent(buf, 2); virBufferAddLit(buf, "1"); - if (virBufferError(buf)) { - VIR_TEST_DEBUG("Buffer had error"); - return -1; - } if (STRNEQ(virBufferCurrentContent(buf), " 1")) { VIR_TEST_DEBUG("Wrong content"); ret =3D -1; @@ -87,11 +80,6 @@ static int testBufAutoIndent(const void *data G_GNUC_UNU= SED) virBufferEscapeShell(buf, " 11"); virBufferAddChar(buf, '\n'); - if (virBufferError(buf)) { - VIR_TEST_DEBUG("Buffer had error"); - return -1; - } - result =3D virBufferContentAndReset(buf); if (!result || STRNEQ(result, expected)) { virTestDifference(stderr, expected, result); @@ -125,11 +113,6 @@ static int testBufTrim(const void *data G_GNUC_UNUSED) virBufferTrim(buf, "b,,", 1); virBufferTrim(buf, ",", -1); - if (virBufferError(buf)) { - VIR_TEST_DEBUG("Buffer had error"); - return -1; - } - result =3D virBufferContentAndReset(buf); if (!result || STRNEQ(result, expected)) { virTestDifference(stderr, expected, result); diff --git a/tests/virfirewalltest.c b/tests/virfirewalltest.c index a5323a4256..c4827918c3 100644 --- a/tests/virfirewalltest.c +++ b/tests/virfirewalltest.c @@ -234,9 +234,6 @@ testFirewallSingleGroup(const void *opaque) if (virFirewallApply(fw) < 0) goto cleanup; - if (virBufferError(&cmdbuf)) - goto cleanup; - actual =3D virBufferCurrentContent(&cmdbuf); if (STRNEQ_NULLABLE(expected, actual)) { @@ -300,9 +297,6 @@ testFirewallRemoveRule(const void *opaque) if (virFirewallApply(fw) < 0) goto cleanup; - if (virBufferError(&cmdbuf)) - goto cleanup; - actual =3D virBufferCurrentContent(&cmdbuf); if (STRNEQ_NULLABLE(expected, actual)) { @@ -373,9 +367,6 @@ testFirewallManyGroups(const void *opaque G_GNUC_UNUSED) if (virFirewallApply(fw) < 0) goto cleanup; - if (virBufferError(&cmdbuf)) - goto cleanup; - actual =3D virBufferCurrentContent(&cmdbuf); if (STRNEQ_NULLABLE(expected, actual)) { @@ -469,9 +460,6 @@ testFirewallIgnoreFailGroup(const void *opaque G_GNUC_U= NUSED) if (virFirewallApply(fw) < 0) goto cleanup; - if (virBufferError(&cmdbuf)) - goto cleanup; - actual =3D virBufferCurrentContent(&cmdbuf); if (STRNEQ_NULLABLE(expected, actual)) { @@ -543,9 +531,6 @@ testFirewallIgnoreFailRule(const void *opaque G_GNUC_UN= USED) if (virFirewallApply(fw) < 0) goto cleanup; - if (virBufferError(&cmdbuf)) - goto cleanup; - actual =3D virBufferCurrentContent(&cmdbuf); if (STRNEQ_NULLABLE(expected, actual)) { @@ -611,9 +596,6 @@ testFirewallNoRollback(const void *opaque G_GNUC_UNUSED) goto cleanup; } - if (virBufferError(&cmdbuf)) - goto cleanup; - actual =3D virBufferCurrentContent(&cmdbuf); if (STRNEQ_NULLABLE(expected, actual)) { @@ -698,9 +680,6 @@ testFirewallSingleRollback(const void *opaque G_GNUC_UN= USED) goto cleanup; } - if (virBufferError(&cmdbuf)) - goto cleanup; - actual =3D virBufferCurrentContent(&cmdbuf); if (STRNEQ_NULLABLE(expected, actual)) { @@ -788,9 +767,6 @@ testFirewallManyRollback(const void *opaque G_GNUC_UNUS= ED) goto cleanup; } - if (virBufferError(&cmdbuf)) - goto cleanup; - actual =3D virBufferCurrentContent(&cmdbuf); if (STRNEQ_NULLABLE(expected, actual)) { @@ -908,9 +884,6 @@ testFirewallChainedRollback(const void *opaque G_GNUC_U= NUSED) goto cleanup; } - if (virBufferError(&cmdbuf)) - goto cleanup; - actual =3D virBufferCurrentContent(&cmdbuf); if (STRNEQ_NULLABLE(expected, actual)) { @@ -1085,9 +1058,6 @@ testFirewallQuery(const void *opaque G_GNUC_UNUSED) if (virFirewallApply(fw) < 0) goto cleanup; - if (virBufferError(&cmdbuf)) - goto cleanup; - actual =3D virBufferCurrentContent(&cmdbuf); if (expectedLineError) { diff --git a/tests/virkmodtest.c b/tests/virkmodtest.c index 853f4ea14e..e013f8f3b6 100644 --- a/tests/virkmodtest.c +++ b/tests/virkmodtest.c @@ -69,11 +69,7 @@ checkOutput(virBufferPtr buf, const char *exp_cmd) char *actual_cmd =3D NULL; if (!(actual_cmd =3D virBufferContentAndReset(buf))) { - int err =3D virBufferError(buf); - if (err) - fprintf(stderr, "buffer's in error state: %d", err); - else - fprintf(stderr, "cannot compare buffer to exp: %s", exp_cmd); + fprintf(stderr, "cannot compare buffer to exp: %s", exp_cmd); goto cleanup; } diff --git a/tests/virnetdevbandwidthtest.c b/tests/virnetdevbandwidthtest.c index 59647173c3..8039fedbc4 100644 --- a/tests/virnetdevbandwidthtest.c +++ b/tests/virnetdevbandwidthtest.c @@ -84,11 +84,6 @@ testVirNetDevBandwidthSet(const void *data) goto cleanup; if (!(actual_cmd =3D virBufferContentAndReset(&buf))) { - int err =3D virBufferError(&buf); - if (err) { - fprintf(stderr, "buffer's in error state: %d", err); - goto cleanup; - } /* This is interesting, no command has been executed. * Maybe that's expected, actually. */ } diff --git a/tests/virsystemdtest.c b/tests/virsystemdtest.c index 1a78f006cc..b85259f61f 100644 --- a/tests/virsystemdtest.c +++ b/tests/virsystemdtest.c @@ -570,9 +570,6 @@ testActivation(bool useNames) setenv("LISTEN_FDS", nfdstr, 1); setenv("LISTEN_PID", pidstr, 1); - if (virBufferError(&names)) - goto cleanup; - if (useNames) setenv("LISTEN_FDNAMES", virBufferCurrentContent(&names), 1); else diff --git a/tools/virsh-checkpoint.c b/tools/virsh-checkpoint.c index 7fd3914ef2..f9749b5f6d 100644 --- a/tools/virsh-checkpoint.c +++ b/tools/virsh-checkpoint.c @@ -267,11 +267,6 @@ cmdCheckpointCreateAs(vshControl *ctl, virBufferAdjustIndent(&buf, -2); virBufferAddLit(&buf, "\n"); - if (virBufferError(&buf)) { - vshError(ctl, "%s", _("Out of memory")); - goto cleanup; - } - buffer =3D virBufferContentAndReset(&buf); if (vshCommandOptBool(cmd, "print-xml")) { diff --git a/tools/virsh-domain-monitor.c b/tools/virsh-domain-monitor.c index bfff08b0f6..d3beda5670 100644 --- a/tools/virsh-domain-monitor.c +++ b/tools/virsh-domain-monitor.c @@ -2410,12 +2410,6 @@ cmdDomIfAddr(vshControl *ctl, const vshCmd *cmd) type, iface->addrs[j].addr, iface->addrs[j].prefix); - if (virBufferError(&buf)) { - virBufferFreeAndReset(&buf); - virReportOOMError(); - goto cleanup; - } - ip_addr_str =3D virBufferContentAndReset(&buf); if (!ip_addr_str) diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c index 2f3ac2d430..ae7777df09 100644 --- a/tools/virsh-domain.c +++ b/tools/virsh-domain.c @@ -754,11 +754,6 @@ cmdAttachDisk(vshControl *ctl, const vshCmd *cmd) virBufferAdjustIndent(&buf, -2); virBufferAddLit(&buf, "\n"); - if (virBufferError(&buf)) { - vshError(ctl, "%s", _("Failed to allocate XML buffer")); - goto cleanup; - } - xml =3D virBufferContentAndReset(&buf); if (vshCommandOptBool(cmd, "print-xml")) { @@ -1072,11 +1067,6 @@ cmdAttachInterface(vshControl *ctl, const vshCmd *cm= d) virBufferAdjustIndent(&buf, -2); virBufferAddLit(&buf, "\n"); - if (virBufferError(&buf)) { - vshError(ctl, "%s", _("Failed to allocate XML buffer")); - goto cleanup; - } - xml =3D virBufferContentAndReset(&buf); if (vshCommandOptBool(cmd, "print-xml")) { @@ -8396,10 +8386,6 @@ cmdDesc(vshControl *ctl, const vshCmd *cmd) virBufferTrim(&buf, " ", -1); - if (virBufferError(&buf)) { - vshError(ctl, "%s", _("Failed to collect new description/title")); - goto cleanup; - } desc =3D virBufferContentAndReset(&buf); if (edit || desc) { @@ -9517,10 +9503,6 @@ cmdQemuMonitorCommand(vshControl *ctl, const vshCmd = *cmd) virBufferTrim(&buf, " ", -1); - if (virBufferError(&buf)) { - vshError(ctl, "%s", _("Failed to collect command")); - return false; - } monitor_cmd =3D virBufferContentAndReset(&buf); if (vshCommandOptBool(cmd, "hmp")) @@ -9818,10 +9800,6 @@ cmdQemuAgentCommand(vshControl *ctl, const vshCmd *c= md) virBufferTrim(&buf, " ", -1); - if (virBufferError(&buf)) { - vshError(ctl, "%s", _("Failed to collect command")); - goto cleanup; - } guest_agent_cmd =3D virBufferContentAndReset(&buf); judge =3D vshCommandOptInt(ctl, cmd, "timeout", &timeout); @@ -11551,12 +11529,6 @@ cmdDomDisplay(vshControl *ctl, const vshCmd *cmd) params =3D true; } - /* Ensure we can print our URI */ - if (virBufferError(&buf)) { - vshError(ctl, "%s", _("Failed to create display URI")); - goto cleanup; - } - /* Print out our full URI */ VIR_FREE(output); output =3D virBufferContentAndReset(&buf); diff --git a/tools/virsh-pool.c b/tools/virsh-pool.c index bd876aefda..2b315caaa7 100644 --- a/tools/virsh-pool.c +++ b/tools/virsh-pool.c @@ -416,11 +416,6 @@ virshBuildPoolXML(vshControl *ctl, virBufferAdjustIndent(&buf, -2); virBufferAddLit(&buf, "\n"); - if (virBufferError(&buf)) { - vshError(ctl, "%s", _("Failed to allocate XML buffer")); - return false; - } - *xml =3D virBufferContentAndReset(&buf); *retname =3D name; return true; @@ -1480,10 +1475,6 @@ cmdPoolDiscoverSourcesAs(vshControl * ctl, const vsh= Cmd * cmd G_GNUC_UNUSED) } virBufferAdjustIndent(&buf, -2); virBufferAddLit(&buf, "\n"); - if (virBufferError(&buf)) { - vshError(ctl, "%s", _("Out of memory")); - return false; - } srcSpec =3D virBufferContentAndReset(&buf); } diff --git a/tools/virsh-snapshot.c b/tools/virsh-snapshot.c index 751186ebf8..a42397b42e 100644 --- a/tools/virsh-snapshot.c +++ b/tools/virsh-snapshot.c @@ -445,11 +445,6 @@ cmdSnapshotCreateAs(vshControl *ctl, const vshCmd *cmd) virBufferAdjustIndent(&buf, -2); virBufferAddLit(&buf, "\n"); - if (virBufferError(&buf)) { - vshError(ctl, "%s", _("Out of memory")); - goto cleanup; - } - buffer =3D virBufferContentAndReset(&buf); if (vshCommandOptBool(cmd, "print-xml")) { diff --git a/tools/virsh-volume.c b/tools/virsh-volume.c index d09d4435ad..3637e7f603 100644 --- a/tools/virsh-volume.c +++ b/tools/virsh-volume.c @@ -341,10 +341,6 @@ cmdVolCreateAs(vshControl *ctl, const vshCmd *cmd) virBufferAdjustIndent(&buf, -2); virBufferAddLit(&buf, "\n"); - if (virBufferError(&buf)) { - vshError(ctl, "%s", _("Failed to allocate XML buffer")); - goto cleanup; - } xml =3D virBufferContentAndReset(&buf); if (printXML) { diff --git a/tools/vsh.c b/tools/vsh.c index 58ee94b52f..5bab5b5c83 100644 --- a/tools/vsh.c +++ b/tools/vsh.c @@ -2269,9 +2269,6 @@ vshOutputLogFile(vshControl *ctl, int log_level, cons= t char *msg_format, virBufferTrim(&buf, "\n", -1); virBufferAddChar(&buf, '\n'); - if (virBufferError(&buf)) - goto error; - str =3D virBufferContentAndReset(&buf); len =3D strlen(str); @@ -2532,9 +2529,6 @@ vshTreePrintInternal(vshControl *ctl, int ret =3D -1; const char *dev =3D (lookup)(devid, false, opaque); - if (virBufferError(indent)) - goto cleanup; - /* Print this device, with indent if not at root */ vshPrint(ctl, "%s%s%s\n", virBufferCurrentContent(indent), root ? "" : "+- ", dev); @@ -2543,8 +2537,6 @@ vshTreePrintInternal(vshControl *ctl, if (!root) { virBufferAddChar(indent, devid =3D=3D lastdev ? ' ' : '|'); virBufferAddChar(indent, ' '); - if (virBufferError(indent)) - goto cleanup; } /* Determine the index of the last child device */ @@ -2561,8 +2553,6 @@ vshTreePrintInternal(vshControl *ctl, /* Finally print all children */ virBufferAddLit(indent, " "); - if (virBufferError(indent)) - goto cleanup; for (i =3D 0; i < num_devices; i++) { const char *parent =3D (lookup)(i, true, opaque); @@ -3318,10 +3308,6 @@ cmdEcho(vshControl *ctl, const vshCmd *cmd) if (xml) { virBufferEscapeString(&xmlbuf, "%s", arg); - if (virBufferError(&xmlbuf)) { - vshError(ctl, "%s", _("Failed to allocate XML buffer")); - return false; - } str =3D virBufferContentAndReset(&xmlbuf); } else { str =3D g_strdup(arg); @@ -3335,10 +3321,6 @@ cmdEcho(vshControl *ctl, const vshCmd *cmd) VIR_FREE(str); } - if (virBufferError(&buf)) { - vshError(ctl, "%s", _("Failed to allocate XML buffer")); - return false; - } arg =3D virBufferContentAndReset(&buf); if (arg) { if (err) --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri Apr 26 20:39:31 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 205.139.110.120 as permitted sender) client-ip=205.139.110.120; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zoho.com: domain of redhat.com designates 205.139.110.120 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=1571925628; cv=none; d=zoho.com; s=zohoarc; b=DkFJynP0ZKktL1lQ87l7T+ELwc6CaR2H6JEAqcXI7RBAUQVeVaL8Vg/v2kLn5Ares6JrDjZhmevOVSi/GP+0jg+z9D5TDZjytcrurzaQzqU82P2zoibb8vbRk2Uu60GBTQT+Xz0VXnZxKcrDN75feIA1xMw9ey2lpK1aEry+eOk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1571925628; 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=6HF/v+ffmZW2Gv0I+VIo/pgws98niTwH8dvso129qPM=; b=HIuLVyjKko59WyoVYYSq9WwTT+aa0DDa9HlsoNp+xpqY4OCjpmwcZeOBFSif/JYJOELhStXgDrWAdV8E4sYn7uKMxNPmd+aUs9RFK4RVxW7E2V7uiqSMMqahnMJUw2zAVufrJqfjt2UkbJyJQ+Nn6aufU1+nx2kaulIA+Pxw46U= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=pass; spf=pass (zoho.com: domain of redhat.com designates 205.139.110.120 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-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) by mx.zohomail.com with SMTPS id 1571925628815592.4199842140292; Thu, 24 Oct 2019 07:00:28 -0700 (PDT) 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-356-2lFy8nDZOomQTrU0KsmaFQ-1; Thu, 24 Oct 2019 09:57:30 -0400 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 DF42C107AD37; Thu, 24 Oct 2019 13:57:22 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id B55F45D772; Thu, 24 Oct 2019 13:57:22 +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 5A5893FB40; Thu, 24 Oct 2019 13:57:22 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x9ODvAqh026457 for ; Thu, 24 Oct 2019 09:57:10 -0400 Received: by smtp.corp.redhat.com (Postfix) id 9C86F100164D; Thu, 24 Oct 2019 13:57:10 +0000 (UTC) Received: from angien.redhat.com (unknown [10.43.2.229]) by smtp.corp.redhat.com (Postfix) with ESMTP id CD2161001B33 for ; Thu, 24 Oct 2019 13:57:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1571925627; 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=6HF/v+ffmZW2Gv0I+VIo/pgws98niTwH8dvso129qPM=; b=SeKkN76LrEo8RG1bCunqCCTqFgti9xs5xhS3af+xWGSIZIrGJctDGWOpZbNdLzRBPa+wxK ufAitIJT+0KFb2XbYNemy8WU/ap3U49ZB3bqeuAkUpYXiyMME6X2FERmNlcWqk19v3lTdo hakUuCn5z4urMfc5+IzAw1rPd6afj/g= From: Peter Krempa To: libvir-list@redhat.com Date: Thu, 24 Oct 2019 15:56:36 +0200 Message-Id: <4a85ff9992329444c1757846c3254e1e80d955a2.1571925291.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 18/19] util: buffer: Remove virBufferCheckError 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 X-MC-Unique: 2lFy8nDZOomQTrU0KsmaFQ-1 X-Mimecast-Spam-Score: 0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" The function now never returned an error so we can drop it fully. Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- src/bhyve/bhyve_command.c | 3 - src/bhyve/bhyve_driver.c | 5 - src/conf/capabilities.c | 16 --- src/conf/checkpoint_conf.c | 3 - src/conf/cpu_conf.c | 7 -- src/conf/domain_addr.c | 2 - src/conf/domain_capabilities.c | 1 - src/conf/domain_conf.c | 38 ------- src/conf/interface_conf.c | 3 - src/conf/network_conf.c | 3 - src/conf/node_device_conf.c | 3 - src/conf/nwfilter_conf.c | 9 -- src/conf/secret_conf.c | 3 - src/conf/snapshot_conf.c | 3 - src/conf/storage_conf.c | 12 -- src/conf/virnetworkobj.c | 3 - src/conf/virnetworkportdef.c | 3 - src/conf/virnwfilterbindingdef.c | 3 - src/conf/virnwfilterbindingobj.c | 3 - src/conf/virsavecookie.c | 3 - src/cpu/cpu_map.c | 2 - src/cpu/cpu_x86.c | 10 -- src/esx/esx_driver.c | 12 -- src/esx/esx_util.c | 6 - src/esx/esx_vi.c | 15 --- src/esx/esx_vi_methods.c | 3 - src/hyperv/hyperv_driver.c | 3 - src/hyperv/hyperv_wmi.c | 10 -- src/libvirt_private.syms | 1 - src/libxl/libxl_conf.c | 5 - src/libxl/libxl_driver.c | 2 - src/libxl/libxl_migration.c | 3 - src/libxl/xen_common.c | 13 --- src/libxl/xen_xl.c | 9 -- src/libxl/xen_xm.c | 3 - src/locking/lock_driver_sanlock.c | 3 - src/lxc/lxc_container.c | 3 - src/lxc/lxc_controller.c | 3 - src/lxc/lxc_driver.c | 2 - src/lxc/lxc_fuse.c | 4 - src/network/bridge_driver.c | 6 - src/node_device/node_device_udev.c | 3 - src/nwfilter/nwfilter_ebiptables_driver.c | 8 -- src/nwfilter/nwfilter_gentech_driver.c | 2 - src/phyp/phyp_driver.c | 4 - src/qemu/qemu_capabilities.c | 3 +- src/qemu/qemu_command.c | 130 ---------------------- src/qemu/qemu_domain.c | 4 - src/qemu/qemu_driver.c | 2 - src/qemu/qemu_migration_cookie.c | 3 - src/qemu/qemu_monitor_json.c | 3 - src/rpc/virnetlibsshsession.c | 6 - src/rpc/virnetsocket.c | 8 -- src/rpc/virnetsshsession.c | 6 - src/storage/storage_backend_rbd.c | 6 - src/storage/storage_util.c | 13 --- src/util/virbitmap.c | 1 - src/util/virbuffer.c | 14 --- src/util/virbuffer.h | 13 --- src/util/vircommand.c | 3 - src/util/virconf.c | 6 - src/util/virdnsmasq.c | 6 - src/util/virfilecache.c | 3 - src/util/virnetdevopenvswitch.c | 3 - src/util/virpidfile.c | 7 -- src/util/virqemu.c | 3 - src/util/virresctrl.c | 4 +- src/util/virstoragefile.c | 3 - src/util/virstring.c | 5 - src/util/virsysinfo.c | 3 - src/util/virsystemd.c | 6 - src/util/viruri.c | 3 - src/util/virxml.c | 5 - src/vmx/vmx.c | 3 - src/vz/vz_driver.c | 5 - tests/qemublocktest.c | 6 - tests/qemumonitorjsontest.c | 6 - tests/qemumonitortestutils.c | 2 - tests/vircgrouptest.c | 2 - tools/virsh-domain.c | 2 - tools/vsh.c | 3 - 81 files changed, 3 insertions(+), 559 deletions(-) diff --git a/src/bhyve/bhyve_command.c b/src/bhyve/bhyve_command.c index 8ea76cee2e..48336ffa1b 100644 --- a/src/bhyve/bhyve_command.c +++ b/src/bhyve/bhyve_command.c @@ -227,9 +227,6 @@ bhyveBuildAHCIControllerArgStr(const virDomainDef *def, virBufferFreeAndReset(&device); } - if (virBufferCheckError(&buf) < 0) - goto error; - virCommandAddArg(cmd, "-s"); virCommandAddArgFormat(cmd, "%d:0,ahci%s", controller->info.addr.pci.slot, diff --git a/src/bhyve/bhyve_driver.c b/src/bhyve/bhyve_driver.c index e3d984f69a..7da48a08d5 100644 --- a/src/bhyve/bhyve_driver.c +++ b/src/bhyve/bhyve_driver.c @@ -258,8 +258,6 @@ bhyveConnectGetSysinfo(virConnectPtr conn, unsigned int= flags) if (virSysinfoFormat(&buf, privconn->hostsysinfo) < 0) return NULL; - if (virBufferCheckError(&buf) < 0) - return NULL; return virBufferContentAndReset(&buf); } @@ -752,9 +750,6 @@ bhyveConnectDomainXMLToNative(virConnectPtr conn, virBufferAdd(&buf, virCommandToString(cmd, false), -1); - if (virBufferCheckError(&buf) < 0) - goto cleanup; - ret =3D virBufferContentAndReset(&buf); cleanup: diff --git a/src/conf/capabilities.c b/src/conf/capabilities.c index 697d464fe9..953464b09d 100644 --- a/src/conf/capabilities.c +++ b/src/conf/capabilities.c @@ -734,10 +734,6 @@ virCapabilitiesDomainDataLookupInternal(virCapsPtr cap= s, if (virBufferCurrentContent(&buf) && !virBufferCurrentContent(&buf)[0]) virBufferAsprintf(&buf, "%s", _("any configuration")); - if (virBufferCheckError(&buf) < 0) { - virBufferFreeAndReset(&buf); - goto error; - } virReportError(VIR_ERR_INVALID_ARG, _("could not find capabilities for %s"), @@ -930,9 +926,6 @@ virCapabilitiesFormatResctrlMonitor(virBufferPtr buf, monitor->features[i]); } - if (virBufferCheckError(&childrenBuf) < 0) - return -1; - virBufferAddBuffer(buf, &childrenBuf); virBufferAddLit(buf, "\n"); @@ -1014,9 +1007,6 @@ virCapabilitiesFormatCaches(virBufferPtr buf, controls->max_allocation); } - if (virBufferCheckError(&childrenBuf) < 0) - return -1; - if (virBufferUse(&childrenBuf)) { virBufferAddLit(buf, ">\n"); virBufferAddBuffer(buf, &childrenBuf); @@ -1068,9 +1058,6 @@ virCapabilitiesFormatMemoryBandwidth(virBufferPtr buf, control->granularity, control->min, control->max_allocation); - if (virBufferCheckError(&childrenBuf) < 0) - return -1; - if (virBufferUse(&childrenBuf)) { virBufferAddLit(buf, ">\n"); virBufferAddBuffer(buf, &childrenBuf); @@ -1367,9 +1354,6 @@ virCapabilitiesFormatXML(virCapsPtr caps) virBufferAdjustIndent(&buf, -2); virBufferAddLit(&buf, "\n"); - if (virBufferCheckError(&buf) < 0) - return NULL; - return virBufferContentAndReset(&buf); error: diff --git a/src/conf/checkpoint_conf.c b/src/conf/checkpoint_conf.c index 4fa743e0b0..3b7d848079 100644 --- a/src/conf/checkpoint_conf.c +++ b/src/conf/checkpoint_conf.c @@ -499,9 +499,6 @@ virDomainCheckpointDefFormatInternal(virBufferPtr buf, virBufferAdjustIndent(buf, -2); virBufferAddLit(buf, "\n"); - if (virBufferCheckError(buf) < 0) - goto error; - return 0; error: diff --git a/src/conf/cpu_conf.c b/src/conf/cpu_conf.c index 1d9feb2f0a..2b644638a7 100644 --- a/src/conf/cpu_conf.c +++ b/src/conf/cpu_conf.c @@ -668,9 +668,6 @@ virCPUDefFormat(virCPUDefPtr def, if (virCPUDefFormatBufFull(&buf, def, numa) < 0) goto cleanup; - if (virBufferCheckError(&buf) < 0) - goto cleanup; - return virBufferContentAndReset(&buf); cleanup: @@ -731,10 +728,6 @@ virCPUDefFormatBufFull(virBufferPtr buf, if (virDomainNumaDefCPUFormatXML(&childrenBuf, numa) < 0) goto cleanup; - if (virBufferCheckError(&attributeBuf) < 0 || - virBufferCheckError(&childrenBuf) < 0) - goto cleanup; - /* Put it all together */ if (virBufferUse(&attributeBuf) || virBufferUse(&childrenBuf)) { virBufferAddLit(buf, "\n"); - virBufferCheckError(&buf); return virBufferContentAndReset(&buf); } diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 1fb538b9a8..778858fe3e 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -24854,9 +24854,6 @@ virDomainFSDefFormat(virBufferPtr buf, virDomainVirtioOptionsFormat(&driverBuf, def->virtio); - if (virBufferCheckError(&driverBuf) < 0) - goto cleanup; - if (virBufferUse(&driverBuf)) { virBufferAddLit(buf, "virtio); - if (virBufferCheckError(&buf) < 0) - return -1; - *outstr =3D virBufferContentAndReset(&buf); return 0; } @@ -26083,9 +26071,6 @@ virDomainSmartcardDefFormat(virBufferPtr buf, if (virDomainDeviceInfoFormat(&childBuf, &def->info, flags) < 0) goto cleanup; - if (virBufferCheckError(&childBuf) < 0) - goto cleanup; - virBufferAsprintf(buf, "type =3D=3D VIR_DOMAIN_SMARTCARD_TYPE_PASSTHROUGH && virDomainChrAttrsDefFormat(buf, def->data.passthru, false) < 0) { @@ -26196,9 +26181,6 @@ virDomainSoundDefFormat(virBufferPtr buf, if (virDomainDeviceInfoFormat(&childBuf, &def->info, flags) < 0) goto cleanup; - if (virBufferCheckError(&childBuf) < 0) - goto cleanup; - virBufferAsprintf(buf, "\n"); @@ -26584,8 +26566,6 @@ virDomainVideoDefFormat(virBufferPtr buf, virBufferAddLit(buf, "