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:
parent
9d40ecacb5
commit
5fafd82927
Notes:
sideshowbarker
2024-07-17 04:49:48 +09:00
Author: https://github.com/BenWiederhake
Commit: 5fafd82927
Pull-request: https://github.com/SerenityOS/serenity/pull/19029
Reviewed-by: https://github.com/gmta ✅
Reviewed-by: https://github.com/kleinesfilmroellchen ✅
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