mirror of
https://github.com/Kelsidavis/WoWee.git
synced 2026-04-07 21:53:51 +00:00
fix: UB in mouse button polling, null deref in BigNum formatting
- input: fix undefined behavior in SDL mouse button loop — SDL_BUTTON(0) computes (1 << -1) which is UB. Start loop at 1 since SDL button indices are 1-based (SDL_BUTTON_LEFT=1, RIGHT=3, MIDDLE=2) - big_num: guard BN_bn2hex/BN_bn2dec against nullptr return on OpenSSL allocation failure — previously constructed std::string from nullptr which is undefined behavior
This commit is contained in:
parent
fe7912b5fa
commit
af604cc442
2 changed files with 7 additions and 1 deletions
|
|
@ -25,7 +25,10 @@ void Input::update() {
|
|||
Uint32 mouseState = SDL_GetMouseState(&mouseX, &mouseY);
|
||||
mousePosition = glm::vec2(static_cast<float>(mouseX), static_cast<float>(mouseY));
|
||||
|
||||
for (int i = 0; i < NUM_MOUSE_BUTTONS; ++i) {
|
||||
// SDL_BUTTON(x) is defined as (1 << (x-1)), so button indices are 1-based.
|
||||
// SDL_BUTTON(0) is undefined behavior (negative shift). Start at 1.
|
||||
currentMouseState[0] = false;
|
||||
for (int i = 1; i < NUM_MOUSE_BUTTONS; ++i) {
|
||||
currentMouseState[i] = (mouseState & SDL_BUTTON(i)) != 0;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue