On Tue, 14 Jun 2011, Derek M Jones wrote:

> Greg,
> 
> > I'm on vacation, so this is more for fun and also so that I can learn
> > more about Coccinelle :) You are right though... and your reasoning is
> > also why I've been leaving these cases alone to date. If I do tackle
> > this problem, it will be more for the academic challenge than anything
> > else.
> 
> More common patterns that can be replaced by a single statement are:
> 
> if (foo) return 1; // or TRUE
> return 0; // or FALSE

Actually, there are far more of these than I expected.  Or at least the 
opposite case, with return 0 under the if.  But I'm not sure what the 
improvement would be, unless it is known that foo is already 1, rather 
than some other nonzero integer.  One could write return !!foo;, but I'm 
not sure that that is an improvement.  And many have fairly complicated 
test expressions.

julia


> and perhaps:
> 
> if (bar) return x+1;
> return x;
> 
> Sometimes an else is involved in the above.
> 
> -- 
> Derek M. Jones                         tel: +44 (0) 1252 520 667
> Knowledge Software Ltd                 mailto:[email protected]
> Source code analysis                   http://www.knosof.co.uk
> _______________________________________________
> Cocci mailing list
> [email protected]
> http://lists.diku.dk/mailman/listinfo/cocci
> (Web access from inside DIKUs LAN only)
> 
_______________________________________________
Cocci mailing list
[email protected]
http://lists.diku.dk/mailman/listinfo/cocci
(Web access from inside DIKUs LAN only)

Reply via email to