A few functions are well-known that they forward just an input parameter as
their return value.

I imagine that the Coccinelle software can find such implementations that are similar to an interface style like "strcat()" or "strcpy()" if the corresponding source files are available for a static code analysis. I hope that a few functions can be found by this approach that do not perform input parameter validation usually.

I would like to try this out from the package "coccinelle 1.0.0-13.4" on my openSUSE 12.1 system. But I stumble on the following messages.


elfring@Sonne:~/Projekte/Coccinelle/lokal/demos/pass-through> SRC=pt1.c && cat $SRC && spatch -sp_file pt1.cocci $SRC -debug
char* my_copy(char const * source, char* destination)
{
  /* Do something ... */

  return destination;
}

char* my_append(char* prefix, char const * addition)
{
  /* Data adjustment ... */

  return prefix;
}

int main(void)
{
  char buffer[123];

  my_append(my_copy("check", buffer), " this out");
}
init_defs_builtins: /usr/share/coccinelle/standard.h
-----------------------------------------------------------------------
processing semantic patch file: pt1.cocci
with isos from: /usr/share/coccinelle/standard.iso
-----------------------------------------------------------------------
@pass_through@
identifier function, input;
type parameter;
@@
 function(..., parameter input, ...)
 {
  ...
  return input;
  ...
 }

@@
identifier pass_through.function;
expression result;
@@
(
*function(...)
|
*result = function(...)
)

HANDLING: pt1.c
-----------------------------------------------------------------------
let's go
-----------------------------------------------------------------------
-----------------------------------------------------------------------
pass_through =
-----------------------------------------------------------------------
dependencies for rule pass_through satisfied:
binding in = []
binding relevant in = []
     transformation info is empty
     binding out = [pass_through.function --> id my_copy]
     transformation info is empty
     binding out = [pass_through.function --> id my_append]
-----------------------------------------------------------------------
rule starting on line 12 =
-----------------------------------------------------------------------
dependencies for rule rule starting on line 12 satisfied:
binding in = [pass_through.function --> id my_copy]
binding relevant in = [pass_through.function --> id my_copy]
     transformation info returned:
          transform state: 7
               with rule_elem: *pass_through:function*(*...*)
               with binding: [pass_through.function --> id my_copy]
     binding out = []
     transform one node: 7
dependencies for rule rule starting on line 12 satisfied:
binding in = [pass_through.function --> id my_append]
binding relevant in = [pass_through.function --> id my_append]
     transformation info returned:
          transform state: 7
               with rule_elem: *pass_through:function*(*...*)
               with binding: [pass_through.function --> id my_append]
     binding out = []
     transform one node: 7

previous modification:
MINUS
According to environment 2:
   pass_through.function -> id my_copy
   pass_through.function -> id my_copy

current modification:
MINUS
According to environment 2:
   pass_through.function -> id my_append
   pass_through.function -> id my_append

Fatal error: exception Failure("rule starting on line 12: already tagged token:
C code context
File "pt1.c", line 19, column 20,  charpos = 271
around = '"check"', whole content = my_append(my_copy("check", buffer), " this out");")


Do I need to adjust my filter pattern a bit more?

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

Reply via email to