Skip to content

Remove unnecessary null pointer checks #5

@elfring

Description

@elfring

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"?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions