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,
':','%','0','2','d',' ','U','T','C',0 };
DateInstance *date;
jsstr_t *date_str;
WCHAR buf[32];
DOUBLE time;
WCHAR sign;
int offset;
......@@ -868,12 +869,6 @@ static HRESULT Date_toTimeString(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags,
time = local_time(date->time, date);
if(r) {
WCHAR *ptr;
date_str = jsstr_alloc_buf(17, &ptr);
if(!date_str)
return E_OUTOFMEMORY;
offset = date->bias +
daylight_saving_ta(time, date);
......@@ -884,13 +879,17 @@ static HRESULT Date_toTimeString(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags,
else sign = '-';
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),
sign, offset/60, offset%60);
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));
date_str = jsstr_alloc(buf);
if(!date_str)
return E_OUTOFMEMORY;
*r = jsval_string(date_str);
}
return S_OK;
......
......@@ -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"));
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();
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(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