2004-09-18 Joerg Wunsch * libc/stdio/vfscanf.c: Fix a logical flaw that caused characters > 'Z' && < 'a' to be misdetected as valid hex digits. Fix for bug #10420. Index: libc/stdio/vfscanf.c =================================================================== RCS file: /cvsroot/avr-libc/avr-libc/libc/stdio/vfscanf.c,v retrieving revision 1.6 diff -u -u -r1.6 vfscanf.c --- libc/stdio/vfscanf.c 21 Jul 2004 22:11:59 -0000 1.6 +++ libc/stdio/vfscanf.c 19 Sep 2004 11:21:24 -0000 @@ -374,9 +374,29 @@ a.ul = 0; for (;;) { j = tolower(i); + /* + * First, assume it is a decimal + * digit. + */ j -= '0'; - if (j > 9) - j -= 'a' - '0' - 10; + if (j > 9) { + /* + * Not a decimal digit. + * Try hex next. + */ + j += '0'; /* undo "- '0'" + * above */ + j -= 'a'; /* 'a' is first + * hex digit */ + if (j >= 0) + /* 'a' has value + * 10 */ + j += 10; + /* + * else: not a hex digit, + * gets caught below. + */ + } if (j < 0 || j >= base) { ungetc(i, stream); break;