From bb1a465e5051f892a6291ee0c98586ac81652f1b Mon Sep 17 00:00:00 2001 From: Chris Thrasher Date: Tue, 17 Oct 2023 13:48:03 -0500 Subject: [PATCH] Add `cppcoreguidelines-pro-type-member-init` clang-tidy check This marks another good step towards systematically rooting out undefined behavior in the form of reading uninitialized memory. --- .clang-tidy | 1 - examples/vulkan/Vulkan.cpp | 2 +- include/SFML/Audio/SoundFileFactory.inl | 8 ++----- include/SFML/Audio/SoundSource.hpp | 2 +- include/SFML/Graphics/Glsl.inl | 2 +- include/SFML/Network/Http.hpp | 12 +++++----- include/SFML/Window/Event.hpp | 6 ++++- src/SFML/Graphics/TextureSaver.hpp | 2 +- src/SFML/Network/Http.cpp | 4 +--- src/SFML/Network/IpAddress.cpp | 4 ++-- src/SFML/Network/SocketSelector.cpp | 2 +- src/SFML/Network/TcpListener.cpp | 4 ++-- src/SFML/Network/TcpSocket.cpp | 8 +++---- src/SFML/Network/UdpSocket.cpp | 2 +- src/SFML/System/Android/Activity.hpp | 24 +++++++++---------- src/SFML/System/Android/SuspendAwareClock.cpp | 2 +- src/SFML/System/Unix/SleepImpl.cpp | 2 +- src/SFML/Window/DRM/InputImpl.cpp | 4 ++-- src/SFML/Window/DRM/WindowImplDRM.cpp | 6 ++--- src/SFML/Window/SensorManager.hpp | 8 +++---- src/SFML/Window/Unix/JoystickImpl.cpp | 4 ++-- src/SFML/Window/Win32/JoystickImpl.cpp | 3 +-- src/SFML/Window/Win32/JoystickImpl.hpp | 14 +++++------ src/SFML/Window/WindowImpl.hpp | 2 +- src/SFML/Window/iOS/WindowImplUIKit.hpp | 10 ++++---- src/SFML/Window/macOS/HIDInputManager.hpp | 4 ++-- src/SFML/Window/macOS/JoystickImpl.hpp | 4 ++-- .../Window/macOS/SFKeyboardModifiersHelper.mm | 2 +- test/Graphics/Image.test.cpp | 2 +- 29 files changed, 73 insertions(+), 77 deletions(-) diff --git a/.clang-tidy b/.clang-tidy index 7b4fbf9bd..5a9532952 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -42,7 +42,6 @@ Checks: > -cppcoreguidelines-pro-bounds-constant-array-index, -cppcoreguidelines-pro-bounds-pointer-arithmetic, -cppcoreguidelines-pro-type-const-cast, - -cppcoreguidelines-pro-type-member-init, -cppcoreguidelines-pro-type-reinterpret-cast, -cppcoreguidelines-pro-type-static-cast-downcast, -cppcoreguidelines-pro-type-union-access, diff --git a/examples/vulkan/Vulkan.cpp b/examples/vulkan/Vulkan.cpp index e73dcb591..225e3f5f5 100644 --- a/examples/vulkan/Vulkan.cpp +++ b/examples/vulkan/Vulkan.cpp @@ -2595,7 +2595,7 @@ private: VkImageView depthImageView{}; VkShaderModule vertexShaderModule{}; VkShaderModule fragmentShaderModule{}; - VkPipelineShaderStageCreateInfo shaderStages[2]; + VkPipelineShaderStageCreateInfo shaderStages[2]{}; VkDescriptorSetLayout descriptorSetLayout{}; VkPipelineLayout pipelineLayout{}; VkRenderPass renderPass{}; diff --git a/include/SFML/Audio/SoundFileFactory.inl b/include/SFML/Audio/SoundFileFactory.inl index 7d20a29e4..f2f134ae0 100644 --- a/include/SFML/Audio/SoundFileFactory.inl +++ b/include/SFML/Audio/SoundFileFactory.inl @@ -51,9 +51,7 @@ void SoundFileFactory::registerReader() unregisterReader(); // Create a new factory with the functions provided by the class - ReaderFactory factory; - factory.check = &T::check; - factory.create = &priv::createReader; + const ReaderFactory factory{&T::check, &priv::createReader}; // Add it s_readers.push_back(factory); @@ -82,9 +80,7 @@ void SoundFileFactory::registerWriter() unregisterWriter(); // Create a new factory with the functions provided by the class - WriterFactory factory; - factory.check = &T::check; - factory.create = &priv::createWriter; + const WriterFactory factory{&T::check, &priv::createWriter}; // Add it s_writers.push_back(factory); diff --git a/include/SFML/Audio/SoundSource.hpp b/include/SFML/Audio/SoundSource.hpp index f75feb643..32c9d8941 100644 --- a/include/SFML/Audio/SoundSource.hpp +++ b/include/SFML/Audio/SoundSource.hpp @@ -290,7 +290,7 @@ protected: //////////////////////////////////////////////////////////// // Member data //////////////////////////////////////////////////////////// - unsigned int m_source; //!< OpenAL source identifier + unsigned int m_source{}; //!< OpenAL source identifier }; // NOLINTEND(readability-make-member-function-const) diff --git a/include/SFML/Graphics/Glsl.inl b/include/SFML/Graphics/Glsl.inl index 97f446b7a..6097e806b 100644 --- a/include/SFML/Graphics/Glsl.inl +++ b/include/SFML/Graphics/Glsl.inl @@ -81,7 +81,7 @@ struct Matrix copyMatrix(transform, *this); } - float array[Columns * Rows]; //!< Array holding matrix data + float array[Columns * Rows]{}; //!< Array holding matrix data }; //////////////////////////////////////////////////////////// diff --git a/include/SFML/Network/Http.hpp b/include/SFML/Network/Http.hpp index df22fe988..bcbad7a3e 100644 --- a/include/SFML/Network/Http.hpp +++ b/include/SFML/Network/Http.hpp @@ -177,12 +177,12 @@ public: //////////////////////////////////////////////////////////// // Member data //////////////////////////////////////////////////////////// - FieldTable m_fields; //!< Fields of the header associated to their value - Method m_method; //!< Method to use for the request - std::string m_uri; //!< Target URI of the request - unsigned int m_majorVersion; //!< Major HTTP version - unsigned int m_minorVersion; //!< Minor HTTP version - std::string m_body; //!< Body of the request + FieldTable m_fields; //!< Fields of the header associated to their value + Method m_method; //!< Method to use for the request + std::string m_uri; //!< Target URI of the request + unsigned int m_majorVersion{1}; //!< Major HTTP version + unsigned int m_minorVersion{}; //!< Minor HTTP version + std::string m_body; //!< Body of the request }; //////////////////////////////////////////////////////////// diff --git a/include/SFML/Window/Event.hpp b/include/SFML/Window/Event.hpp index a88946ead..e2728abd7 100644 --- a/include/SFML/Window/Event.hpp +++ b/include/SFML/Window/Event.hpp @@ -35,6 +35,8 @@ #include +// NOLINTBEGIN(cppcoreguidelines-pro-type-member-init) + namespace sf { //////////////////////////////////////////////////////////// @@ -200,7 +202,7 @@ struct Event //////////////////////////////////////////////////////////// // Member data //////////////////////////////////////////////////////////// - EventType type; //!< Type of the event + EventType type{}; //!< Type of the event union { @@ -220,6 +222,8 @@ struct Event } // namespace sf +// NOLINTEND(cppcoreguidelines-pro-type-member-init) + //////////////////////////////////////////////////////////// /// \class sf::Event diff --git a/src/SFML/Graphics/TextureSaver.hpp b/src/SFML/Graphics/TextureSaver.hpp index b930fcf9c..000311a2a 100644 --- a/src/SFML/Graphics/TextureSaver.hpp +++ b/src/SFML/Graphics/TextureSaver.hpp @@ -59,7 +59,7 @@ private: //////////////////////////////////////////////////////////// // Member data //////////////////////////////////////////////////////////// - GLint m_textureBinding; //!< Texture binding to restore + GLint m_textureBinding{}; //!< Texture binding to restore }; } // namespace sf::priv diff --git a/src/SFML/Network/Http.cpp b/src/SFML/Network/Http.cpp index 3e9e705de..f4ad8fadb 100644 --- a/src/SFML/Network/Http.cpp +++ b/src/SFML/Network/Http.cpp @@ -39,11 +39,9 @@ namespace sf { //////////////////////////////////////////////////////////// -Http::Request::Request(const std::string& uri, Method method, const std::string& body) +Http::Request::Request(const std::string& uri, Method method, const std::string& body) : m_method(method) { - setMethod(method); setUri(uri); - setHttpVersion(1, 0); setBody(body); } diff --git a/src/SFML/Network/IpAddress.cpp b/src/SFML/Network/IpAddress.cpp index ea092d2c7..5d1c96050 100644 --- a/src/SFML/Network/IpAddress.cpp +++ b/src/SFML/Network/IpAddress.cpp @@ -73,7 +73,7 @@ std::optional IpAddress::resolve(std::string_view address) addrinfo* result = nullptr; if (getaddrinfo(address.data(), nullptr, &hints, &result) == 0 && result != nullptr) { - sockaddr_in sin; + sockaddr_in sin{}; std::memcpy(&sin, result->ai_addr, sizeof(*result->ai_addr)); const std::uint32_t ip = sin.sin_addr.s_addr; @@ -102,7 +102,7 @@ IpAddress::IpAddress(std::uint32_t address) : m_address(htonl(address)) //////////////////////////////////////////////////////////// std::string IpAddress::toString() const { - in_addr address; + in_addr address{}; address.s_addr = m_address; return inet_ntoa(address); diff --git a/src/SFML/Network/SocketSelector.cpp b/src/SFML/Network/SocketSelector.cpp index 6f5fefbf2..0b9eaa68b 100644 --- a/src/SFML/Network/SocketSelector.cpp +++ b/src/SFML/Network/SocketSelector.cpp @@ -171,7 +171,7 @@ void SocketSelector::clear() bool SocketSelector::wait(Time timeout) { // Setup the timeout - timeval time; + timeval time{}; time.tv_sec = static_cast(timeout.asMicroseconds() / 1000000); time.tv_usec = static_cast(timeout.asMicroseconds() % 1000000); diff --git a/src/SFML/Network/TcpListener.cpp b/src/SFML/Network/TcpListener.cpp index 3a5e08bd7..bc84d5a19 100644 --- a/src/SFML/Network/TcpListener.cpp +++ b/src/SFML/Network/TcpListener.cpp @@ -48,7 +48,7 @@ unsigned short TcpListener::getLocalPort() const if (getNativeHandle() != priv::SocketImpl::invalidSocket()) { // Retrieve information about the local end of the socket - sockaddr_in address; + sockaddr_in address{}; priv::SocketImpl::AddrLength size = sizeof(address); if (getsockname(getNativeHandle(), reinterpret_cast(&address), &size) != -1) { @@ -114,7 +114,7 @@ Socket::Status TcpListener::accept(TcpSocket& socket) } // Accept a new connection - sockaddr_in address; + sockaddr_in address{}; priv::SocketImpl::AddrLength length = sizeof(address); const SocketHandle remote = ::accept(getNativeHandle(), reinterpret_cast(&address), &length); diff --git a/src/SFML/Network/TcpSocket.cpp b/src/SFML/Network/TcpSocket.cpp index cc8c03df0..11fe1c61f 100644 --- a/src/SFML/Network/TcpSocket.cpp +++ b/src/SFML/Network/TcpSocket.cpp @@ -66,7 +66,7 @@ unsigned short TcpSocket::getLocalPort() const if (getNativeHandle() != priv::SocketImpl::invalidSocket()) { // Retrieve information about the local end of the socket - sockaddr_in address; + sockaddr_in address{}; priv::SocketImpl::AddrLength size = sizeof(address); if (getsockname(getNativeHandle(), reinterpret_cast(&address), &size) != -1) { @@ -85,7 +85,7 @@ std::optional TcpSocket::getRemoteAddress() const if (getNativeHandle() != priv::SocketImpl::invalidSocket()) { // Retrieve information about the remote end of the socket - sockaddr_in address; + sockaddr_in address{}; priv::SocketImpl::AddrLength size = sizeof(address); if (getpeername(getNativeHandle(), reinterpret_cast(&address), &size) != -1) { @@ -104,7 +104,7 @@ unsigned short TcpSocket::getRemotePort() const if (getNativeHandle() != priv::SocketImpl::invalidSocket()) { // Retrieve information about the remote end of the socket - sockaddr_in address; + sockaddr_in address{}; priv::SocketImpl::AddrLength size = sizeof(address); if (getpeername(getNativeHandle(), reinterpret_cast(&address), &size) != -1) { @@ -175,7 +175,7 @@ Socket::Status TcpSocket::connect(const IpAddress& remoteAddress, unsigned short FD_SET(getNativeHandle(), &selector); // Setup the timeout - timeval time; + timeval time{}; time.tv_sec = static_cast(timeout.asMicroseconds() / 1000000); time.tv_usec = static_cast(timeout.asMicroseconds() % 1000000); diff --git a/src/SFML/Network/UdpSocket.cpp b/src/SFML/Network/UdpSocket.cpp index 7972172e7..7b55aa3de 100644 --- a/src/SFML/Network/UdpSocket.cpp +++ b/src/SFML/Network/UdpSocket.cpp @@ -51,7 +51,7 @@ unsigned short UdpSocket::getLocalPort() const if (getNativeHandle() != priv::SocketImpl::invalidSocket()) { // Retrieve information about the local end of the socket - sockaddr_in address; + sockaddr_in address{}; priv::SocketImpl::AddrLength size = sizeof(address); if (getsockname(getNativeHandle(), reinterpret_cast(&address), &size) != -1) { diff --git a/src/SFML/System/Android/Activity.hpp b/src/SFML/System/Android/Activity.hpp index 0f0ccedaa..8a391719e 100644 --- a/src/SFML/System/Android/Activity.hpp +++ b/src/SFML/System/Android/Activity.hpp @@ -61,31 +61,31 @@ struct ActivityStates AInputQueue* inputQueue{}; AConfiguration* config{}; - EGLDisplay display; - EglContext* context; + EGLDisplay display{}; + EglContext* context{}; - void* savedState; - std::size_t savedStateSize; + void* savedState{}; + std::size_t savedStateSize{}; std::recursive_mutex mutex; - void (*forwardEvent)(const Event& event); - int (*processEvent)(int fd, int events, void* data); + void (*forwardEvent)(const Event& event){}; + int (*processEvent)(int fd, int events, void* data){}; std::unordered_map touchEvents; Vector2i mousePosition; - bool isButtonPressed[Mouse::ButtonCount]; + bool isButtonPressed[Mouse::ButtonCount]{}; - bool mainOver; + bool mainOver{}; Vector2i screenSize; - bool initialized; - bool terminated; + bool initialized{}; + bool terminated{}; - bool fullscreen; + bool fullscreen{}; - bool updated; + bool updated{}; LogcatStream logcat; }; diff --git a/src/SFML/System/Android/SuspendAwareClock.cpp b/src/SFML/System/Android/SuspendAwareClock.cpp index 03c778f79..06a557d6c 100644 --- a/src/SFML/System/Android/SuspendAwareClock.cpp +++ b/src/SFML/System/Android/SuspendAwareClock.cpp @@ -34,7 +34,7 @@ namespace sf SuspendAwareClock::time_point SuspendAwareClock::now() noexcept { - ::timespec ts; + ::timespec ts{}; #ifdef CLOCK_BOOTTIME clock_gettime(CLOCK_BOOTTIME, &ts); #else diff --git a/src/SFML/System/Unix/SleepImpl.cpp b/src/SFML/System/Unix/SleepImpl.cpp index 258cd87f4..13d76af87 100644 --- a/src/SFML/System/Unix/SleepImpl.cpp +++ b/src/SFML/System/Unix/SleepImpl.cpp @@ -40,7 +40,7 @@ void sleepImpl(Time time) const std::int64_t usecs = time.asMicroseconds(); // Construct the time to wait - timespec ti; + timespec ti{}; ti.tv_sec = static_cast(usecs / 1000000); ti.tv_nsec = static_cast((usecs % 1000000) * 1000); diff --git a/src/SFML/Window/DRM/InputImpl.cpp b/src/SFML/Window/DRM/InputImpl.cpp index 559aea29e..a2d60c836 100644 --- a/src/SFML/Window/DRM/InputImpl.cpp +++ b/src/SFML/Window/DRM/InputImpl.cpp @@ -377,7 +377,7 @@ bool eventProcess(sf::Event& event) // Check all the open file descriptors for the next event for (auto& fileDescriptor : fileDescriptors) { - input_event inputEvent; + input_event inputEvent{}; bytesRead = read(fileDescriptor, &inputEvent, sizeof(inputEvent)); while (bytesRead > 0) @@ -509,7 +509,7 @@ bool eventProcess(sf::Event& event) newTerminalConfig.c_lflag &= ~static_cast(ICANON); tcsetattr(STDIN_FILENO, TCSANOW, &newTerminalConfig); - timeval timeout; + timeval timeout{}; timeout.tv_sec = 0; timeout.tv_usec = 0; diff --git a/src/SFML/Window/DRM/WindowImplDRM.cpp b/src/SFML/Window/DRM/WindowImplDRM.cpp index ca27738c9..b0c0c9cd7 100644 --- a/src/SFML/Window/DRM/WindowImplDRM.cpp +++ b/src/SFML/Window/DRM/WindowImplDRM.cpp @@ -186,9 +186,9 @@ bool WindowImplDRM::hasFocus() const void WindowImplDRM::processEvents() { - sf::Event ev; - while (sf::priv::InputImpl::checkEvent(ev)) - pushEvent(ev); + sf::Event event; + while (sf::priv::InputImpl::checkEvent(event)) + pushEvent(event); } } // namespace sf::priv diff --git a/src/SFML/Window/SensorManager.hpp b/src/SFML/Window/SensorManager.hpp index 8e7c3143d..0216531fa 100644 --- a/src/SFML/Window/SensorManager.hpp +++ b/src/SFML/Window/SensorManager.hpp @@ -124,10 +124,10 @@ private: //////////////////////////////////////////////////////////// struct Item { - bool available; //!< Is the sensor available on this device? - bool enabled; //!< Current enable state of the sensor - SensorImpl sensor; //!< Sensor implementation - Vector3f value; //!< The current sensor value + bool available{}; //!< Is the sensor available on this device? + bool enabled{}; //!< Current enable state of the sensor + SensorImpl sensor{}; //!< Sensor implementation + Vector3f value; //!< The current sensor value }; //////////////////////////////////////////////////////////// diff --git a/src/SFML/Window/Unix/JoystickImpl.cpp b/src/SFML/Window/Unix/JoystickImpl.cpp index 92febfbbe..112e70af8 100644 --- a/src/SFML/Window/Unix/JoystickImpl.cpp +++ b/src/SFML/Window/Unix/JoystickImpl.cpp @@ -50,7 +50,7 @@ struct JoystickRecord { std::string deviceNode; std::string systemPath; - bool plugged; + bool plugged{}; }; using JoystickList = std::vector; @@ -639,7 +639,7 @@ JoystickState JoystickImpl::JoystickImpl::update() } // pop events from the joystick file - js_event joyState; + js_event joyState{}; ssize_t result = read(m_file, &joyState, sizeof(joyState)); while (result > 0) { diff --git a/src/SFML/Window/Win32/JoystickImpl.cpp b/src/SFML/Window/Win32/JoystickImpl.cpp index cb9e3b819..7454ddd4f 100644 --- a/src/SFML/Window/Win32/JoystickImpl.cpp +++ b/src/SFML/Window/Win32/JoystickImpl.cpp @@ -790,8 +790,7 @@ bool JoystickImpl::openDInput(unsigned int index) { if (m_identification.vendorId && m_identification.productId) { - JoystickBlacklistEntry entry; - + JoystickBlacklistEntry entry{}; entry.vendorId = m_identification.vendorId; entry.productId = m_identification.productId; diff --git a/src/SFML/Window/Win32/JoystickImpl.hpp b/src/SFML/Window/Win32/JoystickImpl.hpp index ba570350b..64021ef25 100644 --- a/src/SFML/Window/Win32/JoystickImpl.hpp +++ b/src/SFML/Window/Win32/JoystickImpl.hpp @@ -212,15 +212,15 @@ private: //////////////////////////////////////////////////////////// // Member data //////////////////////////////////////////////////////////// - unsigned int m_index; //!< Index of the joystick - JOYCAPS m_caps; //!< Joystick capabilities - IDirectInputDevice8W* m_device; //!< DirectInput 8.x device - DIDEVCAPS m_deviceCaps; //!< DirectInput device capabilities - int m_axes[Joystick::AxisCount]; //!< Offsets to the bytes containing the axes states, -1 if not available - int m_buttons[Joystick::ButtonCount]; //!< Offsets to the bytes containing the button states, -1 if not available + unsigned int m_index{}; //!< Index of the joystick + JOYCAPS m_caps{}; //!< Joystick capabilities + IDirectInputDevice8W* m_device{}; //!< DirectInput 8.x device + DIDEVCAPS m_deviceCaps{}; //!< DirectInput device capabilities + int m_axes[Joystick::AxisCount]{}; //!< Offsets to the bytes containing the axes states, -1 if not available + int m_buttons[Joystick::ButtonCount]{}; //!< Offsets to the bytes containing the button states, -1 if not available Joystick::Identification m_identification; //!< Joystick identification JoystickState m_state; //!< Buffered joystick state - bool m_buffered; //!< true if the device uses buffering, false if the device uses polling + bool m_buffered{}; //!< true if the device uses buffering, false if the device uses polling }; } // namespace sf::priv diff --git a/src/SFML/Window/WindowImpl.hpp b/src/SFML/Window/WindowImpl.hpp index 1e38b9179..1cf6ddf11 100644 --- a/src/SFML/Window/WindowImpl.hpp +++ b/src/SFML/Window/WindowImpl.hpp @@ -334,7 +334,7 @@ private: std::unique_ptr m_joystickStatesImpl; //!< Previous state of the joysticks (PImpl) Vector3f m_sensorValue[Sensor::Count]; //!< Previous value of the sensors float m_joystickThreshold{0.1f}; //!< Joystick threshold (minimum motion for "move" event to be generated) - float m_previousAxes[Joystick::Count][Joystick::AxisCount]; //!< Position of each axis last time a move event triggered, in range [-100, 100] + float m_previousAxes[Joystick::Count][Joystick::AxisCount]{}; //!< Position of each axis last time a move event triggered, in range [-100, 100] std::optional m_minimumSize; //!< Minimum window size std::optional m_maximumSize; //!< Maximum window size }; diff --git a/src/SFML/Window/iOS/WindowImplUIKit.hpp b/src/SFML/Window/iOS/WindowImplUIKit.hpp index ed88de1c4..cae78ae17 100644 --- a/src/SFML/Window/iOS/WindowImplUIKit.hpp +++ b/src/SFML/Window/iOS/WindowImplUIKit.hpp @@ -232,11 +232,11 @@ private: //////////////////////////////////////////////////////////// // Member data //////////////////////////////////////////////////////////// - UIWindow* m_window; ///< Pointer to the internal UIKit window - SFView* m_view; ///< OpenGL view of the window - SFViewController* m_viewController; ///< Controller attached to the view - bool m_hasFocus; ///< Current focus state of the window - float m_backingScale; ///< Converts from points to pixels and vice versa + UIWindow* m_window{}; ///< Pointer to the internal UIKit window + SFView* m_view{}; ///< OpenGL view of the window + SFViewController* m_viewController{}; ///< Controller attached to the view + bool m_hasFocus{}; ///< Current focus state of the window + float m_backingScale{}; ///< Converts from points to pixels and vice versa }; } // namespace sf::priv diff --git a/src/SFML/Window/macOS/HIDInputManager.hpp b/src/SFML/Window/macOS/HIDInputManager.hpp index c004ba914..cb0efbf9c 100644 --- a/src/SFML/Window/macOS/HIDInputManager.hpp +++ b/src/SFML/Window/macOS/HIDInputManager.hpp @@ -288,8 +288,8 @@ private: //////////////////////////////////////////////////////////// IOHIDManagerRef m_manager{}; ///< Underlying HID Manager IOHIDElements m_keys[static_cast(Keyboard::Scan::ScancodeCount)]; ///< All the keys on any connected keyboard - Keyboard::Scancode m_keyToScancodeMapping[Keyboard::KeyCount]; ///< Mapping from Key to Scancode - Keyboard::Key m_scancodeToKeyMapping[static_cast(Keyboard::Scan::ScancodeCount)]; ///< Mapping from Scancode to Key + Keyboard::Scancode m_keyToScancodeMapping[Keyboard::KeyCount]{}; ///< Mapping from Key to Scancode + Keyboard::Key m_scancodeToKeyMapping[static_cast(Keyboard::Scan::ScancodeCount)]{}; ///< Mapping from Scancode to Key //////////////////////////////////////////////////////////// /// m_keys' index corresponds to sf::Keyboard::Scancode enum. diff --git a/src/SFML/Window/macOS/JoystickImpl.hpp b/src/SFML/Window/macOS/JoystickImpl.hpp index 5e0bd5ecb..f82b331a4 100644 --- a/src/SFML/Window/macOS/JoystickImpl.hpp +++ b/src/SFML/Window/macOS/JoystickImpl.hpp @@ -115,9 +115,9 @@ private: using ButtonsVector = std::vector; AxisMap m_axis; ///< Axes (but not POV/Hat) of the joystick - IOHIDElementRef m_hat; ///< POV/Hat axis of the joystick + IOHIDElementRef m_hat{}; ///< POV/Hat axis of the joystick ButtonsVector m_buttons; ///< Buttons of the joystick - unsigned int m_index; ///< SFML index + unsigned int m_index{}; ///< SFML index Joystick::Identification m_identification; ///< Joystick identification // NOLINTNEXTLINE(readability-identifier-naming) diff --git a/src/SFML/Window/macOS/SFKeyboardModifiersHelper.mm b/src/SFML/Window/macOS/SFKeyboardModifiersHelper.mm index f28159060..55629f3f3 100644 --- a/src/SFML/Window/macOS/SFKeyboardModifiersHelper.mm +++ b/src/SFML/Window/macOS/SFKeyboardModifiersHelper.mm @@ -153,7 +153,7 @@ void initialiseKeyboardHelper() //////////////////////////////////////////////////////// sf::Event::KeyEvent keyEventWithModifiers(NSUInteger modifiers, sf::Keyboard::Key key, sf::Keyboard::Scancode code) { - sf::Event::KeyEvent event; + sf::Event::KeyEvent event{}; event.code = key; event.scancode = code; event.alt = modifiers & NSAlternateKeyMask; diff --git a/test/Graphics/Image.test.cpp b/test/Graphics/Image.test.cpp index ce9c5a02d..4f5ecd2b7 100644 --- a/test/Graphics/Image.test.cpp +++ b/test/Graphics/Image.test.cpp @@ -61,7 +61,7 @@ TEST_CASE("[Graphics] sf::Image") SECTION("create(Vector2, std::uint8_t*)") { // 10 x 10, with 4 colour channels array - std::array pixels; + std::array pixels{}; for (std::size_t i = 0; i < pixels.size(); i += 4) { pixels[i] = 255; // r