Commit 69437afe authored by Sebastian Lackner's avatar Sebastian Lackner Committed by Alexandre Julliard

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

parent 7c06f1c2
......@@ -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)
{
jsstr_t **str_tab, *ret;
jsstr_t **str_tab, *ret = NULL;
jsval_t val;
DWORD i;
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)) {
WCHAR *ptr = NULL;
ptr = jsstr_alloc_buf(len, &ret);
if(ptr) {
ret = jsstr_alloc_buf(len, &ptr);
if(ret) {
if(str_tab[0])
ptr += jsstr_flush(str_tab[0], ptr);
......
......@@ -548,8 +548,8 @@ static inline HRESULT date_to_string(DOUBLE time, BOOL show_offset, int offset,
offset = -offset;
}
date_str = jsstr_alloc_buf(len, &date_jsstr);
if(!date_str)
date_jsstr = jsstr_alloc_buf(len, &date_str);
if(!date_jsstr)
return E_OUTOFMEMORY;
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);
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)
return E_OUTOFMEMORY;
......@@ -723,7 +723,7 @@ static inline HRESULT create_utc_string(script_ctx_t *ctx, vdisp_t *jsthis, jsva
} while(day);
day = date_from_time(date->time);
ptr = jsstr_alloc_buf(len, &date_str);
date_str = jsstr_alloc_buf(len, &ptr);
if(!date_str)
return E_OUTOFMEMORY;
......@@ -819,8 +819,8 @@ static HRESULT dateobj_to_date_string(DateInstance *date, jsval_t *r)
} while(day);
day = date_from_time(time);
ptr = jsstr_alloc_buf(len, &date_str);
if(!ptr)
date_str = jsstr_alloc_buf(len, &ptr);
if(!date_str)
return E_OUTOFMEMORY;
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) {
WCHAR *ptr;
ptr = jsstr_alloc_buf(17, &date_str);
date_str = jsstr_alloc_buf(17, &ptr);
if(!date_str)
return E_OUTOFMEMORY;
......@@ -925,8 +925,8 @@ static HRESULT Date_toLocaleDateString(script_ctx_t *ctx, vdisp_t *jsthis, WORD
WCHAR *ptr;
len = GetDateFormatW(ctx->lcid, DATE_LONGDATE, &st, NULL, NULL, 0);
ptr = jsstr_alloc_buf(len, &date_str);
if(!ptr)
date_str = jsstr_alloc_buf(len, &ptr);
if(!date_str)
return E_OUTOFMEMORY;
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;
len = GetTimeFormatW(ctx->lcid, 0, &st, NULL, NULL, 0);
ptr = jsstr_alloc_buf(len, &date_str);
if(!ptr)
date_str = jsstr_alloc_buf(len, &ptr);
if(!date_str)
return E_OUTOFMEMORY;
GetTimeFormatW(ctx->lcid, 0, &st, NULL, ptr, len);
......
......@@ -85,8 +85,8 @@ static HRESULT Error_toString(script_ctx_t *ctx, vdisp_t *vthis, WORD flags,
if(name_len && msg_len) {
WCHAR *ptr;
ptr = jsstr_alloc_buf(name_len + msg_len + 2, &ret);
if(ptr) {
ret = jsstr_alloc_buf(name_len + msg_len + 2, &ptr);
if(ret) {
jsstr_flush(name, ptr);
ptr[name_len] = ':';
ptr[name_len+1] = ' ';
......
......@@ -302,8 +302,8 @@ static HRESULT function_to_string(FunctionInstance *function, jsstr_t **ret)
WCHAR *ptr;
name_len = strlenW(function->name);
ptr = jsstr_alloc_buf((sizeof(native_prefixW)+sizeof(native_suffixW))/sizeof(WCHAR) + name_len, &str);
if(!ptr)
str = jsstr_alloc_buf((sizeof(native_prefixW)+sizeof(native_suffixW))/sizeof(WCHAR) + name_len, &ptr);
if(!str)
return E_OUTOFMEMORY;
memcpy(ptr, native_prefixW, sizeof(native_prefixW));
......
......@@ -150,8 +150,8 @@ static HRESULT JSGlobal_escape(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, u
len += 3;
}
ret = jsstr_alloc_buf(len, &ret_str);
if(!ret) {
ret_str = jsstr_alloc_buf(len, &ret);
if(!ret_str) {
jsstr_release(str);
return E_OUTOFMEMORY;
}
......@@ -510,8 +510,8 @@ static HRESULT JSGlobal_unescape(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags,
len++;
}
ret = jsstr_alloc_buf(len, &ret_str);
if(!ret) {
ret_str = jsstr_alloc_buf(len, &ret);
if(!ret_str) {
jsstr_release(str);
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);
if(!rptr) {
ret = jsstr_alloc_buf(len, &rptr);
if(!ret) {
jsstr_release(str);
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);
if(!ret) {
ret_str = jsstr_alloc_buf(len, &ret);
if(!ret_str) {
jsstr_release(str);
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);
if(!ret) {
ret_str = jsstr_alloc_buf(len, &ret);
if(!ret_str) {
jsstr_release(str);
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) {
jsstr_release(str);
return E_OUTOFMEMORY;
......
......@@ -374,8 +374,8 @@ static HRESULT RegExp_toString(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, u
if(f & REG_MULTILINE)
len++;
ptr = jsstr_alloc_buf(len, &ret);
if(!ptr)
ret = jsstr_alloc_buf(len, &ptr);
if(!ret)
return E_OUTOFMEMORY;
*ptr++ = '/';
......
......@@ -66,7 +66,7 @@ static inline void jsstr_init(jsstr_t *str, unsigned len, jsstr_tag_t tag)
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;
......@@ -79,8 +79,8 @@ WCHAR *jsstr_alloc_buf(unsigned len, jsstr_t **r)
jsstr_init(&ret->str, len, JSSTR_INLINE);
ret->buf[len] = 0;
*r = &ret->str;
return ret->buf;
*buf = ret->buf;
return &ret->str;
}
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;
WCHAR *ptr;
ptr = jsstr_alloc_buf(len, &ret);
if(ptr)
ret = jsstr_alloc_buf(len, &ptr);
if(ret)
memcpy(ptr, buf, len*sizeof(WCHAR));
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)
return NULL;
......@@ -308,14 +308,15 @@ BOOL init_strings(void)
{
static const WCHAR NaNW[] = { 'N','a','N',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;
if(!(nan_str = jsstr_alloc(NaNW)))
return FALSE;
if(!(undefined_str = jsstr_alloc(undefinedW)))
return FALSE;
if(!jsstr_alloc_buf(0, &null_bstr_str))
if(!(null_bstr_str = jsstr_alloc_buf(0, &ptr)))
return FALSE;
return TRUE;
}
......
......@@ -95,7 +95,7 @@ typedef struct {
} jsstr_rope_t;
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)
{
......@@ -162,8 +162,8 @@ static inline jsstr_t *jsstr_substr(jsstr_t *str, unsigned off, unsigned len)
jsstr_t *ret;
WCHAR *ptr;
ptr = jsstr_alloc_buf(len, &ret);
if(ptr)
ret = jsstr_alloc_buf(len, &ptr);
if(ret)
jsstr_extract(str, off, len, ptr);
return ret;
}
......
......@@ -127,7 +127,7 @@ static inline jsstr_t *number_to_fixed(double val, int prec)
if(prec)
size += prec+1;
str = jsstr_alloc_buf(size, &ret);
ret = jsstr_alloc_buf(size, &str);
if(!ret)
return NULL;
......@@ -194,7 +194,7 @@ static inline jsstr_t *number_to_exponential(double val, int prec)
if(neg)
size++;
str = jsstr_alloc_buf(size, &ret);
ret = jsstr_alloc_buf(size, &str);
if(!ret)
return NULL;
......
......@@ -73,8 +73,8 @@ static HRESULT Object_toString(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, u
jsstr_t *ret;
WCHAR *ptr;
ptr = jsstr_alloc_buf(9+strlenW(str), &ret);
if(!ptr)
ret = jsstr_alloc_buf(9+strlenW(str), &ptr);
if(!ret)
return E_OUTOFMEMORY;
sprintfW(ptr, formatW, str);
......
......@@ -175,7 +175,7 @@ static HRESULT do_attributeless_tag_format(script_ctx_t *ctx, vdisp_t *jsthis, j
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) {
jsstr_release(str);
return E_OUTOFMEMORY;
......@@ -225,8 +225,8 @@ static HRESULT do_attribute_tag_format(script_ctx_t *ctx, vdisp_t *jsthis, unsig
jsstr_t *ret;
WCHAR *ptr;
ptr = jsstr_alloc_buf(2*tagname_len + attrname_len + jsstr_length(attr_value) + jsstr_length(str) + 9, &ret);
if(ptr) {
ret = jsstr_alloc_buf(2*tagname_len + attrname_len + jsstr_length(attr_value) + jsstr_length(str) + 9, &ptr);
if(ret) {
*ptr++ = '<';
memcpy(ptr, tagname, tagname_len*sizeof(WCHAR));
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,
jsval_t *r)
{
jsstr_t *ret, *str;
jsstr_t *ret = NULL, *str;
HRESULT hres;
TRACE("\n");
......@@ -433,8 +433,8 @@ static HRESULT String_concat(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, uns
}
if(SUCCEEDED(hres)) {
ptr = jsstr_alloc_buf(len, &ret);
if(ptr) {
ret = jsstr_alloc_buf(len, &ptr);
if(ret) {
for(i=0; i < str_cnt; i++)
ptr += jsstr_flush(strs[i], ptr);
}else {
......@@ -1405,8 +1405,8 @@ static HRESULT String_toLowerCase(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags
jsstr_t *ret;
WCHAR *buf;
buf = jsstr_alloc_buf(jsstr_length(str), &ret);
if(!buf) {
ret = jsstr_alloc_buf(jsstr_length(str), &buf);
if(!ret) {
jsstr_release(str);
return E_OUTOFMEMORY;
}
......@@ -1435,8 +1435,8 @@ static HRESULT String_toUpperCase(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags
jsstr_t *ret;
WCHAR *buf;
buf = jsstr_alloc_buf(jsstr_length(str), &ret);
if(!buf) {
ret = jsstr_alloc_buf(jsstr_length(str), &buf);
if(!ret) {
jsstr_release(str);
return E_OUTOFMEMORY;
}
......@@ -1588,8 +1588,8 @@ static HRESULT StringConstr_fromCharCode(script_ctx_t *ctx, vdisp_t *jsthis, WOR
TRACE("\n");
ret_str = jsstr_alloc_buf(argc, &ret);
if(!ret_str)
ret = jsstr_alloc_buf(argc, &ret_str);
if(!ret)
return E_OUTOFMEMORY;
for(i=0; i<argc; i++) {
......
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