ref: 2be292a66210d3d2a1376e8eb1f1075c0d01eb53
parent: 2f26be8a383693a92fe4f47e599c47f63920b9d6
author: Jonathan Dowland <[email protected]>
date: Tue Jul 5 14:23:59 EDT 2016
make two variables static The event_t structs in the mouse button and wheel handling routines have their address passed outside the scope of those routines, which is undefined behaviour. Mark them as static to address this. This makes them singletons, meaning no more than one of each type of event per button/axis can occur in a single tic, but that seems to be true anyway. I_ReadMouse and I_HandleKeyboardEvent also have this problem but I am less confident that applying static is sufficient to fix them. Mark them with XXX comments to make sure we don't forget.
--- a/src/i_input.c
+++ b/src/i_input.c
@@ -242,6 +242,8 @@
void I_HandleKeyboardEvent(SDL_Event *sdlevent)
{
+ // XXX: passing pointers to event for access after this function
+ // has terminated is undefined behaviour
event_t event;
switch (sdlevent->type)
@@ -305,7 +307,7 @@
static void UpdateMouseButtonState(unsigned int button, boolean on)
{
- event_t event;
+ static event_t event;
if (button < SDL_BUTTON_LEFT || button > MAX_MOUSE_BUTTONS)
{
@@ -360,7 +362,7 @@
// SDL2 distinguishes button events from mouse wheel events.
// We want to treat the mouse wheel as two buttons, as per
// SDL1
- event_t up, down;
+ static event_t up, down;
int button;
if (wheel->y <= 0)
@@ -450,6 +452,8 @@
ev.data3 = 0;
}
+ // XXX: undefined behaviour since event is scoped to
+ // this function
D_PostEvent(&ev);
}
}