saitoha / libsixel

A SIXEL encoder/decoder implementation derived from kmiya's sixel (https://github.com/saitoha/sixel).
MIT License
2.49k stars 83 forks source link

Remove unnecessary null pointer checks #6

Closed elfring closed 9 years ago

elfring commented 10 years ago

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 will eventually be generated by the software "Coccinelle"?

saitoha commented 10 years ago

@elfring Fixed. Would this be OK?

elfring commented 10 years ago

Thanks for your small source code improvement.

How do you think about to extend this software update with another clean-up? Would you like to add input parameter validation for functions like "sixel_…_destroy" and "sixel_…_unref" so that corresponding pointer checks can also be deleted directly before their calls?

saitoha commented 10 years ago

@elfring Thanks! I added that things. https://github.com/saitoha/libsixel/compare/fix-issue-6

saitoha commented 9 years ago

fixed.