mirror of
https://github.com/ziglang/zig.git
synced 2026-02-14 05:20:34 +00:00
Fixed readBits to cast errors to the correct errorset. See #1810 for why this wasn't caught earlier.
This commit is contained in:
parent
b6489ff90a
commit
5936bdf8a4
@ -526,7 +526,9 @@ pub fn BitInStream(endian: builtin.Endian, comptime Error: type) type {
|
||||
if (err == error.EndOfStream) {
|
||||
return @intCast(U, out_buffer);
|
||||
}
|
||||
return err;
|
||||
//@BUG: See #1810. Not sure if the bug is that I have to do this for some
|
||||
// streams, or that I don't for streams with emtpy errorsets.
|
||||
return @errSetCast(Error, err);
|
||||
};
|
||||
|
||||
switch (endian) {
|
||||
|
||||
@ -169,6 +169,10 @@ test "BitInStream" {
|
||||
assert(out_bits == 16);
|
||||
|
||||
_ = try bit_stream_be.readBits(u0, 0, &out_bits);
|
||||
|
||||
assert(0 == try bit_stream_be.readBits(u1, 1, &out_bits));
|
||||
assert(out_bits == 0);
|
||||
assertError(bit_stream_be.readBitsNoEof(u1, 1), error.EndOfStream);
|
||||
|
||||
var mem_in_le = io.SliceInStream.init(mem_le[0..]);
|
||||
var bit_stream_le = io.BitInStream(builtin.Endian.Little, InError).init(&mem_in_le.stream);
|
||||
@ -197,6 +201,10 @@ test "BitInStream" {
|
||||
assert(out_bits == 16);
|
||||
|
||||
_ = try bit_stream_le.readBits(u0, 0, &out_bits);
|
||||
|
||||
assert(0 == try bit_stream_le.readBits(u1, 1, &out_bits));
|
||||
assert(out_bits == 0);
|
||||
assertError(bit_stream_le.readBitsNoEof(u1, 1), error.EndOfStream);
|
||||
}
|
||||
|
||||
test "BitOutStream" {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user