This is the mail archive of the
newlib@sourceware.org
mailing list for the newlib project.
asnprintf followup
- From: Eric Blake <ebb9 at byu dot net>
- To: newlib at sources dot redhat dot com
- Date: Wed, 9 May 2007 16:37:51 +0000 (UTC)
- Subject: asnprintf followup
May I commit this? It turns out that GNU code found it useful to call
asnprintf with an existing buf not on the heap, but a calculated remaining size
of 0; asnprintf dumped core when it tried to realloc the user's buf to make
room for the trailing NUL.
2007-05-09 Eric Blake <ebb9@byu.net>
Allow zero size with non-null buf in *asnprintf.
* libc/stdio/asnprintf.c (_asnprintf_r, asnprintf): Avoid free'ing
user's buf.
* libc/stdio/asniprintf.c (_asniprintf_r, asniprintf): Likewise.
* libc/stdio/vasniprintf.c (_vasniprintf_r): Likewise.
* libc/stdio/vasnprintf.c (_vasnprintf_r): Likewise.
Index: libc/stdio/asniprintf.c
===================================================================
RCS file: /cvs/src/src/newlib/libc/stdio/asniprintf.c,v
retrieving revision 1.1
diff -u -r1.1 asniprintf.c
--- libc/stdio/asniprintf.c 4 May 2007 02:55:16 -0000 1.1
+++ libc/stdio/asniprintf.c 9 May 2007 16:36:23 -0000
@@ -34,6 +34,7 @@
/* mark a zero-length reallocatable buffer */
f._flags = __SWR | __SSTR | __SMBF;
len = 0;
+ buf = NULL;
}
f._bf._base = f._p = (unsigned char *) buf;
/* For now, inherit the 32-bit signed limit of FILE._bf._size.
@@ -80,6 +81,7 @@
/* mark a zero-length reallocatable buffer */
f._flags = __SWR | __SSTR | __SMBF;
len = 0;
+ buf = NULL;
}
f._bf._base = f._p = (unsigned char *) buf;
/* For now, inherit the 32-bit signed limit of FILE._bf._size.
Index: libc/stdio/asnprintf.c
===================================================================
RCS file: /cvs/src/src/newlib/libc/stdio/asnprintf.c,v
retrieving revision 1.1
diff -u -r1.1 asnprintf.c
--- libc/stdio/asnprintf.c 4 May 2007 02:55:16 -0000 1.1
+++ libc/stdio/asnprintf.c 9 May 2007 16:36:23 -0000
@@ -34,6 +34,7 @@
/* mark a zero-length reallocatable buffer */
f._flags = __SWR | __SSTR | __SMBF;
len = 0;
+ buf = NULL;
}
f._bf._base = f._p = (unsigned char *) buf;
/* For now, inherit the 32-bit signed limit of FILE._bf._size.
@@ -80,6 +81,7 @@
/* mark a zero-length reallocatable buffer */
f._flags = __SWR | __SSTR | __SMBF;
len = 0;
+ buf = NULL;
}
f._bf._base = f._p = (unsigned char *) buf;
/* For now, inherit the 32-bit signed limit of FILE._bf._size.
Index: libc/stdio/vasniprintf.c
===================================================================
RCS file: /cvs/src/src/newlib/libc/stdio/vasniprintf.c,v
retrieving revision 1.1
diff -u -r1.1 vasniprintf.c
--- libc/stdio/vasniprintf.c 4 May 2007 02:55:16 -0000 1.1
+++ libc/stdio/vasniprintf.c 9 May 2007 16:36:23 -0000
@@ -34,6 +34,7 @@
/* mark a zero-length reallocatable buffer */
f._flags = __SWR | __SSTR | __SMBF;
len = 0;
+ buf = NULL;
}
f._bf._base = f._p = (unsigned char *) buf;
/* For now, inherit the 32-bit signed limit of FILE._bf._size.
Index: libc/stdio/vasnprintf.c
===================================================================
RCS file: /cvs/src/src/newlib/libc/stdio/vasnprintf.c,v
retrieving revision 1.1
diff -u -r1.1 vasnprintf.c
--- libc/stdio/vasnprintf.c 4 May 2007 02:55:16 -0000 1.1
+++ libc/stdio/vasnprintf.c 9 May 2007 16:36:23 -0000
@@ -34,6 +34,7 @@
/* mark a zero-length reallocatable buffer */
f._flags = __SWR | __SSTR | __SMBF;
len = 0;
+ buf = NULL;
}
f._bf._base = f._p = (unsigned char *) buf;
/* For now, inherit the 32-bit signed limit of FILE._bf._size.