1 Submitted By: Robert Connolly <robert at linuxfromscratch dot org> (ashes)
3 Initial Package Version: 2.5
4 Upstream Status: Submitted
5 http://sourceware.org/ml/libc-alpha/2004-05/msg00067.html
6 http://sourceware.org/ml/libc-alpha/2004-06/msg00007.html
7 Origin: Alt-Linux / Dmitry V. Levin
10 The asprintf(3) and vasprintf(3) functions are GNU extentions, not defined
11 by C or Posix standards. In Glibc these functions leave (char **strp) undefined
12 after an error. This patch resets (char **strp) to NULL after an error, for
15 This patch, and the behavior it sets, was reviewed and discussed on the Glibc
16 mailing list, and appeared to be accepted, and then it looks like it was
19 2004-06-03 Dmitry V. Levin <ldv@altlinux.org>
21 * libio/vasprintf.c (_IO_vasprintf): Reset the result pointer
23 * manual/stdio.texi: Reflect the change in asprintf API.
25 --- glibc-2.5.orig/libio/vasprintf.c
26 +++ glibc-2.5/libio/vasprintf.c
27 @@ -50,7 +50,10 @@ _IO_vasprintf (result_ptr, format, args)
28 we know we will never seek on the stream. */
29 string = (char *) malloc (init_string_size);
37 sf._sbf._f._lock = NULL;
39 @@ -64,6 +67,7 @@ #endif
42 free (sf._sbf._f._IO_buf_base);
46 /* Only use realloc if the size we need is of the same (binary)
47 --- glibc-2.5.orig/manual/stdio.texi
48 +++ glibc-2.5/manual/stdio.texi
49 @@ -2398,7 +2398,9 @@ to the newly allocated string at that lo
51 The return value is the number of characters allocated for the buffer, or
52 less than zero if an error occurred. Usually this means that the buffer
53 -could not be allocated.
54 +could not be allocated, and the value of @var{ptr} in this situation is
55 +implementation-dependent (in glibc, @var{ptr} will be set to the null
56 +pointer, but this behavior should not be relied upon).
58 Here is how to use @code{asprintf} to get the same result as the
59 @code{snprintf} example, but more easily: