Skip to content

Segfault when calling string repeat with negative argument #15482

Closed
@ogham

Description

@ogham

I was writing some code to pad strings, and if I pass in a negative number of spaces to add, it compiles fine but segmentation faults at runtime. The following code is enough to trigger it:

fn main() {
    "goodbye".to_string().repeat(-1);
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions