jscript: Change prototype of jsstr_alloc_buf and fix some error handling issues.

Signed-off-by: Sebastian Lackner <sebastian@fds-team.de>
Signed-off-by: Jacek Caban <jacek@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Sebastian Lackner 2016-09-07 10:50:11 +02:00 committed by Alexandre Julliard
parent 7c06f1c218
commit 69437afed1
11 changed files with 59 additions and 58 deletions

View File

@ -240,7 +240,7 @@ static HRESULT Array_concat(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsi
static HRESULT array_join(script_ctx_t *ctx, jsdisp_t *array, DWORD length, const WCHAR *sep, jsval_t *r) static HRESULT array_join(script_ctx_t *ctx, jsdisp_t *array, DWORD length, const WCHAR *sep, jsval_t *r)
{ {
jsstr_t **str_tab, *ret; jsstr_t **str_tab, *ret = NULL;
jsval_t val; jsval_t val;
DWORD i; DWORD i;
HRESULT hres = E_FAIL; HRESULT hres = E_FAIL;
@ -291,8 +291,8 @@ static HRESULT array_join(script_ctx_t *ctx, jsdisp_t *array, DWORD length, cons
if(SUCCEEDED(hres)) { if(SUCCEEDED(hres)) {
WCHAR *ptr = NULL; WCHAR *ptr = NULL;
ptr = jsstr_alloc_buf(len, &ret); ret = jsstr_alloc_buf(len, &ptr);
if(ptr) { if(ret) {
if(str_tab[0]) if(str_tab[0])
ptr += jsstr_flush(str_tab[0], ptr); ptr += jsstr_flush(str_tab[0], ptr);

View File

@ -548,8 +548,8 @@ static inline HRESULT date_to_string(DOUBLE time, BOOL show_offset, int offset,
offset = -offset; offset = -offset;
} }
date_str = jsstr_alloc_buf(len, &date_jsstr); date_jsstr = jsstr_alloc_buf(len, &date_str);
if(!date_str) if(!date_jsstr)
return E_OUTOFMEMORY; return E_OUTOFMEMORY;
if(!show_offset) if(!show_offset)
@ -627,7 +627,7 @@ static HRESULT Date_toLocaleString(script_ctx_t *ctx, vdisp_t *jsthis, WORD flag
date_len = GetDateFormatW(ctx->lcid, DATE_LONGDATE, &st, NULL, NULL, 0); date_len = GetDateFormatW(ctx->lcid, DATE_LONGDATE, &st, NULL, NULL, 0);
time_len = GetTimeFormatW(ctx->lcid, 0, &st, NULL, NULL, 0); time_len = GetTimeFormatW(ctx->lcid, 0, &st, NULL, NULL, 0);
ptr = jsstr_alloc_buf(date_len+time_len-1, &date_str); date_str = jsstr_alloc_buf(date_len+time_len-1, &ptr);
if(!date_str) if(!date_str)
return E_OUTOFMEMORY; return E_OUTOFMEMORY;
@ -723,7 +723,7 @@ static inline HRESULT create_utc_string(script_ctx_t *ctx, vdisp_t *jsthis, jsva
} while(day); } while(day);
day = date_from_time(date->time); day = date_from_time(date->time);
ptr = jsstr_alloc_buf(len, &date_str); date_str = jsstr_alloc_buf(len, &ptr);
if(!date_str) if(!date_str)
return E_OUTOFMEMORY; return E_OUTOFMEMORY;
@ -819,8 +819,8 @@ static HRESULT dateobj_to_date_string(DateInstance *date, jsval_t *r)
} while(day); } while(day);
day = date_from_time(time); day = date_from_time(time);
ptr = jsstr_alloc_buf(len, &date_str); date_str = jsstr_alloc_buf(len, &ptr);
if(!ptr) if(!date_str)
return E_OUTOFMEMORY; return E_OUTOFMEMORY;
sprintfW(ptr, formatAD?formatADW:formatBCW, week, month, day, year); sprintfW(ptr, formatAD?formatADW:formatBCW, week, month, day, year);
@ -870,7 +870,7 @@ static HRESULT Date_toTimeString(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags,
if(r) { if(r) {
WCHAR *ptr; WCHAR *ptr;
ptr = jsstr_alloc_buf(17, &date_str); date_str = jsstr_alloc_buf(17, &ptr);
if(!date_str) if(!date_str)
return E_OUTOFMEMORY; return E_OUTOFMEMORY;
@ -925,8 +925,8 @@ static HRESULT Date_toLocaleDateString(script_ctx_t *ctx, vdisp_t *jsthis, WORD
WCHAR *ptr; WCHAR *ptr;
len = GetDateFormatW(ctx->lcid, DATE_LONGDATE, &st, NULL, NULL, 0); len = GetDateFormatW(ctx->lcid, DATE_LONGDATE, &st, NULL, NULL, 0);
ptr = jsstr_alloc_buf(len, &date_str); date_str = jsstr_alloc_buf(len, &ptr);
if(!ptr) if(!date_str)
return E_OUTOFMEMORY; return E_OUTOFMEMORY;
GetDateFormatW(ctx->lcid, DATE_LONGDATE, &st, NULL, ptr, len); GetDateFormatW(ctx->lcid, DATE_LONGDATE, &st, NULL, ptr, len);
@ -964,8 +964,8 @@ static HRESULT Date_toLocaleTimeString(script_ctx_t *ctx, vdisp_t *jsthis, WORD
WCHAR *ptr; WCHAR *ptr;
len = GetTimeFormatW(ctx->lcid, 0, &st, NULL, NULL, 0); len = GetTimeFormatW(ctx->lcid, 0, &st, NULL, NULL, 0);
ptr = jsstr_alloc_buf(len, &date_str); date_str = jsstr_alloc_buf(len, &ptr);
if(!ptr) if(!date_str)
return E_OUTOFMEMORY; return E_OUTOFMEMORY;
GetTimeFormatW(ctx->lcid, 0, &st, NULL, ptr, len); GetTimeFormatW(ctx->lcid, 0, &st, NULL, ptr, len);

View File

@ -85,8 +85,8 @@ static HRESULT Error_toString(script_ctx_t *ctx, vdisp_t *vthis, WORD flags,
if(name_len && msg_len) { if(name_len && msg_len) {
WCHAR *ptr; WCHAR *ptr;
ptr = jsstr_alloc_buf(name_len + msg_len + 2, &ret); ret = jsstr_alloc_buf(name_len + msg_len + 2, &ptr);
if(ptr) { if(ret) {
jsstr_flush(name, ptr); jsstr_flush(name, ptr);
ptr[name_len] = ':'; ptr[name_len] = ':';
ptr[name_len+1] = ' '; ptr[name_len+1] = ' ';

View File

@ -302,8 +302,8 @@ static HRESULT function_to_string(FunctionInstance *function, jsstr_t **ret)
WCHAR *ptr; WCHAR *ptr;
name_len = strlenW(function->name); name_len = strlenW(function->name);
ptr = jsstr_alloc_buf((sizeof(native_prefixW)+sizeof(native_suffixW))/sizeof(WCHAR) + name_len, &str); str = jsstr_alloc_buf((sizeof(native_prefixW)+sizeof(native_suffixW))/sizeof(WCHAR) + name_len, &ptr);
if(!ptr) if(!str)
return E_OUTOFMEMORY; return E_OUTOFMEMORY;
memcpy(ptr, native_prefixW, sizeof(native_prefixW)); memcpy(ptr, native_prefixW, sizeof(native_prefixW));

View File

@ -150,8 +150,8 @@ static HRESULT JSGlobal_escape(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, u
len += 3; len += 3;
} }
ret = jsstr_alloc_buf(len, &ret_str); ret_str = jsstr_alloc_buf(len, &ret);
if(!ret) { if(!ret_str) {
jsstr_release(str); jsstr_release(str);
return E_OUTOFMEMORY; return E_OUTOFMEMORY;
} }
@ -510,8 +510,8 @@ static HRESULT JSGlobal_unescape(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags,
len++; len++;
} }
ret = jsstr_alloc_buf(len, &ret_str); ret_str = jsstr_alloc_buf(len, &ret);
if(!ret) { if(!ret_str) {
jsstr_release(str); jsstr_release(str);
return E_OUTOFMEMORY; return E_OUTOFMEMORY;
} }
@ -649,8 +649,8 @@ static HRESULT JSGlobal_encodeURI(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags
} }
} }
rptr = jsstr_alloc_buf(len, &ret); ret = jsstr_alloc_buf(len, &rptr);
if(!rptr) { if(!ret) {
jsstr_release(str); jsstr_release(str);
return E_OUTOFMEMORY; return E_OUTOFMEMORY;
} }
@ -728,8 +728,8 @@ static HRESULT JSGlobal_decodeURI(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags
} }
} }
ret = jsstr_alloc_buf(len, &ret_str); ret_str = jsstr_alloc_buf(len, &ret);
if(!ret) { if(!ret_str) {
jsstr_release(str); jsstr_release(str);
return E_OUTOFMEMORY; return E_OUTOFMEMORY;
} }
@ -799,8 +799,8 @@ static HRESULT JSGlobal_encodeURIComponent(script_ctx_t *ctx, vdisp_t *jsthis, W
} }
} }
ret = jsstr_alloc_buf(len, &ret_str); ret_str = jsstr_alloc_buf(len, &ret);
if(!ret) { if(!ret_str) {
jsstr_release(str); jsstr_release(str);
return E_OUTOFMEMORY; return E_OUTOFMEMORY;
} }
@ -899,7 +899,7 @@ static HRESULT JSGlobal_decodeURIComponent(script_ctx_t *ctx, vdisp_t *jsthis, W
} }
} }
out_ptr = jsstr_alloc_buf(len, &ret); ret = jsstr_alloc_buf(len, &out_ptr);
if(!ret) { if(!ret) {
jsstr_release(str); jsstr_release(str);
return E_OUTOFMEMORY; return E_OUTOFMEMORY;

View File

@ -374,8 +374,8 @@ static HRESULT RegExp_toString(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, u
if(f & REG_MULTILINE) if(f & REG_MULTILINE)
len++; len++;
ptr = jsstr_alloc_buf(len, &ret); ret = jsstr_alloc_buf(len, &ptr);
if(!ptr) if(!ret)
return E_OUTOFMEMORY; return E_OUTOFMEMORY;
*ptr++ = '/'; *ptr++ = '/';

View File

@ -66,7 +66,7 @@ static inline void jsstr_init(jsstr_t *str, unsigned len, jsstr_tag_t tag)
str->ref = 1; str->ref = 1;
} }
WCHAR *jsstr_alloc_buf(unsigned len, jsstr_t **r) jsstr_t *jsstr_alloc_buf(unsigned len, WCHAR **buf)
{ {
jsstr_inline_t *ret; jsstr_inline_t *ret;
@ -79,8 +79,8 @@ WCHAR *jsstr_alloc_buf(unsigned len, jsstr_t **r)
jsstr_init(&ret->str, len, JSSTR_INLINE); jsstr_init(&ret->str, len, JSSTR_INLINE);
ret->buf[len] = 0; ret->buf[len] = 0;
*r = &ret->str; *buf = ret->buf;
return ret->buf; return &ret->str;
} }
jsstr_t *jsstr_alloc_len(const WCHAR *buf, unsigned len) jsstr_t *jsstr_alloc_len(const WCHAR *buf, unsigned len)
@ -88,8 +88,8 @@ jsstr_t *jsstr_alloc_len(const WCHAR *buf, unsigned len)
jsstr_t *ret; jsstr_t *ret;
WCHAR *ptr; WCHAR *ptr;
ptr = jsstr_alloc_buf(len, &ret); ret = jsstr_alloc_buf(len, &ptr);
if(ptr) if(ret)
memcpy(ptr, buf, len*sizeof(WCHAR)); memcpy(ptr, buf, len*sizeof(WCHAR));
return ret; return ret;
@ -246,7 +246,7 @@ jsstr_t *jsstr_concat(jsstr_t *str1, jsstr_t *str2)
} }
} }
ptr = jsstr_alloc_buf(len1+len2, &ret); ret = jsstr_alloc_buf(len1+len2, &ptr);
if(!ret) if(!ret)
return NULL; return NULL;
@ -308,14 +308,15 @@ BOOL init_strings(void)
{ {
static const WCHAR NaNW[] = { 'N','a','N',0 }; static const WCHAR NaNW[] = { 'N','a','N',0 };
static const WCHAR undefinedW[] = {'u','n','d','e','f','i','n','e','d',0}; static const WCHAR undefinedW[] = {'u','n','d','e','f','i','n','e','d',0};
WCHAR *ptr;
if(!jsstr_alloc_buf(0, &empty_str)) if(!(empty_str = jsstr_alloc_buf(0, &ptr)))
return FALSE; return FALSE;
if(!(nan_str = jsstr_alloc(NaNW))) if(!(nan_str = jsstr_alloc(NaNW)))
return FALSE; return FALSE;
if(!(undefined_str = jsstr_alloc(undefinedW))) if(!(undefined_str = jsstr_alloc(undefinedW)))
return FALSE; return FALSE;
if(!jsstr_alloc_buf(0, &null_bstr_str)) if(!(null_bstr_str = jsstr_alloc_buf(0, &ptr)))
return FALSE; return FALSE;
return TRUE; return TRUE;
} }

