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

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-08 23:54:54 +02:00 committed by Alexandre Julliard
parent 1c3e0dd3d5
commit fd07a15727
2 changed files with 11 additions and 10 deletions

View File

@ -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;

View File

@ -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);