From nobody Sun May 5 13:36:34 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1579096639; cv=none; d=zohomail.com; s=zohoarc; b=j/e17yQa0fGQnmqdTY+U399ZBP1z0lZpM/a6wCAZfOH+FI4mgCY22tlHd/f4grXT6RT3z+dOjAs+9jyPrxlCNwdLubb1b2/BhSOFCs36v20YAmPqEOWhdWaD6sAGdj+IBNEvOSQ1P3NxgiH/14Zs5vWeCvGpw4SRjIqoM0xHrhA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1579096639; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To; bh=l6dXk7mR0xuvOEX7rAc6XlsFXeiWlU8CW4e7KwhDkXY=; b=JL0SnB3SHovNXRAGLRhJEoRvntNU0QsEC68HJXSQKautSJob40wDL+RywSaoRYsSd2gFrO9KD7DTh4sq1OXjuYiImZlf+OBUdyxSla/GL59BRxIFg4bjpIzZDp5FesSx1h/EUzeZ86JCMaPscuuqV+S32JpdYvwqZWgJH4bROJU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 157909663907722.13959351498795; Wed, 15 Jan 2020 05:57:19 -0800 (PST) Received: from localhost ([::1]:54478 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1irjAb-00009G-E1 for importer@patchew.org; Wed, 15 Jan 2020 08:57:17 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:33652) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1irj9x-00086g-GS for qemu-devel@nongnu.org; Wed, 15 Jan 2020 08:56:38 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1irj9w-0001Pm-95 for qemu-devel@nongnu.org; Wed, 15 Jan 2020 08:56:37 -0500 Received: from fanzine.igalia.com ([178.60.130.6]:50430) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1irj9v-0001M3-MI; Wed, 15 Jan 2020 08:56:36 -0500 Received: from [192.168.12.213] (helo=perseus.local) by fanzine.igalia.com with esmtpsa (Cipher TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim) id 1irj9q-0000d8-RX; Wed, 15 Jan 2020 14:56:30 +0100 Received: from berto by perseus.local with local (Exim 4.92) (envelope-from ) id 1irj9q-00054L-HP; Wed, 15 Jan 2020 14:56:30 +0100 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=Content-Transfer-Encoding:Content-Type:MIME-Version:Message-Id:Date:Subject:Cc:To:From; bh=l6dXk7mR0xuvOEX7rAc6XlsFXeiWlU8CW4e7KwhDkXY=; b=g3vaNMwYc/k9OGjJnLHRRVsNYQ8hFNkgvNVd0INcncnVg3gen8kaCN1aXvAdqghEelXb4WiUZCTW6DA8KrljDWU3WNCZxo+Se0l1A7y35vfotsE/9CyD/DaBQpbdl8cvAQMwVOYq3z7Uexn5D7QCWHniksWc42PVBaMIz55GC0kiThpOSoxRg8Gt3Yatbq6I7dzuAu1DgsMVCrQpQKUyZqosFp2Ldms8ZeksdRlmgf8+fb/hebbZTJYa94n4UkNZgVL3bOBNV4teKKXUM2fMMLxw8qcl3qqXDeR1kr9CHwoDH5xNzPEyTXRsVlKiXe0LgJXrXaFKHevre2IvZU1KYw==; From: Alberto Garcia To: qemu-devel@nongnu.org Subject: [PATCH v2] qcow2: Use a GString in report_unsupported_feature() Date: Wed, 15 Jan 2020 14:56:26 +0100 Message-Id: <20200115135626.19442-1-berto@igalia.com> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x (no timestamps) [generic] [fuzzy] X-Received-From: 178.60.130.6 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Alberto Garcia , qemu-block@nongnu.org, =?UTF-8?q?Alex=20Benn=C3=A9e?= , Max Reitz , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) This is a bit more efficient than having to allocate and free memory for each item. The default size (60) is enough for all the existing incompatible features or the "Unknown incompatible feature" message. Suggested-by: Philippe Mathieu-Daud=C3=A9 Signed-off-by: Alberto Garcia Reviewed-by: Alex Benn=C3=A9e Reviewed-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Stefano Garzarella --- block/qcow2.c | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) v2: Use g_autoptr and update commit message diff --git a/block/qcow2.c b/block/qcow2.c index cef9d72b3a..e29fc07068 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -453,16 +453,15 @@ static void cleanup_unknown_header_ext(BlockDriverSta= te *bs) static void report_unsupported_feature(Error **errp, Qcow2Feature *table, uint64_t mask) { - char *features =3D g_strdup(""); - char *old; + g_autoptr(GString) features =3D g_string_sized_new(60); =20 while (table && table->name[0] !=3D '\0') { if (table->type =3D=3D QCOW2_FEAT_TYPE_INCOMPATIBLE) { if (mask & (1ULL << table->bit)) { - old =3D features; - features =3D g_strdup_printf("%s%s%.46s", old, *old ? ", "= : "", - table->name); - g_free(old); + if (features->len > 0) { + g_string_append(features, ", "); + } + g_string_append_printf(features, "%.46s", table->name); mask &=3D ~(1ULL << table->bit); } } @@ -470,14 +469,14 @@ static void report_unsupported_feature(Error **errp, = Qcow2Feature *table, } =20 if (mask) { - old =3D features; - features =3D g_strdup_printf("%s%sUnknown incompatible feature: %"= PRIx64, - old, *old ? ", " : "", mask); - g_free(old); + if (features->len > 0) { + g_string_append(features, ", "); + } + g_string_append_printf(features, + "Unknown incompatible feature: %" PRIx64, m= ask); } =20 - error_setg(errp, "Unsupported qcow2 feature(s): %s", features); - g_free(features); + error_setg(errp, "Unsupported qcow2 feature(s): %s", features->str); } =20 /* --=20 2.20.1