[PATCH] Trivial fix: sscanf always calls realloc
Paul Pluzhnikov
ppluzhnikov@google.com
Fri Jan 6 01:17:00 GMT 2012
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) \
More information about the Libc-alpha
mailing list