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

Alexandre Julliard julliard at wine.codeweavers.com
Wed Aug 23 16:36:20 CDT 2006


Module: wine
Branch: master
Commit: 4e5c51a6eefb0ee1afff02b8a850e4a5d2a27b2d
URL:    http://source.winehq.org/git/?p=wine.git;a=commit;h=4e5c51a6eefb0ee1afff02b8a850e4a5d2a27b2d

Author: Andrzej Popowski <popej at friko.onet.pl>
Date:   Tue Aug 22 19:38:56 2006 +0200

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

---

 dlls/msvcrt/scanf.h       |    5 ++++-
 dlls/msvcrt/tests/scanf.c |   12 ++++++++++++
 2 files changed, 16 insertions(+), 1 deletions(-)

diff --git a/dlls/msvcrt/scanf.h b/dlls/msvcrt/scanf.h
index 8299b57..139f142 100644
--- a/dlls/msvcrt/scanf.h
+++ b/dlls/msvcrt/scanf.h
@@ -169,7 +169,7 @@ #endif /* WIDE_SCANF */
 		base = 10;
 		goto number;
 	    case 'i': /* generic integer */
-		base = 10;
+		base = 0;
 	    number: {
 		    /* read an integer */
 		    ULONGLONG cur = 0;
@@ -200,6 +200,9 @@ #endif /* WIDE_SCANF */
 			} 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 244327b..71e6e22 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);




More information about the wine-cvs mailing list