summaryrefslogtreecommitdiff
path: root/libc/stdio/stdio.c
diff options
context:
space:
mode:
authorManuel Novoa III <mjn3@codepoet.org>2002-03-16 01:36:11 +0000
committerManuel Novoa III <mjn3@codepoet.org>2002-03-16 01:36:11 +0000
commit48c12e04cad347c03c7bfeb2a291ec6b21e96a1f (patch)
tree483a640b4dc903ef1bf938c79e0c849648ca2ff9 /libc/stdio/stdio.c
parent5e5710cd0c6199b662752b44cd1c745805840c91 (diff)
Fix a pointer bug in setvbuf reported by Bart Visscher <magick@Linux-Fan.com>.
Diffstat (limited to 'libc/stdio/stdio.c')
-rw-r--r--libc/stdio/stdio.c8
1 files changed, 6 insertions, 2 deletions
diff --git a/libc/stdio/stdio.c b/libc/stdio/stdio.c
index 5a2800a05..49d2a74c6 100644
--- a/libc/stdio/stdio.c
+++ b/libc/stdio/stdio.c
@@ -2408,9 +2408,13 @@ int setvbuf(register FILE * __restrict stream, register char * __restrict buf,
allocated_buf_flag = 0;
if ((!buf) && (size != (stream->bufend - stream->bufstart))) {
/* No buffer supplied and requested size different from current. */
- allocated_buf_flag = __FLAG_FREEBUF;
/* If size == 0, create a (hopefully) bogus non-null pointer... */
- if (!(buf = ((size > 0) ? malloc(size) : ((char *)NULL) + 1))) {
+ if (!(buf = ((size > 0)
+ ? ((allocated_buf_flag = __FLAG_FREEBUF), malloc(size))
+ : ((char *)NULL) + 1))
+ ) {
+ /* TODO -- should we really keep current buffer if it was passed
+ * to us earlier by the app? */
goto DONE; /* Keep current buffer. */
}
}