Skip to content

alloc::realloc does not follow requirements of Layout::from_size_align_unchecked #108546

Closed
@overlookmotel

Description

@overlookmotel

The docs for Layout::from_size_align_unchecked state that:

size, when rounded up to the nearest multiple of align, must not overflow isize (i.e., the rounded value must be less than or equal to isize::MAX)

alloc::realloc's docs state a different constraint:

new_size, when rounded up to the nearest multiple of layout.align(), must not overflow (i.e., the rounded value must be less than usize::MAX).

So this would be legal according to alloc::realloc's docs:

let layout = alloc::Layout::from_size_align(1, 1);
let ptr1 = alloc::alloc(layout);
let ptr2 = alloc::realloc(ptr1, layout, usize::MAX);

But this results in a call internally:

Layout::from_size_align_unchecked(usize::MAX, 1)

...which is meant to be UB.

I assume this is just that the docs are out of date after #95295.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-docsArea: Documentation for any part of the project, including the compiler, standard library, and toolsC-bugCategory: This is a bug.T-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions