Replace "if (x) free (x)" with "free (x)"

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Replace "if (x) free (x)" with "free (x)"

Sourceware - cgen list mailing list
Most younger programmers have never heard of a libc "free"
implementation that didn't simply return without doing anything when
passed a NULL pointer, and think it weird that old fossils still write
code that tests for NULL before calling free.  I've been going through
the binutils source removing these unnecessary tests.  This cleans up
some generated files in opcodes/.  OK to apply?

        * desc-cpu.scm (@arch@_cgen_cpu_close): Free without first
        checking for non-NULL.

diff --git a/desc-cpu.scm b/desc-cpu.scm
index b24c9f2..5bf5bc7 100644
--- a/desc-cpu.scm
+++ b/desc-cpu.scm
@@ -918,18 +918,10 @@ void
   regfree (CGEN_INSN_RX (insns));
     }  
 
-  if (cd->macro_insn_table.init_entries)
-    free ((CGEN_INSN *) cd->macro_insn_table.init_entries);
-
-  if (cd->insn_table.init_entries)
-    free ((CGEN_INSN *) cd->insn_table.init_entries);
-
-  if (cd->hw_table.entries)
-    free ((CGEN_HW_ENTRY *) cd->hw_table.entries);
-
-  if (cd->operand_table.entries)
-    free ((CGEN_HW_ENTRY *) cd->operand_table.entries);
-
+  free ((CGEN_INSN *) cd->macro_insn_table.init_entries);
+  free ((CGEN_INSN *) cd->insn_table.init_entries);
+  free ((CGEN_HW_ENTRY *) cd->hw_table.entries);
+  free ((CGEN_HW_ENTRY *) cd->operand_table.entries);
   free (cd);
 }
 

--
Alan Modra
Australia Development Lab, IBM
Reply | Threaded
Open this post in threaded view
|

Re: Replace "if (x) free (x)" with "free (x)"

Sourceware - cgen list mailing list
Hi -

> [...]  OK to apply?

Sure!

- FChE