From 9af3a79b96318471818e0abacfc1a6f8ecc91463 Mon Sep 17 00:00:00 2001 From: David Kahurani Date: Mon, 4 Jul 2022 12:01:48 +0300 Subject: [PATCH] oleaut32: Handle DATE in string form in VarFormat. Testing has proven that coercion functions should reject the value which indicates that this is handled as a special case in VarFormat Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=13778 Signed-off-by: David Kahurani --- dlls/oleaut32/tests/varformat.c | 4 ++-- dlls/oleaut32/varformat.c | 28 +++++++++++++++++++++++++++- 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/dlls/oleaut32/tests/varformat.c b/dlls/oleaut32/tests/varformat.c index d238ef7b049..16506d8e97f 100644 --- a/dlls/oleaut32/tests/varformat.c +++ b/dlls/oleaut32/tests/varformat.c @@ -304,8 +304,8 @@ static void test_VarFormat(void) VARFMT(VT_BSTR,V_BSTR,bstrin,"<&>&",S_OK,"testing"); SysFreeString(bstrin); bstrin = SysAllocString(L"39697.11"); - todo_wine VARFMT(VT_BSTR,V_BSTR,bstrin,"hh:mm",S_OK,"02:38"); - todo_wine VARFMT(VT_BSTR,V_BSTR,bstrin,"mm-dd-yy",S_OK,"09-06-08"); + VARFMT(VT_BSTR,V_BSTR,bstrin,"hh:mm",S_OK,"02:38"); + VARFMT(VT_BSTR,V_BSTR,bstrin,"mm-dd-yy",S_OK,"09-06-08"); SysFreeString(bstrin); /* Numeric values are converted to strings then output */ VARFMT(VT_I1,V_I1,1,"<&>&",S_OK,"1"); diff --git a/dlls/oleaut32/varformat.c b/dlls/oleaut32/varformat.c index 1d6fac4c518..3f69a45a897 100644 --- a/dlls/oleaut32/varformat.c +++ b/dlls/oleaut32/varformat.c @@ -1585,8 +1585,34 @@ static HRESULT VARIANT_FormatDate(LPVARIANT pVarIn, LPOLESTR lpszFormat, USHORT usFlags = dwFlags & VARIANT_CALENDAR_HIJRI ? VAR_CALENDAR_HIJRI : 0; hRes = VariantChangeTypeEx(&vDate, pVarIn, lcid, usFlags, VT_DATE); + /* 31809.40 and similar are treated as invalid by coercion functions but + * it simply is a DATE in string form as far as VarFormat is concerned + */ if (FAILED(hRes)) - return hRes; + { + if (V_TYPE(pVarIn) == VT_BSTR) + { + DATE out; + OLECHAR *endptr = NULL; + /* Try consume the string with wcstod */ + double tmp = wcstod(V_BSTR(pVarIn), &endptr); + + /* Not a double in string form */ + if (*endptr) + return hRes; + + hRes = VarDateFromR8(tmp, &out); + + if (FAILED(hRes)) + return hRes; + + V_VT(&vDate) = VT_DATE; + V_DATE(&vDate) = out; + } + else + return hRes; + } + dateHeader = (FMT_DATE_HEADER*)(rgbTok + FmtGetPositive(header)); }