mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-08-17 07:50:04 +00:00
AK: Avoid overflow when passing i64 minimum value to vformat()
This commit is contained in:
parent
2ea45f4881
commit
f10db48bab
Notes:
sideshowbarker
2024-07-17 04:21:32 +09:00
Author: https://github.com/tcl3
Commit: f10db48bab
Pull-request: https://github.com/SerenityOS/serenity/pull/21384
2 changed files with 9 additions and 2 deletions
|
@ -363,9 +363,14 @@ ErrorOr<void> FormatBuilder::put_i64(
|
|||
SignMode sign_mode)
|
||||
{
|
||||
auto const is_negative = value < 0;
|
||||
value = is_negative ? -value : value;
|
||||
u64 positive_value;
|
||||
if (value == NumericLimits<i64>::min()) {
|
||||
positive_value = static_cast<u64>(NumericLimits<i64>::max()) + 1;
|
||||
} else {
|
||||
positive_value = is_negative ? -value : value;
|
||||
}
|
||||
|
||||
TRY(put_u64(static_cast<u64>(value), base, prefix, upper_case, zero_pad, use_separator, align, min_width, fill, sign_mode, is_negative));
|
||||
TRY(put_u64(positive_value, base, prefix, upper_case, zero_pad, use_separator, align, min_width, fill, sign_mode, is_negative));
|
||||
return {};
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue