### Eclipse Workspace Patch 1.0 #P avr-libc Index: libc/stdio/vfscanf.c =================================================================== RCS file: /sources/avr-libc/avr-libc/libc/stdio/vfscanf.c,v retrieving revision 1.13 diff -u -r1.13 vfscanf.c --- libc/stdio/vfscanf.c 9 Nov 2005 21:54:33 -0000 1.13 +++ libc/stdio/vfscanf.c 25 Oct 2007 23:34:44 -0000 @@ -264,18 +264,15 @@ if (!(flags & FLSTAR)) #endif /* SCANF_LEVEL > SCANF_MIN */ a.cp = va_arg(ap, char *); - do { - i = getc(stream); - } while (isspace(i)); - if (i == EOF) - goto leave; #if SCANF_LEVEL > SCANF_MIN - while (width-- > 0) + do #else for (;;) #endif /* SCANF_LEVEL > SCANF_MIN */ { + if ((i = getc(stream)) == EOF) + break; if (isspace(i)) { ungetc(i, stream); break; @@ -284,10 +281,10 @@ if (!(flags & FLSTAR)) #endif /* SCANF_LEVEL > SCANF_MIN */ *a.cp++ = i; - if ((i = getc(stream)) == EOF) - break; + } #if SCANF_LEVEL > SCANF_MIN + while (--width > 0); if (!(flags & FLSTAR)) #endif /* SCANF_LEVEL > SCANF_MIN */ *a.cp = '\0'; I included a patch file. Here are comment on the patch: do { i = getc(stream); } while (isspace(i)); if (i == EOF) goto leave; this was remove. Reason: Man file state: Matches a sequence of non-white-space characters... Obviosly that part of code as the exact purpose of removing any leading space(or white-space characters). As a second remark, we dont yet decrement width(hit, bug is sscanf eats 1 char too much) . Next modif: - while (width-- > 0) + do Using a post decrement tation will end up in the following senarion. if Width == 6, we will loop 6 time, this way we will read 6 char from the stream. Didn't we just read 1 earlyer? next modification: Bring if ((i = getc(stream)) == EOF) break; just after the do Since we are going to do some test condition on var i, we better have something in it. I guess it was done later on due to the fact that it was red in the part I removed earlyer. final modif: while (--width > 0); To close the do-while, this will ensure a width reading. I have not done much testing on it, just things that came to my mind. Comment are welcome Fred