Menu

#276 Remove unnecessary null pointer checks

2.0
open
nobody
None
2022-12-14
2022-12-14
No

Discussion

  • Git Lost

    Git Lost - 2022-12-14

    Well I think this comes down to a style preference, mine being to check for NULL before calling free(), to make the logic explicit.

     
    • Markus Elfring

      Markus Elfring - 2022-12-14

      I would prefer to get rid of another bit of redundant source code.

       
      • Git Lost

        Git Lost - 2022-12-14

        Yes I can see that point of view. If you wish to do a Merge Request I'll merge it, thanks.

         
        • Markus Elfring

          Markus Elfring - 2022-12-14

          💭 I am curious if another software developer (besides me) can get into the mood to apply a corresponding update suggestion which could be generated by the software “Coccinelle” (also with the help of a variant from the following script).

          @Remove_unnecessary_pointer_checks@
          expression x;
          @@
          -if (\(x != 0 \| x != NULL\))
              free(x);
          
           
          • Git Lost

            Git Lost - 2022-12-14

            That would be useful, yes. Will try it myself at some stage, and although this particular change isn't high on my to-do list, there may be others that are more so!

             

Log in to post a comment.