Hi Bernhard! On 2023-03-01T22:28:56+0100, Bernhard Reutner-Fischer via Gcc-patches <gcc-patches@gcc.gnu.org> wrote: > // POSIX: free(NULL) is perfectly valid > // quote: If ptr is a null pointer, no action shall occur. > @ rule1 @ > expression e; > @@ > > - if (e != NULL) > - { free(e); } > + free (e);
Nice, Coccinelle/spatch! (Another very interesting tool that I so far had no chance to actually use.) > # find ./ \( -name "*.[ch]" -o -name "*.cpp" \) -a \( ! -path > "./gcc/testsuite/*" -a ! -path "./gcc/contrib/*" \) -exec spatch --sp-file > ~/coccinelle/free-without-if-null.0.cocci --in-place Also include '*.cc' if you'd like to find some more in 'gcc/' (and possibly elsewhere, too) than just the following lonely one. ;-) > --- a/gcc/ada/rtinit.c > +++ b/gcc/ada/rtinit.c > @@ -481,8 +481,7 @@ __gnat_runtime_initialize (int install_handler) > > FindClose (hDir); > > - if (dir != NULL) > - free (dir); > + free (dir); Grüße Thomas ----------------- Siemens Electronic Design Automation GmbH; Anschrift: Arnulfstraße 201, 80634 München; Gesellschaft mit beschränkter Haftung; Geschäftsführer: Thomas Heurung, Frank Thürauf; Sitz der Gesellschaft: München; Registergericht München, HRB 106955