From nobody Wed Apr 24 09:02:06 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=1579013781; cv=none; d=zohomail.com; s=zohoarc; b=YNxCrgLkWAO/4r2jy8kSN8PCNmXmmeyfJSlR18ewdu/T4ceEBZu7p+rWv9+SN/Tu7y9VpTJJyXJiK3n065IeYY8y25tYap0SVvlwfFqeAix54q2K2wVBvFgGPxAXeAU9JTVR893RPcj3DmPzT7yJzlV9nNPaLi0iK17LGbYgS4o= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1579013781; 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=FsPv6n8VFRZlWe90o3QUM7ajHEmRyD3J7UuMj6UG8OA=; b=VdfEHvmJ7np4SQibTgPHK5mCYHpn88+Eo8KtU7rY/cqEG1jLqt3IZj9sH+MbuFatvaJn71IFdNqhSIjstqS1gpKhaT8xhuOfJNGCHgrHWdl9wCQS9IB7I6C6b1+WDdMoLfO/dLohvgO1VdZtgtQwf1VN8ZddW+472+GtKe89yhA= 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 1579013781743922.5829012822628; Tue, 14 Jan 2020 06:56:21 -0800 (PST) Received: from localhost ([::1]:41176 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1irNcC-0003Rl-BF for importer@patchew.org; Tue, 14 Jan 2020 09:56:20 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:34851) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1irNak-0001bc-Gb for qemu-devel@nongnu.org; Tue, 14 Jan 2020 09:54:52 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1irNag-0005vT-FH for qemu-devel@nongnu.org; Tue, 14 Jan 2020 09:54:50 -0500 Received: from fanzine.igalia.com ([178.60.130.6]:36819) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1irNaf-0005tc-SL; Tue, 14 Jan 2020 09:54:46 -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 1irNaa-0001Za-Ve; Tue, 14 Jan 2020 15:54:41 +0100 Received: from berto by perseus.local with local (Exim 4.92) (envelope-from ) id 1irNaa-0007OY-MZ; Tue, 14 Jan 2020 15:54:40 +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=FsPv6n8VFRZlWe90o3QUM7ajHEmRyD3J7UuMj6UG8OA=; b=MGtJbYqO1gtTfR0QBCp8hxUgeiriatjodRe/unpXNSe6UIt/agkXcWh9ylZXKO/07MBpYrrOXks8M7jcGT6PBxhdTGQfxTi2p4s+4HOdbt276ae6BkQ/C42qXN4m31xWWC28kTU6DIKHw8oN6EW8lKD927BiTAFp/Nld/fkZaEGHhahFZ6Nd0hrn0pfos7SZKHs5ykbapMNH941ZGfaBp5qNJxWM8hSKHCNodinJDZrvSJK9rc59JJi5nl80246rX9XquW0vlwP4hlFF71qCloU3LG6WvOksSaG34eN965yV3Y8LZa17fK1oWmkv27lL98voQHfi2TxyedFQqo2zhA==; From: Alberto Garcia To: qemu-devel@nongnu.org Subject: [PATCH] qcow2: Use a GString in report_unsupported_feature() Date: Tue, 14 Jan 2020 15:54:37 +0100 Message-Id: <20200114145437.28382-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 , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Alberto Garcia , qemu-block@nongnu.org, Max Reitz 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. Suggested-by: Philippe Mathieu-Daud=C3=A9 Signed-off-by: Alberto Garcia Reviewed-by: Alex Benn=C3=A9e --- block/qcow2.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/block/qcow2.c b/block/qcow2.c index cef9d72b3a..ecf6827420 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; + 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,15 @@ 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); + g_string_free(features, TRUE); } =20 /* --=20 2.20.1