From a3776288dff65e0858b8dc0ca8fb262aa364392b Mon Sep 17 00:00:00 2001 From: ericb Date: Wed, 9 May 2007 19:27:29 +0000 Subject: [PATCH] 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. --- newlib/ChangeLog | 9 +++++++++ newlib/libc/stdio/asniprintf.c | 2 ++ newlib/libc/stdio/asnprintf.c | 2 ++ newlib/libc/stdio/vasniprintf.c | 1 + newlib/libc/stdio/vasnprintf.c | 1 + 5 files changed, 15 insertions(+) diff --git a/newlib/ChangeLog b/newlib/ChangeLog index fc4aa1f78b..fd5194668e 100644 --- a/newlib/ChangeLog +++ b/newlib/ChangeLog @@ -1,3 +1,12 @@ +2007-05-09 Eric Blake + + 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. + 2007-05-07 Charles Wilson * libc/stdio/vfprintf.c: Fix typo in comments that breaks docs. diff --git a/newlib/libc/stdio/asniprintf.c b/newlib/libc/stdio/asniprintf.c index 202d8c13c0..dd74b7c8ca 100644 --- a/newlib/libc/stdio/asniprintf.c +++ b/newlib/libc/stdio/asniprintf.c @@ -34,6 +34,7 @@ _DEFUN(_asniprintf_r, (ptr, buf, lenp, fmt), /* 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 @@ _DEFUN(asniprintf, (buf, lenp, fmt), /* 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. diff --git a/newlib/libc/stdio/asnprintf.c b/newlib/libc/stdio/asnprintf.c index 78d10e803d..ef9bd8900b 100644 --- a/newlib/libc/stdio/asnprintf.c +++ b/newlib/libc/stdio/asnprintf.c @@ -34,6 +34,7 @@ _DEFUN(_asnprintf_r, (ptr, buf, lenp, fmt), /* 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 @@ _DEFUN(asnprintf, (buf, lenp, fmt), /* 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. diff --git a/newlib/libc/stdio/vasniprintf.c b/newlib/libc/stdio/vasniprintf.c index eff6dfd90b..1e5d600c78 100644 --- a/newlib/libc/stdio/vasniprintf.c +++ b/newlib/libc/stdio/vasniprintf.c @@ -34,6 +34,7 @@ _DEFUN(_vasniprintf_r, (ptr, buf, lenp, fmt, ap), /* 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. diff --git a/newlib/libc/stdio/vasnprintf.c b/newlib/libc/stdio/vasnprintf.c index 923ed83079..740aa07003 100644 --- a/newlib/libc/stdio/vasnprintf.c +++ b/newlib/libc/stdio/vasnprintf.c @@ -34,6 +34,7 @@ _DEFUN(_vasnprintf_r, (ptr, buf, lenp, fmt, ap), /* 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. -- 2.11.0