Skip to content

Initializing an array with [0, ..-1] compiles, but causes a segfault at runtime #6977

Closed

Description

@bstrie
fn main() {
    let _x = [0, ..-1];
}

Activity

  1. Aatch commented on Jun 6, 2013

    @Aatch
    Contributor

    Seems like a simple oversight, we should make sure that the length is >= 0. I am surprised it doesn't fail trying to emit a -1 alloca though.

  2. luqmana commented on Jun 6, 2013

    @luqmana
    Contributor

    Hmm yea, the count part is just casted to a uint so this is doing the equivalent of [0, ..(MAX_UINT)]

  3. thestinger commented on Jun 6, 2013

    @thestinger
    Contributor

    Ah, so this is really just crashing because it hits the bug we have on very large arrays. Perhaps this isn't really a separate issue than the integer literal overflow and large stack array ones?

  4. Aatch commented on Jun 6, 2013

    @Aatch
    Contributor

    @thestinger either way, negative-length arrays aren't a sane thing to write and should still fail as it's own thing.

  5. added a commit that references this issue on Jun 7, 2013
    4abd83b
  6. added a commit that references this issue on Apr 8, 2021
  7. added a commit that references this issue on Aug 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    I-crashIssue: The compiler crashes (SIGSEGV, SIGABRT, etc). Use I-ICE instead when the compiler panics.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions