oleaut32: Added a preliminary test, for scale overflow, in VarDecCmp. (resend)

Christopher Cope ccope3 at utk.edu
Mon Oct 21 19:30:06 CDT 2013


This fixes Bug #31269 <http://bugs.winehq.org/show_bug.cgi?id=31269>.

---
  dlls/oleaut32/tests/vartype.c |    2 +-
  dlls/oleaut32/vartype.c       |   33 ++++++++++++++++++++++++++++++++-
  2 files changed, 33 insertions(+), 2 deletions(-)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.winehq.org/pipermail/wine-patches/attachments/20131021/716de0ef/attachment.html>
-------------- next part --------------
>From 30e7c70ff6e45a8225866bb340f78365e3cb74cc Mon Sep 17 00:00:00 2001
From: Christopher Cope <ccope3 at utk.edu>
Date: Mon, 21 Oct 2013 19:40:45 -0400
Subject: oleaut32: Added a preliminary test, for scale overflow, in VarDecCmp.

---
 dlls/oleaut32/tests/vartype.c |    2 +-
 dlls/oleaut32/vartype.c       |   33 ++++++++++++++++++++++++++++++++-
 2 files changed, 33 insertions(+), 2 deletions(-)

diff --git a/dlls/oleaut32/tests/vartype.c b/dlls/oleaut32/tests/vartype.c
index e296e77..7649a98 100644
--- a/dlls/oleaut32/tests/vartype.c
+++ b/dlls/oleaut32/tests/vartype.c
@@ -4513,7 +4513,7 @@ static void test_VarDecCmp(void)
   SETDEC(out,0,DECIMAL_NEG,-1,-1); SETDEC(l,0,DECIMAL_NEG,-1,-1); MATH1(VarDecCmp); EXPECT_EQ;
 
   SETDEC(l,3,0,0,123456); SETDEC64(out,0,0,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF);
-  MATH1(VarDecCmp); todo_wine EXPECT_LT;
+  MATH1(VarDecCmp); EXPECT_LT;
 }
 
 static void test_VarDecCmpR8(void)
diff --git a/dlls/oleaut32/vartype.c b/dlls/oleaut32/vartype.c
index d492e7d..9fb668c 100644
--- a/dlls/oleaut32/vartype.c
+++ b/dlls/oleaut32/vartype.c
@@ -5836,7 +5836,9 @@ HRESULT WINAPI VarDecRound(const DECIMAL* pDecIn, int cDecimals, DECIMAL* pDecOu
 HRESULT WINAPI VarDecCmp(const DECIMAL* pDecLeft, const DECIMAL* pDecRight)
 {
   HRESULT hRet;
-  DECIMAL result;
+  static DECIMAL scaleFactor;
+  DECIMAL result, decTemp;
+  int scaleAmount, i;
 
   if (!pDecLeft || !pDecRight)
     return VARCMP_NULL;
@@ -5848,6 +5850,35 @@ HRESULT WINAPI VarDecCmp(const DECIMAL* pDecLeft, const DECIMAL* pDecRight)
       (DEC_HI32(pDecLeft) | DEC_MID32(pDecLeft) | DEC_LO32(pDecLeft)))
     return VARCMP_LT;
 
+  /* Preliminary check for scale overflow */
+  DEC_LO32(&scaleFactor) = 10;
+  i = scaleAmount = DEC_SCALE(pDecLeft) - DEC_SCALE(pDecRight);
+  if(scaleAmount != 0)
+  {
+    if(scaleAmount > 0)
+      {
+        decTemp = *pDecRight; /* Left is bigger - scale the right hand side */
+      }
+      else
+      {
+        decTemp = *pDecLeft; /* Right is bigger - scale the left hand side */
+        i = scaleAmount = -scaleAmount;
+      }
+  }
+  while(i--)
+  {
+    /* Note we are multiplying by a value with a scale of 0, so we don't recurse */
+    hRet = VarDecMul(&decTemp, &scaleFactor, &result);
+    if(hRet == DISP_E_OVERFLOW)
+    {
+      if(scaleAmount > 0) // Right is bigger
+        return (HRESULT)VARCMP_LT;
+      else // Left is bigger
+        return (HRESULT)VARCMP_GT;
+    }
+    decTemp = result;
+  }
+
   /* Subtract right from left, and compare the result to 0 */
   hRet = VarDecSub(pDecLeft, pDecRight, &result);
 
-- 
1.7.9



More information about the wine-patches mailing list