fix(wlroots): scroll 垂直滚动方向与 win32 保持一致#1269
Merged
MistEO merged 1 commit intoMaaXYZ:mainfrom Apr 14, 2026
Merged
Conversation
Contributor
There was a problem hiding this comment.
Hey - 我发现了 1 个问题
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="source/MaaWlRootsControlUnit/Client/WaylandClient.cpp" line_range="316" />
<code_context>
- const int step_y = dy / 120;
+ // Wayland 的垂直滚动方向与 Maa 对外约定(dy > 0 表示向上滚动)相反,
+ // 这里对 dy 取反以与 Win32 等控制器保持一致行为。
+ const int step_y = -dy / 120;
for (int i = 0; i < abs(step_y); ++i) {
zwlr_virtual_pointer_v1_axis_discrete(
</code_context>
<issue_to_address>
**issue (bug_risk):** 直接对 `dy` 取反在 `dy == INT_MIN` 时可能导致溢出。
当 `dy == INT_MIN` 时,对有符号 `int` 使用 `-dy` 属于未定义行为(UB)。为避免这一点,可以先使用更宽的有符号类型计算 `step_y`,例如:`long long step_y = -static_cast<long long>(dy) / 120;`,然后再在必要时进行截断/转换回 `int`,以在不发生溢出的前提下保持原有行为。
</issue_to_address>帮我变得更有用吧!请在每条评论上点 👍 或 👎,我会根据你的反馈改进后续的评审质量。
Original comment in English
Hey - I've found 1 issue
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="source/MaaWlRootsControlUnit/Client/WaylandClient.cpp" line_range="316" />
<code_context>
- const int step_y = dy / 120;
+ // Wayland 的垂直滚动方向与 Maa 对外约定(dy > 0 表示向上滚动)相反,
+ // 这里对 dy 取反以与 Win32 等控制器保持一致行为。
+ const int step_y = -dy / 120;
for (int i = 0; i < abs(step_y); ++i) {
zwlr_virtual_pointer_v1_axis_discrete(
</code_context>
<issue_to_address>
**issue (bug_risk):** Negating `dy` directly can overflow when `dy == INT_MIN`.
Using `-dy` on a signed `int` is UB when `dy == INT_MIN`. To avoid this, compute `step_y` via a wider signed type, e.g. `long long step_y = -static_cast<long long>(dy) / 120;`, then clamp/cast back to `int` as needed to preserve behavior without overflow.
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
| const int step_y = dy / 120; | ||
| // Wayland 的垂直滚动方向与 Maa 对外约定(dy > 0 表示向上滚动)相反, | ||
| // 这里对 dy 取反以与 Win32 等控制器保持一致行为。 | ||
| const int step_y = -dy / 120; |
Contributor
There was a problem hiding this comment.
issue (bug_risk): 直接对 dy 取反在 dy == INT_MIN 时可能导致溢出。
当 dy == INT_MIN 时,对有符号 int 使用 -dy 属于未定义行为(UB)。为避免这一点,可以先使用更宽的有符号类型计算 step_y,例如:long long step_y = -static_cast<long long>(dy) / 120;,然后再在必要时进行截断/转换回 int,以在不发生溢出的前提下保持原有行为。
Original comment in English
issue (bug_risk): Negating dy directly can overflow when dy == INT_MIN.
Using -dy on a signed int is UB when dy == INT_MIN. To avoid this, compute step_y via a wider signed type, e.g. long long step_y = -static_cast<long long>(dy) / 120;, then clamp/cast back to int as needed to preserve behavior without overflow.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary by Sourcery
错误修复:
Original summary in English
Summary by Sourcery
Bug Fixes: