Skip to content

Commit

Permalink
Require that variables are initialized
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisThrasher committed Apr 27, 2024
1 parent 5da2864 commit 1ba5a1e
Show file tree
Hide file tree
Showing 42 changed files with 222 additions and 216 deletions.
1 change: 0 additions & 1 deletion .clang-tidy
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ Checks: >
-cppcoreguidelines-avoid-do-while,
-cppcoreguidelines-avoid-magic-numbers,
-cppcoreguidelines-avoid-non-const-global-variables,
-cppcoreguidelines-init-variables,
-cppcoreguidelines-macro-to-enum,
-cppcoreguidelines-macro-usage,
-cppcoreguidelines-narrowing-conversions,
Expand Down
4 changes: 2 additions & 2 deletions examples/sockets/Sockets.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ int main()
const unsigned short port = 50001;

// TCP, UDP or connected UDP ?
char protocol;
char protocol = 0;
std::cout << "Do you want to use TCP (t) or UDP (u)? ";
std::cin >> protocol;

// Client or server ?
char who;
char who = 0;
std::cout << "Do you want to be a server (s) or a client (c)? ";
std::cin >> who;

Expand Down
4 changes: 2 additions & 2 deletions examples/sockets/TCP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ void runTcpServer(unsigned short port)

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

// Receive a message from the server
char in[128];
std::size_t received;
std::size_t received = 0;
if (socket.receive(in, sizeof(in), received) != sf::Socket::Status::Done)
return;
std::cout << "Message received from the server: " << std::quoted(in) << std::endl;
Expand Down
8 changes: 4 additions & 4 deletions examples/sockets/UDP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ void runUdpServer(unsigned short port)

// Wait for a message
char in[128];
std::size_t received;
std::size_t received = 0;
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)
return;
std::cout << "Message received from client " << sender.value() << ": " << std::quoted(in) << std::endl;
Expand Down Expand Up @@ -66,9 +66,9 @@ void runUdpClient(unsigned short port)

// Receive an answer from anyone (but most likely from the server)
char in[128];
std::size_t received;
std::size_t received = 0;
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)
return;
std::cout << "Message received from " << sender.value() << ": " << std::quoted(in) << std::endl;
Expand Down
4 changes: 2 additions & 2 deletions examples/sound_capture/SoundCapture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ int main()
}

// 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::cin >> sampleRate;
std::cin.ignore(10000, '\n');
Expand Down Expand Up @@ -87,7 +87,7 @@ int main()
<< " " << buffer.getChannelCount() << " channels" << std::endl;

// 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::cin >> choice;
std::cin.ignore(10000, '\n');
Expand Down
2 changes: 1 addition & 1 deletion examples/voip/Server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ class NetworkAudioStream : public sf::SoundStream
break;

// Extract the message ID
std::uint8_t id;
std::uint8_t id = 0;
packet >> id;

if (id == serverAudioData)
Expand Down
2 changes: 1 addition & 1 deletion examples/voip/VoIP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ int main()
const unsigned short port = 2435;

// Client or server ?
char who;
char who = 0;
std::cout << "Do you want to be a server ('s') or a client ('c')? ";
std::cin >> who;

Expand Down
14 changes: 7 additions & 7 deletions examples/vulkan/Vulkan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1352,7 +1352,7 @@ class VulkanExample
commandBufferAllocateInfo.commandPool = commandPool;
commandBufferAllocateInfo.commandBufferCount = 1;

VkCommandBuffer commandBuffer;
VkCommandBuffer commandBuffer = nullptr;

if (vkAllocateCommandBuffers(device, &commandBufferAllocateInfo, &commandBuffer) != VK_SUCCESS)
return false;
Expand Down Expand Up @@ -1458,7 +1458,7 @@ class VulkanExample
return;
}

void* ptr;
void* ptr = nullptr;

// Map the buffer into our address space
if (vkMapMemory(device, stagingBufferMemory, 0, sizeof(vertexData), 0, &ptr) != VK_SUCCESS)
Expand Down Expand Up @@ -1537,7 +1537,7 @@ class VulkanExample
return;
}

void* ptr;
void* ptr = nullptr;

// Map the buffer into our address space
if (vkMapMemory(device, stagingBufferMemory, 0, sizeof(indexData), 0, &ptr) != VK_SUCCESS)
Expand Down Expand Up @@ -1689,7 +1689,7 @@ class VulkanExample
commandBufferAllocateInfo.commandPool = commandPool;
commandBufferAllocateInfo.commandBufferCount = 1;

VkCommandBuffer commandBuffer;
VkCommandBuffer commandBuffer = nullptr;

