<div dir="ltr"><div><div><div><div>Hi!<br><br></div>Just a minor note: it might give false positives in case there is a side effect in the condition that is repeated.<br><br></div>Wouldn't it be better to catch these kind of bugs using the constraint manager and checking for always true conditions?<br><br></div>Best Regards,<br></div>Gábor Horváth <br></div><div class="gmail_extra"><br><div class="gmail_quote">On 8 May 2015 at 10:46, Daniel Marjamäki <span dir="ltr"><<a href="mailto:Daniel.Marjamaki@evidente.se" target="_blank">Daniel.Marjamaki@evidente.se</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><br>
<br>
Hello!<br>
<br>
This is just a request for comments.<br>
<br>
The patch I attach improves the identicalexpr checker in the static analyser. It adds a warning when there is an identical inner condition inside a if.<br>
<br>
Example code taken from a debian project:<br>
<br>
        if(revint)<br>
        {<br>
            if(revint)<br>
<br>
Testing:<br>
I scanned 477 debian projects with this checker and got 2 warnings. Both are bugs as far as I see. Also, in both these cases the inner conditions does not have an 'else' so there is no unreachable code.<br>
<br>
I think it would be a good idea to add a heuristic to avoid warnings when there is hidden code. For example:<br>
<br>
    if (x)<br>
    {<br>
#if SOME_FALSE_CONDITION<br>
        x = dostuff();<br>
#endif<br>
        if (x)<br>
<br>
But other than that... this checker seems to be reliable imho.<br>
<br>
<br>
A possible further improvement would be to warn also warn if the inner condition "overlaps". For instance:<br>
<br>
    if (x == 15)<br>
    {<br>
        if (x > 0)<br>
        ...<br>
<br>
Any opinions / ideas?<br>
<br>
Best regards,<br>
Daniel Marjamäki<br>
<br>
..................................................................................................................<br>
Daniel Marjamäki Senior Engineer<br>
Evidente ES East AB  Warfvinges väg 34  SE-112 51 Stockholm  Sweden<br>
<br>
Mobile:                 <a href="tel:%2B46%20%280%29709%2012%2042%2062" value="+46709124262">+46 (0)709 12 42 62</a><br>
E-mail:                 <a href="mailto:Daniel.Marjamaki@evidente.se">Daniel.Marjamaki@evidente.se</a><br>
<br>
<a href="http://www.evidente.se" target="_blank">www.evidente.se</a><br>
<br>_______________________________________________<br>
cfe-dev mailing list<br>
<a href="mailto:cfe-dev@cs.uiuc.edu">cfe-dev@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev</a><br>
<br></blockquote></div><br></div>