<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 - alpha.unix.cstring.OutOfBounds wrongly triggers for flexible array members"
   href="https://bugs.llvm.org/show_bug.cgi?id=48136">48136</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>alpha.unix.cstring.OutOfBounds wrongly triggers for flexible array members
          </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>All
          </td>
        </tr>

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

        <tr>
          <th>Severity</th>
          <td>normal
          </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>tss@iki.fi
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>dcoughlin@apple.com, llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>We've been using alpha.unix checks, but OutOfBounds is annoyingly triggering
with flexible array members. Apparently it thinks they are 0 sized.

Using clang 12 from git, checked out Oct 27 2020.

# scan-build -enable-checker alpha.unix gcc test.c -o test
test.c:13:2: warning: Memory set function overflows the destination buffer
[alpha.unix.cstring.OutOfBounds]
        memset(str->data, 'x', 10);
        ^~~~~~~~~~~~~~~~~~~~~~~~~~

When test.c contains:

#include <stdlib.h>
#include <string.h>

struct str {
        size_t len;
        char data[];
};

int main(void)
{
        struct str *str = malloc(sizeof(str) + 10);
        str->len = 10;
        memset(str->data, 'x', 10);
        return 0;
}</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>