From: Markus Armbruster <armbru@redhat.com>
To: Christian <christianslima@proton.me>
Cc: qemu-devel@nongnu.org, Laurent Vivier <laurent@vivier.eu>
Subject: Re: [PATCH] disas: converts malloc to g_malloc0
Date: Tue, 30 Jun 2026 08:53:00 +0200 [thread overview]
Message-ID: <87zf0cplir.fsf@pond.sub.org> (raw)
In-Reply-To: <ivgABRYgjCAvFEp6oiNyDgt4s4XO8EYr1VBiYPbuEzRH4UFDlpqPw4AgUlgFBb2AAKdw2EybEjNzoz8S4QPaJE2cUQjs48fm4BM97KPZ_IQ=@proton.me> (Christian's message of "Tue, 30 Jun 2026 06:02:56 +0000")
Christian <christianslima@proton.me> writes:
> Hi, Markus!
>
>> Any particular reason to initialize, or is it "just in case"?
>
> It's a just in case, the next lines initialize the values.
Suggest to mention that in the commit message, just to be perfectly
clear.
>> g_new0(struct m68k_opcode, m68k_numopcodes) would be more obviously
>> safe, because it checks the multiplication for for overflow.
>
> When I tried g_new0, but the first argument is a pointer to `struct m68k_opcode`, but it gives me an error, so I just used g_malloc0 instead. If I pass just the struct as the first argument gives me the same result as using the g_malloc0?
g_new0(T, N) allocates an array T[N]. The macro's return value is a T
*. So, g_new0(struct m68k_opcode *, m68k_numopcodes) returns struct
m68k_opcode **, which fails type checking. Good, because it's indeed
wrong: you want an array of T, not an array of T *.
Details at <https://docs.gtk.org/glib/func.new0.html>.
Questions?
next prev parent reply other threads:[~2026-06-30 6:53 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-30 0:52 [PATCH] disas: converts malloc to g_malloc0 Christian S. Lima
2026-06-30 4:55 ` Markus Armbruster
2026-06-30 6:02 ` Christian
2026-06-30 6:53 ` Markus Armbruster [this message]
2026-06-30 21:41 ` Christian
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=87zf0cplir.fsf@pond.sub.org \
--to=armbru@redhat.com \
--cc=christianslima@proton.me \
--cc=laurent@vivier.eu \
--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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.