#Tagged union by-value return corrupts bytes within active variant

1 messages · Page 1 of 1 (latest)

fervent elm
#

cant help if we cant inspect your code

paper nova
#

Hey sorry it was a programming error

#

When a union(enum) holds a smaller variant, the bytes within the union storage beyond @sizeOf(ActiveVariant) are undefined. We assumed those bytes would be preserved (specifically, that zeroing a struct before writing it into a union would keep the tail bytes zero at the call site). They're not guaranteed to be — Zig is free to leave them as whatever was previously in that memory. This is expected behavior, not a compiler bug.