From patchwork Sun Jun 4 15:45:15 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Michael Tokarev X-Patchwork-Id: 770934 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3wgjFf0FK3z9rxl for ; Mon, 5 Jun 2017 01:55:02 +1000 (AEST) Received: from localhost ([::1]:57390 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dHXrn-0008Ok-PD for incoming@patchwork.ozlabs.org; Sun, 04 Jun 2017 11:54:59 -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 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" 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ée Signed-off-by: Max Filippov Reviewed-by: Philippe Mathieu-Daudé 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 XtensaMemory *memory, const char *name) { unsigned i; - char *num_name = malloc(strlen(name) + sizeof(i) * 3 + 1); + GString *num_name = g_string_new(NULL); for (i = 0; i < memory->num; ++i) { MemoryRegion *m; - sprintf(num_name, "%s%u", name, i); - m = g_malloc(sizeof(*m)); - memory_region_init_ram(m, NULL, num_name, + g_string_printf(num_name, "%s%u", name, i); + m = 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); } static uint64_t translate_phys_addr(void *opaque, uint64_t addr)