Commit eab29100 authored by Xida Chen's avatar Xida Chen Committed by Commit Bot

[Code health] Fix a float-cast-overflow in WheelEvent

The problem is in the constructor of this class, which calls
NegateIfPossible that takes a int32_t. But the callsites
of the NegateIfPossible give doubles. This CL fixes it
by static_cast<int32_t> on the doubles.

Bug: 1102403
Change-Id: I3ba3097ce99e5b955a885c84c66471b3dc7dd589
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2289613Reviewed-by: default avatarDave Tapuska <dtapuska@chromium.org>
Reviewed-by: default avatarMustaq Ahmed <mustaq@chromium.org>
Commit-Queue: Xida Chen <xidachen@chromium.org>
Cr-Commit-Position: refs/heads/master@{#790496}
parent 5564c675
......@@ -46,13 +46,6 @@ unsigned ConvertDeltaMode(const WebMouseWheelEvent& event) {
: WheelEvent::kDomDeltaPixel;
}
// Negate a long value without integer overflow.
int32_t NegateIfPossible(int32_t value) {
if (value == std::numeric_limits<int32_t>::min())
return value;
return -value;
}
MouseEventInit* GetMouseEventInitForWheel(const WebMouseWheelEvent& event,
AbstractView* view) {
MouseEventInit* initializer = MouseEventInit::Create();
......@@ -98,16 +91,16 @@ WheelEvent::WheelEvent(const AtomicString& type,
: MouseEvent(type, initializer),
wheel_delta_(initializer->wheelDeltaX()
? initializer->wheelDeltaX()
: NegateIfPossible(-initializer->deltaX()),
: static_cast<int32_t>(initializer->deltaX()),
initializer->wheelDeltaY()
? initializer->wheelDeltaY()
: NegateIfPossible(-initializer->deltaY())),
: static_cast<int32_t>(initializer->deltaY())),
delta_x_(initializer->deltaX()
? initializer->deltaX()
: NegateIfPossible(initializer->wheelDeltaX())),
: -static_cast<int32_t>(initializer->wheelDeltaX())),
delta_y_(initializer->deltaY()
? initializer->deltaY()
: NegateIfPossible(initializer->wheelDeltaY())),
: -static_cast<int32_t>(initializer->wheelDeltaY())),
delta_z_(initializer->deltaZ()),
delta_mode_(initializer->deltaMode()) {}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment