On Sat, Jun 25, 2016 at 2:01 PM, Andrew Fuller via cfe-users
<cfe-users@lists.llvm.org> wrote:
> I'm trying to understand an issue reported by Clang's static analysis tool.
> The code below demonstrates the issue:
>
> $ cat problem.c
> #include <stdint.h>
>
> int main() {
> #if VARIANT==1
>    uint32_t data = 0xdeadbeef;
>    uint8_t* byte = (uint8_t*)&data;
>    uint8_t value = byte[0];
> #elif VARIANT==2
>    uint32_t data = 0xdeadbeef;
>    uint8_t* byte = (uint8_t*)&data;
>    uint8_t value = byte[1];
> #elif VARIANT==3
>    uint32_t data[1] = {0xdeadbeef};
>    uint8_t* byte = (uint8_t*)&data[0];
>    uint8_t value = byte[0];
> #elif VARIANT==4
>    uint32_t data[1] = {0xdeadbeef};
>    uint8_t* byte = (uint8_t*)&data[0];
>    uint8_t value = byte[1];
> #else
> #error "Define VARIANT={1,2,3,4}"
> #endif
>    return value;
> }
>

I recall seeing this before, but I don't recall if its valid C:

    uint8_t* byte = (uint8_t*)&data;
    uint8_t value = byte[0];

Are you getting other compiler warnings with it? If not, try -Wall -Wextra.

Jeff
_______________________________________________
cfe-users mailing list
cfe-users@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-users

Reply via email to