From c01562040da27ed0d0d1cd559281cd0064826eb2 Mon Sep 17 00:00:00 2001 From: Jacek Caban Date: Thu, 3 May 2012 10:41:10 +0200 Subject: [PATCH] jscript: Better handling of to_integer result in String.slice. --- dlls/jscript/string.c | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/dlls/jscript/string.c b/dlls/jscript/string.c index 62cc6f0cda9..773e3a3ed73 100644 --- a/dlls/jscript/string.c +++ b/dlls/jscript/string.c @@ -1071,6 +1071,7 @@ static HRESULT String_slice(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DISP BSTR val_str; DWORD length; INT start=0, end; + double d; VARIANT v; HRESULT hres; @@ -1087,8 +1088,10 @@ static HRESULT String_slice(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DISP return hres; } - if(V_VT(&v) == VT_I4) { - start = V_I4(&v); + d = num_val(&v); + + if(is_int32(d)) { + start = d; if(start < 0) { start = length + start; if(start < 0) @@ -1096,11 +1099,9 @@ static HRESULT String_slice(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DISP }else if(start > length) { start = length; } - }else { - start = V_R8(&v) < 0.0 ? 0 : length; + }else if(d > 0) { + start = length; } - }else { - start = 0; } if(arg_cnt(dp) >= 2) { @@ -1110,8 +1111,10 @@ static HRESULT String_slice(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DISP return hres; } - if(V_VT(&v) == VT_I4) { - end = V_I4(&v); + d = num_val(&v); + + if(is_int32(d)) { + end = d; if(end < 0) { end = length + end; if(end < 0) @@ -1120,7 +1123,7 @@ static HRESULT String_slice(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DISP end = length; } }else { - end = V_R8(&v) < 0.0 ? 0 : length; + end = d < 0.0 ? 0 : length; } }else { end = length; -- 2.11.4.GIT