authorgravatar for 4678790+dweiller@users.noreply.github.comDominic <4678790+dweiller@users.noreply.github.com> 2023-01-26 17:04:44+11:00
committergravatar for 4678790+dweiller@users.noreply.github.comDominic <4678790+dweiller@users.noreply.github.com> 2023-02-20 09:09:06+11:00
loge2306ef0a027ab6257613dad234551a013729de3
treec7eab4aae3640dd809440fde510544c5c7f8d7cb
parent7558bf64513ec2be59b95aecc5e0ac50ad88b1f5

std.compress.zstandard: add integer casts u64 -> usize


1 files changed, 6 insertions(+), 4 deletions(-)

lib/std/compress/zstandard/decompress.zig+6-4
......@@ -22,7 +22,7 @@ fn isSkippableMagic(magic: u32) bool {
2222/// if the the frame is skippable, `null` for Zstanndard frames that do not
2323/// declare their content size. Returns `UnusedBitSet` and `ReservedBitSet`
2424/// errors if the respective bits of the the frame descriptor are set.
25pub fn getFrameDecompressedSize(src: []const u8) !?usize {
25pub fn getFrameDecompressedSize(src: []const u8) !?u64 {
2626 switch (try frameType(src)) {
2727 .zstandard => {
2828 const header = try decodeZStandardHeader(src[4..], null);
......@@ -216,7 +216,7 @@ pub const DecodeState = struct {
216216 );
217217 @field(self, field_name).table = .{ .fse = @field(self, field_name ++ "_fse_buffer")[0..table_size] };
218218 @field(self, field_name).accuracy_log = std.math.log2_int_ceil(usize, table_size);
219 return counting_reader.bytes_read;
219 return std.math.cast(usize, counting_reader.bytes_read) orelse return error.MalformedFseTable;
220220 },
221221 .repeat => return if (self.fse_tables_undefined) error.RepeatModeFirst else 0,
222222 }
......@@ -571,7 +571,8 @@ pub fn decodeZStandardFrameAlloc(allocator: std.mem.Allocator, src: []const u8,
571571
572572 if (frame_header.descriptor.dictionary_id_flag != 0) return error.DictionaryIdFlagUnsupported;
573573
574 const window_size = frameWindowSize(frame_header) orelse return error.WindowSizeUnknown;
574 const window_size_raw = frameWindowSize(frame_header) orelse return error.WindowSizeUnknown;
575 const window_size = std.math.cast(usize, window_size_raw) orelse return error.WindowTooLarge;
575576
576577 const should_compute_checksum = frame_header.descriptor.content_checksum_flag and verify_checksum;
577578 var hash = if (should_compute_checksum) std.hash.XxHash64.init(0) else null;
......@@ -1043,7 +1044,8 @@ fn decodeHuffmanTree(src: []const u8, consumed_count: *usize) !LiteralsSection.H
10431044 const table_size = try decodeFseTable(&bit_reader, 256, 6, &entries);
10441045 const accuracy_log = std.math.log2_int_ceil(usize, table_size);
10451046
1046 var huff_data = src[1 + counting_reader.bytes_read .. compressed_size + 1];
1047 const start_index = std.math.cast(usize, 1 + counting_reader.bytes_read) orelse return error.MalformedHuffmanTree;
1048 var huff_data = src[start_index .. compressed_size + 1];
10471049 var huff_bits: ReverseBitReader = undefined;
10481050 try huff_bits.init(huff_data);
10491051