Branch: refs/heads/main
Home: https://github.com/WebKit/WebKit
Commit: c9f0d5b44c9675990e91018b11f68d1c6f503900
https://github.com/WebKit/WebKit/commit/c9f0d5b44c9675990e91018b11f68d1c6f503900
Author: Ahmad Saleem <[email protected]>
Date: 2026-07-20 (Mon, 20 Jul 2026)
Changed paths:
M Source/WTF/wtf/SaturatingArithmetic.h
M Tools/TestWebKitAPI/Tests/WTF/SaturatingArithmeticOperations.cpp
Log Message:
-----------
WTF::saturatingSum variadic overload truncates 3+ argument sums to uint32_t
https://bugs.webkit.org/show_bug.cgi?id=319524
rdar://182346464
Reviewed by Chris Dumez.
The variadic (3+ argument) overload of saturatingSum hardcoded its return
type as uint32_t, even though it delegates to the two-argument overloads,
which correctly return the operand type. As a result, a saturating sum of
three or more arguments of a type wider than 32 bits (e.g. uint64_t) was
computed correctly and then silently narrowed to uint32_t on return.
No in-tree caller currently trips this (the only variadic call site sums
uint32_t values), so this is a latent correctness bug rather than an
active regression, but it is a trap waiting for the next wider-type caller.
Fix the return type to follow the operand type (IntegralType) instead of
the hardcoded uint32_t, and add API test coverage for the wide-type,
3+ argument case, including a static_assert pinning the deduced return
type to the operand type.
Test: Tools/TestWebKitAPI/Tests/WTF/SaturatingArithmeticOperations.cpp
* Source/WTF/wtf/SaturatingArithmetic.h:
(WTF::saturatingSum):
* Tools/TestWebKitAPI/Tests/WTF/SaturatingArithmeticOperations.cpp:
(TestWebKitAPI::TEST(WTF, SaturatingArithmeticAddition)):
Canonical link: https://commits.webkit.org/317530@main
To unsubscribe from these emails, change your notification settings at
https://github.com/WebKit/WebKit/settings/notifications