diff --git a/dlls/msvcrt/scanf.h b/dlls/msvcrt/scanf.h index 8299b57ee6e..139f1426e10 100644 --- a/dlls/msvcrt/scanf.h +++ b/dlls/msvcrt/scanf.h @@ -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); diff --git a/dlls/msvcrt/tests/scanf.c b/dlls/msvcrt/tests/scanf.c index 244327bc61c..71e6e228077 100644 --- a/dlls/msvcrt/tests/scanf.c +++ b/dlls/msvcrt/tests/scanf.c @@ -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);