Skip to content
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

segmentation fault pointer dereference runtime #2298

Closed
iamnobodytoo opened this issue Apr 17, 2019 · 2 comments
Closed

segmentation fault pointer dereference runtime #2298

iamnobodytoo opened this issue Apr 17, 2019 · 2 comments
Labels
bug Observed behavior contradicts documented or intended behavior miscompilation The compiler reports success but produces semantically incorrect code. stage1 The process of building from source via WebAssembly and the C backend.
Milestone

Comments

@iamnobodytoo
Copy link

iamnobodytoo commented Apr 17, 2019

pub fn main() void {
    var b1: *u8 = &@as(u8, 101);
    b1.* += 1;
}

if I do it like this (by using an additional var) it works fine

pub fn main() void {
    var ba: u8 = 101;
    var b1: *u8 = &ba; // or &u8(ba)
    b1.* +=1;
}

zig version: 0.4.0
system: antergos linux 5.0.7-arch1-1-ARCH

@andrewrk andrewrk added this to the 0.5.0 milestone Apr 17, 2019
@andrewrk andrewrk added the bug Observed behavior contradicts documented or intended behavior label Apr 17, 2019
@andrewrk
Copy link
Member

This should be a compile error, &u8(101) should be a const pointer.

@andrewrk andrewrk modified the milestones: 0.5.0, 0.6.0 Sep 27, 2019
@andrewrk andrewrk added the stage1 The process of building from source via WebAssembly and the C backend. label Feb 10, 2020
@andrewrk andrewrk added the miscompilation The compiler reports success but produces semantically incorrect code. label Mar 4, 2020
@andrewrk andrewrk modified the milestones: 0.6.0, 0.7.0 Apr 1, 2020
@Vexu
Copy link
Member

Vexu commented Apr 8, 2020

Duplicate of #2130, fixed by #4971.

Semantic Analysis [530/822] ./build/a.zig:270:20: error: expected type '*u8', found '*const u8'
    var b1: *u8 = &@as(u8, 101);
                   ^
./build/a.zig:270:20: note: cast discards const qualifier
    var b1: *u8 = &@as(u8, 101);
                   ^

@Vexu Vexu closed this as completed Apr 8, 2020
@Vexu Vexu modified the milestones: 0.7.0, 0.6.0 Apr 8, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Observed behavior contradicts documented or intended behavior miscompilation The compiler reports success but produces semantically incorrect code. stage1 The process of building from source via WebAssembly and the C backend.
Projects
None yet
Development

No branches or pull requests

3 participants