about summary refs log tree commit diff
diff options
context:
space:
mode:
authorJeehoon Kang <jeehoon.kang@sf.snu.ac.kr>2015-07-31 23:55:01 +0900
committerJeehoon Kang <jeehoon.kang@sf.snu.ac.kr>2015-08-06 15:40:41 +0900
commit9bfb8d3addc8eed916b3ff0747131c1f9bb97e52 (patch)
tree9acdc2f664f2f965573a5d5e3b28b95f4794a9ce
parentd03456183e85fe7bd465bbe7c8f67885a2528444 (diff)
downloadrust-9bfb8d3addc8eed916b3ff0747131c1f9bb97e52.tar.gz
rust-9bfb8d3addc8eed916b3ff0747131c1f9bb97e52.zip
Revise TARPL's description for allocating 0 bytes
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://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.
-rw-r--r--src/doc/nomicon/exotic-sizes.md4
1 files changed, 2 insertions, 2 deletions
diff --git a/src/doc/nomicon/exotic-sizes.md b/src/doc/nomicon/exotic-sizes.md
index 0b653a7ad3a..e8637e38ac7 100644
--- a/src/doc/nomicon/exotic-sizes.md
+++ b/src/doc/nomicon/exotic-sizes.md
@@ -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.