<html>
    <head>
      <base href="https://bugs.llvm.org/">
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - CSA assumes illegal array access"
   href="https://bugs.llvm.org/show_bug.cgi?id=41833">41833</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>CSA assumes illegal array access
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>clang
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>trunk
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>Linux
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>enhancement
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>Static Analyzer
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>dcoughlin@apple.com
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>jhenry@grammatech.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>dcoughlin@apple.com, llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>I was expecting CSA to find an array-out-of-bounds error when dereferencing
s[1] in the following code:

-----------------
extern char *fcall();

static void example(buf, size, endp) char *buf;
int size;
char **endp;
{
    register char *beg;
    beg = buf+1;
    // begin
    beg = fcall();
    if (beg != buf + 4) {
        return;
    }
    // end
    if (beg > buf && beg[-1] != '\n') {
      char *s = "";
      char c = s[1];
    }
}
-----------------

In the above code, if we comment the lines between // begin and // end, the bug
is found because beg[-1] is safe. 
However, if we have a call to an external function that changes the value of
beg, clang somehow assumes that beg[-1] is always incorrect (and consequently
stops the exploration of that path).
I've added an earlier check that makes sure beg == buf+4 but that did not help.

Is this the expected behavior?</pre>
        </div>
      </p>


      <hr>
      <span>You are receiving this mail because:</span>

      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>