Signed-off-by: Philippe Mathieu-Daudé <f4...@amsat.org> --- 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; + //////////////////////////////////////// // // last transformations: cleanups -- 2.14.2