From 05c801f346a56918384035241c92bc0073cf83ef Mon Sep 17 00:00:00 2001 From: Tim Culverhouse Date: Mon, 14 Oct 2024 19:45:01 -0500 Subject: WidthData: define error set as mem.Allocator.Error The reader is a static embedded file. All of the reads are readInt. This function should not ever fail at runtime with a read error. Make all read errors unreachable, leaving only allocation errors as the error set. --- src/WidthData.zig | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'src/WidthData.zig') diff --git a/src/WidthData.zig b/src/WidthData.zig index 1f1ae6f..1b7fb2e 100644 --- a/src/WidthData.zig +++ b/src/WidthData.zig @@ -13,7 +13,7 @@ s2: []i3 = undefined, const Self = @This(); -pub fn init(allocator: mem.Allocator) !Self { +pub fn init(allocator: mem.Allocator) mem.Allocator.Error!Self { const decompressor = compress.flate.inflate.decompressor; const in_bytes = @embedFile("dwp"); var in_fbs = std.io.fixedBufferStream(in_bytes); @@ -28,15 +28,15 @@ pub fn init(allocator: mem.Allocator) !Self { }; errdefer self.g_data.deinit(); - const stage_1_len: u16 = try reader.readInt(u16, endian); + const stage_1_len: u16 = reader.readInt(u16, endian) catch unreachable; self.s1 = try allocator.alloc(u16, stage_1_len); errdefer allocator.free(self.s1); - for (0..stage_1_len) |i| self.s1[i] = try reader.readInt(u16, endian); + for (0..stage_1_len) |i| self.s1[i] = reader.readInt(u16, endian) catch unreachable; - const stage_2_len: u16 = try reader.readInt(u16, endian); + const stage_2_len: u16 = reader.readInt(u16, endian) catch unreachable; self.s2 = try allocator.alloc(i3, stage_2_len); errdefer allocator.free(self.s2); - for (0..stage_2_len) |i| self.s2[i] = @intCast(try reader.readInt(i8, endian)); + for (0..stage_2_len) |i| self.s2[i] = @intCast(reader.readInt(i8, endian) catch unreachable); return self; } -- cgit v1.2.3