While working in vbscript, I noticed abs on a `BSTR` value with a positive number would come back with an invalid value.
Given the following script:
``` Dim x x = "30000" Debug.Print "x" & "=" & abs(x) ```
Outputs:
``` Script.Print 'x=3.08221696253945E-314' ```
After debugging, `pVarIn` gets the R8 value but is never shallow copied into `pVarOut`.
I'm not sure how to write a test case in `oleaut32`, so I included a test case in `vbscript`.
From: Jason Millard jsm174@gmail.com
--- dlls/oleaut32/variant.c | 3 ++- dlls/vbscript/tests/api.vbs | 1 + 2 files changed, 3 insertions(+), 1 deletion(-)
diff --git a/dlls/oleaut32/variant.c b/dlls/oleaut32/variant.c index 885082cc659..f3242ea5dc6 100644 --- a/dlls/oleaut32/variant.c +++ b/dlls/oleaut32/variant.c @@ -4374,8 +4374,9 @@ HRESULT WINAPI VarAbs(LPVARIANT pVarIn, LPVARIANT pVarOut) hRet = VarR8FromStr(V_BSTR(pVarIn), LOCALE_USER_DEFAULT, 0, &V_R8(&varIn)); if (FAILED(hRet)) break; - V_VT(pVarOut) = VT_R8; pVarIn = &varIn; + *pVarOut = *pVarIn; + V_VT(pVarOut) = VT_R8; /* Fall through ... */ case VT_DATE: ABS_CASE(R8,R8_MIN); diff --git a/dlls/vbscript/tests/api.vbs b/dlls/vbscript/tests/api.vbs index c0ac6c56cf5..842cce33f83 100644 --- a/dlls/vbscript/tests/api.vbs +++ b/dlls/vbscript/tests/api.vbs @@ -1672,6 +1672,7 @@ Call ok(Abs(True) = 1, "Abs(True) = " & Abs(True)) Call ok(getVT(Abs(True)) = "VT_I2", "getVT(Abs(True)) = " & getVT(Abs(True))) Call ok(Abs(CByte(1)) = 1, "Abs(CByte(1)) = " & Abs(CByte(1))) Call ok(getVT(Abs(CByte(1))) = "VT_UI1", "getVT(Abs(CByte(1))) = " & getVT(Abs(CByte(1)))) +Call ok(Abs("30000") = 30000, "Abs(""30000"") = " & Abs("30000"))
Sub testAbsError(strings, error_num1, error_num2) on error resume next
Tests for this should go to oleaut32/tests/vartest.c:test_VarAbs().