1
0
Fork 0
mirror of https://github.com/LadybirdBrowser/ladybird.git synced 2025-06-09 09:34:57 +09: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:
Ben Wiederhake 2023-05-24 22:19:17 +02:00 committed by Jelle Raaijmakers
parent 9d40ecacb5
commit 5fafd82927
Notes: sideshowbarker 2024-07-17 04:49:48 +09:00
3 changed files with 13 additions and 37 deletions

View file

@ -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;