mouse_motion_to_scroll: momentum_minus_ may be read before initialization
Details
Hi! While reviewing Karabiner-Elements 16.3.0, I noticed a possible uninitialized read in mouse_motion_to_scroll::counter.
Reviewed commit: 9312593e1a3bf72b94c63c524ebabe2637442e8a. File: src/share/manipulator/manipulators/mouse_motion_to_scroll/counter.hpp.
The source path is:
- momentum_minus_ is declared as an int without an in-class initializer (line 426), and is omitted from the constructor's initializer list (lines 32–45). async_reset() also leaves it unchanged (lines 75–89).
- The timer callback calls process_entries() and then scroll() (lines 64–65). If the recent-entry time window has not elapsed, process_entries() returns early (lines 101–103), before assigning momentum_minus_.
- scroll() can then pass momentum_minus_ by value to reduce() (lines 334–335). Even if total_x_ and total_y_ are still zero, the argument is evaluated before entering reduce().
On September 29, I also compared the latest default-branch commit affecting this file (026f9e91e4a06f30bff1028b556c0317a455eee2). It adds a dispatcher constructor exception guard, but leaves the member initialization and the relevant process_entries()/scroll() logic unchanged.
Would it make sense to initialize momentum_minus_ explicitly alongside the other momentum fields and give it a defined reset value in async_reset(), so that every path into scroll() has valid state?
This is a static source finding. I have not reproduced a crash, visible scrolling malfunction, or sanitizer diagnostic in the running application, and am not attributing any reported scrolling symptoms to this issue.
Thank you!
Source: pqrs-org/Karabiner-Elements