kernel: split RtlTimeFieldsToTime range check into their own if statements for clear reading

Plus fixed a bug for leap year's day range
This commit is contained in:
RadWolfie 2024-01-05 01:15:15 -06:00
parent 06c28a847e
commit bf6193202a
1 changed files with 22 additions and 12 deletions

View File

@ -1622,19 +1622,29 @@ XBSYSAPI EXPORTNUM(304) xbox::boolean_xt NTAPI xbox::RtlTimeFieldsToTime
int month, year, cleaps, day;
/* FIXME: normalize the TIME_FIELDS structure here */
/* No, native just returns 0 (error) if the fields are not */
if (TimeFields->Millisecond < 0 || TimeFields->Millisecond > 999 ||
TimeFields->Second < 0 || TimeFields->Second > 59 ||
TimeFields->Minute < 0 || TimeFields->Minute > 59 ||
TimeFields->Hour < 0 || TimeFields->Hour > 23 ||
TimeFields->Month < 1 || TimeFields->Month > 12 ||
TimeFields->Day < 1 ||
TimeFields->Day > MonthLengths
[TimeFields->Month == 2 || IsLeapYear(TimeFields->Year)]
[TimeFields->Month - 1] ||
TimeFields->Year < 1601)
/* Verify each TimeFields' variables are within range */
if (TimeFields->Millisecond < 0 || TimeFields->Millisecond > 999) {
return FALSE;
}
if (TimeFields->Second < 0 || TimeFields->Second > 59) {
return FALSE;
}
if (TimeFields->Minute < 0 || TimeFields->Minute > 59) {
return FALSE;
}
if (TimeFields->Hour < 0 || TimeFields->Hour > 23) {
return FALSE;
}
if (TimeFields->Month < 1 || TimeFields->Month > 12) {
return FALSE;
}
if (TimeFields->Day < 1 ||
TimeFields->Day > MonthLengths[IsLeapYear(TimeFields->Year)][TimeFields->Month - 1]) {
return FALSE;
}
if (TimeFields->Year < 1601) {
return FALSE;
}
/* now calculate a day count from the date
* First start counting years from March. This way the leap days