View File

@ -95,7 +95,7 @@ typedef struct {
} jsstr_rope_t; } jsstr_rope_t;
jsstr_t *jsstr_alloc_len(const WCHAR*,unsigned) DECLSPEC_HIDDEN; jsstr_t *jsstr_alloc_len(const WCHAR*,unsigned) DECLSPEC_HIDDEN;
WCHAR *jsstr_alloc_buf(unsigned,jsstr_t**) DECLSPEC_HIDDEN; jsstr_t *jsstr_alloc_buf(unsigned,WCHAR**) DECLSPEC_HIDDEN;
static inline jsstr_t *jsstr_alloc(const WCHAR *str) static inline jsstr_t *jsstr_alloc(const WCHAR *str)
{ {
@ -162,8 +162,8 @@ static inline jsstr_t *jsstr_substr(jsstr_t *str, unsigned off, unsigned len)
jsstr_t *ret; jsstr_t *ret;
WCHAR *ptr; WCHAR *ptr;
ptr = jsstr_alloc_buf(len, &ret); ret = jsstr_alloc_buf(len, &ptr);
if(ptr) if(ret)
jsstr_extract(str, off, len, ptr); jsstr_extract(str, off, len, ptr);
return ret; return ret;
} }

View File

@ -127,7 +127,7 @@ static inline jsstr_t *number_to_fixed(double val, int prec)
if(prec) if(prec)
size += prec+1; size += prec+1;
str = jsstr_alloc_buf(size, &ret); ret = jsstr_alloc_buf(size, &str);
if(!ret) if(!ret)
return NULL; return NULL;
@ -194,7 +194,7 @@ static inline jsstr_t *number_to_exponential(double val, int prec)
if(neg) if(neg)
size++; size++;
str = jsstr_alloc_buf(size, &ret); ret = jsstr_alloc_buf(size, &str);
if(!ret) if(!ret)
return NULL; return NULL;

