Require that variables are initialized

This commit is contained in:
Chris Thrasher 2024-04-27 06:44:27 +00:00
parent 5da286487a
commit 249caa2fb2
42 changed files with 222 additions and 216 deletions

View File

@ -32,7 +32,6 @@ Checks: >
-cppcoreguidelines-avoid-do-while, -cppcoreguidelines-avoid-do-while,
-cppcoreguidelines-avoid-magic-numbers, -cppcoreguidelines-avoid-magic-numbers,
-cppcoreguidelines-avoid-non-const-global-variables, -cppcoreguidelines-avoid-non-const-global-variables,
-cppcoreguidelines-init-variables,
-cppcoreguidelines-macro-to-enum, -cppcoreguidelines-macro-to-enum,
-cppcoreguidelines-macro-usage, -cppcoreguidelines-macro-usage,
-cppcoreguidelines-narrowing-conversions, -cppcoreguidelines-narrowing-conversions,

View File

@ -22,12 +22,12 @@ int main()
const unsigned short port = 50001; const unsigned short port = 50001;
// TCP, UDP or connected UDP ? // TCP, UDP or connected UDP ?
char protocol; char protocol = 0;
std::cout << "Do you want to use TCP (t) or UDP (u)? "; std::cout << "Do you want to use TCP (t) or UDP (u)? ";
std::cin >> protocol; std::cin >> protocol;
// Client or server ? // Client or server ?
char who; char who = 0;
std::cout << "Do you want to be a server (s) or a client (c)? "; std::cout << "Do you want to be a server (s) or a client (c)? ";
std::cin >> who; std::cin >> who;

View File

@ -39,7 +39,7 @@ void runTcpServer(unsigned short port)
// Receive a message back from the client // Receive a message back from the client
char in[128]; char in[128];
std::size_t received; std::size_t received = 0;
if (socket.receive(in, sizeof(in), received) != sf::Socket::Status::Done) if (socket.receive(in, sizeof(in), received) != sf::Socket::Status::Done)
return; return;
std::cout << "Answer received from the client: " << std::quoted(in) << std::endl; std::cout << "Answer received from the client: " << std::quoted(in) << std::endl;
@ -71,7 +71,7 @@ void runTcpClient(unsigned short port)
// Receive a message from the server // Receive a message from the server
char in[128]; char in[128];
std::size_t received; std::size_t received = 0;
if (socket.receive(in, sizeof(in), received) != sf::Socket::Status::Done) if (socket.receive(in, sizeof(in), received) != sf::Socket::Status::Done)
return; return;
std::cout << "Message received from the server: " << std::quoted(in) << std::endl; std::cout << "Message received from the server: " << std::quoted(in) << std::endl;

View File

@ -26,9 +26,9 @@ void runUdpServer(unsigned short port)
// Wait for a message // Wait for a message
char in[128]; char in[128];
std::size_t received; std::size_t received = 0;
std::optional<sf::IpAddress> sender; std::optional<sf::IpAddress> sender;
unsigned short senderPort; unsigned short senderPort = 0;
if (socket.receive(in, sizeof(in), received, sender, senderPort) != sf::Socket::Status::Done) if (socket.receive(in, sizeof(in), received, sender, senderPort) != sf::Socket::Status::Done)
return; return;
std::cout << "Message received from client " << sender.value() << ": " << std::quoted(in) << std::endl; std::cout << "Message received from client " << sender.value() << ": " << std::quoted(in) << std::endl;
@ -66,9 +66,9 @@ void runUdpClient(unsigned short port)
// Receive an answer from anyone (but most likely from the server) // Receive an answer from anyone (but most likely from the server)
char in[128]; char in[128];
std::size_t received; std::size_t received = 0;
std::optional<sf::IpAddress> sender; std::optional<sf::IpAddress> sender;
unsigned short senderPort; unsigned short senderPort = 0;
if (socket.receive(in, sizeof(in), received, sender, senderPort) != sf::Socket::Status::Done) if (socket.receive(in, sizeof(in), received, sender, senderPort) != sf::Socket::Status::Done)
return; return;
std::cout << "Message received from " << sender.value() << ": " << std::quoted(in) << std::endl; std::cout << "Message received from " << sender.value() << ": " << std::quoted(in) << std::endl;

View File

@ -48,7 +48,7 @@ int main()
} }
// Choose the sample rate // Choose the sample rate
unsigned int sampleRate; unsigned int sampleRate = 0;
std::cout << "Please choose the sample rate for sound capture (44100 is CD quality): "; std::cout << "Please choose the sample rate for sound capture (44100 is CD quality): ";
std::cin >> sampleRate; std::cin >> sampleRate;
std::cin.ignore(10000, '\n'); std::cin.ignore(10000, '\n');
@ -87,7 +87,7 @@ int main()
<< " " << buffer.getChannelCount() << " channels" << std::endl; << " " << buffer.getChannelCount() << " channels" << std::endl;
// Choose what to do with the recorded sound data // Choose what to do with the recorded sound data
char choice; char choice = 0;
std::cout << "What do you want to do with captured sound (p = play, s = save) ? "; std::cout << "What do you want to do with captured sound (p = play, s = save) ? ";
std::cin >> choice; std::cin >> choice;
std::cin.ignore(10000, '\n'); std::cin.ignore(10000, '\n');

View File

@ -122,7 +122,7 @@ private:
break; break;
// Extract the message ID // Extract the message ID
std::uint8_t id; std::uint8_t id = 0;
packet >> id; packet >> id;
if (id == serverAudioData) if (id == serverAudioData)

View File

@ -24,7 +24,7 @@ int main()
const unsigned short port = 2435; const unsigned short port = 2435;
// Client or server ? // Client or server ?
char who; char who = 0;
std::cout << "Do you want to be a server ('s') or a client ('c')? "; std::cout << "Do you want to be a server ('s') or a client ('c')? ";
std::cin >> who; std::cin >> who;

View File

