diff options
| author | 2024-10-14 19:45:01 -0500 | |
|---|---|---|
| committer | 2024-10-14 19:45:01 -0500 | |
| commit | 05c801f346a56918384035241c92bc0073cf83ef (patch) | |
| tree | 07ab43f86fa96c93c275b4b90d685a9ef31d3865 /src/WidthData.zig | |
| parent | GraphemeData: define error set as mem.Allocator.Error (diff) | |
| download | zg-05c801f346a56918384035241c92bc0073cf83ef.tar.gz zg-05c801f346a56918384035241c92bc0073cf83ef.tar.xz zg-05c801f346a56918384035241c92bc0073cf83ef.zip | |
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.
Diffstat (limited to 'src/WidthData.zig')
| -rw-r--r-- | src/WidthData.zig | 10 |
1 files changed, 5 insertions, 5 deletions
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, | |||
| 13 | 13 | ||
| 14 | const Self = @This(); | 14 | const Self = @This(); |
| 15 | 15 | ||
| 16 | pub fn init(allocator: mem.Allocator) !Self { | 16 | pub fn init(allocator: mem.Allocator) mem.Allocator.Error!Self { |
| 17 | const decompressor = compress.flate.inflate.decompressor; | 17 | const decompressor = compress.flate.inflate.decompressor; |
| 18 | const in_bytes = @embedFile("dwp"); | 18 | const in_bytes = @embedFile("dwp"); |
| 19 | var in_fbs = std.io.fixedBufferStream(in_bytes); | 19 | var in_fbs = std.io.fixedBufferStream(in_bytes); |
| @@ -28,15 +28,15 @@ pub fn init(allocator: mem.Allocator) !Self { | |||
| 28 | }; | 28 | }; |
| 29 | errdefer self.g_data.deinit(); | 29 | errdefer self.g_data.deinit(); |
| 30 | 30 | ||
| 31 | const stage_1_len: u16 = try reader.readInt(u16, endian); | 31 | const stage_1_len: u16 = reader.readInt(u16, endian) catch unreachable; |
| 32 | self.s1 = try allocator.alloc(u16, stage_1_len); | 32 | self.s1 = try allocator.alloc(u16, stage_1_len); |
| 33 | errdefer allocator.free(self.s1); | 33 | errdefer allocator.free(self.s1); |
| 34 | for (0..stage_1_len) |i| self.s1[i] = try reader.readInt(u16, endian); | 34 | for (0..stage_1_len) |i| self.s1[i] = reader.readInt(u16, endian) catch unreachable; |
| 35 | 35 | ||
| 36 | const stage_2_len: u16 = try reader.readInt(u16, endian); | 36 | const stage_2_len: u16 = reader.readInt(u16, endian) catch unreachable; |
| 37 | self.s2 = try allocator.alloc(i3, stage_2_len); | 37 | self.s2 = try allocator.alloc(i3, stage_2_len); |
| 38 | errdefer allocator.free(self.s2); | 38 | errdefer allocator.free(self.s2); |
| 39 | for (0..stage_2_len) |i| self.s2[i] = @intCast(try reader.readInt(i8, endian)); | 39 | for (0..stage_2_len) |i| self.s2[i] = @intCast(reader.readInt(i8, endian) catch unreachable); |
| 40 | 40 | ||
| 41 | return self; | 41 | return self; |
| 42 | } | 42 | } |