-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Disallow reader.readStruct for packed structs #12960
Copy link
Copy link
Closed
Labels
breakingImplementing this issue could cause existing code to no longer compile or have different behavior.Implementing this issue could cause existing code to no longer compile or have different behavior.contributor friendlyThis issue is limited in scope and/or knowledge of Zig internals.This issue is limited in scope and/or knowledge of Zig internals.standard libraryThis issue involves writing Zig code for the standard library.This issue involves writing Zig code for the standard library.
Milestone
Metadata
Metadata
Assignees
Labels
breakingImplementing this issue could cause existing code to no longer compile or have different behavior.Implementing this issue could cause existing code to no longer compile or have different behavior.contributor friendlyThis issue is limited in scope and/or knowledge of Zig internals.This issue is limited in scope and/or knowledge of Zig internals.standard libraryThis issue involves writing Zig code for the standard library.This issue involves writing Zig code for the standard library.
Zig Version
0.9.1 (windows, chocolatey),0.10.0-dev.4166+cae76d829
Steps to Reproduce
zig test repro.zigExpected Behavior
Test passes.
Log output should be
14. 14Actual Behavior
Test fails. Log output is
16, 14.This is because
@sizeOf(PackedStruct)is 16.However, using sizeOf in readStruct is undesirable for reading consecutive packed structs, because now the seeker position is wrong, affecting future reads downstream. To correct this manually, the developer has to check if packed struct requires padding, and manually wind the seeker back using
seekBy.