[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH 3/3] Use g_new() & friends where that makes obvious sense
From: |
Markus Armbruster |
Subject: |
Re: [PATCH 3/3] Use g_new() & friends where that makes obvious sense |
Date: |
Tue, 15 Mar 2022 15:03:02 +0100 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux) |
Eric Blake <eblake@redhat.com> writes:
> On Mon, Mar 14, 2022 at 05:01:08PM +0100, Markus Armbruster wrote:
>> 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).
>>
>> Patch created mechanically with:
>>
>> $ spatch --in-place --sp-file scripts/coccinelle/use-g_new-etc.cocci \
>> --macro-file scripts/cocci-macro-file.h FILES...
>>
>> Signed-off-by: Markus Armbruster <armbru@redhat.com>
>> ---
>
> I agree that this is mechanical, but...
>
> <snip>
>> qga/commands-win32.c | 8 ++---
>> qga/commands.c | 2 +-
>> qom/qom-qmp-cmds.c | 2 +-
>> replay/replay-char.c | 4 +--
>> replay/replay-events.c | 10 +++---
>> scripts/coverity-scan/model.c | 2 +-
>
> ...are we sure we want to touch this particular file?
Good catch!
>> diff --git a/scripts/coverity-scan/model.c b/scripts/coverity-scan/model.c
>> index 9d4fba53d9..30bea672e1 100644
>> --- a/scripts/coverity-scan/model.c
>> +++ b/scripts/coverity-scan/model.c
>> @@ -356,7 +356,7 @@ int g_poll (GPollFD *fds, unsigned nfds, int timeout)
>> typedef struct _GIOChannel GIOChannel;
>> GIOChannel *g_io_channel_unix_new(int fd)
>> {
>> - GIOChannel *c = g_malloc0(sizeof(GIOChannel));
>> + GIOChannel *c = g_new0(GIOChannel, 1);
>> __coverity_escape__(fd);
>> return c;
>> }
>
> Our model has a definition of g_malloc0(), but I'm not sure whether
> Coverity picks up the macro g_new0() in the same manner.
I believe it does, by parsing the macro definition from the header.
Regardless, I'd prefer to keep model.c self-contained. I'll drop this
hunk.
Thanks!
- Re: [PATCH 3/3] Use g_new() & friends where that makes obvious sense, (continued)
Re: [PATCH 3/3] Use g_new() & friends where that makes obvious sense, Eric Blake, 2022/03/15
- Re: [PATCH 3/3] Use g_new() & friends where that makes obvious sense,
Markus Armbruster <=
Re: [PATCH 3/3] Use g_new() & friends where that makes obvious sense, Dr. David Alan Gilbert, 2022/03/15
[PATCH 2/3] 9pfs: Use g_new() & friends where that makes obvious sense, Markus Armbruster, 2022/03/14
[PATCH 1/3] scripts/coccinelle: New use-g_new-etc.cocci, Markus Armbruster, 2022/03/14
Re: [PATCH 0/3] Use g_new() & friends where that makes obvious, Philippe Mathieu-Daudé, 2022/03/14