Received: from eggs.gnu.org ([2001:4830:134:3::10]:58368) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Y0Yg6-00061A-TK for qemu-devel@nongnu.org; Mon, 15 Dec 2014 11:39:29 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Y0Yg0-00059a-GT for qemu-devel@nongnu.org; Mon, 15 Dec 2014 11:39:22 -0500 Received: from mx1.redhat.com ([209.132.183.28]:56845) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Y0Yg0-00059J-89 for qemu-devel@nongnu.org; Mon, 15 Dec 2014 11:39:16 -0500 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id sBFGdEte024106 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL) for ; Mon, 15 Dec 2014 11:39:15 -0500 From: Paolo Bonzini Date: Mon, 15 Dec 2014 17:38:03 +0100 Message-Id: <1418661511-22348-20-git-send-email-pbonzini@redhat.com> In-Reply-To: <1418661511-22348-1-git-send-email-pbonzini@redhat.com> References: <1418661511-22348-1-git-send-email-pbonzini@redhat.com> Subject: [Qemu-devel] [PULL 19/47] x86: Use g_new() & friends where that makes obvious sense List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Markus Armbruster From: Markus Armbruster g_new(T, n) is neater than g_malloc(sizeof(T) * n). It's also safer, for two reasons. One, it catches multiplication overflowing size_t. Two, it returns T * rather than void *, which lets the compiler catch more type errors. This commit only touches allocations with size arguments of the form sizeof(T). Signed-off-by: Markus Armbruster Reviewed-by: Eric Blake Signed-off-by: Paolo Bonzini --- hw/i386/pc.c | 3 +-- target-i386/kvm.c | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/hw/i386/pc.c b/hw/i386/pc.c index 8be50a4..60c1d54 100644 --- a/hw/i386/pc.c +++ b/hw/i386/pc.c @@ -601,8 +601,7 @@ int e820_add_entry(uint64_t address, uint64_t length, uint32_t type) } /* new "etc/e820" file -- include ram too */ - e820_table = g_realloc(e820_table, - sizeof(struct e820_entry) * (e820_entries+1)); + e820_table = g_renew(struct e820_entry, e820_table, e820_entries + 1); e820_table[e820_entries].address = cpu_to_le64(address); e820_table[e820_entries].length = cpu_to_le64(length); e820_table[e820_entries].type = cpu_to_le32(type); diff --git a/target-i386/kvm.c b/target-i386/kvm.c index 60c4475..8832a02 100644 --- a/target-i386/kvm.c +++ b/target-i386/kvm.c @@ -278,7 +278,7 @@ static void kvm_hwpoison_page_add(ram_addr_t ram_addr) return; } } - page = g_malloc(sizeof(HWPoisonPage)); + page = g_new(HWPoisonPage, 1); page->ram_addr = ram_addr; QLIST_INSERT_HEAD(&hwpoison_page_list, page, list); } -- 1.8.3.1