Skip to content

clamp allocations of size 0 to 1 or pass size to free #11998

Closed
@thestinger

Description

@thestinger

A call to malloc(0) may return a null pointer or it may return a unique pointer to an allocation. Rust cannot call malloc(0) as then the check for null to determine if the allocation has failed will not work. I special-cased it to always return null for zero-size allocations to avoid this error case.

However, this has exposed a new issue. If the exchange allocator returns a null pointer, then the assumption of unique pointers being non-null does not hold. For example, Some(~()) is considered to be None.

The only solution I can think of is clamping allocations to a minimum size of 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