mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 14:27:35 +00:00
AK+Everywhere: Don't crash on invalid months
Sadly, we don't have proper error propagation here. However, crashing the Kernel just because a CDROM contains an invalid month seems like a bad idea.
This commit is contained in:
parent
9d40ecacb5
commit
5fafd82927
3 changed files with 13 additions and 37 deletions
|
@ -54,7 +54,10 @@ unsigned day_of_week(int year, unsigned month, int day);
|
|||
// can be negative.
|
||||
constexpr int day_of_year(int year, unsigned month, int day)
|
||||
{
|
||||
VERIFY(month >= 1 && month <= 12);
|
||||
if (is_constant_evaluated())
|
||||
VERIFY(month >= 1 && month <= 12); // Note that this prevents bad constexpr months, but never actually prints anything.
|
||||
else if (!(month >= 1 && month <= 12))
|
||||
return 0;
|
||||
|
||||
constexpr Array seek_table = { 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334 };
|
||||
int day_of_year = seek_table[month - 1] + day - 1;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue