[git commit branch/0.9.33] Revert "_scanf.c: Implement 'm' modifier for 'c' and '[' conversions."

Bernhard Reutner-Fischer rep.dot.nop at gmail.com
Fri Mar 29 12:27:17 UTC 2013


commit: http://git.uclibc.org/uClibc/commit/?id=ea36d1d1181cd7896f8f5a7b5a24b254b1fc0614
branch: http://git.uclibc.org/uClibc/commit/?id=refs/heads/0.9.33

This reverts commit e567c399ff86d007d8c4586f0dd5e0ca61e283ca.
since it breaks badly (e.g. busybox netstat)

Signed-off-by: Bernhard Reutner-Fischer <rep.dot.nop at gmail.com>
---
 libc/stdio/_scanf.c |   51 +++++++++++++++++++--------------------------------
 1 files changed, 19 insertions(+), 32 deletions(-)

diff --git a/libc/stdio/_scanf.c b/libc/stdio/_scanf.c
index c862afb..952853c 100644
--- a/libc/stdio/_scanf.c
+++ b/libc/stdio/_scanf.c
@@ -1355,21 +1355,7 @@ int VFSCANF (FILE *__restrict fp, const Wchar *__restrict format, va_list arg)
 				(psfs.conv_num >= CONV_c)
 #endif /* __UCLIBC_HAS_WCHAR__ */
 			{
-				/* We might have to handle the allocation ourselves */
-				int len;
-				unsigned char **ptr;
-
 				b = (psfs.store ? ((unsigned char *) psfs.cur_ptr) : buf);
-				/* With 'm', we actually got a pointer to a pointer */
-				ptr = (void *)b;
-
-				i = 0;
-				if (psfs.flags & FLAG_MALLOC) {
-					len = 0;
-					b = NULL;
-				} else
-					len = -1;
-
 				fail = 1;
 
 				if (psfs.conv_num == CONV_c) {
@@ -1377,25 +1363,31 @@ int VFSCANF (FILE *__restrict fp, const Wchar *__restrict format, va_list arg)
 						sc.width = 1;
 					}
 
-					if (psfs.flags & FLAG_MALLOC)
-						b = malloc(sc.width);
-
 					while (__scan_getc(&sc) >= 0) {
 						zero_conversions = 0;
-						b[i] = sc.cc;
-						i += psfs.store;
+						*b = sc.cc;
+						b += psfs.store;
 					}
 					__scan_ungetc(&sc);
 					if (sc.width > 0) {	/* Failed to read all required. */
 						goto DONE;
 					}
-					if (psfs.flags & FLAG_MALLOC)
-						*ptr = b;
 					psfs.cnt += psfs.store;
 					goto NEXT_FMT;
 				}
 
 				if (psfs.conv_num == CONV_s) {
+					/* We might have to handle the allocation ourselves */
+					int len;
+					/* With 'm', we actually got a pointer to a pointer */
+					unsigned char **ptr = (void *)b;
+
+					i = 0;
+					if (psfs.flags & FLAG_MALLOC) {
+						len = 0;
+						b = NULL;
+					} else
+						len = -1;
 
 					/* Yes, believe it or not, a %s conversion can store nuls. */
 					while ((__scan_getc(&sc) >= 0) && !isspace(sc.cc)) {
@@ -1411,6 +1403,10 @@ int VFSCANF (FILE *__restrict fp, const Wchar *__restrict format, va_list arg)
 						fail = 0;
 					}
 
+					if (psfs.flags & FLAG_MALLOC)
+						*ptr = b;
+					/* The code below takes care of terminating NUL */
+					b += i;
 				} else {
 #ifdef __UCLIBC_HAS_WCHAR__
 					assert((psfs.conv_num == CONV_LEFTBRACKET) || \
@@ -1466,14 +1462,8 @@ int VFSCANF (FILE *__restrict fp, const Wchar *__restrict format, va_list arg)
 						if (!scanset[sc.cc]) {
 							break;
 						}
-						if (i == len) {
-							/* Pick a size that won't trigger a lot of
-							 * mallocs early on ... */
-							len += 256;
-							b = realloc(b, len + 1);
-						}
-						b[i] = sc.cc;
-						i += psfs.store;
+						*b = sc.cc;
+						b += psfs.store;
 						fail = 0;
 					}
 				}
@@ -1483,9 +1473,6 @@ int VFSCANF (FILE *__restrict fp, const Wchar *__restrict format, va_list arg)
 				if (fail) {	/* nothing stored! */
 					goto DONE;
 				}
-				if (psfs.flags & FLAG_MALLOC)
-					*ptr = b;
-				b += i;
 				*b = 0;		/* Nul-terminate string. */
 				psfs.cnt += psfs.store;
 				goto NEXT_FMT;


More information about the uClibc-cvs mailing list