<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div><div>On Dec 5, 2011, at 4:43 PM, Jeffrey Yasskin wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><span class="Apple-style-span" style="border-collapse: separate; font-family: Helvetica; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-size: medium; ">Klocwork has a similar heuristic, and it proved obnoxious in practice.<br>~75%-90% of the time, the real problem in the code was that someone<br>was checking against 0, but the pointer was actually guaranteed not to<br>be 0, so the check was redundant. Unless the analyzer has other<br>evidence that the pointer may actually be 0, it should treat<br>"dereference null" and "redundant check" as similar likelihood and<br>include both in the warning, or omit the warning.<br></span></blockquote></div><div><br></div>Hi Jeffrey,<div><br></div><div>Excellent points.  I think the heuristic is still valuable, however.  Either the pointer could be null, and thus result in a null dereference, or the logic is redundant, and thus the invariants of the code aren't well documented or well understood.  I agree that the latter is less severe than the other.  In such cases, I'd argue that the runtime check should be an assert() or the code should use __attribute__((nonnull)) to document the assumptions in the code.  The analyzer cues off of either of these, and so do other programmers.</div><div><div><br></div><div>Do you think it would be reasonable to still emit a warning here, but categorize it differently in the places where we are less certain that the issue is a null dereference?</div></div><div><br></div><div>Cheers,</div><div>Ted</div></body></html>