From 8ad043fe5e0f05bbe654a93a14ecc8269473379b Mon Sep 17 00:00:00 2001 From: Timothy Flynn Date: Sat, 15 Jan 2022 17:36:25 -0500 Subject: [PATCH] LibJS: Ensure final computation in DayFromYear is performed on a double When we multiple by 365, ensure the result is a double (not an i32) to prevent overflow. --- Userland/Libraries/LibJS/Runtime/Date.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Userland/Libraries/LibJS/Runtime/Date.cpp b/Userland/Libraries/LibJS/Runtime/Date.cpp index 96706e5fb4d..152870d0f67 100644 --- a/Userland/Libraries/LibJS/Runtime/Date.cpp +++ b/Userland/Libraries/LibJS/Runtime/Date.cpp @@ -133,7 +133,7 @@ u16 days_in_year(i32 y) double day_from_year(i32 y) { // 𝔽(365 × (ℝ(y) - 1970) + floor((ℝ(y) - 1969) / 4) - floor((ℝ(y) - 1901) / 100) + floor((ℝ(y) - 1601) / 400)) - return 365 * (y - 1970) + floor((y - 1969) / 4.0) - floor((y - 1901) / 100.0) + floor((y - 1601) / 400.0); + return 365.0 * (y - 1970) + floor((y - 1969) / 4.0) - floor((y - 1901) / 100.0) + floor((y - 1601) / 400.0); } // TimeFromYear(y), https://tc39.es/ecma262/#eqn-TimeFromYear