David Kahurani : oleaut32: Do not skip the first decimal digit in VarParseNumFromStr().

Alexandre Julliard julliard at winehq.org
Mon Mar 7 16:04:58 CST 2022


Module: wine
Branch: master
Commit: a4ba88c0ff25c71687fd26792cda40c20d8eaed1
URL:    https://source.winehq.org/git/wine.git/?a=commit;h=a4ba88c0ff25c71687fd26792cda40c20d8eaed1

Author: David Kahurani <k.kahurani at gmail.com>
Date:   Mon Mar  7 18:47:31 2022 +0100

oleaut32: Do not skip the first decimal digit in VarParseNumFromStr().

Add more tests to probe what happens if the integral part is omitted.

Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=52476
Signed-off-by: Francois Gouget <fgouget at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>

---

 dlls/oleaut32/tests/vartest.c | 47 +++++++++++++++++++++++++++++++++++++++++++
 dlls/oleaut32/variant.c       |  2 +-
 2 files changed, 48 insertions(+), 1 deletion(-)

diff --git a/dlls/oleaut32/tests/vartest.c b/dlls/oleaut32/tests/vartest.c
index f25a448645c..a4e2700c7df 100644
--- a/dlls/oleaut32/tests/vartest.c
+++ b/dlls/oleaut32/tests/vartest.c
@@ -1775,6 +1775,45 @@ static void test_VarParseNumFromStrEn(void)
   EXPECT(1,NUMPRS_DECIMAL,NUMPRS_DECIMAL,2,0,0);
   EXPECT2(1,FAILDIG);
 
+  /* Skipping the integer part is not an error */
+  CONVERT(".2", NUMPRS_DECIMAL);
+  EXPECT(1,NUMPRS_DECIMAL,NUMPRS_DECIMAL,2,0,-1);
+  EXPECT2(2,FAILDIG);
+
+  /* Even zero gets an exponent (it sort of indicates 'precision') */
+  CONVERT(".0", NUMPRS_DECIMAL);
+  EXPECT(1,NUMPRS_DECIMAL,NUMPRS_DECIMAL,2,0,-1);
+  EXPECT2(0,FAILDIG);
+
+  CONVERT(".000", NUMPRS_DECIMAL);
+  EXPECT(1,NUMPRS_DECIMAL,NUMPRS_DECIMAL,4,0,-3);
+  EXPECTRGB(0,0);
+  EXPECTRGB(3,FAILDIG);
+
+  CONVERT("$.02", NUMPRS_CURRENCY|NUMPRS_DECIMAL);
+  EXPECT(1,NUMPRS_CURRENCY|NUMPRS_DECIMAL,NUMPRS_CURRENCY|NUMPRS_DECIMAL,4,0,-2);
+  EXPECT2(2,FAILDIG);
+
+  CONVERT(".001", NUMPRS_DECIMAL);
+  EXPECT(1,NUMPRS_DECIMAL,NUMPRS_DECIMAL,4,0,-3);
+  EXPECT2(1,FAILDIG);
+
+  CONVERT(".101", NUMPRS_DECIMAL);
+  EXPECT(3,NUMPRS_DECIMAL,NUMPRS_DECIMAL,4,0,-3);
+  EXPECT2(1,0);
+  EXPECTRGB(2,1);
+  EXPECTRGB(3,FAILDIG);
+
+  CONVERT(".30", NUMPRS_DECIMAL);
+  EXPECT(1,NUMPRS_DECIMAL,NUMPRS_DECIMAL,3,0,-1);
+  /* See the NUMPRS_THOUSANDS comment about trailing zeroes */
+  EXPECTRGB(0,3);
+  EXPECTRGB(2,FAILDIG);
+
+  /* But skipping both the integer and decimal part is not allowed */
+  CONVERT(".", NUMPRS_DECIMAL);
+  EXPECTFAIL;
+
   /* Consumes only one decimal point */
   CONVERT("1.1.", NUMPRS_DECIMAL);
   EXPECT(2,NUMPRS_DECIMAL,NUMPRS_DECIMAL,3,0,-1);
@@ -2131,6 +2170,14 @@ static void test_VarParseNumFromStrFr(void)
   CONVERT("1.2", NUMPRS_DECIMAL);
   EXPECT(1,NUMPRS_DECIMAL,0,1,0,0);
   EXPECT2(1,FAILDIG);
+
+  /* The integer part can still be omitted */
+  CONVERT(",2", NUMPRS_DECIMAL);
+  EXPECT(1,NUMPRS_DECIMAL,NUMPRS_DECIMAL,2,0,-1);
+  EXPECT2(2,FAILDIG);
+
+  CONVERT(".2", NUMPRS_DECIMAL);
+  EXPECTFAIL;
 }
 
 static void test_VarParseNumFromStrMisc(void)
diff --git a/dlls/oleaut32/variant.c b/dlls/oleaut32/variant.c
index bf8f041b9c6..885082cc659 100644
--- a/dlls/oleaut32/variant.c
+++ b/dlls/oleaut32/variant.c
@@ -1633,7 +1633,7 @@ HRESULT WINAPI VarParseNumFromStr(const OLECHAR *lpszStr, LCID lcid, ULONG dwFla
       /* If we have no digits so far, skip leading zeros */
       if (!pNumprs->cDig)
       {
-        while (lpszStr[1] == '0')
+        while (*lpszStr == '0')
         {
           dwState |= B_LEADING_ZERO;
           cchUsed++;




More information about the wine-cvs mailing list