mirror of
https://github.com/zebrajr/ladybird.git
synced 2026-01-15 12:15:15 +00:00
AK: Use NumericLimits instead of hardcoded limits in Duration methods
Running test-web via Windows clang-cl reported the following UBSAN error: runtime error: negation of -9223372036854775808 cannot be represented in type 'long long'; cast to an unsigned type to negate this value to itself.
This commit is contained in:
committed by
Alexander Kalenik
parent
2bbb5a455f
commit
dffb971436
12
AK/Time.cpp
12
AK/Time.cpp
@@ -115,7 +115,7 @@ i64 Duration::to_truncated_milliseconds() const
|
||||
}
|
||||
if (!milliseconds.has_overflow())
|
||||
return milliseconds.value();
|
||||
return m_seconds < 0 ? -0x8000'0000'0000'0000LL : 0x7fff'ffff'ffff'ffffLL;
|
||||
return m_seconds < 0 ? NumericLimits<i64>::min() : NumericLimits<i64>::max();
|
||||
}
|
||||
|
||||
i64 Duration::to_truncated_microseconds() const
|
||||
@@ -134,7 +134,7 @@ i64 Duration::to_truncated_microseconds() const
|
||||
}
|
||||
if (!microseconds.has_overflow())
|
||||
return microseconds.value();
|
||||
return m_seconds < 0 ? -0x8000'0000'0000'0000LL : 0x7fff'ffff'ffff'ffffLL;
|
||||
return m_seconds < 0 ? NumericLimits<i64>::min() : NumericLimits<i64>::max();
|
||||
}
|
||||
|
||||
i64 Duration::to_seconds() const
|
||||
@@ -143,7 +143,7 @@ i64 Duration::to_seconds() const
|
||||
if (m_seconds >= 0 && m_nanoseconds) {
|
||||
Checked<i64> seconds(m_seconds);
|
||||
seconds++;
|
||||
return seconds.has_overflow() ? 0x7fff'ffff'ffff'ffffLL : seconds.value();
|
||||
return seconds.has_overflow() ? NumericLimits<i64>::max() : seconds.value();
|
||||
}
|
||||
return m_seconds;
|
||||
}
|
||||
@@ -168,7 +168,7 @@ i64 Duration::to_milliseconds() const
|
||||
}
|
||||
if (!milliseconds.has_overflow())
|
||||
return milliseconds.value();
|
||||
return m_seconds < 0 ? -0x8000'0000'0000'0000LL : 0x7fff'ffff'ffff'ffffLL;
|
||||
return m_seconds < 0 ? NumericLimits<i64>::min() : NumericLimits<i64>::max();
|
||||
}
|
||||
|
||||
i64 Duration::to_microseconds() const
|
||||
@@ -185,7 +185,7 @@ i64 Duration::to_microseconds() const
|
||||
}
|
||||
if (!microseconds.has_overflow())
|
||||
return microseconds.value();
|
||||
return m_seconds < 0 ? -0x8000'0000'0000'0000LL : 0x7fff'ffff'ffff'ffffLL;
|
||||
return m_seconds < 0 ? NumericLimits<i64>::min() : NumericLimits<i64>::max();
|
||||
}
|
||||
|
||||
i64 Duration::to_nanoseconds() const
|
||||
@@ -200,7 +200,7 @@ i64 Duration::to_nanoseconds() const
|
||||
}
|
||||
if (!nanoseconds.has_overflow())
|
||||
return nanoseconds.value();
|
||||
return m_seconds < 0 ? -0x8000'0000'0000'0000LL : 0x7fff'ffff'ffff'ffffLL;
|
||||
return m_seconds < 0 ? NumericLimits<i64>::min() : NumericLimits<i64>::max();
|
||||
}
|
||||
|
||||
timespec Duration::to_timespec() const
|
||||
|
||||
Reference in New Issue
Block a user