@ -1352,7 +1352,7 @@ public:
commandBufferAllocateInfo.commandPool = commandPool; commandBufferAllocateInfo.commandPool = commandPool;
commandBufferAllocateInfo.commandBufferCount = 1; commandBufferAllocateInfo.commandBufferCount = 1;
VkCommandBuffer commandBuffer; VkCommandBuffer commandBuffer = nullptr;
if (vkAllocateCommandBuffers(device, &commandBufferAllocateInfo, &commandBuffer) != VK_SUCCESS) if (vkAllocateCommandBuffers(device, &commandBufferAllocateInfo, &commandBuffer) != VK_SUCCESS)
return false; return false;
@ -1458,7 +1458,7 @@ public:
return; return;
} }
void* ptr; void* ptr = nullptr;
// Map the buffer into our address space // Map the buffer into our address space
if (vkMapMemory(device, stagingBufferMemory, 0, sizeof(vertexData), 0, &ptr) != VK_SUCCESS) if (vkMapMemory(device, stagingBufferMemory, 0, sizeof(vertexData), 0, &ptr) != VK_SUCCESS)
@ -1537,7 +1537,7 @@ public:
return; return;
} }
void* ptr; void* ptr = nullptr;
// Map the buffer into our address space // Map the buffer into our address space
if (vkMapMemory(device, stagingBufferMemory, 0, sizeof(indexData), 0, &ptr) != VK_SUCCESS) if (vkMapMemory(device, stagingBufferMemory, 0, sizeof(indexData), 0, &ptr) != VK_SUCCESS)
@ -1689,7 +1689,7 @@ public:
commandBufferAllocateInfo.commandPool = commandPool; commandBufferAllocateInfo.commandPool = commandPool;
commandBufferAllocateInfo.commandBufferCount = 1; commandBufferAllocateInfo.commandBufferCount = 1;
VkCommandBuffer commandBuffer; VkCommandBuffer commandBuffer = nullptr;
if (vkAllocateCommandBuffers(device, &commandBufferAllocateInfo, &commandBuffer) != VK_SUCCESS) if (vkAllocateCommandBuffers(device, &commandBufferAllocateInfo, &commandBuffer) != VK_SUCCESS)
{ {
@ -1820,7 +1820,7 @@ public:
stagingBuffer, stagingBuffer,
stagingBufferMemory); stagingBufferMemory);
void* ptr; void* ptr = nullptr;
// Map the buffer into our address space // Map the buffer into our address space
if (vkMapMemory(device, stagingBufferMemory, 0, imageSize, 0, &ptr) != VK_SUCCESS) if (vkMapMemory(device, stagingBufferMemory, 0, imageSize, 0, &ptr) != VK_SUCCESS)
@ -1862,7 +1862,7 @@ public:
commandBufferAllocateInfo.commandPool = commandPool; commandBufferAllocateInfo.commandPool = commandPool;
commandBufferAllocateInfo.commandBufferCount = 1; commandBufferAllocateInfo.commandBufferCount = 1;
VkCommandBuffer commandBuffer; VkCommandBuffer commandBuffer = nullptr;
if (vkAllocateCommandBuffers(device, &commandBufferAllocateInfo, &commandBuffer) != VK_SUCCESS) if (vkAllocateCommandBuffers(device, &commandBufferAllocateInfo, &commandBuffer) != VK_SUCCESS)
{ {
@ -2431,7 +2431,7 @@ public:
matrixPerspective(projection, fov, aspect, nearPlane, farPlane); matrixPerspective(projection, fov, aspect, nearPlane, farPlane);
char* ptr; char* ptr = nullptr;
// Map the current frame's uniform buffer into our address space // Map the current frame's uniform buffer into our address space
if (vkMapMemory(device, uniformBuffersMemory[currentFrame], 0, sizeof(Matrix) * 3, 0, reinterpret_cast<void**>(&ptr)) != if (vkMapMemory(device, uniformBuffersMemory[currentFrame], 0, sizeof(Matrix) * 3, 0, reinterpret_cast<void**>(&ptr)) !=

View File

@ -158,7 +158,7 @@ Out Utf<8>::encode(std::uint32_t input, Out output, std::uint8_t replacement)
template <typename In> template <typename In>
In Utf<8>::next(In begin, In end) In Utf<8>::next(In begin, In end)
{ {
std::uint32_t codepoint; std::uint32_t codepoint = 0;
return decode(begin, end, codepoint); return decode(begin, end, codepoint);
} }
@ -225,9 +225,9 @@ Out Utf<8>::toAnsi(In begin, In end, Out output, char replacement, const std::lo
{ {
while (begin < end) while (begin < end)
{ {
std::uint32_t codepoint; std::uint32_t codepoint = 0;
begin = decode(begin, end, codepoint); begin = decode(begin, end, codepoint);
output = Utf<32>::encodeAnsi(codepoint, output, replacement, locale); output = Utf<32>::encodeAnsi(codepoint, output, replacement, locale);
} }
return output; return output;
@ -240,9 +240,9 @@ Out Utf<8>::toWide(In begin, In end, Out output, wchar_t replacement)
{ {
while (begin < end) while (begin < end)
{ {
std::uint32_t codepoint; std::uint32_t codepoint = 0;
begin = decode(begin, end, codepoint); begin = decode(begin, end, codepoint);
output = Utf<32>::encodeWide(codepoint, output, replacement); output = Utf<32>::encodeWide(codepoint, output, replacement);
} }
return output; return output;
@ -257,9 +257,9 @@ Out Utf<8>::toLatin1(In begin, In end, Out output, char replacement)
// and can thus be treated as (a sub-range of) UTF-32 // and can thus be treated as (a sub-range of) UTF-32
while (begin < end) while (begin < end)
{ {
std::uint32_t codepoint; std::uint32_t codepoint = 0;
begin = decode(begin, end, codepoint); begin = decode(begin, end, codepoint);
*output++ = codepoint < 256 ? static_cast<char>(codepoint) : replacement; *output++ = codepoint < 256 ? static_cast<char>(codepoint) : replacement;
} }
return output; return output;
@ -280,9 +280,9 @@ Out Utf<8>::toUtf16(In begin, In end, Out output)
{ {
while (begin < end) while (begin < end)
{ {
std::uint32_t codepoint; std::uint32_t codepoint = 0;
begin = decode(begin, end, codepoint); begin = decode(begin, end, codepoint);
output = Utf<16>::encode(codepoint, output); output = Utf<16>::encode(codepoint, output);
} }
return output; return output;
@ -295,9 +295,9 @@ Out Utf<8>::toUtf32(In begin, In end, Out output)
{ {
while (begin < end) while (begin < end)
{ {
std::uint32_t codepoint; std::uint32_t codepoint = 0;
begin = decode(begin, end, codepoint); begin = decode(begin, end, codepoint);
*output++ = codepoint; *output++ = codepoint;
} }
return output; return output;
@ -385,7 +385,7 @@ Out Utf<16>::encode(std::uint32_t input, Out output, std::uint16_t replacement)
template <typename In> template <typename In>
In Utf<16>::next(In begin, In end) In Utf<16>::next(In begin, In end)
{ {
std::uint32_t codepoint; std::uint32_t codepoint = 0;
return decode(begin, end, codepoint); return decode(begin, end, codepoint);
} }
@ -449,9 +449,9 @@ Out Utf<16>::toAnsi(In begin, In end, Out output, char replacement, const std::l
{ {
while (begin < end) while (begin < end)
{ {
std::uint32_t codepoint; std::uint32_t codepoint = 0;
begin = decode(begin, end, codepoint); begin = decode(begin, end, codepoint);
output = Utf<32>::encodeAnsi(codepoint, output, replacement, locale); output = Utf<32>::encodeAnsi(codepoint, output, replacement, locale);
} }
return output; return output;
@ -464,9 +464,9 @@ Out Utf<16>::toWide(In begin, In end, Out output, wchar_t replacement)
{ {
while (begin < end) while (begin < end)
{ {
std::uint32_t codepoint; std::uint32_t codepoint = 0;
begin = decode(begin, end, codepoint); begin = decode(begin, end, codepoint);
output = Utf<32>::encodeWide(codepoint, output, replacement); output = Utf<32>::encodeWide(codepoint, output, replacement);
} }
return output; return output;
@ -495,9 +495,9 @@ Out Utf<16>::toUtf8(In begin, In end, Out output)
{ {
while (begin < end) while (begin < end)
{ {
std::uint32_t codepoint; std::uint32_t codepoint = 0;
begin = decode(begin, end, codepoint); begin = decode(begin, end, codepoint);
output = Utf<8>::encode(codepoint, output); output = Utf<8>::encode(codepoint, output);
} }
return output; return output;
@ -518,9 +518,9 @@ Out Utf<16>::toUtf32(In begin, In end, Out output)
{ {
while (begin < end) while (begin < end)
{ {
std::uint32_t codepoint; std::uint32_t codepoint = 0;
begin = decode(begin, end, codepoint); begin = decode(begin, end, codepoint);
*output++ = codepoint; *output++ = codepoint;
} }
return output; return output;

View File

@ -79,7 +79,7 @@ AudioDevice::AudioDevice()
} }
// Count the playback devices // Count the playback devices
ma_uint32 deviceCount; ma_uint32 deviceCount = 0;
if (auto result = ma_context_get_devices(&*m_context, nullptr, &deviceCount, nullptr, nullptr); result != MA_SUCCESS) if (auto result = ma_context_get_devices(&*m_context, nullptr, &deviceCount, nullptr, nullptr); result != MA_SUCCESS)
{ {

View File

@ -72,9 +72,9 @@ struct SavedSettings
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
SavedSettings saveSettings(const ma_sound& sound) SavedSettings saveSettings(const ma_sound& sound)
{ {
float innerAngle; float innerAngle = 0;
float outerAngle; float outerAngle = 0;
float outerGain; float outerGain = 0;
ma_sound_get_cone(&sound, &innerAngle, &outerAngle, &outerGain); ma_sound_get_cone(&sound, &innerAngle, &outerAngle, &outerGain);
return SavedSettings{ma_sound_get_pitch(&sound), return SavedSettings{ma_sound_get_pitch(&sound),

View File

@ -125,8 +125,8 @@ struct SoundRecorder::Impl
} }
// Enumerate the capture devices // Enumerate the capture devices
ma_device_info* deviceInfos; ma_device_info* deviceInfos = nullptr;
ma_uint32 deviceCount; ma_uint32 deviceCount = 0;
if (auto result = ma_context_get_devices(&context, nullptr, nullptr, &deviceInfos, &deviceCount); if (auto result = ma_context_get_devices(&context, nullptr, nullptr, &deviceInfos, &deviceCount);
result != MA_SUCCESS) result != MA_SUCCESS)

View File

@ -143,7 +143,7 @@ bool Font::loadFromFile(const std::filesystem::path& filename)
} }
// Load the new font face from the specified file // Load the new font face from the specified file
FT_Face face; FT_Face face = nullptr;
if (FT_New_Face(fontHandles->library, filename.string().c_str(), 0, &face) != 0) if (FT_New_Face(fontHandles->library, filename.string().c_str(), 0, &face) != 0)
{ {
err() << "Failed to load font (failed to create the font face)\n" << formatDebugPathInfo(filename) << std::endl; err() << "Failed to load font (failed to create the font face)\n" << formatDebugPathInfo(filename) << std::endl;
@ -201,7 +201,7 @@ bool Font::loadFromMemory(const void* data, std::size_t sizeInBytes)
} }
// Load the new font face from the specified file // Load the new font face from the specified file
FT_Face face; FT_Face face = nullptr;
if (FT_New_Memory_Face(fontHandles->library, if (FT_New_Memory_Face(fontHandles->library,
reinterpret_cast<const FT_Byte*>(data), reinterpret_cast<const FT_Byte*>(data),
static_cast<FT_Long>(sizeInBytes), static_cast<FT_Long>(sizeInBytes),
@ -276,7 +276,7 @@ bool Font::loadFromStream(InputStream& stream)
args.driver = nullptr; args.driver = nullptr;
// Load the new font face from the specified stream // Load the new font face from the specified stream
FT_Face face; FT_Face face = nullptr;
if (FT_Open_Face(fontHandles->library, &args, 0, &face) != 0) if (FT_Open_Face(fontHandles->library, &args, 0, &face) != 0)
{ {
err() << "Failed to load font from stream (failed to create the font face)" << std::endl; err() << "Failed to load font from stream (failed to create the font face)" << std::endl;
@ -520,7 +520,7 @@ Glyph Font::loadGlyph(std::uint32_t codePoint, unsigned int characterSize, bool
return glyph; return glyph;
// Retrieve the glyph // Retrieve the glyph
FT_Glyph glyphDesc; FT_Glyph glyphDesc = nullptr;
if (FT_Get_Glyph(face->glyph, &glyphDesc) != 0) if (FT_Get_Glyph(face->glyph, &glyphDesc) != 0)
return glyph; return glyph;

View File

@ -430,7 +430,7 @@ bool RenderTextureImplFBO::createFrameBuffer()
glCheck(GLEXT_glFramebufferTexture2D(GLEXT_GL_FRAMEBUFFER, GLEXT_GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, m_textureId, 0)); glCheck(GLEXT_glFramebufferTexture2D(GLEXT_GL_FRAMEBUFFER, GLEXT_GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, m_textureId, 0));
// A final check, just to be sure... // A final check, just to be sure...
GLenum status; GLenum status = 0;
glCheck(status = GLEXT_glCheckFramebufferStatus(GLEXT_GL_FRAMEBUFFER)); glCheck(status = GLEXT_glCheckFramebufferStatus(GLEXT_GL_FRAMEBUFFER));
if (status != GLEXT_GL_FRAMEBUFFER_COMPLETE) if (status != GLEXT_GL_FRAMEBUFFER_COMPLETE)
{ {

View File

@ -801,20 +801,20 @@ bool Shader::compile(const char* vertexShaderCode, const char* geometryShaderCod
m_uniforms.clear(); m_uniforms.clear();
// Create the program // Create the program
GLEXT_GLhandle shaderProgram; GLEXT_GLhandle shaderProgram{};
glCheck(shaderProgram = GLEXT_glCreateProgramObject()); glCheck(shaderProgram = GLEXT_glCreateProgramObject());
// Create the vertex shader if needed // Create the vertex shader if needed
if (vertexShaderCode) if (vertexShaderCode)
{ {
// Create and compile the shader // Create and compile the shader
GLEXT_GLhandle vertexShader; GLEXT_GLhandle vertexShader{};
glCheck(vertexShader = GLEXT_glCreateShaderObject(GLEXT_GL_VERTEX_SHADER)); glCheck(vertexShader = GLEXT_glCreateShaderObject(GLEXT_GL_VERTEX_SHADER));
glCheck(GLEXT_glShaderSource(vertexShader, 1, &vertexShaderCode, nullptr)); glCheck(GLEXT_glShaderSource(vertexShader, 1, &vertexShaderCode, nullptr));
glCheck(GLEXT_glCompileShader(vertexShader)); glCheck(GLEXT_glCompileShader(vertexShader));
// Check the compile log // Check the compile log
GLint success; GLint success = 0;
glCheck(GLEXT_glGetObjectParameteriv(vertexShader, GLEXT_GL_OBJECT_COMPILE_STATUS, &success)); glCheck(GLEXT_glGetObjectParameteriv(vertexShader, GLEXT_GL_OBJECT_COMPILE_STATUS, &success));
if (success == GL_FALSE) if (success == GL_FALSE)
{ {
@ -840,7 +840,7 @@ bool Shader::compile(const char* vertexShaderCode, const char* geometryShaderCod
glCheck(GLEXT_glCompileShader(geometryShader)); glCheck(GLEXT_glCompileShader(geometryShader));
// Check the compile log // Check the compile log
GLint success; GLint success = 0;
glCheck(GLEXT_glGetObjectParameteriv(geometryShader, GLEXT_GL_OBJECT_COMPILE_STATUS, &success)); glCheck(GLEXT_glGetObjectParameteriv(geometryShader, GLEXT_GL_OBJECT_COMPILE_STATUS, &success));
if (success == GL_FALSE) if (success == GL_FALSE)
{ {
@ -861,13 +861,13 @@ bool Shader::compile(const char* vertexShaderCode, const char* geometryShaderCod
if (fragmentShaderCode) if (fragmentShaderCode)
{ {
// Create and compile the shader // Create and compile the shader
GLEXT_GLhandle fragmentShader; GLEXT_GLhandle fragmentShader{};
glCheck(fragmentShader = GLEXT_glCreateShaderObject(GLEXT_GL_FRAGMENT_SHADER)); glCheck(fragmentShader = GLEXT_glCreateShaderObject(GLEXT_GL_FRAGMENT_SHADER));
glCheck(GLEXT_glShaderSource(fragmentShader, 1, &fragmentShaderCode, nullptr)); glCheck(GLEXT_glShaderSource(fragmentShader, 1, &fragmentShaderCode, nullptr));
glCheck(GLEXT_glCompileShader(fragmentShader)); glCheck(GLEXT_glCompileShader(fragmentShader));
// Check the compile log // Check the compile log
GLint success; GLint success = 0;
glCheck(GLEXT_glGetObjectParameteriv(fragmentShader, GLEXT_GL_OBJECT_COMPILE_STATUS, &success)); glCheck(GLEXT_glGetObjectParameteriv(fragmentShader, GLEXT_GL_OBJECT_COMPILE_STATUS, &success));
if (success == GL_FALSE) if (success == GL_FALSE)
{ {
@ -888,7 +888,7 @@ bool Shader::compile(const char* vertexShaderCode, const char* geometryShaderCod
glCheck(GLEXT_glLinkProgram(shaderProgram)); glCheck(GLEXT_glLinkProgram(shaderProgram));
// Check the link log // Check the link log
GLint success; GLint success = 0;
glCheck(GLEXT_glGetObjectParameteriv(shaderProgram, GLEXT_GL_OBJECT_LINK_STATUS, &success)); glCheck(GLEXT_glGetObjectParameteriv(shaderProgram, GLEXT_GL_OBJECT_LINK_STATUS, &success));
if (success == GL_FALSE) if (success == GL_FALSE)
{ {

View File

@ -186,7 +186,7 @@ bool Texture::create(const Vector2u& size)
// Create the OpenGL texture if it doesn't exist yet // Create the OpenGL texture if it doesn't exist yet
if (!m_texture) if (!m_texture)
{ {
GLuint texture; GLuint texture = 0;
glCheck(glGenTextures(1, &texture)); glCheck(glGenTextures(1, &texture));
m_texture = texture; m_texture = texture;
} }
@ -382,7 +382,7 @@ Image Texture::copyToImage() const
glCheck(GLEXT_glGenFramebuffers(1, &frameBuffer)); glCheck(GLEXT_glGenFramebuffers(1, &frameBuffer));
if (frameBuffer) if (frameBuffer)
{ {
GLint previousFrameBuffer; GLint previousFrameBuffer = 0;
glCheck(glGetIntegerv(GLEXT_GL_FRAMEBUFFER_BINDING, &previousFrameBuffer)); glCheck(glGetIntegerv(GLEXT_GL_FRAMEBUFFER_BINDING, &previousFrameBuffer));
glCheck(GLEXT_glBindFramebuffer(GLEXT_GL_FRAMEBUFFER, frameBuffer)); glCheck(GLEXT_glBindFramebuffer(GLEXT_GL_FRAMEBUFFER, frameBuffer));
@ -570,10 +570,10 @@ void Texture::update(const Texture& texture, const Vector2u& dest)
GLEXT_glFramebufferTexture2D(GLEXT_GL_DRAW_FRAMEBUFFER, GLEXT_GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, m_texture, 0)); GLEXT_glFramebufferTexture2D(GLEXT_GL_DRAW_FRAMEBUFFER, GLEXT_GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, m_texture, 0));
// A final check, just to be sure... // A final check, just to be sure...
GLenum sourceStatus; GLenum sourceStatus = 0;
glCheck(sourceStatus = GLEXT_glCheckFramebufferStatus(GLEXT_GL_READ_FRAMEBUFFER)); glCheck(sourceStatus = GLEXT_glCheckFramebufferStatus(GLEXT_GL_READ_FRAMEBUFFER));
GLenum destStatus; GLenum destStatus = 0;
glCheck(destStatus = GLEXT_glCheckFramebufferStatus(GLEXT_GL_DRAW_FRAMEBUFFER)); glCheck(destStatus = GLEXT_glCheckFramebufferStatus(GLEXT_GL_DRAW_FRAMEBUFFER));
if ((sourceStatus == GLEXT_GL_FRAMEBUFFER_COMPLETE) && (destStatus == GLEXT_GL_FRAMEBUFFER_COMPLETE)) if ((sourceStatus == GLEXT_GL_FRAMEBUFFER_COMPLETE) && (destStatus == GLEXT_GL_FRAMEBUFFER_COMPLETE))

View File

@ -382,7 +382,7 @@ Ftp::Response Ftp::getResponse()
{ {
// Receive the response from the server // Receive the response from the server
char buffer[1024]; char buffer[1024];
std::size_t length; std::size_t length = 0;
if (m_receiveBuffer.empty()) if (m_receiveBuffer.empty())
{ {
@ -401,11 +401,11 @@ Ftp::Response Ftp::getResponse()
while (in) while (in)
{ {
// Try to extract the code // Try to extract the code
unsigned int code; unsigned int code = 0;
if (in >> code) if (in >> code)
{ {
// Extract the separator // Extract the separator
char separator; char separator = 0;
in.get(separator); in.get(separator);
// The '-' character means a multiline response // The '-' character means a multiline response
@ -587,7 +587,7 @@ void Ftp::DataChannel::receive(std::ostream& stream)
{ {
// Receive data // Receive data
char buffer[1024]; char buffer[1024];
std::size_t received; std::size_t received = 0;
while (m_dataSocket.receive(buffer, sizeof(buffer), received) == Socket::Status::Done) while (m_dataSocket.receive(buffer, sizeof(buffer), received) == Socket::Status::Done)
{ {
stream.write(buffer, static_cast<std::streamsize>(received)); stream.write(buffer, static_cast<std::streamsize>(received));
@ -609,7 +609,7 @@ void Ftp::DataChannel::send(std::istream& stream)
{ {
// Send data // Send data
char buffer[1024]; char buffer[1024];
std::size_t count; std::size_t count = 0;
for (;;) for (;;)
{ {

View File

@ -209,7 +209,7 @@ void Http::Response::parse(const std::string& data)
} }
// Extract the status code from the first line // Extract the status code from the first line
int status; int status = 0;
if (in >> status) if (in >> status)
{ {
m_status = static_cast<Status>(status); m_status = static_cast<Status>(status);
@ -238,7 +238,7 @@ void Http::Response::parse(const std::string& data)
else else
{ {
// Chunked - have to read chunk by chunk // Chunked - have to read chunk by chunk
std::size_t length; std::size_t length = 0;
// Read all chunks, identified by a chunk-size not being 0 // Read all chunks, identified by a chunk-size not being 0
while (in >> std::hex >> length) while (in >> std::hex >> length)

View File

@ -96,7 +96,7 @@ Packet::operator bool() const
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
Packet& Packet::operator>>(bool& data) Packet& Packet::operator>>(bool& data)
{ {
std::uint8_t value; std::uint8_t value = 0;
if (*this >> value) if (*this >> value)
data = (value != 0); data = (value != 0);

View File

@ -227,7 +227,7 @@ Socket::Status TcpSocket::send(const void* data, std::size_t size)
if (!isBlocking()) if (!isBlocking())
err() << "Warning: Partial sends might not be handled properly." << std::endl; err() << "Warning: Partial sends might not be handled properly." << std::endl;
std::size_t sent; std::size_t sent = 0;
return send(data, size, sent); return send(data, size, sent);
} }
@ -347,7 +347,7 @@ Socket::Status TcpSocket::send(Packet& packet)
#pragma GCC diagnostic push #pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wsign-conversion" #pragma GCC diagnostic ignored "-Wsign-conversion"
// Send the data block // Send the data block
std::size_t sent; std::size_t sent = 0;
const Status status = send(m_blockToSendBuffer.data() + packet.m_sendPos, const Status status = send(m_blockToSendBuffer.data() + packet.m_sendPos,
static_cast<priv::SocketImpl::Size>(m_blockToSendBuffer.size() - packet.m_sendPos), static_cast<priv::SocketImpl::Size>(m_blockToSendBuffer.size() - packet.m_sendPos),
sent); sent);

View File

@ -329,7 +329,7 @@ int WindowImplAndroid::processEvent(int /* fd */, int /* events */, void* /* dat
int WindowImplAndroid::processScrollEvent(AInputEvent* inputEvent, ActivityStates& states) int WindowImplAndroid::processScrollEvent(AInputEvent* inputEvent, ActivityStates& states)
{ {
// Prepare the Java virtual machine // Prepare the Java virtual machine
jint lResult; jint lResult = 0;
JavaVM* lJavaVM = states.activity->vm; JavaVM* lJavaVM = states.activity->vm;
JNIEnv* lJNIEnv = states.activity->env; JNIEnv* lJNIEnv = states.activity->env;
@ -714,7 +714,7 @@ int WindowImplAndroid::getUnicode(AInputEvent* event)
const std::lock_guard lock(states.mutex); const std::lock_guard lock(states.mutex);
// Initializes JNI // Initializes JNI
jint lResult; jint lResult = 0;
JavaVM* lJavaVM = states.activity->vm; JavaVM* lJavaVM = states.activity->vm;
JNIEnv* lJNIEnv = states.activity->env; JNIEnv* lJNIEnv = states.activity->env;

View File

@ -254,7 +254,7 @@ int getResources(int fd, drmModeResPtr& resources)
int hasMonitorConnected(int fd, drmModeRes& resources) int hasMonitorConnected(int fd, drmModeRes& resources)
{ {
drmModeConnectorPtr connector; drmModeConnectorPtr connector = nullptr;
for (int i = 0; i < resources.count_connectors; ++i) for (int i = 0; i < resources.count_connectors; ++i)
{ {
connector = drmModeGetConnector(fd, resources.connectors[i]); connector = drmModeGetConnector(fd, resources.connectors[i]);
@ -314,7 +314,7 @@ int findDrmDevice(drmModeResPtr& resources)
int initDrm(sf::priv::Drm& drm, const char* device, const char* modeStr, unsigned int vrefresh) int initDrm(sf::priv::Drm& drm, const char* device, const char* modeStr, unsigned int vrefresh)
{ {
drmModeResPtr resources; drmModeResPtr resources = nullptr;
if (device) if (device)
{ {
@ -486,8 +486,8 @@ EGLDisplay getInitializedDisplay()
eglCheck(display = eglGetDisplay(reinterpret_cast<EGLNativeDisplayType>(gbmDevice))); eglCheck(display = eglGetDisplay(reinterpret_cast<EGLNativeDisplayType>(gbmDevice)));
EGLint major; EGLint major = 0;
EGLint minor; EGLint minor = 0;
eglCheck(eglInitialize(display, &major, &minor)); eglCheck(eglInitialize(display, &major, &minor));
gladLoaderLoadEGL(display); gladLoaderLoadEGL(display);
@ -576,7 +576,7 @@ DRMContext::DRMContext(DRMContext* shared, const ContextSettings& settings, cons
DRMContext::~DRMContext() DRMContext::~DRMContext()
{ {
// Deactivate the current context // Deactivate the current context
EGLContext currentContext; EGLContext currentContext = nullptr;
eglCheck(currentContext = eglGetCurrentContext()); eglCheck(currentContext = eglGetCurrentContext());
if (currentContext == m_context) if (currentContext == m_context)
@ -692,7 +692,7 @@ void DRMContext::createContext(DRMContext* shared)
{ {
const EGLint contextVersion[] = {EGL_CONTEXT_CLIENT_VERSION, 1, EGL_NONE}; const EGLint contextVersion[] = {EGL_CONTEXT_CLIENT_VERSION, 1, EGL_NONE};
EGLContext toShared; EGLContext toShared = nullptr;
if (shared) if (shared)
toShared = shared->m_context; toShared = shared->m_context;
@ -785,7 +785,7 @@ EGLConfig DRMContext::getBestConfig(EGLDisplay display, unsigned int bitsPerPixe
#endif #endif
EGL_NONE }; EGL_NONE };
EGLint configCount; EGLint configCount = 0;
EGLConfig configs[1]; EGLConfig configs[1];
// Ask EGL for the best config matching our video settings // Ask EGL for the best config matching our video settings
@ -798,7 +798,7 @@ EGLConfig DRMContext::getBestConfig(EGLDisplay display, unsigned int bitsPerPixe
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
void DRMContext::updateSettings() void DRMContext::updateSettings()
{ {
EGLint tmp; EGLint tmp = 0;
// Update the internal context settings with the current config // Update the internal context settings with the current config
eglCheck(eglGetConfigAttrib(m_display, m_config, EGL_DEPTH_SIZE, &tmp)); eglCheck(eglGetConfigAttrib(m_display, m_config, EGL_DEPTH_SIZE, &tmp));

View File

@ -374,7 +374,7 @@ bool eventProcess(sf::Event& event)
return true; return true;
} }
ssize_t bytesRead; ssize_t bytesRead = 0;
// Check all the open file descriptors for the next event // Check all the open file descriptors for the next event
for (auto& fileDescriptor : fileDescriptors) for (auto& fileDescriptor : fileDescriptors)

View File

@ -262,7 +262,7 @@ void EglContext::createContext(EglContext* shared)
{ {
const EGLint contextVersion[] = {EGL_CONTEXT_CLIENT_VERSION, 1, EGL_NONE}; const EGLint contextVersion[] = {EGL_CONTEXT_CLIENT_VERSION, 1, EGL_NONE};
EGLContext toShared; EGLContext toShared = nullptr;
if (shared) if (shared)
toShared = shared->m_context; toShared = shared->m_context;
@ -301,7 +301,7 @@ EGLConfig EglContext::getBestConfig(EGLDisplay display, unsigned int bitsPerPixe
EglContextImpl::ensureInit(); EglContextImpl::ensureInit();
// Determine the number of available configs // Determine the number of available configs
EGLint configCount; EGLint configCount = 0;
eglCheck(eglGetConfigs(display, nullptr, 0, &configCount)); eglCheck(eglGetConfigs(display, nullptr, 0, &configCount));
// Retrieve the list of available configs // Retrieve the list of available configs
@ -316,23 +316,23 @@ EGLConfig EglContext::getBestConfig(EGLDisplay display, unsigned int bitsPerPixe
for (std::size_t i = 0; i < static_cast<std::size_t>(configCount); ++i) for (std::size_t i = 0; i < static_cast<std::size_t>(configCount); ++i)
{ {
// Check mandatory attributes // Check mandatory attributes
int surfaceType; int surfaceType = 0;
int renderableType; int renderableType = 0;
eglCheck(eglGetConfigAttrib(display, configs[i], EGL_SURFACE_TYPE, &surfaceType)); eglCheck(eglGetConfigAttrib(display, configs[i], EGL_SURFACE_TYPE, &surfaceType));
eglCheck(eglGetConfigAttrib(display, configs[i], EGL_RENDERABLE_TYPE, &renderableType)); eglCheck(eglGetConfigAttrib(display, configs[i], EGL_RENDERABLE_TYPE, &renderableType));
if (!(surfaceType & (EGL_WINDOW_BIT | EGL_PBUFFER_BIT)) || !(renderableType & EGL_OPENGL_ES_BIT)) if (!(surfaceType & (EGL_WINDOW_BIT | EGL_PBUFFER_BIT)) || !(renderableType & EGL_OPENGL_ES_BIT))
continue; continue;
// Extract the components of the current config // Extract the components of the current config
int red; int red = 0;
int green; int green = 0;
int blue; int blue = 0;
int alpha; int alpha = 0;
int depth; int depth = 0;
int stencil; int stencil = 0;
int multiSampling; int multiSampling = 0;
int samples; int samples = 0;
int caveat; int caveat = 0;
eglCheck(eglGetConfigAttrib(display, configs[i], EGL_RED_SIZE, &red)); eglCheck(eglGetConfigAttrib(display, configs[i], EGL_RED_SIZE, &red));
eglCheck(eglGetConfigAttrib(display, configs[i], EGL_GREEN_SIZE, &green)); eglCheck(eglGetConfigAttrib(display, configs[i], EGL_GREEN_SIZE, &green));
eglCheck(eglGetConfigAttrib(display, configs[i], EGL_BLUE_SIZE, &blue)); eglCheck(eglGetConfigAttrib(display, configs[i], EGL_BLUE_SIZE, &blue));
@ -344,8 +344,15 @@ EGLConfig EglContext::getBestConfig(EGLDisplay display, unsigned int bitsPerPixe
eglCheck(eglGetConfigAttrib(display, configs[i], EGL_CONFIG_CAVEAT, &caveat)); eglCheck(eglGetConfigAttrib(display, configs[i], EGL_CONFIG_CAVEAT, &caveat));
// Evaluate the config // Evaluate the config
int color = red + green + blue + alpha; const int color = red + green + blue + alpha;
int score = evaluateFormat(bitsPerPixel, settings, color, depth, stencil, multiSampling ? samples : 0, caveat == EGL_NONE, false); const int score = evaluateFormat(bitsPerPixel,
settings,
color,
depth,
stencil,
multiSampling ? samples : 0,
caveat == EGL_NONE,
false);
// If it's better than the current best, make it the new best // If it's better than the current best, make it the new best
if (score < bestScore) if (score < bestScore)
@ -410,7 +417,7 @@ XVisualInfo EglContext::selectBestVisual(::Display* xDisplay, unsigned int bitsP
EGLConfig config = getBestConfig(display, bitsPerPixel, settings); EGLConfig config = getBestConfig(display, bitsPerPixel, settings);
// Retrieve the visual id associated with this EGL config // Retrieve the visual id associated with this EGL config
EGLint nativeVisualId; EGLint nativeVisualId = 0;
eglCheck(eglGetConfigAttrib(display, config, EGL_NATIVE_VISUAL_ID, &nativeVisualId)); eglCheck(eglGetConfigAttrib(display, config, EGL_NATIVE_VISUAL_ID, &nativeVisualId));

View File

@ -216,11 +216,11 @@ void ClipboardImpl::processEvent(XEvent& windowEvent)
if ((selectionEvent.property == None) || (selectionEvent.selection != m_clipboard)) if ((selectionEvent.property == None) || (selectionEvent.selection != m_clipboard))
break; break;
Atom type; Atom type = 0;
int format; int format = 0;
unsigned long items; unsigned long items = 0;
unsigned long remainingBytes; unsigned long remainingBytes = 0;
unsigned char* data = nullptr; unsigned char* data = nullptr;
// The selection owner should have wrote the selection // The selection owner should have wrote the selection
// data to the specified window property // data to the specified window property

View File

@ -170,7 +170,7 @@ bool CursorImpl::loadFromSystem(Cursor::Type type)
{ {
release(); release();
unsigned int shape; unsigned int shape = 0;
// clang-format off // clang-format off
switch (type) switch (type)

View File

@ -95,7 +95,7 @@ std::shared_ptr<_XIM> openXim()
// We need the default (environment) locale and X locale for opening // We need the default (environment) locale and X locale for opening
// the IM and properly receiving text // the IM and properly receiving text
// First save the previous ones (this might be able to be written more elegantly?) // First save the previous ones (this might be able to be written more elegantly?)
const char* p; const char* p = nullptr;
const std::string prevLoc((p = std::setlocale(LC_ALL, nullptr)) ? p : ""); const std::string prevLoc((p = std::setlocale(LC_ALL, nullptr)) ? p : "");
const std::string prevXLoc((p = XSetLocaleModifiers(nullptr)) ? p : ""); const std::string prevXLoc((p = XSetLocaleModifiers(nullptr)) ? p : "");

View File

@ -312,7 +312,7 @@ XVisualInfo GlxContext::selectBestVisual(::Display* display, unsigned int bitsPe
const int screen = DefaultScreen(display); const int screen = DefaultScreen(display);
// Retrieve all the visuals // Retrieve all the visuals
int count; int count = 0;
auto visuals = X11Ptr<XVisualInfo[]>(XGetVisualInfo(display, 0, nullptr, &count)); auto visuals = X11Ptr<XVisualInfo[]>(XGetVisualInfo(display, 0, nullptr, &count));
if (visuals) if (visuals)
{ {
@ -326,21 +326,21 @@ XVisualInfo GlxContext::selectBestVisual(::Display* display, unsigned int bitsPe
continue; continue;
// Check mandatory attributes // Check mandatory attributes
int doubleBuffer; int doubleBuffer = 0;
glXGetConfig(display, &visuals[i], GLX_DOUBLEBUFFER, &doubleBuffer); glXGetConfig(display, &visuals[i], GLX_DOUBLEBUFFER, &doubleBuffer);
if (!doubleBuffer) if (!doubleBuffer)
continue; continue;
// Extract the components of the current visual // Extract the components of the current visual
int red; int red = 0;
int green; int green = 0;
int blue; int blue = 0;
int alpha; int alpha = 0;
int depth; int depth = 0;
int stencil; int stencil = 0;
int multiSampling; int multiSampling = 0;
int samples; int samples = 0;
int sRgb; int sRgb = 0;
glXGetConfig(display, &visuals[i], GLX_RED_SIZE, &red); glXGetConfig(display, &visuals[i], GLX_RED_SIZE, &red);
glXGetConfig(display, &visuals[i], GLX_GREEN_SIZE, &green); glXGetConfig(display, &visuals[i], GLX_GREEN_SIZE, &green);
glXGetConfig(display, &visuals[i], GLX_BLUE_SIZE, &blue); glXGetConfig(display, &visuals[i], GLX_BLUE_SIZE, &blue);
@ -406,11 +406,11 @@ XVisualInfo GlxContext::selectBestVisual(::Display* display, unsigned int bitsPe
void GlxContext::updateSettingsFromVisualInfo(XVisualInfo* visualInfo) void GlxContext::updateSettingsFromVisualInfo(XVisualInfo* visualInfo)
{ {
// Update the creation settings from the chosen format // Update the creation settings from the chosen format
int depth; int depth = 0;
int stencil; int stencil = 0;
int multiSampling; int multiSampling = 0;
int samples; int samples = 0;
int sRgb; int sRgb = 0;
glXGetConfig(m_display.get(), visualInfo, GLX_DEPTH_SIZE, &depth); glXGetConfig(m_display.get(), visualInfo, GLX_DEPTH_SIZE, &depth);
glXGetConfig(m_display.get(), visualInfo, GLX_STENCIL_SIZE, &stencil); glXGetConfig(m_display.get(), visualInfo, GLX_STENCIL_SIZE, &stencil);

View File

@ -88,12 +88,12 @@ bool isMouseButtonPressed(Mouse::Button button)
const auto display = openDisplay(); const auto display = openDisplay();
// we don't care about these but they are required // we don't care about these but they are required
::Window root; ::Window root = 0;
::Window child; ::Window child = 0;
int wx; int wx = 0;
int wy; int wy = 0;
int gx; int gx = 0;
int gy; int gy = 0;
unsigned int buttons = 0; unsigned int buttons = 0;
XQueryPointer(display.get(), DefaultRootWindow(display.get()), &root, &child, &gx, &gy, &wx, &wy, &buttons); XQueryPointer(display.get(), DefaultRootWindow(display.get()), &root, &child, &gx, &gy, &wx, &wy, &buttons);
@ -122,11 +122,11 @@ Vector2i getMousePosition()
const auto display = openDisplay(); const auto display = openDisplay();
// we don't care about these but they are required // we don't care about these but they are required
::Window root; ::Window root = 0;
::Window child; ::Window child = 0;
int x; int x = 0;
int y; int y = 0;
unsigned int buttons; unsigned int buttons = 0;
int gx = 0; int gx = 0;
int gy = 0; int gy = 0;
@ -146,11 +146,11 @@ Vector2i getMousePosition(const WindowBase& relativeTo)
const auto display = openDisplay(); const auto display = openDisplay();
// we don't care about these but they are required // we don't care about these but they are required
::Window root; ::Window root = 0;
::Window child; ::Window child = 0;
int gx; int gx = 0;
int gy; int gy = 0;
unsigned int buttons; unsigned int buttons = 0;
int x = 0; int x = 0;
int y = 0; int y = 0;

View File

@ -208,7 +208,7 @@ void updatePluggedList(udev_device* udevDevice = nullptr)
} }
udev_list_entry* devices = udev_enumerate_get_list_entry(udevEnumerator); udev_list_entry* devices = udev_enumerate_get_list_entry(udevEnumerator);
udev_list_entry* device; udev_list_entry* device = nullptr;
udev_list_entry_foreach(device, devices) udev_list_entry_foreach(device, devices)
{ {
@ -589,14 +589,14 @@ JoystickCaps JoystickImpl::getCapabilities() const
return caps; return caps;
// Get the number of buttons // Get the number of buttons
char buttonCount; char buttonCount = 0;
ioctl(m_file, JSIOCGBUTTONS, &buttonCount); ioctl(m_file, JSIOCGBUTTONS, &buttonCount);
caps.buttonCount = static_cast<unsigned int>(buttonCount); caps.buttonCount = static_cast<unsigned int>(buttonCount);
if (caps.buttonCount > Joystick::ButtonCount) if (caps.buttonCount > Joystick::ButtonCount)
caps.buttonCount = Joystick::ButtonCount; caps.buttonCount = Joystick::ButtonCount;
// Get the supported axes // Get the supported axes
char axesCount; char axesCount = 0;
ioctl(m_file, JSIOCGAXES, &axesCount); ioctl(m_file, JSIOCGAXES, &axesCount);
for (int i = 0; i < axesCount; ++i) for (int i = 0; i < axesCount; ++i)
{ {

View File

@ -64,7 +64,7 @@ std::vector<VideoMode> VideoModeImpl::getFullscreenModes()
const int screen = DefaultScreen(display.get()); const int screen = DefaultScreen(display.get());
// Check if the XRandR extension is present // Check if the XRandR extension is present
int version; int version = 0;
if (XQueryExtension(display.get(), "RANDR", &version, &version, &version)) if (XQueryExtension(display.get(), "RANDR", &version, &version, &version))
{ {
// Get the current configuration // Get the current configuration
@ -72,8 +72,8 @@ std::vector<VideoMode> VideoModeImpl::getFullscreenModes()
if (config) if (config)
{ {
// Get the available screen sizes // Get the available screen sizes
int nbSizes; int nbSizes = 0;
XRRScreenSize* sizes = XRRConfigSizes(config.get(), &nbSizes); XRRScreenSize* sizes = XRRConfigSizes(config.get(), &nbSizes);
if (sizes && (nbSizes > 0)) if (sizes && (nbSizes > 0))
{ {
// Get the list of supported depths // Get the list of supported depths
@ -91,7 +91,7 @@ std::vector<VideoMode> VideoModeImpl::getFullscreenModes()
static_cast<unsigned int>(sizes[j].height)}, static_cast<unsigned int>(sizes[j].height)},
static_cast<unsigned int>(depths[i])); static_cast<unsigned int>(depths[i]));
Rotation currentRotation; Rotation currentRotation = 0;
XRRConfigRotations(config.get(), &currentRotation); XRRConfigRotations(config.get(), &currentRotation);
if (currentRotation == RR_Rotate_90 || currentRotation == RR_Rotate_270) if (currentRotation == RR_Rotate_90 || currentRotation == RR_Rotate_270)
@ -141,7 +141,7 @@ VideoMode VideoModeImpl::getDesktopMode()
const int screen = DefaultScreen(display.get()); const int screen = DefaultScreen(display.get());
// Check if the XRandR extension is present // Check if the XRandR extension is present
int version; int version = 0;
if (XQueryExtension(display.get(), "RANDR", &version, &version, &version)) if (XQueryExtension(display.get(), "RANDR", &version, &version, &version))
{ {
// Get the current configuration // Get the current configuration
@ -149,19 +149,19 @@ VideoMode VideoModeImpl::getDesktopMode()
if (config) if (config)
{ {
// Get the current video mode // Get the current video mode
Rotation currentRotation; Rotation currentRotation = 0;
const int currentMode = XRRConfigCurrentConfiguration(config.get(), &currentRotation); const int currentMode = XRRConfigCurrentConfiguration(config.get(), &currentRotation);
// Get the available screen sizes // Get the available screen sizes
int nbSizes; int nbSizes = 0;
XRRScreenSize* sizes = XRRConfigSizes(config.get(), &nbSizes); XRRScreenSize* sizes = XRRConfigSizes(config.get(), &nbSizes);
if (sizes && (nbSizes > 0)) if (sizes && (nbSizes > 0))
{ {
desktopMode = VideoMode({static_cast<unsigned int>(sizes[currentMode].width), desktopMode = VideoMode({static_cast<unsigned int>(sizes[currentMode].width),
static_cast<unsigned int>(sizes[currentMode].height)}, static_cast<unsigned int>(sizes[currentMode].height)},
static_cast<unsigned int>(DefaultDepth(display.get(), screen))); static_cast<unsigned int>(DefaultDepth(display.get(), screen)));
Rotation modeRotation; Rotation modeRotation = 0;
XRRConfigRotations(config.get(), &modeRotation); XRRConfigRotations(config.get(), &modeRotation);
if (modeRotation == RR_Rotate_90 || modeRotation == RR_Rotate_270) if (modeRotation == RR_Rotate_90 || modeRotation == RR_Rotate_270)

View File

@ -169,11 +169,11 @@ bool ewmhSupported()
const auto display = sf::priv::openDisplay(); const auto display = sf::priv::openDisplay();
Atom actualType; Atom actualType = 0;
int actualFormat; int actualFormat = 0;
unsigned long numItems; unsigned long numItems = 0;
unsigned long numBytes; unsigned long numBytes = 0;
unsigned char* data; unsigned char* data = nullptr;
int result = XGetWindowProperty(display.get(), int result = XGetWindowProperty(display.get(),
DefaultRootWindow(display.get()), DefaultRootWindow(display.get()),
@ -289,10 +289,10 @@ bool ewmhSupported()
// Get the parent window. // Get the parent window.
::Window getParentWindow(::Display* disp, ::Window win) ::Window getParentWindow(::Display* disp, ::Window win)
{ {
::Window root; ::Window root = 0;
::Window parent; ::Window parent = 0;
::Window* children = nullptr; ::Window* children = nullptr;
unsigned int numChildren; unsigned int numChildren = 0;
XQueryTree(disp, win, &root, &parent, &children, &numChildren); XQueryTree(disp, win, &root, &parent, &children, &numChildren);
@ -315,11 +315,11 @@ bool getEWMHFrameExtents(::Display* disp, ::Window win, long& xFrameExtent, long
return false; return false;
bool gotFrameExtents = false; bool gotFrameExtents = false;
Atom actualType; Atom actualType = 0;
int actualFormat; int actualFormat = 0;
unsigned long numItems; unsigned long numItems = 0;
unsigned long numBytesLeft; unsigned long numBytesLeft = 0;
unsigned char* data = nullptr; unsigned char* data = nullptr;
const int result = XGetWindowProperty(disp, const int result = XGetWindowProperty(disp,
win, win,
@ -781,9 +781,9 @@ Vector2i WindowImplX11::getPosition() const
// window actually is, but not necessarily to where we told it to // window actually is, but not necessarily to where we told it to
// go using setPosition() and XMoveWindow(). To have the two match // go using setPosition() and XMoveWindow(). To have the two match
// as expected, we may have to subtract decorations and borders. // as expected, we may have to subtract decorations and borders.
::Window child; ::Window child = 0;
int xAbsRelToRoot; int xAbsRelToRoot = 0;
int yAbsRelToRoot; int yAbsRelToRoot = 0;
XTranslateCoordinates(m_display.get(), m_window, DefaultRootWindow(m_display.get()), 0, 0, &xAbsRelToRoot, &yAbsRelToRoot, &child); XTranslateCoordinates(m_display.get(), m_window, DefaultRootWindow(m_display.get()), 0, 0, &xAbsRelToRoot, &yAbsRelToRoot, &child);
@ -796,8 +796,8 @@ Vector2i WindowImplX11::getPosition() const
// CASE 2: most modern WMs support EWMH and can define _NET_FRAME_EXTENTS // CASE 2: most modern WMs support EWMH and can define _NET_FRAME_EXTENTS
// with the exact frame size to subtract, so if present, we prefer it and // with the exact frame size to subtract, so if present, we prefer it and
// query it first. According to spec, this already includes any borders. // query it first. According to spec, this already includes any borders.
long xFrameExtent; long xFrameExtent = 0;
long yFrameExtent; long yFrameExtent = 0;
if (getEWMHFrameExtents(m_display.get(), m_window, xFrameExtent, yFrameExtent)) if (getEWMHFrameExtents(m_display.get(), m_window, xFrameExtent, yFrameExtent))
{ {
@ -830,12 +830,12 @@ Vector2i WindowImplX11::getPosition() const
// Get final X/Y coordinates: take the relative position to // Get final X/Y coordinates: take the relative position to
// the root of the furthest ancestor window. // the root of the furthest ancestor window.
int xRelToRoot; int xRelToRoot = 0;
int yRelToRoot; int yRelToRoot = 0;
unsigned int width; unsigned int width = 0;
unsigned int height; unsigned int height = 0;
unsigned int borderWidth; unsigned int borderWidth = 0;
unsigned int depth; unsigned int depth = 0;
XGetGeometry(m_display.get(), ancestor, &root, &xRelToRoot, &yRelToRoot, &width, &height, &borderWidth, &depth); XGetGeometry(m_display.get(), ancestor, &root, &xRelToRoot, &yRelToRoot, &width, &height, &borderWidth, &depth);
@ -1272,8 +1272,8 @@ void WindowImplX11::setVideoMode(const VideoMode& mode)
return; return;
// Check if the XRandR extension is present // Check if the XRandR extension is present
int xRandRMajor; int xRandRMajor = 0;
int xRandRMinor; int xRandRMinor = 0;
if (!checkXRandR(xRandRMajor, xRandRMinor)) if (!checkXRandR(xRandRMajor, xRandRMinor))
{ {
// XRandR extension is not supported: we cannot use fullscreen mode // XRandR extension is not supported: we cannot use fullscreen mode
@ -1312,7 +1312,7 @@ void WindowImplX11::setVideoMode(const VideoMode& mode)
// Find RRMode to set // Find RRMode to set
bool modeFound = false; bool modeFound = false;
RRMode xRandMode; RRMode xRandMode = 0;
for (int i = 0; (i < res->nmode) && !modeFound; ++i) for (int i = 0; (i < res->nmode) && !modeFound; ++i)
{ {
@ -1363,8 +1363,8 @@ void WindowImplX11::resetVideoMode()
{ {
// Try to set old configuration // Try to set old configuration
// Check if the XRandR extension // Check if the XRandR extension
int xRandRMajor; int xRandRMajor = 0;
int xRandRMinor; int xRandRMinor = 0;
if (checkXRandR(xRandRMajor, xRandRMinor)) if (checkXRandR(xRandRMajor, xRandRMinor))
{ {
auto res = X11Ptr<XRRScreenResources>( auto res = X11Ptr<XRRScreenResources>(
@ -1383,7 +1383,7 @@ void WindowImplX11::resetVideoMode()
return; return;
} }
RROutput output; RROutput output = 0;
// if version >= 1.3 get the primary screen else take the first screen // if version >= 1.3 get the primary screen else take the first screen
if ((xRandRMajor == 1 && xRandRMinor >= 3) || xRandRMajor > 1) if ((xRandRMajor == 1 && xRandRMinor >= 3) || xRandRMajor > 1)
@ -1841,7 +1841,7 @@ bool WindowImplX11::processEvent(XEvent& windowEvent)
#ifdef X_HAVE_UTF8_STRING #ifdef X_HAVE_UTF8_STRING
if (m_inputContext) if (m_inputContext)
{ {
Status status; Status status = 0;
std::uint8_t keyBuffer[64]; std::uint8_t keyBuffer[64];
const int length = Xutf8LookupString(m_inputContext, const int length = Xutf8LookupString(m_inputContext,
@ -2089,7 +2089,7 @@ bool WindowImplX11::processEvent(XEvent& windowEvent)
bool WindowImplX11::checkXRandR(int& xRandRMajor, int& xRandRMinor) bool WindowImplX11::checkXRandR(int& xRandRMajor, int& xRandRMinor)
{ {
// Check if the XRandR extension is present // Check if the XRandR extension is present
int version; int version = 0;
if (!XQueryExtension(m_display.get(), "RANDR", &version, &version, &version)) if (!XQueryExtension(m_display.get(), "RANDR", &version, &version, &version))
{ {
err() << "XRandR extension is not supported" << std::endl; err() << "XRandR extension is not supported" << std::endl;
@ -2145,8 +2145,8 @@ Vector2i WindowImplX11::getPrimaryMonitorPosition()
} }
// Get xRandr version // Get xRandr version
int xRandRMajor; int xRandRMajor = 0;
int xRandRMinor; int xRandRMinor = 0;
if (!checkXRandR(xRandRMajor, xRandRMinor)) if (!checkXRandR(xRandRMajor, xRandRMinor))
xRandRMajor = xRandRMinor = 0; xRandRMajor = xRandRMinor = 0;

View File

@ -120,7 +120,7 @@ bool lazyUpdates = false;
// Get a system error string from an error code // Get a system error string from an error code
std::string getErrorString(DWORD error) std::string getErrorString(DWORD error)
{ {
PTCHAR buffer; PTCHAR buffer = nullptr;
if (FormatMessage(FORMAT_MESSAGE_MAX_WIDTH_MASK | FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM, if (FormatMessage(FORMAT_MESSAGE_MAX_WIDTH_MASK | FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
nullptr, nullptr,
@ -142,9 +142,9 @@ sf::String getDeviceName(unsigned int index, JOYCAPS caps)
// Give the joystick a default name // Give the joystick a default name
sf::String joystickDescription = "Unknown Joystick"; sf::String joystickDescription = "Unknown Joystick";
LONG result; LONG result = 0;
HKEY rootKey; HKEY rootKey = nullptr;
HKEY currentKey; HKEY currentKey = nullptr;
std::basic_string<TCHAR> subkey; std::basic_string<TCHAR> subkey;
subkey = REGSTR_PATH_JOYCONFIG; subkey = REGSTR_PATH_JOYCONFIG;

View File

@ -103,7 +103,7 @@ namespace sf::priv
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
String getErrorString(DWORD errorCode) String getErrorString(DWORD errorCode)
{ {
PTCHAR buffer; PTCHAR buffer = nullptr;
if (FormatMessage(FORMAT_MESSAGE_MAX_WIDTH_MASK | FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | if (FormatMessage(FORMAT_MESSAGE_MAX_WIDTH_MASK | FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM |
FORMAT_MESSAGE_IGNORE_INSERTS, FORMAT_MESSAGE_IGNORE_INSERTS,
nullptr, nullptr,

View File

@ -428,8 +428,8 @@ void WindowImplWin32::setKeyRepeatEnabled(bool enabled)
void WindowImplWin32::requestFocus() void WindowImplWin32::requestFocus()
{ {
// Allow focus stealing only within the same process; compare PIDs of current and foreground window // Allow focus stealing only within the same process; compare PIDs of current and foreground window
DWORD thisPid; DWORD thisPid = 0;
DWORD foregroundPid; DWORD foregroundPid = 0;
GetWindowThreadProcessId(m_handle, &thisPid); GetWindowThreadProcessId(m_handle, &thisPid);
GetWindowThreadProcessId(GetForegroundWindow(), &foregroundPid); GetWindowThreadProcessId(GetForegroundWindow(), &foregroundPid);

View File

@ -212,8 +212,8 @@ void EaglContext::recreateRenderBuffers(SFView* glView)
: GL_DEPTH_COMPONENT16_OES; : GL_DEPTH_COMPONENT16_OES;
// Get the size of the color-buffer (which fits the current size of the GL view) // Get the size of the color-buffer (which fits the current size of the GL view)
GLint width; GLint width = 0;
GLint height; GLint height = 0;
glGetRenderbufferParameterivOESFunc(GL_RENDERBUFFER_OES, GL_RENDERBUFFER_WIDTH_OES, &width); glGetRenderbufferParameterivOESFunc(GL_RENDERBUFFER_OES, GL_RENDERBUFFER_WIDTH_OES, &width);
glGetRenderbufferParameterivOESFunc(GL_RENDERBUFFER_OES, GL_RENDERBUFFER_HEIGHT_OES, &height); glGetRenderbufferParameterivOESFunc(GL_RENDERBUFFER_OES, GL_RENDERBUFFER_HEIGHT_OES, &height);

View File

@ -80,8 +80,8 @@
const char* end = utf8 + std::strlen(utf8); const char* end = utf8 + std::strlen(utf8);
while (utf8 < end) while (utf8 < end)
{ {
std::uint32_t character; std::uint32_t character = 0;
utf8 = sf::Utf8::decode(utf8, end, character); utf8 = sf::Utf8::decode(utf8, end, character);
[[SFAppDelegate getInstance] notifyCharacter:character]; [[SFAppDelegate getInstance] notifyCharacter:character];
} }
} }
@ -90,7 +90,7 @@
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
- (void)touchesBegan:(NSSet*)touches withEvent:(UIEvent*)event - (void)touchesBegan:(NSSet*)touches withEvent:(UIEvent*)event
{ {
for (UITouch* touch in touches) for (UITouch* touch in touches) // NOLINT(cppcoreguidelines-init-variables)
{ {
// find an empty slot for the new touch // find an empty slot for the new touch
NSUInteger index = [self.touches indexOfObject:[NSNull null]]; NSUInteger index = [self.touches indexOfObject:[NSNull null]];
@ -117,7 +117,7 @@
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
- (void)touchesMoved:(NSSet*)touches withEvent:(UIEvent*)event - (void)touchesMoved:(NSSet*)touches withEvent:(UIEvent*)event
{ {
for (UITouch* touch in touches) for (UITouch* touch in touches) // NOLINT(cppcoreguidelines-init-variables)
{ {
// find the touch // find the touch
NSUInteger index = [self.touches indexOfObject:touch]; NSUInteger index = [self.touches indexOfObject:touch];
@ -137,7 +137,7 @@
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
- (void)touchesEnded:(NSSet*)touches withEvent:(UIEvent*)event - (void)touchesEnded:(NSSet*)touches withEvent:(UIEvent*)event
{ {
for (UITouch* touch in touches) for (UITouch* touch in touches) // NOLINT(cppcoreguidelines-init-variables)
{ {
// find the touch // find the touch
NSUInteger index = [self.touches indexOfObject:touch]; NSUInteger index = [self.touches indexOfObject:touch];

View File

@ -755,7 +755,7 @@ void HIDInputManager::initializeKeyboard()
} }
auto* const keyboards = static_cast<NSSet*>(underlying); // Toll-Free Bridge auto* const keyboards = static_cast<NSSet*>(underlying); // Toll-Free Bridge
for (id keyboard in keyboards) for (id keyboard in keyboards) // NOLINT(cppcoreguidelines-init-variables)
loadKeyboard(static_cast<IOHIDDeviceRef>(keyboard)); loadKeyboard(static_cast<IOHIDDeviceRef>(keyboard));
CFRelease(underlying); CFRelease(underlying);
@ -776,7 +776,7 @@ void HIDInputManager::loadKeyboard(IOHIDDeviceRef keyboard)
} }
auto* const keys = static_cast<NSArray*>(underlying); // Toll-Free Bridge auto* const keys = static_cast<NSArray*>(underlying); // Toll-Free Bridge
for (id key in keys) for (id key in keys) // NOLINT(cppcoreguidelines-init-variables)
{ {
auto* elem = static_cast<IOHIDElementRef>(key); auto* elem = static_cast<IOHIDElementRef>(key);
if (IOHIDElementGetUsagePage(elem) == kHIDPage_KeyboardOrKeypad) if (IOHIDElementGetUsagePage(elem) == kHIDPage_KeyboardOrKeypad)

View File

@ -71,7 +71,7 @@ SFOpenGLView* getSFOpenGLViewFromSFMLWindow(const sf::WindowBase& window)
if ([view isKindOfClass:[NSView class]]) if ([view isKindOfClass:[NSView class]])
{ {
NSArray* const subviews = [view subviews]; NSArray* const subviews = [view subviews];
for (NSView* subview in subviews) for (NSView* subview in subviews) // NOLINT(cppcoreguidelines-init-variables)
{ {
if ([subview isKindOfClass:[SFOpenGLView class]]) if ([subview isKindOfClass:[SFOpenGLView class]])
{ {
@ -92,7 +92,7 @@ SFOpenGLView* getSFOpenGLViewFromSFMLWindow(const sf::WindowBase& window)
{ {
// If system handle is a view then from a subview of kind SFOpenGLView. // If system handle is a view then from a subview of kind SFOpenGLView.
NSArray* const subviews = [nsHandle subviews]; NSArray* const subviews = [nsHandle subviews];
for (NSView* subview in subviews) for (NSView* subview in subviews) // NOLINT(cppcoreguidelines-init-variables)
{ {
if ([subview isKindOfClass:[SFOpenGLView class]]) if ([subview isKindOfClass:[SFOpenGLView class]])
{ {

View File

@ -71,7 +71,7 @@ unsigned int getDeviceUint(IOHIDDeviceRef ref, CFStringRef prop, unsigned int in
CFTypeRef typeRef = IOHIDDeviceGetProperty(ref, prop); CFTypeRef typeRef = IOHIDDeviceGetProperty(ref, prop);
if (typeRef && (CFGetTypeID(typeRef) == CFNumberGetTypeID())) if (typeRef && (CFGetTypeID(typeRef) == CFNumberGetTypeID()))
{ {
SInt32 value; SInt32 value = 0;
CFNumberGetValue(static_cast<CFNumberRef>(typeRef), kCFNumberSInt32Type, &value); CFNumberGetValue(static_cast<CFNumberRef>(typeRef), kCFNumberSInt32Type, &value);
return static_cast<unsigned int>(value); return static_cast<unsigned int>(value);
} }

View File

@ -60,7 +60,7 @@ NSString* sfStringToNSString(const sf::String& string)
const auto length = static_cast<std::uint32_t>(string.getSize() * sizeof(std::uint32_t)); const auto length = static_cast<std::uint32_t>(string.getSize() * sizeof(std::uint32_t));
const void* data = reinterpret_cast<const void*>(string.getData()); const void* data = reinterpret_cast<const void*>(string.getData());
NSStringEncoding encoding; NSStringEncoding encoding = 0;
if (NSHostByteOrder() == NS_LittleEndian) if (NSHostByteOrder() == NS_LittleEndian)
encoding = NSUTF32LittleEndianStringEncoding; encoding = NSUTF32LittleEndianStringEncoding;
else else

View File

@ -271,7 +271,7 @@ TEST_CASE("[Network] sf::Packet")
SECTION("onSend") SECTION("onSend")
{ {
Packet packet; Packet packet;
std::size_t size; std::size_t size = 0;
CHECK(packet.onSend(size) == nullptr); CHECK(packet.onSend(size) == nullptr);
CHECK(size == 0); CHECK(size == 0);