From nobody Sun Feb 8 16:24:07 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1569604676; cv=none; d=zoho.com; s=zohoarc; b=CkIVm70P4K01TuYneb11rFQRiBBx+C16DAaYuIV9jz6C8ZsYXoretDbeNzf0IoP5ASbUPVbdLxPJkM9vI+ec4kpFhV4y74zP/O1KJr3YNZlqNFvEwlTtbCwBi4vaShTchqOckbaVnbgspxwtuz8B9H1BP6Ojmb+l0N5TI/JdL0c= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1569604676; 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:ARC-Authentication-Results; bh=cBx42dpiNl9MpHTnwS2hqQyGgTz98ksBW9Tcb4sZRj8=; b=Jb6mivBhqSFe3aybRTnzdZ9LJSNx/OXuVhXXQcxwQHUJ/zXiABD0lXyFso/zY7G/o08GrzxKPIfj4wayawOy791ikkeTD2HMgsfViksBbtznlfr1dSqdoXq59w4RB+stGoN/d9BYLT5IgNUXdTVb83DO0puat/oczNnDbOm2fus= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1569604676165942.3764988188594; Fri, 27 Sep 2019 10:17:56 -0700 (PDT) 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 mx1.redhat.com (Postfix) with ESMTPS id A61942111; Fri, 27 Sep 2019 17:17:54 +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 8360460624; Fri, 27 Sep 2019 17:17:54 +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 42AFD4EE6A; Fri, 27 Sep 2019 17:17:54 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x8RHHjEh016557 for ; Fri, 27 Sep 2019 13:17:45 -0400 Received: by smtp.corp.redhat.com (Postfix) id 5709A6012A; Fri, 27 Sep 2019 17:17:45 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-112-55.ams2.redhat.com [10.36.112.55]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8492C600C6; Fri, 27 Sep 2019 17:17:44 +0000 (UTC) From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Date: Fri, 27 Sep 2019 18:17:27 +0100 Message-Id: <20190927171733.10842-6-berrange@redhat.com> In-Reply-To: <20190927171733.10842-1-berrange@redhat.com> References: <20190927171733.10842-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 05/11] util: use glib string allocation/formatting functions X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.6.2 (mx1.redhat.com [10.5.110.71]); Fri, 27 Sep 2019 17:17:55 +0000 (UTC) Convert the string duplication APIs to use the g_strdup family of APIs. Annoyingly our virVasprintf/virAsprintf functions return the character count, even though 90% of our usage doesn't need it. To retain compat with these semantics we have a call to strlen which costs CPU time. We previously used the 'strdup-posix' gnulib module because mingw does not set errno to ENOMEM on failure We previously used the 'strndup' gnulib module because this function does not exist on mingw. We previously used the 'vasprintf' gnulib module because of many GNU supported format specifiers not working on non-Linux platforms. glib's own equivalent standardizes on GNU format specifiers too. Signed-off-by: Daniel P. Berrang=C3=A9 --- bootstrap.conf | 3 --- src/util/virstring.c | 19 +++++++------------ 2 files changed, 7 insertions(+), 15 deletions(-) diff --git a/bootstrap.conf b/bootstrap.conf index 549d18c6d4..b6b75f9301 100644 --- a/bootstrap.conf +++ b/bootstrap.conf @@ -100,8 +100,6 @@ stat-time stdarg stpcpy strchrnul -strdup-posix -strndup strerror strerror_r-posix strptime @@ -117,7 +115,6 @@ uname unsetenv useless-if-before-free usleep -vasprintf verify vc-list-files vsnprintf diff --git a/src/util/virstring.c b/src/util/virstring.c index a4cc7e9c0a..c8c888b2a0 100644 --- a/src/util/virstring.c +++ b/src/util/virstring.c @@ -730,12 +730,9 @@ virVasprintfInternal(char **strp, const char *fmt, va_list list) { - int ret; + *strp =3D g_strdup_vprintf(fmt, list); =20 - if ((ret =3D vasprintf(strp, fmt, list)) =3D=3D -1) - abort(); - - return ret; + return strlen(*strp); } =20 int @@ -743,12 +740,12 @@ virAsprintfInternal(char **strp, const char *fmt, ...) { va_list ap; - int ret; =20 va_start(ap, fmt); - ret =3D virVasprintfInternal(strp, fmt, ap); + *strp =3D g_strdup_vprintf(fmt, ap); va_end(ap); - return ret; + + return strlen(*strp); } =20 /** @@ -936,8 +933,7 @@ virStrdup(char **dest, *dest =3D NULL; if (!src) return 0; - if (!(*dest =3D strdup(src))) - abort(); + *dest =3D g_strdup(src); =20 return 1; } @@ -965,8 +961,7 @@ virStrndup(char **dest, return 0; if (n < 0) n =3D strlen(src); - if (!(*dest =3D strndup(src, n))) - abort(); + *dest =3D g_strndup(src, n); =20 return 1; } --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list