Commit fd07a157 authored by Sebastian Lackner's avatar Sebastian Lackner Committed by Alexandre Julliard

jscript: Allocate string of correct size in Date toTimeString method.

parent 1c3e0dd3
...@@ -850,6 +850,7 @@ static HRESULT Date_toTimeString(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, ...@@ -850,6 +850,7 @@ static HRESULT Date_toTimeString(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags,
':','%','0','2','d',' ','U','T','C',0 }; ':','%','0','2','d',' ','U','T','C',0 };
DateInstance *date; DateInstance *date;
jsstr_t *date_str; jsstr_t *date_str;
WCHAR buf[32];
DOUBLE time; DOUBLE time;
WCHAR sign; WCHAR sign;
int offset; int offset;
...@@ -868,12 +869,6 @@ static HRESULT Date_toTimeString(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, ...@@ -868,12 +869,6 @@ static HRESULT Date_toTimeString(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags,
time = local_time(date->time, date); time = local_time(date->time, date);
if(r) { if(r) {
WCHAR *ptr;
date_str = jsstr_alloc_buf(17, &ptr);
if(!date_str)
return E_OUTOFMEMORY;
offset = date->bias + offset = date->bias +
daylight_saving_ta(time, date); daylight_saving_ta(time, date);
...@@ -884,13 +879,17 @@ static HRESULT Date_toTimeString(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, ...@@ -884,13 +879,17 @@ static HRESULT Date_toTimeString(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags,
else sign = '-'; else sign = '-';
if(offset) if(offset)
sprintfW(ptr, formatW, (int)hour_from_time(time), sprintfW(buf, formatW, (int)hour_from_time(time),
(int)min_from_time(time), (int)sec_from_time(time), (int)min_from_time(time), (int)sec_from_time(time),
sign, offset/60, offset%60); sign, offset/60, offset%60);
else else
sprintfW(ptr, formatUTCW, (int)hour_from_time(time), sprintfW(buf, formatUTCW, (int)hour_from_time(time),
(int)min_from_time(time), (int)sec_from_time(time)); (int)min_from_time(time), (int)sec_from_time(time));
date_str = jsstr_alloc(buf);
if(!date_str)
return E_OUTOFMEMORY;
*r = jsval_string(date_str); *r = jsval_string(date_str);
} }
return S_OK; return S_OK;
......
...@@ -2147,9 +2147,11 @@ ok(Date.parse("Tue, 22 Mar 2016 09:57:55 +0400") === Date.parse("Tue, 22 Mar 201 ...@@ -2147,9 +2147,11 @@ ok(Date.parse("Tue, 22 Mar 2016 09:57:55 +0400") === Date.parse("Tue, 22 Mar 201
"Date.parse(\"Tue, 22 Mar 2016 09:57:55 +0400\") = " + Date.parse("Tue, 22 Mar 2016 09:57:55 +0400")); "Date.parse(\"Tue, 22 Mar 2016 09:57:55 +0400\") = " + Date.parse("Tue, 22 Mar 2016 09:57:55 +0400"));
tmp = (new Date()).toLocaleDateString(); tmp = (new Date()).toLocaleDateString();
ok(tmp.charCodeAt(tmp.length-1) != 0, "invalid null byte"); ok(tmp.indexOf(String.fromCharCode(0)) == -1, "invalid null byte");
tmp = (new Date()).toLocaleTimeString(); tmp = (new Date()).toLocaleTimeString();
ok(tmp.charCodeAt(tmp.length-1) != 0, "invalid null byte"); ok(tmp.indexOf(String.fromCharCode(0)) == -1, "invalid null byte");
tmp = (new Date()).toTimeString();
ok(tmp.indexOf(String.fromCharCode(0)) == -1, "invalid null byte");
ok(typeof(Math.PI) === "number", "typeof(Math.PI) = " + typeof(Math.PI)); ok(typeof(Math.PI) === "number", "typeof(Math.PI) = " + typeof(Math.PI));
ok(Math.floor(Math.PI*100) === 314, "Math.PI = " + Math.PI); ok(Math.floor(Math.PI*100) === 314, "Math.PI = " + Math.PI);
......
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