[PATCH 0/1] MR10107: msvcrt: Ignore negative precision for float args in printf().
Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=59403 Signed-off-by: Eric Pouech <epouech@codeweavers.com> -- https://gitlab.winehq.org/wine/wine/-/merge_requests/10107
From: Eric Pouech <epouech@codeweavers.com> Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=59403 Signed-off-by: Eric Pouech <epouech@codeweavers.com> --- dlls/msvcrt/printf.h | 4 ++-- dlls/msvcrt/tests/printf.c | 8 ++++++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/dlls/msvcrt/printf.h b/dlls/msvcrt/printf.h index be30d6ae719..cfcfd5be771 100644 --- a/dlls/msvcrt/printf.h +++ b/dlls/msvcrt/printf.h @@ -375,7 +375,7 @@ static inline int FUNC_NAME(pf_output_special_fp)(FUNC_NAME(puts_clbk) pf_puts, if(!flags->Alternate && (flags->Format == 'g' || flags->Format == 'G')) sfx_len = frac_len; else sfx_len = flags->Precision; - if(sfx_len == -1) { + if(sfx_len < 0) { if(strchr("fFeE", flags->Format)) sfx_len = 6; else if(flags->Format == 'a' || flags->Format == 'A') sfx_len = 13; } @@ -614,7 +614,7 @@ static inline int FUNC_NAME(pf_output_fp)(FUNC_NAME(puts_clbk) pf_puts, void *pu ULONGLONG m; DWORD l; - if(flags->Precision == -1) + if(flags->Precision < 0) flags->Precision = 6; v = frexp(v, &e2); diff --git a/dlls/msvcrt/tests/printf.c b/dlls/msvcrt/tests/printf.c index dc0038b3372..c21b1285275 100644 --- a/dlls/msvcrt/tests/printf.c +++ b/dlls/msvcrt/tests/printf.c @@ -377,6 +377,14 @@ static void test_sprintf( void ) ok(!strcmp(buffer,"foo "),"Negative field width ignored \"%s\"\n",buffer); ok( r==5, "return count wrong\n"); + r = p_sprintf(buffer, "%.*f", 0x80000000, 3.14); + ok(!strcmp(buffer,"3.140000"),"Negative precision ignored \"%s\"\n",buffer); + ok( r==8, "return count wrong\n"); + + r = p_sprintf(buffer, "%.*f", 0x80000000, NAN); + ok(!strcmp(buffer,"1.#QNAN0"),"Negative precision ignored \"%s\"\n",buffer); + ok( r==8, "return count wrong\n"); + x = 0; r = p_sprintf(buffer, "asdf%n", &x ); if (r == -1) -- GitLab https://gitlab.winehq.org/wine/wine/-/merge_requests/10107
Paul Gofman (@gofman) commented about dlls/msvcrt/tests/printf.c:
ok(!strcmp(buffer,"foo "),"Negative field width ignored \"%s\"\n",buffer); ok( r==5, "return count wrong\n");
+ r = p_sprintf(buffer, "%.*f", 0x80000000, 3.14); + ok(!strcmp(buffer,"3.140000"),"Negative precision ignored \"%s\"\n",buffer); + ok( r==8, "return count wrong\n"); + + r = p_sprintf(buffer, "%.*f", 0x80000000, NAN);
Does it really ignore it or maybe uses just some bits, or checks maximum value (what will it do for 0x7fffffff?) or maybe even that 0x80000000 is meaningful undocuemnted flag? I'd suggest to extend the test with some other values, like 0x80000001 for a start and overall check for more values, even if locally not to overload the test suite with paranoid checks for any possible condition. -- https://gitlab.winehq.org/wine/wine/-/merge_requests/10107#note_129704
On Sat Feb 14 17:46:19 2026 +0000, Paul Gofman wrote:
Does it really ignore it or maybe uses just some bits, or checks maximum value (what will it do for 0x7fffffff?) or maybe even that 0x80000000 is meaningful undocuemnted flag? I'd suggest to extend the test with some other values, like 0x80000001 for a start and overall check for more values, even if locally not to overload the test suite with paranoid checks for any possible condition. I actually tested on Win10 all precision values in \[-64k,-1\], \[INT_MIN, INT_MIN+64k\] and \[INT_MIN, -1\] by 0x1000 step and all behave the same
I'm not sure it's worth extending the tests -- https://gitlab.winehq.org/wine/wine/-/merge_requests/10107#note_129708
This merge request was approved by Piotr Caban. -- https://gitlab.winehq.org/wine/wine/-/merge_requests/10107
participants (4)
-
Eric Pouech -
eric pouech (@epo) -
Paul Gofman (@gofman) -
Piotr Caban (@piotr)