[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: |
Alex Bennée |
Subject: |
Re: [PATCH 3/3] Use g_new() & friends where that makes obvious sense |
Date: |
Tue, 15 Mar 2022 16:16:54 +0000 |
User-agent: |
mu4e 1.7.10; emacs 28.0.92 |
Markus Armbruster <armbru@redhat.com> writes:
> Philippe Mathieu-Daudé <philippe.mathieu.daude@gmail.com> writes:
>
>> On 15/3/22 14:59, Markus Armbruster wrote:
>>> Alex Bennée <alex.bennee@linaro.org> writes:
>>>
>>>> Markus Armbruster <armbru@redhat.com> writes:
>>>>
>>>>> 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.
>>>>>
>>>> <snip>
>>>>> diff --git a/semihosting/config.c b/semihosting/config.c
>>>>> index 137171b717..6d48ec9566 100644
>>>>> --- a/semihosting/config.c
>>>>> +++ b/semihosting/config.c
>>>>> @@ -98,7 +98,7 @@ static int add_semihosting_arg(void *opaque,
>>>>> if (strcmp(name, "arg") == 0) {
>>>>> s->argc++;
>>>>> /* one extra element as g_strjoinv() expects NULL-terminated
>>>>> array */
>>>>> - s->argv = g_realloc(s->argv, (s->argc + 1) * sizeof(void *));
>>>>> + s->argv = g_renew(void *, s->argv, s->argc + 1);
>>>>
>>>> This did indeed break CI because s->argv is an array of *char:
>>>>
>>>> ../semihosting/config.c:101:17: error: assignment to ‘const char **’ from
>>>> incompatible pointer type ‘void **’ [-Werror=incompatible-pointer-types]
>>>> 101 | s->argv = g_renew(void *, s->argv, s->argc + 1);
>>>> | ^
>>>> cc1: all warnings being treated as errors
>>>>
>>>> So it did the job of type checking but failed to build ;-)
>>>
>>> You found a hole in my compile testing, thanks!
>>>
>>> I got confused about the configuration of my build trees. Catching such
>>> mistakes is what CI is for :)
>>
>> FYI Alex fixed this here:
>> 20220315121251.2280317-8-alex.bennee@linaro.org/">https://lore.kernel.org/qemu-devel/20220315121251.2280317-8-alex.bennee@linaro.org/
>>
>> So your series could go on top (modulo the Coverity change).
>
> I dropped this hunk in v2.
>
> Whether my v2 or Alex's series goes in first doesn't matter.
That's great. Thanks for finding the ugliness in the first place ;-)
--
Alex Bennée
- 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, Cédric Le Goater, 2022/03/14
Re: [PATCH 3/3] Use g_new() & friends where that makes obvious sense, Alex Bennée, 2022/03/14
Re: [PATCH 3/3] Use g_new() & friends where that makes obvious sense, Alex Bennée, 2022/03/14
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, 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