comctl32: Fix invalid date/time check in MCM_SETRANGE: ignore time and fail on bad date.

This commit is contained in:
Vitaliy Margolen 2006-02-14 17:12:45 +01:00 committed by Alexandre Julliard
parent 8aee2f2951
commit bc2b9e3feb
2 changed files with 36 additions and 25 deletions

View File

@ -160,14 +160,10 @@ int MONTHCAL_MonthLength(int month, int year)
/* make sure that time is valid */
static int MONTHCAL_ValidateTime(SYSTEMTIME time)
{
if(time.wMonth > 12) return FALSE;
if(time.wMonth < 1 || time.wMonth > 12 ) return FALSE;
if(time.wDayOfWeek > 6) return FALSE;
if(time.wDay > MONTHCAL_MonthLength(time.wMonth, time.wYear))
return FALSE;
if(time.wHour > 23) return FALSE;
if(time.wMinute > 59) return FALSE;
if(time.wSecond > 59) return FALSE;
if(time.wMilliseconds > 999) return FALSE;
return TRUE;
}
@ -943,29 +939,25 @@ MONTHCAL_GetMaxTodayWidth(MONTHCAL_INFO *infoPtr)
static LRESULT
MONTHCAL_SetRange(MONTHCAL_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
{
SYSTEMTIME *lprgSysTimeArray=(SYSTEMTIME *)lParam;
int prev;
SYSTEMTIME *lprgSysTimeArray=(SYSTEMTIME *)lParam;
int prev;
TRACE("%x %lx\n", wParam, lParam);
TRACE("%x %lx\n", wParam, lParam);
if(wParam & GDTR_MAX) {
if(MONTHCAL_ValidateTime(lprgSysTimeArray[1])){
MONTHCAL_CopyTime(&lprgSysTimeArray[1], &infoPtr->maxDate);
infoPtr->rangeValid|=GDTR_MAX;
} else {
GetSystemTime(&infoPtr->todaysDate);
MONTHCAL_CopyTime(&infoPtr->todaysDate, &infoPtr->maxDate);
if ((wParam & GDTR_MIN && !MONTHCAL_ValidateTime(lprgSysTimeArray[0])) ||
(wParam & GDTR_MAX && !MONTHCAL_ValidateTime(lprgSysTimeArray[1])))
return FALSE;
if (wParam & GDTR_MIN)
{
MONTHCAL_CopyTime(&lprgSysTimeArray[0], &infoPtr->minDate);
infoPtr->rangeValid |= GDTR_MIN;
}
}
if(wParam & GDTR_MIN) {
if(MONTHCAL_ValidateTime(lprgSysTimeArray[0])) {
MONTHCAL_CopyTime(&lprgSysTimeArray[0], &infoPtr->minDate);
infoPtr->rangeValid|=GDTR_MIN;
} else {
GetSystemTime(&infoPtr->todaysDate);
MONTHCAL_CopyTime(&infoPtr->todaysDate, &infoPtr->minDate);
if (wParam & GDTR_MAX)
{
MONTHCAL_CopyTime(&lprgSysTimeArray[1], &infoPtr->maxDate);
infoPtr->rangeValid |= GDTR_MAX;
}
}
prev = infoPtr->monthRange;
infoPtr->monthRange = infoPtr->maxDate.wMonth - infoPtr->minDate.wMonth;

View File

@ -31,13 +31,32 @@
void test_monthcal(void)
{
HWND hwnd;
SYSTEMTIME st[2];
SYSTEMTIME st[2], st1[2];
INITCOMMONCONTROLSEX ic = {sizeof(INITCOMMONCONTROLSEX), ICC_DATE_CLASSES};
InitCommonControlsEx(&ic);
hwnd = CreateWindowA(MONTHCAL_CLASSA, "MonthCal", WS_POPUP | WS_VISIBLE, CW_USEDEFAULT,
0, 300, 300, 0, 0, NULL, NULL);
ok(hwnd != NULL, "Failed to create MonthCal\n");
GetSystemTime(&st[0]);
st[1] = st[0];
/* Invalid date/time */
st[0].wYear = 2000;
/* Time should not matter */
st[1].wHour = st[1].wMinute = st[1].wSecond = 70;
ok(SendMessage(hwnd, MCM_SETRANGE, GDTR_MAX, (LPARAM)st), "Failed to set MAX limit\n");
ok(SendMessage(hwnd, MCM_GETRANGE, 0, (LPARAM)st1) == GDTR_MAX, "No limits should be set\n");
ok(st1[0].wYear != 2000, "Lover limit changed\n");
st[1].wMonth = 0;
ok(!SendMessage(hwnd, MCM_SETRANGE, GDTR_MIN | GDTR_MAX, (LPARAM)st), "Should have failed to set limits\n");
ok(SendMessage(hwnd, MCM_GETRANGE, 0, (LPARAM)st1) == GDTR_MAX, "No limits should be set\n");
ok(st1[0].wYear != 2000, "Lover limit changed\n");
ok(!SendMessage(hwnd, MCM_SETRANGE, GDTR_MAX, (LPARAM)st), "Should have failed to set MAX limit\n");
ok(SendMessage(hwnd, MCM_GETRANGE, 0, (LPARAM)st1) == GDTR_MAX, "No limits should be set\n");
ok(st1[0].wYear != 2000, "Lover limit changed\n");
GetSystemTime(&st[0]);
st[0].wMonth = 5;
st[1] = st[0];