On Tue, 13 Dec 2011, SF Markus Elfring wrote:

If you want feedback about the degree to which you code can be parsed, you can use the -parse_c option, perhaps additionally with -verbose_parsing, if you want
more information.

How do you think about a test result like the following?


elfring@Sonne:~/altes Heim/Projekte/Coccinelle/Probe> LANG=C && LINE='-----' && SRC=Cstdlib-test1.c && cat $SRC && echo $LINE && g++ $SRC && echo $LINE && P=../pattern1.cocci && cat $P && echo $LINE && spatch -sp_file $P $SRC -I /usr/include -parse_c -verbose_parsing
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <signal.h>

sig_atomic_t termination = 0;

void action(int ID)
{
 termination = 1;
}

int main(void)
{
 static char const name[] = "check.txt";
 char* x = (char*) malloc(123);

 strcpy(x, name);
 signal(SIGTERM, action);

 {
   FILE* c = fopen(x, "r");

   {
     fread(x, 1, 12, c);
     printf("file: %s", name);
     fclose(c);
   }

   realloc(x, 456);
 }

 fprintf(stderr, "terminated: %d", (int) termination);

 return EXIT_SUCCESS;
}
-----
Cstdlib-test1.c: In function 'int main()':
Cstdlib-test1.c:30:20: warning: ignoring return value of 'void* realloc(void*, size_t)', declared with attribute warn_unused_result [-Wunused-result]
-----
@r@
identifier f;
@@
f(...)
{
 ...
}

@is_void@
identifier r.f;
@@
void f(...)
{
 ...
}

@depends on !is_void@
identifier r.f;
identifier g;
@@
g(...)
{<+...
* f(...);
...+>}
-----
init_defs_builtins: /usr/share/coccinelle/standard.h

PARSING: Cstdlib-test1.c
-----------------------------------------------------------------------
maybe 10 most problematic tokens
-----------------------------------------------------------------------
-----------------------------------------------------------------------
NB total files = 1; perfect = 1; pbs = 0; timeout = 0; =========> 100%
nb good = 35,  nb passed = 0 =========> 0.000000% passed
nb good = 35,  nb bad = 0 =========> 100.000000% good


Should any more unchecked return values be detected from the shown functions before further usage in this example?

I don't know what function prototypes you are finding in the header files. If you like, you can print out their names using python, by matching a function prototype in one rule, and then inheriting the metavariable containing the function name into a python rule and then printing it.

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

Reply via email to