Module: wine Branch: master Commit: 7240170ceedecef6aac674e795fdc4e1a74e131a URL: http://source.winehq.org/git/wine.git/?a=commit;h=7240170ceedecef6aac674e795...
Author: Piotr Caban piotr@codeweavers.com Date: Mon Apr 16 16:32:57 2012 +0200
msvcrt: Added more length modifiers in scanf function.
---
dlls/msvcrt/scanf.h | 12 +++++++++--- dlls/msvcrt/tests/scanf.c | 20 ++++++++++++++++++++ 2 files changed, 29 insertions(+), 3 deletions(-)
diff --git a/dlls/msvcrt/scanf.h b/dlls/msvcrt/scanf.h index 9f6911e..cc2b861 100644 --- a/dlls/msvcrt/scanf.h +++ b/dlls/msvcrt/scanf.h @@ -198,8 +198,14 @@ _FUNCTION_ { /* read prefix (if any) */ while (!prefix_finished) { switch(*format) { - case 'h': h_prefix = 1; break; - case 'l': l_prefix = 1; break; + case 'h': h_prefix++; break; + case 'l': + if(*(format+1) == 'l') { + I64_prefix = 1; + format++; + } + l_prefix = 1; + break; case 'w': w_prefix = 1; break; case 'L': L_prefix = 1; break; case 'I': @@ -294,7 +300,7 @@ _FUNCTION_ { #define _SET_NUMBER_(type) *va_arg(ap, type*) = negative ? -cur : cur if (I64_prefix) _SET_NUMBER_(LONGLONG); else if (l_prefix) _SET_NUMBER_(LONG); - else if (h_prefix) _SET_NUMBER_(short int); + else if (h_prefix == 1) _SET_NUMBER_(short int); else _SET_NUMBER_(int); } } diff --git a/dlls/msvcrt/tests/scanf.c b/dlls/msvcrt/tests/scanf.c index 8b13bdc..fb9d8e8 100644 --- a/dlls/msvcrt/tests/scanf.c +++ b/dlls/msvcrt/tests/scanf.c @@ -27,6 +27,7 @@ static void test_sscanf( void ) char buffer[100], buffer1[100]; char format[20]; int result, ret; + LONGLONG result64; char c; void *ptr; float res1= -82.6267f, res2= 27.76f, res11, res12; @@ -125,6 +126,25 @@ static void test_sscanf( void ) ok(ret == 0 , "problem with format arg "%%*c%%n"\n"); ok(number_so_far == 1,"Read wrong arg for "%%n" %d instead of 2\n",number_so_far);
+ result = 0xdeadbeef; + strcpy(buffer,"12345678"); + ret = sscanf(buffer, "%hd", &result); + ok(ret == 1, "Wrong number of arguments read: %d\n", ret); + ok(result == 0xdead614e, "Wrong number read (%x)\n", result); + + result = 0xdeadbeef; + ret = sscanf(buffer, "%hhd", &result); + ok(ret == 1, "Wrong number of arguments read: %d\n", ret); + ok(result == 0xbc614e, "Wrong number read (%x)\n", result); + + strcpy(buffer,"12345678901234"); + ret = sscanf(buffer, "%lld", &result64); + ok(ret == 1, "Wrong number of arguments read: %d\n", ret); + ret = sprintf(buffer1, "%lld", result64); + ok(ret==14 || broken(ret==10), "sprintf retuned %d\n", ret); + if(ret == 14) + ok(!strcmp(buffer, buffer1), "got %s, expected %s\n", buffer1, buffer); + /* Check %i according to bug 1878 */ strcpy(buffer,"123"); ret = sscanf(buffer, "%i", &result);