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:
Kelsi 2026-03-30 15:37:38 -07:00
parent fe7912b5fa
commit af604cc442
2 changed files with 7 additions and 1 deletions

View file

@ -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;
}