From: Stuart Brady <sdb@zubnet.me.uk>
To: qemu-devel@nongnu.org
Cc: Stuart Brady <sdb@zubnet.me.uk>
Subject: [Qemu-devel] [PATCH 4/5] Convert remaining calls to g_malloc(sizeof(type)) using casts to g_new()
Date: Thu, 20 Oct 2011 09:03:39 +0100 [thread overview]
Message-ID: <1319097820-4788-4-git-send-email-sdb@zubnet.me.uk> (raw)
In-Reply-To: <1319097820-4788-1-git-send-email-sdb@zubnet.me.uk>
Convert calls to g_malloc() and g_malloc0() to g_new() and g_new0()
respectively, in cases where the return value is casted to the same
type as specified using sizeof(type) as passed to g_malloc().
Coccinelle did not match these when matching assignments involving an
expression corresponding to the type used for determining the size to
allocate. Such cases deserve more careful review, in case the types do
not match, so are submitted separately.
This was achieved using Coccinelle with the following semantic patch:
@@ type T; @@
-(T *)g_malloc(sizeof(T))
+g_new(T, 1)
@@ type T; @@
-(T *)g_malloc0(sizeof(T))
+g_new0(T, 1)
@@ type T; expression N; @@
-(T *)g_malloc(sizeof(T) * N)
+g_new(T, N)
@@ type T; expression N; @@
-(T *)g_malloc0(sizeof(T) * N)
+g_new0(T, N)
Signed-off-by: Stuart Brady <sdb@zubnet.me.uk>
---
hw/sd.c | 2 +-
libcacard/vcard_emul_nss.c | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/hw/sd.c b/hw/sd.c
index c6186c1..038d60c 100644
--- a/hw/sd.c
+++ b/hw/sd.c
@@ -410,7 +410,7 @@ static void sd_reset(SDState *sd, BlockDriverState *bdrv)
if (sd->wp_groups)
g_free(sd->wp_groups);
sd->wp_switch = bdrv ? bdrv_is_read_only(bdrv) : 0;
- sd->wp_groups = (int *) g_malloc0(sizeof(int) * sect);
+ sd->wp_groups = g_new0(int, sect);
memset(sd->function_group, 0, sizeof(int) * 6);
sd->erase_start = 0;
sd->erase_end = 0;
diff --git a/libcacard/vcard_emul_nss.c b/libcacard/vcard_emul_nss.c
index 8897bae..795aeaa 100644
--- a/libcacard/vcard_emul_nss.c
+++ b/libcacard/vcard_emul_nss.c
@@ -1180,7 +1180,7 @@ vcard_emul_options(const char *args)
g_strndup(type_params, type_params_length);
count = count_tokens(args, ',', ')') + 1;
vreaderOpt->cert_count = count;
- vreaderOpt->cert_name = (char **)g_malloc(count*sizeof(char *));
+ vreaderOpt->cert_name = g_new(char *, count);
for (i = 0; i < count; i++) {
const char *cert = args;
args = strpbrk(args, ",)");
--
1.7.4.1
next prev parent reply other threads:[~2011-10-20 8:04 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-10-20 8:03 [Qemu-devel] [PATCH 1/5] Convert calls to g_malloc() using casts to g_new() Stuart Brady
2011-10-20 8:03 ` [Qemu-devel] [PATCH 2/5] Convert use of ptr = g_malloc(sizeof(*ptr)) " Stuart Brady
2011-10-20 8:03 ` [Qemu-devel] [PATCH 3/5] Convert use of ptr = g_malloc(sizeof(type)) " Stuart Brady
2011-10-20 8:03 ` Stuart Brady [this message]
2011-10-20 8:03 ` [Qemu-devel] [PATCH 5/5] Convert remaining calls to " Stuart Brady
2011-10-20 9:05 ` Paolo Bonzini
2011-10-21 0:26 ` Stuart Brady
2011-10-21 7:37 ` Paolo Bonzini
2011-10-21 17:56 ` Stuart Brady
2011-10-23 13:45 ` Blue Swirl
2011-10-20 8:55 ` [Qemu-devel] [PATCH 1/5] Convert calls to g_malloc() using casts " Paolo Bonzini
2011-10-21 0:34 ` Stuart Brady
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=1319097820-4788-4-git-send-email-sdb@zubnet.me.uk \
--to=sdb@zubnet.me.uk \
--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).