diff --git a/dlls/jscript/array.c b/dlls/jscript/array.c index fef37e67c05..5987ef1f091 100644 --- a/dlls/jscript/array.c +++ b/dlls/jscript/array.c @@ -286,15 +286,10 @@ static HRESULT array_join(script_ctx_t *ctx, jsdisp_t *array, DWORD length, cons if(SUCCEEDED(hres)) ret = jsstr_alloc_buf(len); if(ret) { - unsigned tmplen; - ptr = ret->str; - if(str_tab[0]) { - tmplen = jsstr_length(str_tab[0]); - memcpy(ptr, str_tab[0]->str, tmplen*sizeof(WCHAR)); - ptr += tmplen; - } + if(str_tab[0]) + ptr += jsstr_flush(str_tab[0], ptr); for(i=1; i < length; i++) { if(seplen) { @@ -302,13 +297,9 @@ static HRESULT array_join(script_ctx_t *ctx, jsdisp_t *array, DWORD length, cons ptr += seplen; } - if(str_tab[i]) { - tmplen = jsstr_length(str_tab[i]); - memcpy(ptr, str_tab[i]->str, tmplen*sizeof(WCHAR)); - ptr += tmplen; - } + if(str_tab[i]) + ptr += jsstr_flush(str_tab[i], ptr); } - *ptr=0; }else { hres = E_OUTOFMEMORY; } diff --git a/dlls/jscript/jsstr.h b/dlls/jscript/jsstr.h index 8883dcbd255..cbe68ef3437 100644 --- a/dlls/jscript/jsstr.h +++ b/dlls/jscript/jsstr.h @@ -59,6 +59,13 @@ static inline BOOL jsstr_eq(jsstr_t *str1, jsstr_t *str2) return len == jsstr_length(str2) && !memcmp(str1->str, str2->str, len*sizeof(WCHAR)); } +static inline unsigned jsstr_flush(jsstr_t *str, WCHAR *buf) +{ + unsigned len = jsstr_length(str); + memcpy(buf, str->str, len*sizeof(WCHAR)); + return len; +} + static inline jsstr_t *jsstr_substr(jsstr_t *str, unsigned off, unsigned len) { return jsstr_alloc_len(str->str+off, len);