View File

@ -73,8 +73,8 @@ static HRESULT Object_toString(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, u
jsstr_t *ret; jsstr_t *ret;
WCHAR *ptr; WCHAR *ptr;
ptr = jsstr_alloc_buf(9+strlenW(str), &ret); ret = jsstr_alloc_buf(9+strlenW(str), &ptr);
if(!ptr) if(!ret)
return E_OUTOFMEMORY; return E_OUTOFMEMORY;
sprintfW(ptr, formatW, str); sprintfW(ptr, formatW, str);

View File

@ -175,7 +175,7 @@ static HRESULT do_attributeless_tag_format(script_ctx_t *ctx, vdisp_t *jsthis, j
tagname_len = strlenW(tagname); tagname_len = strlenW(tagname);
ptr = jsstr_alloc_buf(jsstr_length(str) + 2*tagname_len + 5, &ret); ret = jsstr_alloc_buf(jsstr_length(str) + 2*tagname_len + 5, &ptr);
if(!ret) { if(!ret) {
jsstr_release(str); jsstr_release(str);
return E_OUTOFMEMORY; return E_OUTOFMEMORY;
@ -225,8 +225,8 @@ static HRESULT do_attribute_tag_format(script_ctx_t *ctx, vdisp_t *jsthis, unsig
jsstr_t *ret; jsstr_t *ret;
WCHAR *ptr; WCHAR *ptr;
ptr = jsstr_alloc_buf(2*tagname_len + attrname_len + jsstr_length(attr_value) + jsstr_length(str) + 9, &ret); ret = jsstr_alloc_buf(2*tagname_len + attrname_len + jsstr_length(attr_value) + jsstr_length(str) + 9, &ptr);
if(ptr) { if(ret) {
*ptr++ = '<'; *ptr++ = '<';
memcpy(ptr, tagname, tagname_len*sizeof(WCHAR)); memcpy(ptr, tagname, tagname_len*sizeof(WCHAR));
ptr += tagname_len; ptr += tagname_len;
@ -376,7 +376,7 @@ static HRESULT String_charCodeAt(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags,
static HRESULT String_concat(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, jsval_t *argv, static HRESULT String_concat(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, jsval_t *argv,
jsval_t *r) jsval_t *r)
{ {
jsstr_t *ret, *str; jsstr_t *ret = NULL, *str;
HRESULT hres; HRESULT hres;
TRACE("\n"); TRACE("\n");
@ -433,8 +433,8 @@ static HRESULT String_concat(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, uns
} }
if(SUCCEEDED(hres)) { if(SUCCEEDED(hres)) {
ptr = jsstr_alloc_buf(len, &ret); ret = jsstr_alloc_buf(len, &ptr);
if(ptr) { if(ret) {
for(i=0; i < str_cnt; i++) for(i=0; i < str_cnt; i++)
ptr += jsstr_flush(strs[i], ptr); ptr += jsstr_flush(strs[i], ptr);
}else { }else {
@ -1405,8 +1405,8 @@ static HRESULT String_toLowerCase(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags
jsstr_t *ret; jsstr_t *ret;
WCHAR *buf; WCHAR *buf;
buf = jsstr_alloc_buf(jsstr_length(str), &ret); ret = jsstr_alloc_buf(jsstr_length(str), &buf);
if(!buf) { if(!ret) {
jsstr_release(str); jsstr_release(str);
return E_OUTOFMEMORY; return E_OUTOFMEMORY;
} }
@ -1435,8 +1435,8 @@ static HRESULT String_toUpperCase(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags
jsstr_t *ret; jsstr_t *ret;
WCHAR *buf; WCHAR *buf;
buf = jsstr_alloc_buf(jsstr_length(str), &ret); ret = jsstr_alloc_buf(jsstr_length(str), &buf);
if(!buf) { if(!ret) {
jsstr_release(str); jsstr_release(str);
return E_OUTOFMEMORY; return E_OUTOFMEMORY;
} }
@ -1588,8 +1588,8 @@ static HRESULT StringConstr_fromCharCode(script_ctx_t *ctx, vdisp_t *jsthis, WOR
TRACE("\n"); TRACE("\n");
ret_str = jsstr_alloc_buf(argc, &ret); ret = jsstr_alloc_buf(argc, &ret_str);
if(!ret_str) if(!ret)
return E_OUTOFMEMORY; return E_OUTOFMEMORY;
for(i=0; i<argc; i++) { for(i=0; i<argc; i++) {