ziglang / zig

General-purpose programming language and toolchain for maintaining robust, optimal, and reusable software.
https://ziglang.org
MIT License
34.94k stars 2.55k forks source link

runtime safety checking for pointer arithmetic #1918

Open andrewrk opened 5 years ago

andrewrk commented 5 years ago

There should be a test in test/runtime_safety.zig to make sure that unknown length pointer arithmetic does not wrap past the end of the address space.

andrewrk commented 5 years ago

Extracted from https://github.com/ziglang/zig/issues/1059#issuecomment-462101897

These apply to unknown length pointers and C pointers.

wooster0 commented 5 months ago

Should also check that the resulting pointer if non-allowzero doesn't result in zero like it can currently:

const std = @import("std");

pub fn main() void {
    const x: [*]u8 = @ptrFromInt(1);
    const a: [*]u8 = x - 1;
    std.debug.print("address: {*}\n",.{a});
}
address: u8@0