-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
mem: fix UB in readInt
/writeInt
and delete variants
#17802
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
09ceb0b
to
763c7cb
Compare
763c7cb
to
ecb7344
Compare
These warnings are new when bootstrapping:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changes to resinator
look correct.
huh. I don't understand how that passed the CI before, or why it's passing on x86_64-windows-debug. |
Have a fix, but waiting for a CI run to complete.
It's obvious what happened (clash between f-max and fma-x), but like you said, who knows why it happened on this run in particular. I can only assume either a bad roll gave us a different image (different compiler version?) somehow, or an msvc bugs means the error is not consistent. |
Well, not related to the changes in this PR at least: https://github.com/ziglang/zig/actions/runs/6710563026/job/18236031654 |
Use inline to vastly simplify the exposed API. This allows a comptime-known endian parameter to be propogated, making extra functions for a specific endianness completely unnecessary.
After deleting all potentially incorrect usages, there were no more remaining.
Let's take this breaking change opportunity to fix the style of this enum.
ecb7344
to
13b1e10
Compare
In Zig, loads and stores affect
@sizeOf(T)
bytes of memory. The old implementations of these functions were pointer casting a buffer of@divExact(@bitSizeOf(T), 8)
bytes which is not guaranteed to be large enough to perform a load or store ofT
directly. This only ever worked because llvm has weird store size rules, and in fact, after this change, some non-llvm backends mysteriously started passing these tests.By making use of
inline
, the complicated nest of variant functions could all be reduced to four functions without compromising functionality. After removing some incorrect uses of two of these, there were no references to them remaining, so I deleted them too.Migration guide
These apply to both the functions in
std.mem
and the methods onstd.io.GenericReader
,std.io.AnyReader
, andstd.io.Writer
.readInt(...)
→readInt(...)
readIntLittle(...)
→readInt(..., .little)
readIntBig(...)
→std.mem.readInt(..., .big)
readIntNative(...)
→std.mem.readInt(..., @import("builtin").cpu.arch.endian())
or just@as(T, @bitCast(buffer.*))
for thestd.mem
versionreadIntForeign(...)
→@byteSwap(std.mem.readInt(..., @import("builtin").cpu.arch.endian()))
or just@byteSwap(@as(T, @bitCast(buffer.*)))
for thestd.mem
versionwriteInt(...)
→std.mem.writeInt(...)
writeIntLittle(...)
→std.mem.writeInt(..., .little)
writeIntBig(...)
→std.mem.writeInt(..., .big)
writeIntNative(...)
→std.mem.writeInt(..., @import("builtin").cpu.arch.endian())
or justbuffer.* = @bitCast(value)
for thestd.mem
versionwriteIntForeign(...)
→std.mem.writeInt(..., @byteSwap(value), @import("builtin").cpu.arch.endian())
or justbuffer.* = @bitCast(@byteSwap(value))
for thestd.mem
version@Luukdegram unfortunately, this new pattern regressed the self-hosted wasm backend, so just letting you know that there are three new
.stage2_wasm
checks inlib/test_runner.zig
,test/behavior/bugs/1851.zig
, andtest/behavior/struct.zig
.