You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
std.mem: Add packedArrayByteLen function (and use it)
This is a helper function intended to make using writePackedInt/readPackedInt to write to/read from packed arrays a bit less error prone. The math involved is easy, but a naive implementation will overflow when calculating a valid length. For example:
std.math.divCeil(usize, @bitSizeOf(u4) * some_slice.len, byte_size_in_bits)
This will overflow during the multiplication if `some_slice.len` is > `maxInt(usize) / 4 + 1`, even though the final calculated byte count would be able to fit in a `usize`. When using this newly added function, `error.Overflow` is returned only when the *result* can't fit in a `usize`.
0 commit comments