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

Zero sized DST struct item causes invalid free #23491

Closed
talchas opened this issue Mar 18, 2015 · 5 comments · Fixed by #27132
Closed

Zero sized DST struct item causes invalid free #23491

talchas opened this issue Mar 18, 2015 · 5 comments · Fixed by #27132
Labels
A-dst Area: Dynamically Sized Types E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added.

Comments

@talchas
Copy link

talchas commented Mar 18, 2015

struct Node<T: ?Sized>(T);

fn main() {
   let x: Box<Node<[isize]>> = box Node([]);
}

seems to result in a call to foo::heap::exchange_free(1, 0, 1) in the drop glue (and no allocates), which results in a crash. Just doing Box<[isize]> works, as do non-empty input arrays.

@alexcrichton
Copy link
Member

cc @nrc

@steveklabnik steveklabnik added the A-dst Area: Dynamically Sized Types label Mar 18, 2015
@nrc
Copy link
Member

nrc commented Mar 19, 2015

cc @eddyb should this have been fixed by #23376? Or did #23376 cause a regression?

@eddyb eddyb added the E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. label Mar 19, 2015
@eddyb
Copy link
Member

eddyb commented Mar 19, 2015

@nrc it appears to have been fixed, this example doesn't crash in my local branch (assuming it's not something else I've done since).

@fhahn
Copy link
Contributor

fhahn commented Apr 23, 2015

I have added 2 tests based on @talchas example, one using the box syntax and one using Box::new. Interestingly, using Box::new causes a compile time error:

issue-23491-2.rs:5:41: 5:49 error: mismatched types:
     expected `Node<[isize]>`,
     found `Node<[isize; 0]>`
 (expected slice,
    found array of 0 elements) [E0308]
issue-23491-2.rs:5    let x: Box<Node<[isize]>> = Box::new(Node([]));
                                                           ^~~~~~~~
issue-23491-2.rs:5:32: 5:40 error: the trait `core::marker::Sized` is not implemented for the type  `[isize]` [E0277]
issue-23491-2.rs:5    let x: Box<Node<[isize]>> = Box::new(Node([]));
                                                   ^~~~~~~~
issue-23491-2.rs:5:32: 5:40 note: `[isize]` does not have a constant size known at compile-time
issue-23491-2.rs:5    let x: Box<Node<[isize]>> = Box::new(Node([]));
                                                    ^~~~~~~~
error: aborting due to 2 previous errors

Shouldn't they both behave similar in this case?

@apasel422
Copy link
Contributor

@fhahn's test with Box::new doesn't compile because the argument to that function must be Sized. However, the code does compile and run successfully with the box syntax, so a PR containing src/test/run-pass/issue-23491.rs
from fhahn@e8d7122 should close this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-dst Area: Dynamically Sized Types E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants