Skip to content

Some( NULL ) returns None #17120

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

Closed
kaseyc opened this issue Sep 9, 2014 · 5 comments
Closed

Some( NULL ) returns None #17120

kaseyc opened this issue Sep 9, 2014 · 5 comments
Labels
A-codegen Area: Code generation A-DSTs Area: Dynamically-sized types (DSTs)
Milestone

Comments

@kaseyc
Copy link
Contributor

kaseyc commented Sep 9, 2014

If you try to take Some of a null pointer, it will be interpreted as None. This seems to occur for any two element enum with the same signature as option,

Example:

enum Foo<T> {
    Bar(T),
    Baz
}

impl<T> Foo<T> {
    fn as_string(&self) -> String {
        match *self {
            Bar(_) => "Bar(_)".to_string(),
            Baz => "Baz".to_string(),
        }
    }

    fn is_bar(&self) -> bool {
        match *self {
            Bar(_) => true,
            _ => false
        }
    }

    fn is_baz(&self) -> bool {
        match *self {
            Baz => true,
            _ => false
        }
    }
}


fn main() {
        println!("Should be Some: {}", Some( 0u8 as *const u8))
        let foo = Bar( 0u8 as *const u8 );
        println!("Should be Bar: {}\nBar: {}, Baz: {}", foo.as_string(), foo.is_bar(), foo.is_baz() );
}

Which prints:

Should be Some: None
Should be Bar: Baz
Bar: false, Baz: true
@huonw huonw added the I-wrong label Sep 9, 2014
@kaseyc kaseyc changed the title Some( NULL ) is returns None Some( NULL ) returns None Sep 9, 2014
@keeperofdakeys
Copy link
Contributor

I'm guessing this is a nullable pointer bug. Can this be enabled only for borrows, and not for raw pointers?

@thestinger thestinger added the A-codegen Area: Code generation label Sep 9, 2014
@bluss
Copy link
Member

bluss commented Sep 9, 2014

I'd suspect this is from 52d6d3b @nick29581

@brson
Copy link
Contributor

brson commented Sep 9, 2014

Nominating because I want to make sure this is solvable.

@pcwalton
Copy link
Contributor

This is not a 1.0 issue, IMO. Just a miscompilation.

@pnkfelix
Copy link
Member

Marking as P-backcompat-lang + 1.0 blocker, mostly because that is the conservative thing for us to do here at the moment. Hopefully we can fix quickly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-codegen Area: Code generation A-DSTs Area: Dynamically-sized types (DSTs)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

9 participants