Skip to contentSkip to conversation

Finding non-zero returning functions with SmPL

Cocci SF Markus Elfring 2 participants 3 messages Jul 27, 2015

lore
Share & tools
lore
#0 lore raw

Hello,

I have tried the following small SmPL script out

@non_zero_returning_functions@
identifier work;
type return_type;
@@
*return_type work(...)
{
<+...
return ... when != 0

             when != NULL
         ;

...+>
}

on this bit of source code.

#include <API-test1.h>

int my_status(void)
{
return 1;
}

int main(void)
{
return my_status();
}

elfring at Sonne:~/Projekte/Coccinelle/janitor> spatch.opt -sp-file show_non-zero_returning_functions1.cocci ../Probe/API-test1.c
init_defs_builtins: /usr/local/lib/coccinelle/standard.h
116 120
Fatal error: exception Failure("minus: parse error: \n = File \"show_non-zero_returning_functions1.cocci\", line 8, column 13, charpos = 116\n around = 'when', whole content = return ... when != 0;\n")

Do I use the SmPL construct "when" in an inappropriate way here?

Regards,
Markus

#1 lore raw
Quoted 5 lines

*return_type work(...)
{
<+...
return ... when != 0

             when != NULL

You can't put when on a ... that represents a single expression.

The simplest thing would be to put return e; and then when you declare e, put

expression e != {0,NULL};

julia

#2 lore raw
Quoted 7 lines
Quoted 5 lines

*return_type work(...)
{
<+...
return ... when != 0

             when != NULL

You can't put when on a ... that represents a single expression.

Thanks for your quick clarification.

Would it make sense that the Coccinelle software will also support this construct at such a script place directly?

Quoted 1 line

expression e != {0,NULL};

The use of this SmPL metavariable seems to work to some degree.

Regards,
Markus