Bill Medland (medbi01@accpac.com) Correct GetDateFormat handling of uninitialised fields: Only the year, month and day fields matter; the rest may be uninitialised. Index: wine/ole/ole2nls.c =================================================================== RCS file: /home/wine/wine/ole/ole2nls.c,v retrieving revision 1.111 diff -u -r1.111 ole2nls.c --- wine/ole/ole2nls.c 19 Dec 2002 21:11:54 -0000 1.111 +++ wine/ole/ole2nls.c 15 Jan 2003 04:00:19 -0000 @@ -1789,14 +1789,26 @@ /* because this conversion will fix invalid time values */ /* check to see if the time/date is valid */ /* set ERROR_INVALID_PARAMETER and return 0 if invalid */ - if((xtime->wDay > 31) || (xtime->wDayOfWeek > 6) || (xtime->wMonth > 12)) + if((xtime->wDay > 31) || (xtime->wMonth > 12)) { SetLastError(ERROR_INVALID_PARAMETER); return 0; } + /* For all we know the day of week and the time may be absolute + * rubbish. Therefore if we are going to use conversion through + * FileTime we had better use a clean time (and hopefully we won't + * fall over any timezone complications). + * If we go with an alternative method of correcting the day of week + * (e.g. Zeller's congruence) then we won't need to, but we will need + * to check the date. + */ + memset (&t, 0, sizeof(t)); + t.wYear = xtime->wYear; + t.wMonth = xtime->wMonth; + t.wDay = xtime->wDay; /* Silently correct wDayOfWeek by transforming to FileTime and back again */ - res=SystemTimeToFileTime(xtime,&ft); + res=SystemTimeToFileTime(&t,&ft); /* Check year(?)/month and date for range and set ERROR_INVALID_PARAMETER on error */ if(!res) Index: wine/dlls/kernel/tests/locale.c =================================================================== RCS file: /home/wine/wine/dlls/kernel/tests/locale.c,v retrieving revision 1.11 diff -u -r1.11 locale.c --- wine/dlls/kernel/tests/locale.c 2 Jan 2003 17:47:22 -0000 1.11 +++ wine/dlls/kernel/tests/locale.c 15 Jan 2003 04:00:19 -0000 @@ -540,14 +540,16 @@ ok (ret != 0 && error == 0, "GetDateFormatW did not permit null buffer pointer when counting."); /* 1c An incorrect day of week is corrected. */ + /* 1d The incorrect day of week can even be out of range. */ + /* 1e The time doesn't matter */ curtime.wYear = 2002; curtime.wMonth = 10; curtime.wDay = 23; - curtime.wDayOfWeek = 5; /* should be 3 - Wednesday */ - curtime.wHour = 0; - curtime.wMinute = 0; - curtime.wSecond = 0; - curtime.wMilliseconds = 234; + curtime.wDayOfWeek = 45612; /* should be 3 - Wednesday */ + curtime.wHour = 65432; + curtime.wMinute = 34512; + curtime.wSecond = 65535; + curtime.wMilliseconds = 12345; MultiByteToWideChar (CP_ACP, 0, "dddd d MMMM yyyy", -1, format, COUNTOF(format)); ret = GetDateFormatW (lcid, 0, &curtime, format, buffer, COUNTOF(buffer)); error = ret ? 0 : GetLastError(); -- Bill Medland ACCPAC International, Inc. medbi01@accpac.com Corporate: www.accpac.com Hosted Services: www.accpaconline.com