aboutsummaryrefslogtreecommitdiff
path: root/lib/std/debug.zig
diff options
context:
space:
mode:
authorAli Chraghi <chraghiali1@gmail.com>2022-05-22 19:36:59 +0430
committerAndrew Kelley <andrew@ziglang.org>2022-05-27 16:43:33 -0400
commit0e6285c8fc31ff866df96847fe34e660da38b4a9 (patch)
tree5d5830d5b3ce6c13041aacb7e073763551cb4852 /lib/std/debug.zig
parentddd5b57045d38b7d1f7d5a4120302797433233cd (diff)
downloadzig-0e6285c8fc31ff866df96847fe34e660da38b4a9.tar.gz
zig-0e6285c8fc31ff866df96847fe34e660da38b4a9.zip
math: make `cast` return optional instead of an error
Diffstat (limited to 'lib/std/debug.zig')
-rw-r--r--lib/std/debug.zig12
1 files changed, 6 insertions, 6 deletions
diff --git a/lib/std/debug.zig b/lib/std/debug.zig
index 86ed1c5a65..7fb632084b 100644
--- a/lib/std/debug.zig
+++ b/lib/std/debug.zig
@@ -853,9 +853,9 @@ fn readCoffDebugInfo(allocator: mem.Allocator, coff_file: File) !ModuleDebugInfo
}
}
-fn chopSlice(ptr: []const u8, offset: u64, size: u64) ![]const u8 {
- const start = try math.cast(usize, offset);
- const end = start + try math.cast(usize, size);
+fn chopSlice(ptr: []const u8, offset: u64, size: u64) error{Overflow}![]const u8 {
+ const start = math.cast(usize, offset) orelse return error.Overflow;
+ const end = start + (math.cast(usize, size) orelse return error.Overflow);
return ptr[start..end];
}
@@ -880,7 +880,7 @@ pub fn readElfDebugInfo(allocator: mem.Allocator, elf_file: File) !ModuleDebugIn
const str_section_off = shoff + @as(u64, hdr.e_shentsize) * @as(u64, hdr.e_shstrndx);
const str_shdr = @ptrCast(
*const elf.Shdr,
- @alignCast(@alignOf(elf.Shdr), &mapped_mem[try math.cast(usize, str_section_off)]),
+ @alignCast(@alignOf(elf.Shdr), &mapped_mem[math.cast(usize, str_section_off) orelse return error.Overflow]),
);
const header_strings = mapped_mem[str_shdr.sh_offset .. str_shdr.sh_offset + str_shdr.sh_size];
const shdrs = @ptrCast(
@@ -1119,7 +1119,7 @@ fn mapWholeFile(file: File) ![]align(mem.page_size) const u8 {
nosuspend {
defer file.close();
- const file_len = try math.cast(usize, try file.getEndPos());
+ const file_len = math.cast(usize, try file.getEndPos()) orelse math.maxInt(usize);
const mapped_mem = try os.mmap(
null,
file_len,
@@ -1248,7 +1248,7 @@ pub const DebugInfo = struct {
if (windows.kernel32.K32EnumProcessModules(
process_handle,
modules.ptr,
- try math.cast(windows.DWORD, modules.len * @sizeOf(windows.HMODULE)),
+ math.cast(windows.DWORD, modules.len * @sizeOf(windows.HMODULE)) orelse return error.Overflow,
&bytes_needed,
) == 0)
return error.MissingDebugInfo;