glimpse icon indicating copy to clipboard operation
glimpse copied to clipboard

Remove unnecessary null pointer checks

Open elfring opened this issue 10 years ago • 0 comments

An extra null pointer check is not needed in functions like the following.

Would you like to add the following semantic patch approach to a test directory?

@Remove_unnecessary_pointer_checks1@
expression x;
@@
-if (\(x != 0 \| x != NULL\))
    free(x);

@Remove_unnecessary_pointer_checks2@
expression x;
@@
-if (\(x != 0 \| x != NULL\)) {
    free(x);
    x = \(0 \| NULL\);
-}

@Remove_unnecessary_pointer_checks3@
expression a, b;
@@
-if (\(a != 0 \| a != NULL\) && \(b != 0 \| b != NULL\))
+if (a)
    free(b);

@Remove_unnecessary_pointer_checks4@
expression a, b;
@@
-if (\(a != 0 \| a != NULL\) && \(b != 0 \| b != NULL\)) {
+if (a) {
    free(b);
    b = \(0 \| NULL\);
 }

How do you think about to apply a corresponding update suggestion which can be generated by the software "Coccinelle"?

elfring avatar Sep 27 '14 10:09 elfring