News for hackers. Stuff that matters.
Re:The Lost Art of Structure Packing (2018) by gambiting on Monday April 27, 2020 @12:20PM (#22997258)
I don't have the code in front of me, but something like

  int hash=0;
  for(int i=0;i<sizeof(obj);i++)
   hash += hashing_method(reintepret_cast<char*>(&obj)+i);
  return hash;
Basically hashing each byte of the memory containing the object, regardless of what the object itself represents.

We can argue whether that's a smart thing to do or not, but I wasn't in charge of implementing it - it's a relic from a codebase that's more than a decade old at this point. It's a simple hashing method that works with most types, but obviously dies horrendously in a case like this.

Re:The Lost Art of Structure Packing (2018) by nly on Monday April 27, 2020 @07:47PM (#23001618)
This doesn't help you, because the contents of the padding bytes is not guaranteed to be anything in particular. Two structs containing identical field values can have different padding bytes. Reading the padding bytes is UB.

Just pack the struct and be done with it.

Re:The Lost Art of Structure Packing (2018) by saagarjha on Monday April 27, 2020 @12:48PM (#22997512)
Yeah, this is technically undefined.