[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-devel] [PATCH 04/88] cocci: avoid use of g_new0()
From: |
Philippe Mathieu-Daudé |
Subject: |
Re: [Qemu-devel] [PATCH 04/88] cocci: avoid use of g_new0() |
Date: |
Sat, 7 Oct 2017 00:41:53 -0300 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.3.0 |
On 10/06/2017 08:48 PM, Philippe Mathieu-Daudé wrote:
> Signed-off-by: Philippe Mathieu-Daudé <address@hidden>
> ---
> scripts/coccinelle/g_new.cocci | 46
> ++++++++++++++++++++++++++++++++++++++++++
> 1 file changed, 46 insertions(+)
>
> diff --git a/scripts/coccinelle/g_new.cocci b/scripts/coccinelle/g_new.cocci
> index 368f0c5651..9643ce3f23 100644
> --- a/scripts/coccinelle/g_new.cocci
> +++ b/scripts/coccinelle/g_new.cocci
> @@ -127,6 +127,52 @@ T **m;
> - *m = g_malloc0(sizeof(**m));
> + *m = g_new0(T *, 1);
>
> +////////////////////////////////////////
> +//
> +// no point in zeroing the allocation
> +//
> +
> +// the loop right afterwards fully initializes the memory
> +@@
> +type T;
> +identifier a, i;
> +expression c, e;
> +@@
> +(
> +-a = g_new0(T, c);
> + ... when != a, c
> ++a = g_new(T, c);
> + for (i = 0; i < c; i++) {
> + a[i] = e;
> + }
> +|
> +-a = g_try_new0(T, c);
> + ... when != a, c
> ++a = g_try_new(T, c);
> + for (i = 0; i < c; i++) {
> + a[i] = e;
> + }
> +)
> +
> +// compound literals
> +@@
> +type T;
> +identifier p;
> +expression s, e;
> +@@
> +(
> +- p = g_malloc0(s);
> ++ p = g_malloc(s);
> +|
> +- p = g_try_malloc0(s);
> ++ p = g_try_malloc(s);
> +|
> +- p = g_new0(T, 1);
> ++ p = g_new(T, 1);
> +)
> + ... when != p
> + *p = e;
It seems I misunderstood compound literals, I somehow believed this
would imply uninitialized fields would be zeroed.
So this transformation leads to incorrect code.
> +
> ////////////////////////////////////////
> //
> // last transformations: cleanups
>
- [Qemu-devel] [PATCH 00/88] use g_new() family of functions, Philippe Mathieu-Daudé, 2017/10/06
- [Qemu-devel] [PATCH 01/88] cocci: script to use g_new() & friends, Philippe Mathieu-Daudé, 2017/10/06
- [Qemu-devel] [PATCH 02/88] cocci: add more g_new() transformations, Philippe Mathieu-Daudé, 2017/10/06
- [Qemu-devel] [PATCH 03/88] cocci: extract typeof() from g_new(), Philippe Mathieu-Daudé, 2017/10/06
- [Qemu-devel] [PATCH 04/88] cocci: avoid use of g_new0(), Philippe Mathieu-Daudé, 2017/10/06
- Re: [Qemu-devel] [PATCH 04/88] cocci: avoid use of g_new0(),
Philippe Mathieu-Daudé <=
- [Qemu-devel] [PATCH 05/88] cocci: use g_strfreev(), Philippe Mathieu-Daudé, 2017/10/06
- [Qemu-devel] [PATCH 06/88] ARM: use g_new() family of functions, Philippe Mathieu-Daudé, 2017/10/06
- [Qemu-devel] [PATCH 07/88] Audio: use g_new() family of functions, Philippe Mathieu-Daudé, 2017/10/06
- [Qemu-devel] [PATCH 08/88] BT: use g_new() family of functions, Philippe Mathieu-Daudé, 2017/10/06
- [Qemu-devel] [PATCH 09/88] Bootdevice: use g_new() family of functions, Philippe Mathieu-Daudé, 2017/10/06
- [Qemu-devel] [PATCH 10/88] Character devices: use g_new() family of functions, Philippe Mathieu-Daudé, 2017/10/06
- [Qemu-devel] [PATCH 11/88] Cryptodev Backends: use g_new() family of functions, Philippe Mathieu-Daudé, 2017/10/06
- [Qemu-devel] [PATCH 12/88] backends/hostmem: use g_new() family of functions, Philippe Mathieu-Daudé, 2017/10/06
- [Qemu-devel] [PATCH 13/88] Dirty Bitmaps: use g_new() family of functions, Philippe Mathieu-Daudé, 2017/10/06