This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
[PATCH] Trivial fix: sscanf always calls realloc
- From: ppluzhnikov at google dot com (Paul Pluzhnikov)
- To: libc-alpha at sourceware dot org
- Cc: ppluzhnikov at google dot com
- Date: Thu, 5 Jan 2012 17:05:48 -0800 (PST)
- Subject: [PATCH] Trivial fix: sscanf always calls realloc
Greetings,
The patch below fixes apparent thinko: as is, _IO_vfscanf_internal always
calls realloc() when it should use alloca instead.
This can be observed with the following test program:
#include <stdio.h>
#include <stdlib.h>
void *realloc (void *p, size_t new_size)
{
abort();
}
int main()
{
const char *buf = "123";
int i;
sscanf(buf, "%d", &i);
return 123 - i;
}
Tested on Linux/x86_64.
Thanks,
--
2012-01-05 Paul Pluzhnikov <ppluzhnikov@google.com>
* stdio-common/vfscanf.c (_IO_vfscanf_internal): Use alloca when
appropriate.
diff --git a/stdio-common/vfscanf.c b/stdio-common/vfscanf.c
index 0e71deb..c96367e3 100644
--- a/stdio-common/vfscanf.c
+++ b/stdio-common/vfscanf.c
@@ -274,7 +274,7 @@ _IO_vfscanf_internal (_IO_FILE *s, const char *format, _IO_va_list argptr,
CHAR_T *old = wp; \
size_t newsize = (UCHAR_MAX + 1 > 2 * wpmax \
? UCHAR_MAX + 1 : 2 * wpmax); \
- if (use_malloc || __libc_use_alloca (newsize)) \
+ if (use_malloc || !__libc_use_alloca (newsize)) \
{ \
wp = realloc (use_malloc ? wp : NULL, newsize); \
if (wp == NULL) \