Piotr Caban : msvcrt: Fixed 'h' modifier handling when printing integers.

Alexandre Julliard julliard at winehq.org
Mon Apr 16 13:35:47 CDT 2012


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

Author: Piotr Caban <piotr at codeweavers.com>
Date:   Mon Apr 16 15:21:47 2012 +0200

msvcrt: Fixed 'h' modifier handling when printing integers.

---

 dlls/msvcrt/printf.h       |   10 ++++++----
 dlls/msvcrt/tests/printf.c |   10 ++++++++++
 2 files changed, 16 insertions(+), 4 deletions(-)

diff --git a/dlls/msvcrt/printf.h b/dlls/msvcrt/printf.h
index a60ba74..79a03a9 100644
--- a/dlls/msvcrt/printf.h
+++ b/dlls/msvcrt/printf.h
@@ -525,11 +525,13 @@ int FUNC_NAME(pf_printf)(FUNC_NAME(puts_clbk) pf_puts, void *puts_ctx, const API
                 FUNC_NAME(pf_integer_conv)(tmp, max_len, &flags, pf_args(args_ctx, pos,
                             VT_I8, valist).get_longlong);
             else if(flags.Format=='d' || flags.Format=='i')
-                FUNC_NAME(pf_integer_conv)(tmp, max_len, &flags, pf_args(args_ctx, pos,
-                            VT_INT, valist).get_int);
+                FUNC_NAME(pf_integer_conv)(tmp, max_len, &flags, flags.IntegerLength!='h' ?
+                        pf_args(args_ctx, pos, VT_INT, valist).get_int :
+                        (short)pf_args(args_ctx, pos, VT_INT, valist).get_int);
             else
-                FUNC_NAME(pf_integer_conv)(tmp, max_len, &flags, (unsigned)pf_args(
-                            args_ctx, pos, VT_INT, valist).get_int);
+                FUNC_NAME(pf_integer_conv)(tmp, max_len, &flags, flags.IntegerLength!='h' ?
+                        (unsigned)pf_args(args_ctx, pos, VT_INT, valist).get_int :
+                        (unsigned short)pf_args(args_ctx, pos, VT_INT, valist).get_int);
 
 #ifdef PRINTF_WIDE
             i = FUNC_NAME(pf_output_format_wstr)(pf_puts, puts_ctx, tmp, -1, &flags, locinfo);
diff --git a/dlls/msvcrt/tests/printf.c b/dlls/msvcrt/tests/printf.c
index ff86516..1507a01 100644
--- a/dlls/msvcrt/tests/printf.c
+++ b/dlls/msvcrt/tests/printf.c
@@ -607,6 +607,16 @@ static void test_sprintf( void )
     r = sprintf(buffer, format);
     ok(!strcmp(buffer,"%0"), "failed: \"%s\"\n", buffer);
     ok( r==2, "return count wrong\n");
+
+    format = "%hx";
+    r = sprintf(buffer, format, 0x12345);
+    ok(!strcmp(buffer,"2345"), "failed \"%s\"\n", buffer);
+
+    format = "%hhx";
+    r = sprintf(buffer, format, 0x123);
+    ok(!strcmp(buffer,"123"), "failed: \"%s\"\n", buffer);
+    r = sprintf(buffer, format, 0x12345);
+    ok(!strcmp(buffer,"2345"), "failed \"%s\"\n", buffer);
 }
 
 static void test_swprintf( void )




More information about the wine-cvs mailing list