It generally works fine, however fails when using array name as a pointer:
--- src/b.c
+++ /tmp/cocci-output-7286-034148-b.c
    int * ala;
    char b[12] = "mmm";
    char *c = b + 1;
-    malloc(ala + 1);
-    my_malloc(ala + 2);
+    malloc(*(ala + 1)); // OK
+    my_malloc(*(ala + 2)); // OK

-    malloc(c - b);
+    malloc(*(c - b)); // NOT OK
    return 0;
}

When I replace b declaration with char * b it works fine and doesn't
suggest changing last malloc. Do I miss anything from C spec? Or is it
a bug?

There is clearly a problem. But just for information, you can see the type assigned to each C expression using the -type_c flag. It says that c-b has type char *, which is of course wrong.

julia
_______________________________________________
Cocci mailing list
[email protected]
http://lists.diku.dk/mailman/listinfo/cocci
(Web access from inside DIKUs LAN only)

Reply via email to