[cfe-dev] static analyzer false positive? (when reinterpreting buffer as char*)

Eli Friedman eli.friedman at gmail.com
Tue Sep 25 13:46:06 PDT 2012


On Tue, Sep 25, 2012 at 1:41 PM, Sean McBride <sean at rogue-research.com> wrote:
> Hi all,
>
> Consider:
>
> ----------------
> #include <stdint.h>
>
> int main (void)
> {
>         uint16_t bar[2] = {0, 0}; // 4 bytes
>         char* foo = (char*)bar;
>         int x = foo[3]; // warning here
>   (void)x;
>
>          return 0;
> }
> ----------------
>
> $ clang --version
> clang version 3.2 (trunk 164470)
>
> $ clang -Weverything test.c
> (no output)
>
> $ clang --analyze test.c
> test.c:7:2: warning: Assigned value is garbage or undefined
>         int x = foo[3];
>         ^       ~~~~~~
> 1 warning generated.
>
> I'm not a language lawyer, but isn't this a false positive?  (It is new in Xcode 4.5 vs 4.4.1 and repros in ToT).

Yes, it is.

-Eli



More information about the cfe-dev mailing list