From: Francis De Brabandere <francisdb@gmail.com> Native VBScript propagates Null through the string operand of Left() and raises error 94 (illegal Null use) when the length operand is Null. Wine's Right() already does this; bring Left() in line. --- dlls/vbscript/global.c | 22 +++++++++++++--------- dlls/vbscript/tests/api.vbs | 20 ++++++++++++++++++++ 2 files changed, 33 insertions(+), 9 deletions(-) diff --git a/dlls/vbscript/global.c b/dlls/vbscript/global.c index ac7e707a041..32c6b7652f9 100644 --- a/dlls/vbscript/global.c +++ b/dlls/vbscript/global.c @@ -1330,6 +1330,19 @@ static HRESULT Global_Left(BuiltinDisp *This, VARIANT *args, unsigned args_cnt, TRACE("(%s %s)\n", debugstr_variant(args+1), debugstr_variant(args)); + if(V_VT(args+1) == VT_NULL) + return MAKE_VBSERROR(VBSE_ILLEGAL_NULL_USE); + + hres = to_int(args+1, &len); + if(FAILED(hres)) + return hres; + + if(len < 0) + return MAKE_VBSERROR(VBSE_ILLEGAL_FUNC_CALL); + + if(V_VT(args) == VT_NULL) + return return_null(res); + if(V_VT(args) == VT_BSTR) { str = V_BSTR(args); }else { @@ -1339,15 +1352,6 @@ static HRESULT Global_Left(BuiltinDisp *This, VARIANT *args, unsigned args_cnt, str = conv_str; } - hres = to_int(args+1, &len); - if(FAILED(hres)) - return hres; - - if(len < 0) { - FIXME("len = %d\n", len); - return E_FAIL; - } - str_len = SysStringLen(str); if(len > str_len) len = str_len; diff --git a/dlls/vbscript/tests/api.vbs b/dlls/vbscript/tests/api.vbs index 9917997a9aa..a7603e0de93 100644 --- a/dlls/vbscript/tests/api.vbs +++ b/dlls/vbscript/tests/api.vbs @@ -2901,6 +2901,26 @@ end sub call testFilterError() +sub testLeftNull() + on error resume next + dim r + + call Err.clear() + r = Left(Null, 3) + Call ok(Err.number = 0, "Left(Null, 3) Err.number = " & Err.number) + Call ok(IsNull(r), "Left(Null, 3) should be Null") + + call Err.clear() + r = Left("abcde", Null) + Call ok(Err.number = 94, "Left(""abcde"", Null) Err.number = " & Err.number) + + call Err.clear() + r = Left("abcde", -1) + Call ok(Err.number = 5, "Left(""abcde"", -1) Err.number = " & Err.number) +end sub + +call testLeftNull() + ' GetLocale/SetLocale tests Dim origLocale origLocale = GetLocale() -- GitLab https://gitlab.winehq.org/wine/wine/-/merge_requests/10819