mirror of
https://codeberg.org/ziglang/zig.git
synced 2025-12-06 13:54:21 +00:00
std: check for overflow in writeCurrentStackTrace
On arm64 macOS, the address of the last frame is 0x0 rather than a positive value like 0x1 on x86_64 macOS, therefore, we overflow an integer trying to subtract 1 when printing the stack trace. This patch fixes it by first checking for this condition before trying to subtract 1. Note that we do not need to signal the `SignalIterator` about this as it will correctly detect this condition on the subsequent iteration and return `null`, thus terminating the loop.
This commit is contained in:
parent
871f6343f4
commit
68e26a2cee
1 changed files with 6 additions and 1 deletions
|
|
@ -438,7 +438,12 @@ pub fn writeCurrentStackTrace(
|
|||
}
|
||||
var it = StackIterator.init(start_addr, null);
|
||||
while (it.next()) |return_address| {
|
||||
try printSourceAtAddress(debug_info, out_stream, return_address - 1, tty_config);
|
||||
// On arm64 macOS, the address of the last frame is 0x0 rather than 0x1 as on x86_64 macOS,
|
||||
// therefore, we do a check for `return_address == 0` before subtracting 1 from it to avoid
|
||||
// an overflow. We do not need to signal `StackIterator` as it will correctly detect this
|
||||
// condition on the subsequent iteration and return `null` thus terminating the loop.
|
||||
const address = if (return_address == 0) return_address else return_address - 1;
|
||||
try printSourceAtAddress(debug_info, out_stream, address, tty_config);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue