Skip to content

Commit

Permalink
Auto merge of rust-lang#27434 - jeehoonkang:master, r=Gankro
Browse files Browse the repository at this point in the history
In Section 3.2, TARPL says that "standard allocators (including jemalloc, the one used by default in Rust) generally consider passing in 0 for the size of an allocation as Undefined Behaviour."
However, the C standard and jemalloc manual says allocating zero bytes
should succeed:

- C11 7.22.3 paragraph 1: "If the size of the space requested is zero, the behavior is implementation-defined: either a null pointer is returned, or the behavior is as if the size were some nonzero value, except that the returned pointer shall not be used to access an object."
- [jemalloc manual](http:https://www.freebsd.org/cgi/man.cgi?query=jemalloc&sektion=3): "The malloc and calloc functions return a	pointer	to the allocated memory if successful; otherwise a NULL pointer is returned and errno is set to ENOMEM."
    + Note that the description for `allocm` says "Behavior	is undefined if	size is 0," but it is an experimental API.

r? @gankro
  • Loading branch information
bors committed Aug 6, 2015
2 parents 8f3901f + 9bfb8d3 commit 83f2667
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/doc/nomicon/exotic-sizes.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@ support values.
Safe code need not worry about ZSTs, but *unsafe* code must be careful about the
consequence of types with no size. In particular, pointer offsets are no-ops,
and standard allocators (including jemalloc, the one used by default in Rust)
generally consider passing in `0` for the size of an allocation as Undefined
Behaviour.
may return `nullptr` when a zero-sized allocation is requested, which is
indistinguishable from out of memory.



Expand Down

0 comments on commit 83f2667

Please sign in to comment.