cocci.inria.fr archive mirror
 help / color / mirror / Atom feed
* [Cocci] RFC catching hidden code in if conditions
@ 2019-03-25 13:03 Nicholas Mc Guire
  2019-03-25 13:14 ` Julia Lawall
  2019-03-26 19:04 ` Markus Elfring
  0 siblings, 2 replies; 3+ messages in thread
From: Nicholas Mc Guire @ 2019-03-25 13:03 UTC (permalink / raw)
  To: Cocci


HI !

 Noticed that the nuveau driver uses a fair number of if (var=val,boolean-condition){}
 which while legal C-code just makes it hard to read - and some seems buggy 
 actually. The below spatch find about 50 cases - not sure though if this is
 actually complete ?

thx!
hofrat

/// Check for unconditional code "hiding" in an if condition
/// effectively that code is unconditionally executed before
/// reaching the actual branch statement - which just makes it
/// hard to read and thus is always wrong.
/// Some of the cases found also look buggy  
/// In other cases some excess () are left in place in the
/// generated patches - so some postprocessing may be needed.
///
/// As of 5.0-rc8 all 50 cases look like they are found and fixed
/// correctly - incorrectly only in the sense that the patched 
/// code is equivalent to the original code. but as this is in
/// the nouveau driver only it might well be that this only
/// fits that specific pattern and others might have wilder ways
/// to achieve the same - so confidence Low for now
///
// Confidence: Low
// Comments:
// Options: --no-includes --include-headers

virtual patch
virtual report

@badif@
position p;
statement S;
expression E1,E2;
@@

  if@p (E1,E2) S

@script:python depends on report@
p << badif.p;
@@

msg = "unconditional code hiding in if condition" 
coccilib.report.print_report(p[0],msg)

@fixbadif depends on badif && patch@
position p=badif.p;
statement S;
expression E1=badif.E1,E2=badif.E2;
@@

+ E1;
  if@p (
- E1,
  E2) 
  S 

_______________________________________________
Cocci mailing list
Cocci@systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2019-03-26 19:05 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-03-25 13:03 [Cocci] RFC catching hidden code in if conditions Nicholas Mc Guire
2019-03-25 13:14 ` Julia Lawall
2019-03-26 19:04 ` Markus Elfring

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).