| ▲ | el_pollo_diablo 3 hours ago | |||||||||||||||||||||||||
> There is no OoB access of an array Yes, there is. It does not matter that storage happens to be allocated beyond the end of said array. Strict aliasing implies that it is UB to reinterpret the array as anything else. And it is UB to access an array out of bounds. Flexible array members specifically exist for these dynamically-allocated trailing arrays. They do not solve the strict aliasing problem, though. > if the payload type has an alignment that's greater than the size of a pointer The amount of padding is implementation-defined. The only portable guarantee is that 'payload' is aligned for its element type, char. To over-align, use _Alignas, as in: | ||||||||||||||||||||||||||
| ▲ | Joker_vD 3 hours ago | parent [-] | |||||||||||||||||||||||||
> It does not matter that storage happens to be allocated beyond the end of said array. It does matter, for malloc-returned storage. You can put whatever objects you want into that storage as long as it fits and the pointer is properly aligned. > Strict aliasing ...is not violated; memcpy takes a void pointer as its destination, sets the effective type of the storage behind it, and the treats it as an array of unsigned chars. | ||||||||||||||||||||||||||
| ||||||||||||||||||||||||||