3 ms·
I feel like accessing the bytes that correspond to padding might be implementation-defined, but I couldn't find this in the standard.
by saagarjha 8y ago
I feel like accessing the bytes that correspond to padding might be implementation-defined, but I couldn't find this in the standard.
- mehrdadn 8y agoI don't think it is. It wouldn't make sense since memcpy is basically supposed to convert between arbitrary binary data.
- saagarjha 8y agoFrom a practical point of view, yes, but I would be very surprised if the C standard had any accommodation for memcpy being a way to leak the value of a structure's padding.
- DougBTX 8y agoParent comment was edited to include this quote: _6 When a value is stored in an object of structure or union type, including in a member object, the bytes of the object representation that correspond to any padding bytes take unspecified values. 51)_ So sure, a memcpy after a memset aught to preserve all the bytes, but if they are updated through a struct which contains padding then the values in the padding bytes will be left unspecified.