<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><div>This seems sensible to me. I am worried about one source of false positives: functions that take a pointer value solely for the purpose of using the pointer as an ID. However, this will never happen with stack variables, and static variables are always initialized, so it's only heap variables where this could be a problem. We could choose to special-case that or not.</div><div><br></div><div>Checking "const T&" parameters as well as "const T*" makes sense to me.</div><div><br></div><div>Please use SVal::getAsRegion instead of getAs<loc::MemRegionVal>. In almost all cases this makes no difference today, but the latter is at least easier to read and declares intent a little better, even though it will unnecessarily check for LocAsInteger values as well.</div><div><br></div><div>And finally, since this is a new set of checks with potential new false positives, please make a new entry in Checkers.td for it, and parameterize CallAndMessageChecker the same way as CheckSecuritySyntaxOnly.</div><div><br></div><div>This could be a very useful checker. Thank you for working on it!</div><div>Jordan</div><div><br></div><br><div><div>On Feb 19, 2014, at 0:58 , Per Viberg <<a href="mailto:Per.Viberg@evidente.se">Per.Viberg@evidente.se</a>> wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div ocsi="0" fpstyle="1" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><div style="direction: ltr; font-family: Tahoma; font-size: 10pt;">Hi,<br><div><br>Here is a proposed design draft to implement an extension of the check that warns for uninitialized arguments.<br>Any objections/opinions on this solution?.<span class="Apple-converted-space"> </span><br><br>Primarily looking for comments on: interfaces I plan to use and if it's correct to put the change in CallAndMessageChecker::checkPreCall etc.<br><br>The new feature is to find arguments that are pointers to uninitialized variables, i.e. detect this:<br><b><font face="Courier New"><br>void doStuff(const int *p);<br>void f(void);<br><br>void f(void) {<br> int x;<br> doStuff(&x); // ← warning<span class="Apple-converted-space"> </span></font></b><b><font face="Courier New">"Function call argument is a pointer to uninitialized value"<span class="Apple-converted-space"> </span><br>}</font></b><br><br>I propose this design:<br><br>1. Extend the CallAndMessageChecker::checkPreCall to analyse the parameters in conjunction with arguments.<br>2. If argument is declared as const Type*,<span class="Apple-converted-space"> </span><br>3. but corresponding parameter is pointer to undefined value in current function call,<br>3. then generate warning "Function call argument is a pointer to uninitialized value"<br><br>I am going to use mainly the following interfaces:<br>SVal::getAs<loc::MemRegionVal>()<br>MemRegionVal::getRegion()<br>CheckerContext::&getState()<br>SVal::isUndef()<br>QualType::getTypePtr()<br>Type::getPointeeType()<span class="Apple-converted-space"> </span><br>QualType::isConstQualified()<br>FunctionDecl::getParamDecl(unsigned i)<br><br>any objects/opinions on the design?<br><br>cheers!<br>/Per<br><br><br><div style="font-size: 13px; font-family: Tahoma;"><div style="margin-top: 0px; margin-bottom: 0px;"><span lang="EN-US" style="font-size: 8pt; font-family: Arial, sans-serif; color: gray;">.......................................................................................................................</span><span lang="EN-US" style="font-size: 8pt; font-family: Arial, sans-serif;"><br>Per Viberg<span class="Apple-converted-space"> </span></span><span lang="EN-US" style="font-size: 8pt; font-family: Arial, sans-serif; color: gray;">Senior Engineer</span><span lang="EN-US" style="font-size: 8.5pt; font-family: Arial, sans-serif; color: gray;"><br>Evidente ES East</span><span lang="EN-US" style="font-size: 8pt; font-family: Arial, sans-serif; color: gray;"><span class="Apple-converted-space"> </span>AB Warfvinges väg 34 SE-112 51 Stockholm Sweden</span><span lang="EN-US" style="font-size: 10pt; font-family: Tahoma, sans-serif;"></span></div><div style="margin-top: 0px; margin-bottom: 0px;"><span lang="EN-GB" style="font-size: 8pt; font-family: Arial, sans-serif; color: gray;">Phone: +46 (0)8 402 79 00<br>Mobile: +46 (0)70 912 42 52<br>E-mail: <span class="Apple-converted-space"> </span><a href="mailto:Per.Viberg@evidente.se" target="_blank"><font color="#0000ff">Per.Viberg@evidente.se</font></a><span class="Apple-converted-space"> </span></span><span lang="EN-GB" style="font-size: 8pt; font-family: Arial, sans-serif;"><br><br><a href="http://www.evidente.se/" target="_blank"><font color="#0000ff">www.evidente.se</font></a></span></div><div style="margin-top: 0px; margin-bottom: 0px;"><span lang="EN-GB" style="font-size: 6pt; font-family: Arial, sans-serif;">This e-mail, which might contain confidential information, is addressed to the above stated person/company. If you are not the correct addressee, employee or in any other way the person concerned, please notify the sender immediately. At the same time, please delete this e-mail and destroy any prints. Thank You.</span></div></div></div><div style="font-family: 'Times New Roman'; font-size: 16px;"><hr tabindex="-1"><div id="divRpF283255" style="direction: ltr;"><font face="Tahoma" size="2"><b>Från:</b><span class="Apple-converted-space"> </span>Per Viberg<br><b>Skickat:</b><span class="Apple-converted-space"> </span>den 14 februari 2014 13:41<br><b>Till:</b><span class="Apple-converted-space"> </span>Clang Dev [<a href="mailto:cfe-dev@cs.uiuc.edu">cfe-dev@cs.uiuc.edu</a>]<br><b>Ämne:</b><span class="Apple-converted-space"> </span>improving detection of uninitialized arguments (the CallAndMessageChecker)<br></font><br></div><div></div><div><div style="direction: ltr; font-family: Tahoma; font-size: 10pt;"><br><div>Hi,<br><br>I'm looking into extending the check that warns for uninitialized arguments. Below I've described what should be detected. Any opinions on if it's a useful check or potential problems/drawbacks with it?.<br><br>Check: should this be detected as a warning for uninitialized argument?:"<b><font face="Courier New">warning: Function call argument is an uninitialized value"</font></b><br><br><b><font face="Courier New">void doStuff(const int *p);<br>void f(void);<br><br>void f(void) {<br> int x;<br> doStuff(&x); // ← warning?<br>}</font></b><br><br>My rationale behind the warning:<br>1. it's not possible to write to *p, because it's of type const<br>2. content of *p is uninitialized stack value, and shouldn't be used.<br>3. the value of p is of no interest, since it's an address of an stack variable.<br><br>if any of the above criteria are not fulfilled, then no warning. Thus the function prototype must state pointer to const for the argument, the variable that the function is called with must be address of local/stack variable.<br><br>currently, only this is detected:<br><br><b><font face="Courier New">void doStuff2(int p);<br>void g(void);<br><br>void g(void) {<br> int y;<br> doStuff2(y); //<span class="Apple-converted-space"> </span></font></b><b><font face="Courier New">warning: Function call argument is an uninitialized value</font></b><br><br><br>/Per<br><br><br><br><div style="font-size: 13px; font-family: Tahoma;"><div style="margin-top: 0px; margin-bottom: 0px;"><span lang="EN-US" style="font-size: 8pt; font-family: Arial, sans-serif; color: gray;">.......................................................................................................................</span><span lang="EN-US" style="font-size: 8pt; font-family: Arial, sans-serif;"><br>Per Viberg<span class="Apple-converted-space"> </span></span><span lang="EN-US" style="font-size: 8pt; font-family: Arial, sans-serif; color: gray;">Senior Engineer</span><span lang="EN-US" style="font-size: 8.5pt; font-family: Arial, sans-serif; color: gray;"><br>Evidente ES East</span><span lang="EN-US" style="font-size: 8pt; font-family: Arial, sans-serif; color: gray;"><span class="Apple-converted-space"> </span>AB Warfvinges väg 34 SE-112 51 Stockholm Sweden</span><span lang="EN-US" style="font-size: 10pt; font-family: Tahoma, sans-serif;"></span></div><div style="margin-top: 0px; margin-bottom: 0px;"><span lang="EN-GB" style="font-size: 8pt; font-family: Arial, sans-serif; color: gray;">Phone: +46 (0)8 402 79 00<br>Mobile: +46 (0)70 912 42 52<br>E-mail: <span class="Apple-converted-space"> </span><a href="mailto:Per.Viberg@evidente.se" target="_blank"><font color="#0000ff">Per.Viberg@evidente.se</font></a><span class="Apple-converted-space"> </span></span><span lang="EN-GB" style="font-size: 8pt; font-family: Arial, sans-serif;"><br><br><a href="http://www.evidente.se/" target="_blank"><font color="#0000ff">www.evidente.se</font></a></span></div><div style="margin-top: 0px; margin-bottom: 0px;"><span lang="EN-GB" style="font-size: 6pt; font-family: Arial, sans-serif;">This e-mail, which might contain confidential information, is addressed to the above stated person/company. If you are not the correct addressee, employee or in any other way the person concerned, please notify the sender immediately. At the same time, please delete this e-mail and destroy any prints. Thank You.</span></div></div></div><div style="font-family: 'Times New Roman'; font-size: 16px;"><hr tabindex="-1"><br></div></div></div></div></div>_______________________________________________<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">http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev</a></div></blockquote></div><br></body></html>