coccinelle: polish FREE_AND_NULL rules
authorRené Scharfe <l.s.r@web.de>
Sun, 25 Jun 2017 08:01:04 +0000 (10:01 +0200)
committerJunio C Hamano <gitster@pobox.com>
Thu, 29 Jun 2017 17:46:16 +0000 (10:46 -0700)
There are two rules for using FREE_AND_NULL in free.cocci, one for
pointer types and one for expressions. Both cause coccinelle to remove
empty lines and even newline characters between replacements for some
reason; consecutive "free(x);/x=NULL;" sequences end up as multiple
FREE_AND_NULL calls on the same time.

Remove the type rule, as the expression rule already covers it, and
rearrange the lines of the latter to place the addition of FREE_AND_NULL
between the removals, which causes coccinelle to leave surrounding
whitespace untouched.

Signed-off-by: Rene Scharfe <l.s.r@web.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
contrib/coccinelle/free.cocci
index f2d97e755b891aac988121212a3bb2188b3a150a..4490069df9650df6be58a8ad3f566329f7afd6ae 100644 (file)
@@ -10,17 +10,9 @@ expression E;
 - if (!E)
   free(E);
 
-@@
-type T;
-T *ptr;
-@@
-- free(ptr);
-- ptr = NULL;
-+ FREE_AND_NULL(ptr);
-
 @@
 expression E;
 @@
 - free(E);
-- E = NULL;
 + FREE_AND_NULL(E);
+- E = NULL;