superfluous conditionals around free()
Remove superfluous conditions around free().
It is perfectly valid to call free(NULL):
https://pubs.opengroup.org/onlinepubs/9699919799/functions/free.html
If ptr is a null pointer, no action shall occur.
Hence i suggest the following patch to remove the superfluous "if" statements before calling free():
The coccinelle patch below
$ cat free-without-if-null.0.cocci ; echo EOF // 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); EOF
would be run like
cd freeciv # attention, we will modify the files in-place for simplicity here: freeciv$ find ./ \( -name "*.[ch]" -o -name "*.cpp" \) -exec spatch --sp-file ~/free-without-if-null.0.cocci --in-place
I can attach a sample patch against the main branch.
From the looks we could remove the function string_free and use plain free() directly. WDYT?
And a quick question about strvec_new, why doesn't this simply use fc_calloc?
thanks,
Remove superfluous conditions around free().
It is perfectly valid to call free(NULL):
https://pubs.opengroup.org/onlinepubs/9699919799/functions/free.html
If ptr is a null pointer, no action shall occur.
Hence i suggest the following patch to remove the superfluous "if" statements before calling free():
The coccinelle patch below
would be run like
I can attach a sample patch against the main branch.