Summary: | array subscript 'long unsigned int[0]' is partly outside array bounds of 'unsigned char[4]' | ||
---|---|---|---|
Product: | gcc | Reporter: | Curtis J Blank <Curt.Blank> |
Component: | middle-end | Assignee: | Not yet assigned to anyone <unassigned> |
Status: | RESOLVED INVALID | ||
Severity: | normal | CC: | Curt.Blank |
Priority: | P3 | Keywords: | diagnostic |
Version: | 13.3.0 | ||
Target Milestone: | --- | ||
Host: | Target: | ||
Build: | Known to work: | ||
Known to fail: | Last reconfirmed: |
Description
Curtis J Blank
2024-06-21 00:15:38 UTC
The warning is correct. sizeof(long) on x86_64 is 8 rather than 4 that it was on i686. So when you do this: unsigned char cValue[4]; unsigned long *value = 0; value = (unsigned long *)cValue; *value & 0xffffffff You get undefined behavior because you are reading 8 bytes from a 4 byte array. Note this code also violates C/C++ aliasing rules but that is a different issue. Note there is also an alignment requirement that you violate with the assignment and access of the char array too. Thank you the information. So I should use unsigned int now on x86_64? Where can I read more on the rule violations and what would be the proper so do this? |