mirror of
https://github.com/SFML/SFML.git
synced 2024-11-25 04:41:05 +08:00
Ensure struct data members are given an initial value
While I don't suspect there are any uninitialize variable bugs present, it's still good to err on the side of safety and provide an initial value nonetheless.
This commit is contained in:
parent
95a23c2d05
commit
d6e1961112
@ -37,8 +37,8 @@ const unsigned int blockCount = 32;
|
||||
|
||||
struct WorkItem
|
||||
{
|
||||
sf::Vertex* targetBuffer;
|
||||
unsigned int index;
|
||||
sf::Vertex* targetBuffer{};
|
||||
unsigned int index{};
|
||||
};
|
||||
|
||||
std::deque<WorkItem> workQueue;
|
||||
@ -50,8 +50,8 @@ std::recursive_mutex workQueueMutex;
|
||||
|
||||
struct Setting
|
||||
{
|
||||
const char* name;
|
||||
float* value;
|
||||
const char* name{};
|
||||
float* value{};
|
||||
};
|
||||
|
||||
// Terrain noise parameters
|
||||
|
@ -74,5 +74,5 @@ private:
|
||||
bool m_isLoaded{};
|
||||
|
||||
// NOLINTNEXTLINE(readability-identifier-naming)
|
||||
static const sf::Font* s_font;
|
||||
static inline const sf::Font* s_font{};
|
||||
};
|
||||
|
@ -21,8 +21,6 @@ std::random_device rd;
|
||||
std::mt19937 rng(rd());
|
||||
} // namespace
|
||||
|
||||
const sf::Font* Effect::s_font = nullptr;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// "Pixelate" fragment shader
|
||||
////////////////////////////////////////////////////////////
|
||||
|
@ -55,8 +55,8 @@ public:
|
||||
////////////////////////////////////////////////////////////
|
||||
struct Chunk
|
||||
{
|
||||
const std::int16_t* samples; //!< Pointer to the audio samples
|
||||
std::size_t sampleCount; //!< Number of samples pointed by Samples
|
||||
const std::int16_t* samples{}; //!< Pointer to the audio samples
|
||||
std::size_t sampleCount{}; //!< Number of samples pointed by Samples
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
|
@ -547,18 +547,18 @@ private:
|
||||
////////////////////////////////////////////////////////////
|
||||
struct StatesCache
|
||||
{
|
||||
bool enable; //!< Is the cache enabled?
|
||||
bool enable{}; //!< Is the cache enabled?
|
||||
bool glStatesSet{}; //!< Are our internal GL states set yet?
|
||||
bool viewChanged; //!< Has the current view changed since last draw?
|
||||
bool scissorEnabled; //!< Is scissor testing enabled?
|
||||
bool stencilEnabled; //!< Is stencil testing enabled?
|
||||
bool viewChanged{}; //!< Has the current view changed since last draw?
|
||||
bool scissorEnabled{}; //!< Is scissor testing enabled?
|
||||
bool stencilEnabled{}; //!< Is stencil testing enabled?
|
||||
BlendMode lastBlendMode; //!< Cached blending mode
|
||||
StencilMode lastStencilMode; //!< Cached stencil
|
||||
std::uint64_t lastTextureId; //!< Cached texture
|
||||
CoordinateType lastCoordinateType; //!< Texture coordinate type
|
||||
bool texCoordsArrayEnabled; //!< Is GL_TEXTURE_COORD_ARRAY client state enabled?
|
||||
bool useVertexCache; //!< Did we previously use the vertex cache?
|
||||
std::array<Vertex, 4> vertexCache; //!< Pre-transformed vertices cache
|
||||
std::uint64_t lastTextureId{}; //!< Cached texture
|
||||
CoordinateType lastCoordinateType{}; //!< Texture coordinate type
|
||||
bool texCoordsArrayEnabled{}; //!< Is GL_TEXTURE_COORD_ARRAY client state enabled?
|
||||
bool useVertexCache{}; //!< Did we previously use the vertex cache?
|
||||
std::array<Vertex, 4> vertexCache{}; //!< Pre-transformed vertices cache
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
|
@ -96,7 +96,7 @@ struct SFML_GRAPHICS_API StencilValue
|
||||
template <typename T>
|
||||
StencilValue(T) = delete;
|
||||
|
||||
unsigned int value = 0u; //!< The stored stencil value
|
||||
unsigned int value{}; //!< The stored stencil value
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
|
@ -497,8 +497,8 @@ private:
|
||||
/// \code
|
||||
/// struct MyStruct
|
||||
/// {
|
||||
/// float number;
|
||||
/// std::int8_t integer;
|
||||
/// float number{};
|
||||
/// std::int8_t integer{};
|
||||
/// std::string str;
|
||||
/// };
|
||||
///
|
||||
|
@ -45,10 +45,10 @@ namespace sf
|
||||
////////////////////////////////////////////////////////////
|
||||
struct SocketSelector::SocketSelectorImpl
|
||||
{
|
||||
fd_set allSockets; //!< Set containing all the sockets handles
|
||||
fd_set socketsReady; //!< Set containing handles of the sockets that are ready
|
||||
int maxSocket; //!< Maximum socket handle
|
||||
int socketCount; //!< Number of socket handles
|
||||
fd_set allSockets{}; //!< Set containing all the sockets handles
|
||||
fd_set socketsReady{}; //!< Set containing handles of the sockets that are ready
|
||||
int maxSocket{}; //!< Maximum socket handle
|
||||
int socketCount{}; //!< Number of socket handles
|
||||
};
|
||||
|
||||
|
||||
|
@ -53,14 +53,14 @@ namespace
|
||||
{
|
||||
struct DrmFb
|
||||
{
|
||||
gbm_bo* bo;
|
||||
std::uint32_t fbId;
|
||||
gbm_bo* bo{};
|
||||
std::uint32_t fbId{};
|
||||
};
|
||||
|
||||
bool initialized = false;
|
||||
sf::priv::Drm drmNode;
|
||||
drmEventContext drmEventCtx;
|
||||
pollfd pollFD;
|
||||
drmEventContext drmEventCtx{};
|
||||
pollfd pollFD{};
|
||||
gbm_device* gbmDevice = nullptr;
|
||||
int contextCount = 0;
|
||||
EGLDisplay display = EGL_NO_DISPLAY;
|
||||
|
@ -43,16 +43,16 @@ namespace sf::priv
|
||||
{
|
||||
struct Drm
|
||||
{
|
||||
int fileDescriptor;
|
||||
int fileDescriptor{};
|
||||
|
||||
drmModeModeInfoPtr mode;
|
||||
std::uint32_t crtcId;
|
||||
std::uint32_t connectorId;
|
||||
drmModeModeInfoPtr mode{};
|
||||
std::uint32_t crtcId{};
|
||||
std::uint32_t connectorId{};
|
||||
|
||||
drmModeCrtcPtr originalCrtc;
|
||||
drmModeCrtcPtr originalCrtc{};
|
||||
|
||||
drmModeConnectorPtr savedConnector;
|
||||
drmModeEncoderPtr savedEncoder;
|
||||
drmModeConnectorPtr savedConnector{};
|
||||
drmModeEncoderPtr savedEncoder{};
|
||||
};
|
||||
|
||||
class WindowImplDRM;
|
||||
|
@ -425,7 +425,7 @@ struct GlContext::Impl
|
||||
// Structure to track which unshared object belongs to which context
|
||||
struct UnsharedGlObject
|
||||
{
|
||||
std::uint64_t contextId;
|
||||
std::uint64_t contextId{};
|
||||
std::shared_ptr<void> object;
|
||||
};
|
||||
|
||||
|
@ -564,17 +564,12 @@ m_cursorGrabbed(m_fullscreen)
|
||||
|
||||
struct WMHints
|
||||
{
|
||||
unsigned long flags;
|
||||
unsigned long functions;
|
||||
unsigned long decorations;
|
||||
long inputMode;
|
||||
unsigned long state;
|
||||
};
|
||||
|
||||
auto hints = WMHints();
|
||||
hints.flags = MWM_HINTS_FUNCTIONS | MWM_HINTS_DECORATIONS;
|
||||
hints.decorations = 0;
|
||||
hints.functions = 0;
|
||||
unsigned long flags{MWM_HINTS_FUNCTIONS | MWM_HINTS_DECORATIONS};
|
||||
unsigned long functions{};
|
||||
unsigned long decorations{};
|
||||
long inputMode{};
|
||||
unsigned long state{};
|
||||
} hints;
|
||||
|
||||
if (style & Style::Titlebar)
|
||||
{
|
||||
|
@ -79,9 +79,9 @@ IDirectInput8W* directInput = nullptr;
|
||||
|
||||
struct JoystickRecord
|
||||
{
|
||||
GUID guid;
|
||||
unsigned int index;
|
||||
bool plugged;
|
||||
GUID guid{};
|
||||
unsigned int index{};
|
||||
bool plugged{};
|
||||
};
|
||||
|
||||
using JoystickList = std::vector<JoystickRecord>;
|
||||
@ -89,8 +89,8 @@ JoystickList joystickList;
|
||||
|
||||
struct JoystickBlacklistEntry
|
||||
{
|
||||
unsigned int vendorId;
|
||||
unsigned int productId;
|
||||
unsigned int vendorId{};
|
||||
unsigned int productId{};
|
||||
};
|
||||
|
||||
using JoystickBlacklist = std::vector<JoystickBlacklistEntry>;
|
||||
|
@ -286,12 +286,12 @@ int WglContext::selectBestPixelFormat(HDC deviceContext, unsigned int bitsPerPix
|
||||
// we can cache the result of the lookup instead of having to perform it multiple times for the same inputs
|
||||
struct PixelFormatCacheEntry
|
||||
{
|
||||
unsigned int bitsPerPixel;
|
||||
unsigned int depthBits;
|
||||
unsigned int stencilBits;
|
||||
unsigned int antialiasingLevel;
|
||||
bool pbuffer;
|
||||
int bestFormat;
|
||||
unsigned int bitsPerPixel{};
|
||||
unsigned int depthBits{};
|
||||
unsigned int stencilBits{};
|
||||
unsigned int antialiasingLevel{};
|
||||
bool pbuffer{};
|
||||
int bestFormat{};
|
||||
};
|
||||
|
||||
static std::mutex cacheMutex;
|
||||
|
@ -96,9 +96,10 @@ namespace sf::priv
|
||||
////////////////////////////////////////////////////////////
|
||||
struct WindowImpl::JoystickStatesImpl
|
||||
{
|
||||
JoystickState states[Joystick::Count]; //!< Previous state of the joysticks
|
||||
JoystickState states[Joystick::Count]{}; //!< Previous state of the joysticks
|
||||
};
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
std::unique_ptr<WindowImpl> WindowImpl::create(
|
||||
VideoMode mode,
|
||||
|
@ -54,15 +54,15 @@
|
||||
/// Modifiers states
|
||||
struct ModifiersState
|
||||
{
|
||||
BOOL rightShiftWasDown;
|
||||
BOOL leftShiftWasDown;
|
||||
BOOL rightCommandWasDown;
|
||||
BOOL leftCommandWasDown;
|
||||
BOOL rightAlternateWasDown;
|
||||
BOOL leftAlternateWasDown;
|
||||
BOOL leftControlWasDown;
|
||||
BOOL rightControlWasDown;
|
||||
BOOL capsLockWasOn;
|
||||
BOOL rightShiftWasDown{};
|
||||
BOOL leftShiftWasDown{};
|
||||
BOOL rightCommandWasDown{};
|
||||
BOOL leftCommandWasDown{};
|
||||
BOOL rightAlternateWasDown{};
|
||||
BOOL leftAlternateWasDown{};
|
||||
BOOL leftControlWasDown{};
|
||||
BOOL rightControlWasDown{};
|
||||
BOOL capsLockWasOn{};
|
||||
};
|
||||
|
||||
|
||||
|
@ -1,9 +1,24 @@
|
||||
#include <SFML/Audio/SoundStream.hpp>
|
||||
|
||||
#include <catch2/catch_test_macros.hpp>
|
||||
|
||||
#include <type_traits>
|
||||
|
||||
static_assert(!std::is_constructible_v<sf::SoundStream>);
|
||||
static_assert(!std::is_copy_constructible_v<sf::SoundStream>);
|
||||
static_assert(!std::is_copy_assignable_v<sf::SoundStream>);
|
||||
static_assert(!std::is_nothrow_move_constructible_v<sf::SoundStream>);
|
||||
static_assert(!std::is_nothrow_move_assignable_v<sf::SoundStream>);
|
||||
TEST_CASE("[Audio] sf::SoundStream")
|
||||
{
|
||||
SECTION("Type traits")
|
||||
{
|
||||
STATIC_CHECK(!std::is_constructible_v<sf::SoundStream>);
|
||||
STATIC_CHECK(!std::is_copy_constructible_v<sf::SoundStream>);
|
||||
STATIC_CHECK(!std::is_copy_assignable_v<sf::SoundStream>);
|
||||
STATIC_CHECK(!std::is_nothrow_move_constructible_v<sf::SoundStream>);
|
||||
STATIC_CHECK(!std::is_nothrow_move_assignable_v<sf::SoundStream>);
|
||||
}
|
||||
|
||||
SECTION("Chunk")
|
||||
{
|
||||
const sf::SoundStream::Chunk chunk;
|
||||
CHECK(chunk.samples == nullptr);
|
||||
CHECK(chunk.sampleCount == 0);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user