feature. See also
. The project being documented here (as the example) is the Zig library itself.
ubsan_rt.pointerOverflow
fn pointerOverflow(
_: *const PointerOverflowData,
base: usize,
result: usize,
) callconv(.c) noreturn
File
Code
fn pointerOverflow(
_: *const PointerOverflowData,
base: usize,
result: usize,
) callconv(.c) noreturn {
if (base == 0) {
if (result == 0) {
panic(@returnAddress(), "applying zero offset to null pointer", .{});
} else {
panic(@returnAddress(), "applying non-zero offset {d} to null pointer", .{result});
}
} else {
if (result == 0) {
panic(
@returnAddress(),
"applying non-zero offset to non-null pointer 0x{x} produced null pointer",
.{base},
);
} else {
const signed_base: isize = @bitCast(base);
const signed_result: isize = @bitCast(result);
if ((signed_base >= 0) == (signed_result >= 0)) {
if (base > result) {
panic(
@returnAddress(),
"addition of unsigned offset to 0x{x} overflowed to 0x{x}",
.{ base, result },
);
} else {
panic(
@returnAddress(),
"subtraction of unsigned offset to 0x{x} overflowed to 0x{x}",
.{ base, result },
);
}
} else {
panic(
@returnAddress(),
"pointer index expression with base 0x{x} overflowed to 0x{x}",
.{ base, result },
);
}
}
}
}