// Dereference of an expression that has been checked to be NULL
//
// Confidence: Moderate
// Copyright: (C) Gilles Muller, Julia Lawall, EMN, INRIA, DIKU.  GPLv2.
// URL: https://coccinelle.gitlabpages.inria.fr/website/rules/isnull.html
// Options:

@r exists@
expression E, E1;
identifier f, f1;
statement S1,S2,S3;
position p;
@@

if (E == NULL)
{
  ... when != if (E == NULL) S1 else S2
      when != E = E1
      when != f1(...,&E,...)
  E@p->f
  ... when any
  return ...;
}
else S3

@script:python@
E << r.E;
p << r.p;
@@

print "* file: %s deref of NULL value %s on line %s" % (p[0].file,E,p[0].line)