From patchwork Wed Jan 15 13:56:26 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Alberto Garcia X-Patchwork-Id: 11334687 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 19B2014B7 for ; Wed, 15 Jan 2020 13:57:09 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id C2AFC222C3 for ; Wed, 15 Jan 2020 13:57:08 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=igalia.com header.i=@igalia.com header.b="g3vaNMwY" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org C2AFC222C3 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=igalia.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:54478 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1irjAR-00009G-PW for patchwork-qemu-devel@patchwork.kernel.org; Wed, 15 Jan 2020 08:57:07 -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 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==; 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 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 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_Benn=C3=A9e?= , Max Reitz , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" 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é Signed-off-by: Alberto Garcia Reviewed-by: Alex Bennée Reviewed-by: Philippe Mathieu-Daudé 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(BlockDriverState *bs) static void report_unsupported_feature(Error **errp, Qcow2Feature *table, uint64_t mask) { - char *features = g_strdup(""); - char *old; + g_autoptr(GString) features = g_string_sized_new(60); while (table && table->name[0] != '\0') { if (table->type == QCOW2_FEAT_TYPE_INCOMPATIBLE) { if (mask & (1ULL << table->bit)) { - old = features; - features = 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 &= ~(1ULL << table->bit); } } @@ -470,14 +469,14 @@ static void report_unsupported_feature(Error **errp, Qcow2Feature *table, } if (mask) { - old = features; - features = 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, mask); } - error_setg(errp, "Unsupported qcow2 feature(s): %s", features); - g_free(features); + error_setg(errp, "Unsupported qcow2 feature(s): %s", features->str); } /*