From nobody Wed Nov 5 18:24:20 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1496591756244647.3846795079638; Sun, 4 Jun 2017 08:55:56 -0700 (PDT) Received: from localhost ([::1]:57400 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dHXsg-0000vb-VR for importer@patchew.org; Sun, 04 Jun 2017 11:55:55 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60921) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dHXpW-0006qg-8P for qemu-devel@nongnu.org; Sun, 04 Jun 2017 11:52:39 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dHXpS-0004zF-Cy for qemu-devel@nongnu.org; Sun, 04 Jun 2017 11:52:38 -0400 Received: from isrv.corpit.ru ([86.62.121.231]:58581) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dHXpS-0004yB-5u; Sun, 04 Jun 2017 11:52:34 -0400 Received: from tsrv.tls.msk.ru (tsrv.tls.msk.ru [192.168.177.2]) by isrv.corpit.ru (Postfix) with ESMTP id 6467E404E4; Sun, 4 Jun 2017 18:52:33 +0300 (MSK) Received: from tls.msk.ru (mjt.vpn.tls.msk.ru [192.168.177.99]) by tsrv.tls.msk.ru (Postfix) with SMTP id AFE9D5F1; Sun, 4 Jun 2017 18:45:29 +0300 (MSK) Received: (nullmailer pid 16377 invoked by uid 1000); Sun, 04 Jun 2017 15:45:27 -0000 From: Michael Tokarev To: qemu-devel@nongnu.org Date: Sun, 4 Jun 2017 18:45:15 +0300 Message-Id: X-Mailer: git-send-email 2.11.0 In-Reply-To: References: In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 86.62.121.231 Subject: [Qemu-devel] [PULL 11/22] hw/xtensa: sim: use g_string/g_new X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: qemu-trivial@nongnu.org, Max Filippov , Michael Tokarev Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" From: Max Filippov Replace malloc/free/sprintf with g_string/g_string_printf/g_string_free. Replace g_malloc with g_new when allocating the MemoryRegion to get more type safety. Suggested-by: Alex Benn=C3=A9e Signed-off-by: Max Filippov Reviewed-by: Philippe Mathieu-Daud=C3=A9 Signed-off-by: Michael Tokarev --- hw/xtensa/sim.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/hw/xtensa/sim.c b/hw/xtensa/sim.c index d2d1d3a6fd..b27e28d802 100644 --- a/hw/xtensa/sim.c +++ b/hw/xtensa/sim.c @@ -41,21 +41,21 @@ static void xtensa_create_memory_regions(const XtensaMe= mory *memory, const char *name) { unsigned i; - char *num_name =3D malloc(strlen(name) + sizeof(i) * 3 + 1); + GString *num_name =3D g_string_new(NULL); =20 for (i =3D 0; i < memory->num; ++i) { MemoryRegion *m; =20 - sprintf(num_name, "%s%u", name, i); - m =3D g_malloc(sizeof(*m)); - memory_region_init_ram(m, NULL, num_name, + g_string_printf(num_name, "%s%u", name, i); + m =3D g_new(MemoryRegion, 1); + memory_region_init_ram(m, NULL, num_name->str, memory->location[i].size, &error_fatal); vmstate_register_ram_global(m); memory_region_add_subregion(get_system_memory(), memory->location[i].addr, m); } - free(num_name); + g_string_free(num_name, true); } =20 static uint64_t translate_phys_addr(void *opaque, uint64_t addr) --=20 2.11.0