https://bugs.llvm.org/show_bug.cgi?id=48136

            Bug ID: 48136
           Summary: alpha.unix.cstring.OutOfBounds wrongly triggers for
                    flexible array members
           Product: clang
           Version: trunk
          Hardware: PC
                OS: All
            Status: NEW
          Severity: normal
          Priority: P
         Component: Static Analyzer
          Assignee: dcough...@apple.com
          Reporter: t...@iki.fi
                CC: dcough...@apple.com, llvm-bugs@lists.llvm.org

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;
}

-- 
You are receiving this mail because:
You are on the CC list for the bug.
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to