Commit 4d67ffd5 authored by Sebastian Lackner's avatar Sebastian Lackner Committed by Alexandre Julliard

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

parent 79f18d02
......@@ -769,9 +769,10 @@ static HRESULT dateobj_to_date_string(DateInstance *date, jsval_t *r)
BOOL formatAD = TRUE;
WCHAR week[64], month[64];
WCHAR buf[192];
jsstr_t *date_str;
DOUBLE time;
int len, size, year, day;
int year, day;
DWORD lcid_en;
if(isnan(date->time)) {
......@@ -783,46 +784,27 @@ static HRESULT dateobj_to_date_string(DateInstance *date, jsval_t *r)
time = local_time(date->time, date);
if(r) {
WCHAR *ptr;
len = 5;
lcid_en = MAKELCID(MAKELANGID(LANG_ENGLISH,SUBLANG_ENGLISH_US),SORT_DEFAULT);
size = GetLocaleInfoW(lcid_en, week_ids[(int)week_day(time)], week, sizeof(week)/sizeof(*week));
assert(size);
len += size-1;
week[0] = 0;
GetLocaleInfoW(lcid_en, week_ids[(int)week_day(time)], week, sizeof(week)/sizeof(*week));
size = GetLocaleInfoW(lcid_en, month_ids[(int)month_from_time(time)], month, sizeof(month)/sizeof(*month));
assert(size);
len += size-1;
year = year_from_time(time);
if(year<0)
year = -year+1;
do {
year /= 10;
len++;
} while(year);
month[0] = 0;
GetLocaleInfoW(lcid_en, month_ids[(int)month_from_time(time)], month, sizeof(month)/sizeof(*month));
year = year_from_time(time);
if(year<0) {
formatAD = FALSE;
year = -year+1;
len += 5;
}
day = date_from_time(time);
do {
day /= 10;
len++;
} while(day);
day = date_from_time(time);
date_str = jsstr_alloc_buf(len, &ptr);
sprintfW(buf, formatAD ? formatADW : formatBCW, week, month, day, year);
date_str = jsstr_alloc(buf);
if(!date_str)
return E_OUTOFMEMORY;
sprintfW(ptr, formatAD?formatADW:formatBCW, week, month, day, year);
*r = jsval_string(date_str);
}
......
......@@ -2153,6 +2153,8 @@ ok(Date.parse("Tue, 22 Mar 2016 09:57:55 +0400") === Date.parse("Tue, 22 Mar 201
tmp = (new Date()).toLocaleDateString();
ok(tmp.indexOf(String.fromCharCode(0)) == -1, "invalid null byte");
tmp = (new Date(1600, 1, 1, 0, 0, 0, 0)).toLocaleDateString();
ok(tmp.indexOf(String.fromCharCode(0)) == -1, "invalid null byte");
tmp = (new Date()).toLocaleTimeString();
ok(tmp.indexOf(String.fromCharCode(0)) == -1, "invalid null byte");
tmp = (new Date()).toTimeString();
......
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