[Cocci] Remove unnecessary null pointer checks?

SF Markus Elfring elfring at users.sourceforge.net
Sun Feb 23 23:14:02 CET 2014


> But I think that a switch is highly improbable for making such a test,
> so you could just drop it.

I have got another idea for a bit of fine-tuning. I got the impression from the
manual that the SmPL syntax element "singleton" might be applicable.

elfring at Sonne:~/Projekte/Coccinelle/janitor> LINE='-----' && echo $LINE &&
PAT=list_input_parameter_validation2.cocci && cat $PAT && echo $LINE &&
SP=/usr/local/bin/spatch && $SP --version && $SP --sp-file $PAT
/usr/src/linux-stable/fs/btrfs/extent_map.c
-----


@initialize:python@
@@
import sys
result = []
mark = ['"', '', '"']
delimiter = '|'

def store_positions(fun, typ, point, places):
    """Add source code positions to an internal list."""
    for place in places:
        fields = []
        fields.append(fun)

        mark[1] = typ
        fields.append(''.join(mark))

        fields.append(point)

        mark[1] = place.file.replace('"', '""')
        fields.append(''.join(mark))

        fields.append(place.line)
        fields.append(str(int(place.column) + 1))
        result.append(delimiter.join(fields))

@safety_check@
identifier work, input;
type data_type;
position pos;
statement is, es;
@@
 void work at pos(...,data_type input,...)
 {
  ...
( if (!input) return;
| if (input) is
? else es
  ;
)
  ...
 }

@script:python collection depends on safety_check@
typ << safety_check.data_type;
fun << safety_check.work;
point << safety_check.input;
places << safety_check.pos;
@@
store_positions(fun, typ, point, places)

@finalize:python@
@@
if result:
   result.insert(0, delimiter.join(("function", '"data type"', '"parameter"',
'"source file"', "line", "column")))
   print("\r\n".join(result))
else:
   sys.stderr.write("No result for this analysis!\n")
-----
spatch version 1.0.0-rc20 with Python support and with PCRE support
init_defs_builtins: /usr/local/share/coccinelle/standard.h
warning: incompatible arity found on line 36
?safety_check:es
Fatal error: exception Failure("get_before_e: not supported")


Can this situation be improved?

Regards,
Markus



More information about the Cocci mailing list