]> git.ipfire.org Git - people/ms/ipfire-3.x.git/blame - glibc/patches/glibc-2.10.1-asprintf_reset2null-1.patch
powertop: Update to 2.6.1
[people/ms/ipfire-3.x.git] / glibc / patches / glibc-2.10.1-asprintf_reset2null-1.patch
CommitLineData
b2ec3c8a
MT
1Submitted By: Robert Connolly <robert at linuxfromscratch dot org> (ashes)
2Date: 2007-05-07
3Initial Package Version: 2.5
4Upstream Status: Submitted
5http://sourceware.org/ml/libc-alpha/2004-05/msg00067.html
6http://sourceware.org/ml/libc-alpha/2004-06/msg00007.html
7Origin: Alt-Linux / Dmitry V. Levin
8Description:
9
10The asprintf(3) and vasprintf(3) functions are GNU extentions, not defined
11by C or Posix standards. In Glibc these functions leave (char **strp) undefined
12after an error. This patch resets (char **strp) to NULL after an error, for
13sanity.
14
15This patch, and the behavior it sets, was reviewed and discussed on the Glibc
16mailing list, and appeared to be accepted, and then it looks like it was
17forgotten about.
18
192004-06-03 Dmitry V. Levin <ldv@altlinux.org>
20
21 * libio/vasprintf.c (_IO_vasprintf): Reset the result pointer
22 to NULL on any error.
23 * manual/stdio.texi: Reflect the change in asprintf API.
24
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);
30 if (string == NULL)
31- return -1;
32+ {
33+ *result_ptr = NULL;
34+ return -1;
35+ }
36 #ifdef _IO_MTSAFE_IO
37 sf._sbf._f._lock = NULL;
38 #endif
39@@ -64,6 +67,7 @@ #endif
40 if (ret < 0)
41 {
42 free (sf._sbf._f._IO_buf_base);
43+ *result_ptr = NULL;
44 return ret;
45 }
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
50
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).
57
58 Here is how to use @code{asprintf} to get the same result as the
59 @code{snprintf} example, but more easily: