From 5c5538685e59012727758ebc8228979ef7706700 Mon Sep 17 00:00:00 2001 From: sfan5 Date: Thu, 31 Oct 2024 19:24:43 +0100 Subject: [PATCH] Don't memset SEvent directly (#15359) Fixes a compiler warning by manually zeroing the tag and the largest union member instead --- irr/include/IEventReceiver.h | 13 +++++++------ irr/src/CIrrDeviceLinux.cpp | 1 - src/gui/guiTable.cpp | 1 - 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/irr/include/IEventReceiver.h b/irr/include/IEventReceiver.h index 7fb9e5f4e..332b23158 100644 --- a/irr/include/IEventReceiver.h +++ b/irr/include/IEventReceiver.h @@ -18,7 +18,7 @@ enum EEVENT_TYPE to mouse or keyboard events. When a GUI element receives an event it will either process it and return true, or pass the event to its parent. If an event is not absorbed before it reaches the root element then it will then be passed to the user receiver. */ - EET_GUI_EVENT = 0, + EET_GUI_EVENT = 1, //! A mouse input event. /** Mouse events are created by the device and passed to IrrlichtDevice::postEventFromUser @@ -332,6 +332,9 @@ struct SEvent //! True if ctrl was also pressed bool Control : 1; + //! Is this a simulated mouse event generated by the engine itself? + bool Simulated : 1; + //! A bitmap of button states. You can use isButtonPressed() to determine //! if a button is pressed or not. u32 ButtonStates; @@ -347,9 +350,6 @@ struct SEvent //! Type of mouse event EMOUSE_INPUT_EVENT Event; - - //! Is this a simulated mouse event generated by Minetest itself? - bool Simulated; }; //! Any kind of keyboard event. @@ -543,8 +543,9 @@ struct SEvent }; SEvent() { - // would be left uninitialized in many places otherwise - MouseInput.Simulated = false; + EventType = static_cast(0); + // zero the biggest union member we have, which clears all others too + memset(&JoystickEvent, 0, sizeof(JoystickEvent)); } }; diff --git a/irr/src/CIrrDeviceLinux.cpp b/irr/src/CIrrDeviceLinux.cpp index 8538c05d1..f20be36f7 100644 --- a/irr/src/CIrrDeviceLinux.cpp +++ b/irr/src/CIrrDeviceLinux.cpp @@ -1581,7 +1581,6 @@ bool CIrrDeviceLinux::activateJoysticks(core::array &joystickInfo fcntl(info.fd, F_SETFL, O_NONBLOCK); #endif - (void)memset(&info.persistentData, 0, sizeof(info.persistentData)); info.persistentData.EventType = irr::EET_JOYSTICK_INPUT_EVENT; info.persistentData.JoystickEvent.Joystick = ActiveJoysticks.size(); diff --git a/src/gui/guiTable.cpp b/src/gui/guiTable.cpp index 6c1ea91b2..0c10a2b64 100644 --- a/src/gui/guiTable.cpp +++ b/src/gui/guiTable.cpp @@ -1107,7 +1107,6 @@ void GUITable::sendTableEvent(s32 column, bool doubleclick) m_sel_doubleclick = doubleclick; if (Parent) { SEvent e; - memset(&e, 0, sizeof e); e.EventType = EET_GUI_EVENT; e.GUIEvent.Caller = this; e.GUIEvent.Element = 0;