diff --git a/AK/Checked.h b/AK/Checked.h index 8d5321d5b6..0a92152162 100644 --- a/AK/Checked.h +++ b/AK/Checked.h @@ -183,6 +183,13 @@ public: constexpr void div(T other) { + if constexpr (IsSigned) { + // Ensure that the resulting value won't be out of range, this can only happen when dividing by -1. + if (other == -1 && m_value == NumericLimits::min()) { + m_overflow = true; + return; + } + } m_value /= other; }