Skip to content

GlobalAlloc and Allocator traits missing base + size <= usize::MAX from the allocation conditions #153542

@susitsm

Description

@susitsm

Location (URL)

GlobalAlloc and Allocator trait documentation

Summary

The core::ptr module's allocation paragraph states that base + size <= usize::MAX must hold for an allocation, which is later reinforced by the statement in pointer::add: vec.as_ptr().add(vec.len()) is always safe. This is not documented as a requirement for allocations in the GlobalAlloc and Allocator traits.

An allocator following the current trait documentation could cause UB by allocating 1 byte at usize::MAX.

Metadata

Metadata

Assignees

Labels

A-allocatorsArea: Custom and system allocatorsA-docsArea: Documentation for any part of the project, including the compiler, standard library, and toolsC-bugCategory: This is a bug.E-easyCall for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.T-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.T-opsemRelevant to the opsem team

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions