diff --git a/dlls/jscript/string.c b/dlls/jscript/string.c index 79d7884cc0e..d88ed1c06e9 100644 --- a/dlls/jscript/string.c +++ b/dlls/jscript/string.c @@ -1131,21 +1131,20 @@ static HRESULT String_split(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsi jsval_t *r) { match_state_t match_result, *match_ptr = &match_result; - DWORD length, i, match_len = 0; + size_t length, i = 0, match_len = 0; const WCHAR *ptr, *ptr2, *str, *match_str = NULL; unsigned limit = ~0u; jsdisp_t *array, *regexp = NULL; jsstr_t *jsstr, *match_jsstr, *tmp_str; HRESULT hres; - TRACE("\n"); - hres = get_string_flat_val(ctx, jsthis, &jsstr, &str); if(FAILED(hres)) return hres; - length = jsstr_length(jsstr); + TRACE("%s\n", debugstr_wn(str, length)); + if(!argc || (is_undefined(argv[0]) && ctx->version >= SCRIPTLANGUAGEVERSION_ES5)) { if(!r) return S_OK; @@ -1203,11 +1202,29 @@ static HRESULT String_split(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsi if(SUCCEEDED(hres)) { ptr = str; match_result.cp = str; - for(i=0; i ptr) { + tmp_str = jsstr_alloc_len(ptr, ptr2-ptr); + if(!tmp_str) { + hres = E_OUTOFMEMORY; + break; + } - hres = jsdisp_propput_idx(array, i, jsval_string(tmp_str)); - jsstr_release(tmp_str); - if(FAILED(hres)) - break; + hres = jsdisp_propput_idx(array, i++, jsval_string(tmp_str)); + jsstr_release(tmp_str); + if(FAILED(hres)) + break; + } if(regexp) ptr = match_result.cp; @@ -1242,7 +1261,7 @@ static HRESULT String_split(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsi if(SUCCEEDED(hres) && (match_str || regexp) && i