msvcrt: Fix scanf format "%i" base detection.

This commit is contained in:
Andrzej Popowski 2006-08-22 19:38:56 +02:00 committed by Alexandre Julliard
parent 803f3bd0a9
commit 4e5c51a6ee
2 changed files with 16 additions and 1 deletions

View file

@ -169,7 +169,7 @@ _FUNCTION_ {
base = 10;
goto number;
case 'i': /* generic integer */
base = 10;
base = 0;
number: {
/* read an integer */
ULONGLONG cur = 0;
@ -200,6 +200,9 @@ _FUNCTION_ {
} else if (base==0)
base = 8;
}
/* format %i without indication of base */
if (base==0)
base = 10;
/* throw away leading zeros */
while (width!=0 && nch=='0') {
nch = _GETC_(file);

View file

@ -110,6 +110,18 @@ static void test_sscanf( void )
ok(ret == 1, "Wrong number of arguments read: %d (expected 1)\n", ret);
ok(result == -1, "Read %d, expected -1\n", result);
/* Check %i for octal and hexadecimal input */
result = 0;
strcpy(buffer,"017");
ret = sscanf(buffer, "%i", &result);
ok(ret == 1, "Wrong number of arguments read: %d\n", ret);
ok(result == 15, "Wrong number read\n");
result = 0;
strcpy(buffer,"0x17");
ret = sscanf(buffer, "%i", &result);
ok(ret == 1, "Wrong number of arguments read: %d\n", ret);
ok(result == 23, "Wrong number read\n");
/* %o */
result = 0;
ret = sscanf("-1", "%o", &result);