<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div><div>On Jul 14, 2011, at 10:39 AM, Joerg Sonnenberger 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; ">On Thu, Jul 14, 2011 at 10:28:52AM -0700, Ted Kremenek wrote:<br><blockquote type="cite">Hi Kaelyn,<br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">I was reviewing this patch (which I think is a great step), and I had a high-level comment about the following test case:<br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">+void swallow (const char *x) { (void)x; }<br></blockquote><blockquote type="cite">+void test_pointer_arithmetic() {<br></blockquote><blockquote type="cite">+ const char hello[] = "Hello world!"; // expected-note 2 {{declared here}}<br></blockquote><blockquote type="cite">+ const char *helloptr = hello;<br></blockquote><blockquote type="cite">+<br></blockquote><blockquote type="cite">+ swallow("Hello world!" + 6); // no-warning<br></blockquote><blockquote type="cite">+ swallow("Hello world!" - 6); // expected-warning {{refers before the beginning of the array}}<br></blockquote><blockquote type="cite">+ swallow("Hello world!" + 14); // expected-warning {{refers past the end of the array}}<br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">Do we really want this to be a warning? There are plenty of examples where an out-of-bounds pointer is computed for legit reasons. As long as that address is not dereferenced, there isn't necessarily a problem. I'm fearful this may generate a fair amount of noise on codebases that do elaborate tricks with pointer offsets. Indeed this very example doesn't actually exhibit a "bug".<br></blockquote><br>I'm not sure yet, but I think this is something that really should be<br>investigated on real code bases first (and it should be a separate<br>option for that reason).</span></blockquote></div><br><div>Years ago one example I saw was the "Numerical Recipes" library, which tried to turn all C one-dimensional arrays into arrays with a "base index" of 1 (to be amendable for scientists previously coding with Fortran). I'm not arguing that this is a good idea, but on that example this warning would likely fire thousands of times.</div></body></html>