Commit 47ecca25 authored by Nikolay Sivov's avatar Nikolay Sivov Committed by Alexandre Julliard

vbscript: Improve invalid argument checks in Right().

parent 51483239
......@@ -1348,6 +1348,19 @@ static HRESULT Global_Right(BuiltinDisp *This, VARIANT *args, unsigned args_cnt,
TRACE("(%s %s)\n", debugstr_variant(args), debugstr_variant(args+1));
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 {
......@@ -1357,15 +1370,6 @@ static HRESULT Global_Right(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;
......
......@@ -842,7 +842,28 @@ TestRight "test", 0, ""
TestRight 123, 2, "23"
TestRight "test", "3", "est"
TestRight 123, "2", "23"
TestRight empty, 0, ""
TestRight empty, 1, ""
TestRight "test", empty, ""
TestRight "test", empty, ""
if isEnglishLang then TestRight true, 2, "ue"
call Right(null, 0)
call ok(getVT(Right(null, 0)) = "VT_NULL", "getVT(Right(null, 0)) = " & getVT(Right(null, 0)))
call ok(getVT(Right(null, 1)) = "VT_NULL", "getVT(Right(null, 1)) = " & getVT(Right(null, 1)))
sub TestRightError()
on error resume next
call Err.clear()
call Right("test", -1)
call ok(Err.number = 5, "Err.number = " & Err.number)
call Err.clear()
call Right(null, -1)
call ok(Err.number = 5, "Err.number = " & Err.number)
call Err.clear()
call Right("test", null)
call ok(Err.number = 94, "Err.number = " & Err.number)
end sub
call TestRightError()
Sub TestTrim(str, exstr)
Call ok(Trim(str) = exstr, "Trim(" & str & ") = " & Trim(str))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment