News for hackers. Stuff that matters.
Re:Stop Memsetting Structures by saagarjha on Saturday April 27, 2019 @10:57PM (#19769030)
I feel like accessing the bytes that correspond to padding might be implementation-defined, but I couldn't find this in the standard.
Re:Stop Memsetting Structures by DougBTX on Sunday April 28, 2019 @06:35AM (#19770363)
Parent 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.

Re:Stop Memsetting Structures by mehrdadn on Saturday April 27, 2019 @11:03PM (#19769056)
I don't think it is. It wouldn't make sense since memcpy is basically supposed to convert between arbitrary binary data.
Re:Stop Memsetting Structures by saagarjha on Saturday April 27, 2019 @11:12PM (#19769092)
From 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.
Re:Stop Memsetting Structures by jcr1488 on Sunday April 28, 2019 @05:23AM (#19770173)
You clearly haven't understood the thread.
Re:Stop Memsetting Structures by saagarjha on Sunday April 28, 2019 @05:26AM (#19770180)
How so? Did I miss something important?