if (vkAllocateCommandBuffers(device, &commandBufferAllocateInfo, &commandBuffer) != VK_SUCCESS)
{
Expand Down Expand Up @@ -1820,7 +1820,7 @@ class VulkanExample
stagingBuffer,
stagingBufferMemory);

void* ptr;
void* ptr = nullptr;

// Map the buffer into our address space
if (vkMapMemory(device, stagingBufferMemory, 0, imageSize, 0, &ptr) != VK_SUCCESS)
Expand Down Expand Up @@ -1862,7 +1862,7 @@ class VulkanExample
commandBufferAllocateInfo.commandPool = commandPool;
commandBufferAllocateInfo.commandBufferCount = 1;

VkCommandBuffer commandBuffer;
VkCommandBuffer commandBuffer = nullptr;

if (vkAllocateCommandBuffers(device, &commandBufferAllocateInfo, &commandBuffer) != VK_SUCCESS)
{
Expand Down Expand Up @@ -2431,7 +2431,7 @@ class VulkanExample

matrixPerspective(projection, fov, aspect, nearPlane, farPlane);

char* ptr;
char* ptr = nullptr;

// 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)) !=
Expand Down
58 changes: 29 additions & 29 deletions include/SFML/System/Utf.inl
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ Out Utf<8>::encode(std::uint32_t input, Out output, std::uint8_t replacement)
template <typename In>
In Utf<8>::next(In begin, In end)
{
std::uint32_t codepoint;
std::uint32_t codepoint = 0;
return decode(begin, end, codepoint);
}

Expand Down Expand Up @@ -225,9 +225,9 @@ Out Utf<8>::toAnsi(In begin, In end, Out output, char replacement, const std::lo
{
while (begin < end)
{
std::uint32_t codepoint;
begin = decode(begin, end, codepoint);
output = Utf<32>::encodeAnsi(codepoint, output, replacement, locale);
std::uint32_t codepoint = 0;
begin = decode(begin, end, codepoint);
output = Utf<32>::encodeAnsi(codepoint, output, replacement, locale);
}

return output;
Expand All @@ -240,9 +240,9 @@ Out Utf<8>::toWide(In begin, In end, Out output, wchar_t replacement)
{
while (begin < end)
{
std::uint32_t codepoint;
begin = decode(begin, end, codepoint);
output = Utf<32>::encodeWide(codepoint, output, replacement);
std::uint32_t codepoint = 0;
begin = decode(begin, end, codepoint);
output = Utf<32>::encodeWide(codepoint, output, replacement);
}

return output;
Expand All @@ -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
while (begin < end)
{
std::uint32_t codepoint;
begin = decode(begin, end, codepoint);
*output++ = codepoint < 256 ? static_cast<char>(codepoint) : replacement;
std::uint32_t codepoint = 0;
begin = decode(begin, end, codepoint);
*output++ = codepoint < 256 ? static_cast<char>(codepoint) : replacement;
}

return output;
Expand All @@ -280,9 +280,9 @@ Out Utf<8>::toUtf16(In begin, In end, Out output)
{
while (begin < end)
{
std::uint32_t codepoint;
begin = decode(begin, end, codepoint);
output = Utf<16>::encode(codepoint, output);
std::uint32_t codepoint = 0;
begin = decode(begin, end, codepoint);
output = Utf<16>::encode(codepoint, output);
}

return output;
Expand All @@ -295,9 +295,9 @@ Out Utf<8>::toUtf32(In begin, In end, Out output)
{
while (begin < end)
{
std::uint32_t codepoint;
begin = decode(begin, end, codepoint);
*output++ = codepoint;
std::uint32_t codepoint = 0;
begin = decode(begin, end, codepoint);
*output++ = codepoint;
}

return output;
Expand Down Expand Up @@ -385,7 +385,7 @@ Out Utf<16>::encode(std::uint32_t input, Out output, std::uint16_t replacement)
template <typename In>
In Utf<16>::next(In begin, In end)
{
std::uint32_t codepoint;
std::uint32_t codepoint = 0;
return decode(begin, end, codepoint);
}

Expand Down Expand Up @@ -449,9 +449,9 @@ Out Utf<16>::toAnsi(In begin, In end, Out output, char replacement, const std::l
{
while (begin < end)
{
std::uint32_t codepoint;
begin = decode(begin, end, codepoint);
output = Utf<32>::encodeAnsi(codepoint, output, replacement, locale);
std::uint32_t codepoint = 0;
begin = decode(begin, end, codepoint);
output = Utf<32>::encodeAnsi(codepoint, output, replacement, locale);
}

return output;
Expand All @@ -464,9 +464,9 @@ Out Utf<16>::toWide(In begin, In end, Out output, wchar_t replacement)
{
while (begin < end)
{
std::uint32_t codepoint;
begin = decode(begin, end, codepoint);
output = Utf<32>::encodeWide(codepoint, output, replacement);
std::uint32_t codepoint = 0;
begin = decode(begin, end, codepoint);
output = Utf<32>::encodeWide(codepoint, output, replacement);
}

return output;
Expand Down Expand Up @@ -495,9 +495,9 @@ Out Utf<16>::toUtf8(In begin, In end, Out output)
{
while (begin < end)
{
std::uint32_t codepoint;
begin = decode(begin, end, codepoint);
output = Utf<8>::encode(codepoint, output);
std::uint32_t codepoint = 0;
begin = decode(begin, end, codepoint);
output = Utf<8>::encode(codepoint, output);
}

return output;
Expand All @@ -518,9 +518,9 @@ Out Utf<16>::toUtf32(In begin, In end, Out output)
{
while (begin < end)
{
std::uint32_t codepoint;
begin = decode(begin, end, codepoint);
*output++ = codepoint;
std::uint32_t codepoint = 0;
begin = decode(begin, end, codepoint);
*output++ = codepoint;
}

return output;
Expand Down
2 changes: 1 addition & 1 deletion src/SFML/Audio/AudioDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ AudioDevice::AudioDevice()
}

// 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)
{
Expand Down
6 changes: 3 additions & 3 deletions src/SFML/Audio/MiniaudioUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,9 @@ struct SavedSettings
////////////////////////////////////////////////////////////
SavedSettings saveSettings(const ma_sound& sound)
{
float innerAngle;
float outerAngle;
float outerGain;
float innerAngle = 0;
float outerAngle = 0;
float outerGain = 0;
ma_sound_get_cone(&sound, &innerAngle, &outerAngle, &outerGain);

return SavedSettings{ma_sound_get_pitch(&sound),
Expand Down
4 changes: 2 additions & 2 deletions src/SFML/Audio/SoundRecorder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,8 @@ struct SoundRecorder::Impl
}

// Enumerate the capture devices
ma_device_info* deviceInfos;
ma_uint32 deviceCount;
ma_device_info* deviceInfos = nullptr;
ma_uint32 deviceCount = 0;

if (auto result = ma_context_get_devices(&context, nullptr, nullptr, &deviceInfos, &deviceCount);
result != MA_SUCCESS)
Expand Down
8 changes: 4 additions & 4 deletions src/SFML/Graphics/Font.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ bool Font::loadFromFile(const std::filesystem::path& filename)
}

// 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)
{
err() << "Failed to load font (failed to create the font face)\n" << formatDebugPathInfo(filename) << std::endl;
Expand Down Expand Up @@ -201,7 +201,7 @@ bool Font::loadFromMemory(const void* data, std::size_t sizeInBytes)
}

// Load the new font face from the specified file
FT_Face face;
FT_Face face = nullptr;
if (FT_New_Memory_Face(fontHandles->library,
reinterpret_cast<const FT_Byte*>(data),
static_cast<FT_Long>(sizeInBytes),
Expand Down Expand Up @@ -276,7 +276,7 @@ bool Font::loadFromStream(InputStream& stream)
args.driver = nullptr;

// 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)
{
err() << "Failed to load font from stream (failed to create the font face)" << std::endl;
Expand Down Expand Up @@ -520,7 +520,7 @@ Glyph Font::loadGlyph(std::uint32_t codePoint, unsigned int characterSize, bool
return glyph;

// Retrieve the glyph
FT_Glyph glyphDesc;
FT_Glyph glyphDesc = nullptr;
if (FT_Get_Glyph(face->glyph, &glyphDesc) != 0)
return glyph;

Expand Down
2 changes: 1 addition & 1 deletion src/SFML/Graphics/RenderTextureImplFBO.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,7 @@ bool RenderTextureImplFBO::createFrameBuffer()
glCheck(GLEXT_glFramebufferTexture2D(GLEXT_GL_FRAMEBUFFER, GLEXT_GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, m_textureId, 0));

// A final check, just to be sure...
GLenum status;
GLenum status = 0;
glCheck(status = GLEXT_glCheckFramebufferStatus(GLEXT_GL_FRAMEBUFFER));
if (status != GLEXT_GL_FRAMEBUFFER_COMPLETE)
{
Expand Down
Loading

0 comments on commit 1ba5a1e

Please sign in to comment.