[cfe-dev] static analyzer false positive? (when reinterpreting buffer as char*)
Sean McBride
sean at rogue-research.com
Tue Sep 25 13:41:21 PDT 2012
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).
Cheers,
--
____________________________________________________________
Sean McBride, B. Eng sean at rogue-research.com
Rogue Research www.rogue-research.com
Mac Software Developer Montréal, Québec, Canada
More information about the cfe-dev
mailing list