Merge branch 'stable'
[gnulib.git] / doc / posix-functions / realloc.texi
1 @node realloc
2 @section @code{realloc}
3 @findex realloc
4
5 POSIX specification:@* @url{http://www.opengroup.org/onlinepubs/9699919799/functions/realloc.html}
6
7 Gnulib module: realloc-posix
8
9 Portability problems fixed by Gnulib:
10 @itemize
11 @item
12 Upon failure, the function does not set @code{errno} to @code{ENOMEM} on
13 some platforms:
14 mingw, MSVC 9.
15 @end itemize
16
17 Portability problems not fixed by Gnulib:
18 @itemize
19 @item
20 It is not portable to call @code{realloc} with a size of 0.  With a
21 NULL pointer argument, this is the same ambiguity as @code{malloc (0)}
22 on whether a unique zero-size object is created.  With a non-NULL
23 pointer argument, C99 requires that if @code{realloc (p, 0)} returns
24 @code{NULL} then @code{p} is still valid.  Among implementations that
25 obey C99, behavior varies on whether @code{realloc (p, 0)} always
26 fails and leaves @code{p} valid, or usually succeeds and returns a
27 unique zero-size object; either way, a program not suspecting these
28 semantics will leak memory (either the still-valid @code{p}, or the
29 non-NULL return value).  Meanwhile, several implementations violate
30 C99, by always calling @code{free (p)} but returning NULL:
31 glibc, Cygwin
32 @end itemize
33
34 Extension: Gnulib provides a module @samp{realloc-gnu} that substitutes a
35 @code{realloc} implementation that behaves more like the glibc implementation.