From: Stefan Weil <sw@weilnetz.de>
To: qemu-devel@nongnu.org
Cc: "Edgar E. Iglesias" <edgar.iglesias@gmail.com>,
Stefan Weil <sw@weilnetz.de>
Subject: [Qemu-devel] [PATCH] cris-dis: Clean memory allocation
Date: Mon, 9 Jan 2012 19:23:42 +0100 [thread overview]
Message-ID: <1326133422-1106-1-git-send-email-sw@weilnetz.de> (raw)
The old code used sizeof(const struct cris_opcode **) where it should
have used sizeof(const struct cris_opcode *). As both sizes give the
same value, the resulting binary was ok, but static code analyzers
like coverity and clang complained.
This is fixed here, and the code is also simplified by using g_new0.
Signed-off-by: Stefan Weil <sw@weilnetz.de>
---
cris-dis.c | 34 ++++++----------------------------
1 files changed, 6 insertions(+), 28 deletions(-)
diff --git a/cris-dis.c b/cris-dis.c
index 5b8e90b..1d174ba 100644
--- a/cris-dis.c
+++ b/cris-dis.c
@@ -1396,34 +1396,12 @@ get_opcode_entry (unsigned int insn,
/* Allocate and clear the opcode-table. */
if (opc_table == NULL)
{
- opc_table = g_malloc (65536 * sizeof (opc_table[0]));
-
- memset (opc_table, 0, 65536 * sizeof (const struct cris_opcode *));
-
- dip_prefixes
- = g_malloc (65536 * sizeof (const struct cris_opcode **));
-
- memset (dip_prefixes, 0, 65536 * sizeof (dip_prefixes[0]));
-
- bdapq_m1_prefixes
- = g_malloc (65536 * sizeof (const struct cris_opcode **));
-
- memset (bdapq_m1_prefixes, 0, 65536 * sizeof (bdapq_m1_prefixes[0]));
-
- bdapq_m2_prefixes
- = g_malloc (65536 * sizeof (const struct cris_opcode **));
-
- memset (bdapq_m2_prefixes, 0, 65536 * sizeof (bdapq_m2_prefixes[0]));
-
- bdapq_m4_prefixes
- = g_malloc (65536 * sizeof (const struct cris_opcode **));
-
- memset (bdapq_m4_prefixes, 0, 65536 * sizeof (bdapq_m4_prefixes[0]));
-
- rest_prefixes
- = g_malloc (65536 * sizeof (const struct cris_opcode **));
-
- memset (rest_prefixes, 0, 65536 * sizeof (rest_prefixes[0]));
+ opc_table = g_new0(const struct cris_opcode *, 65536);
+ dip_prefixes = g_new0(const struct cris_opcode *, 65536);
+ bdapq_m1_prefixes = g_new0(const struct cris_opcode *, 65536);
+ bdapq_m2_prefixes = g_new0(const struct cris_opcode *, 65536);
+ bdapq_m4_prefixes = g_new0(const struct cris_opcode *, 65536);
+ rest_prefixes = g_new0(const struct cris_opcode *, 65536);
}
/* Get the right table if this is a prefix.
--
1.7.2.5
next reply other threads:[~2012-01-09 18:23 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-01-09 18:23 Stefan Weil [this message]
2012-01-10 8:38 ` [Qemu-devel] [PATCH] cris-dis: Clean memory allocation Edgar E. Iglesias
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1326133422-1106-1-git-send-email-sw@weilnetz.de \
--to=sw@weilnetz.de \
--cc=edgar.iglesias@gmail.com \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).