[PATCH v2] oleaut32: Do not skip the first decimal digit in VarParseNumFromStr().
Francois Gouget
fgouget at codeweavers.com
Mon Mar 7 11:47:31 CST 2022
Add more tests to probe what happens if the integral part is omitted.
From: David Kahurani <k.kahurani at gmail.com>
Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=52476
Signed-off-by: Francois Gouget <fgouget at codeweavers.com>
---
v2: Fix the subject to not imply this is a test patch.
Without the fix the new tests would fail in EXPECT() which performs
multiple ok() calls, making adding a todo_wine() impractical. So I
opted for submitting the fix and the new tests together.
---
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 0a8b56bb2ee..dc1fb476307 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++;
--
2.30.2
More information about the wine-devel
mailing list