Skip to content

runtime safety checking for pointer arithmetic #1918

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
andrewrk opened this issue Feb 5, 2019 · 2 comments
Open

runtime safety checking for pointer arithmetic #1918

andrewrk opened this issue Feb 5, 2019 · 2 comments
Labels
docs enhancement Solving this issue will likely involve adding new logic or components to the codebase. frontend Tokenization, parsing, AstGen, Sema, and Liveness.
Milestone

Comments

@andrewrk
Copy link
Member

andrewrk commented Feb 5, 2019

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 andrewrk added the enhancement Solving this issue will likely involve adding new logic or components to the codebase. label Feb 5, 2019
@andrewrk andrewrk added this to the 0.5.0 milestone Feb 5, 2019
@andrewrk andrewrk added the docs label Feb 15, 2019
@andrewrk
Copy link
Member Author

Extracted from #1059 (comment)

  • compile error test for compile time pointer arithmetic overflowing
  • runtime safety test for pointer arithmetic overflowing
  • compile error test for comptime ptr arithmetic with undefined
  • docs

These apply to unknown length pointers and C pointers.

@andrewrk andrewrk modified the milestones: 0.5.0, 0.6.0 Sep 20, 2019
@andrewrk andrewrk modified the milestones: 0.6.0, 0.7.0 Feb 10, 2020
@andrewrk andrewrk added the frontend Tokenization, parsing, AstGen, Sema, and Liveness. label Oct 9, 2020
@andrewrk andrewrk modified the milestones: 0.7.0, 0.8.0 Oct 9, 2020
@andrewrk andrewrk modified the milestones: 0.8.0, 0.9.0 Jun 4, 2021
@andrewrk andrewrk modified the milestones: 0.9.0, 0.10.0 Nov 21, 2021
@andrewrk andrewrk modified the milestones: 0.10.0, 0.11.0 Aug 24, 2022
@andrewrk andrewrk modified the milestones: 0.11.0, 0.12.0 Apr 9, 2023
@wooster0
Copy link
Contributor

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

@mlugg mlugg added this to Safety Aug 22, 2024
@mlugg mlugg moved this to To do in Safety Aug 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs enhancement Solving this issue will likely involve adding new logic or components to the codebase. frontend Tokenization, parsing, AstGen, Sema, and Liveness.
Projects
Status: To do
Development

No branches or pull requests

2 participants