From 6bd9e3eca8172098be35ea3b33c5901048c8b7e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Janiszewski?= Date: Fri, 27 Jan 2017 07:35:48 +0100 Subject: [PATCH] Make sure various fields are initialised properly --- src/openrct2/core/FileScanner.cpp | 6 +++--- .../drawing/engines/SoftwareDrawingEngine.cpp | 14 ++++++------- .../engines/opengl/OpenGLDrawingEngine.cpp | 18 ++++++++--------- .../drawing/engines/opengl/SwapFramebuffer.h | 12 +++++------ .../drawing/engines/opengl/TextureCache.cpp | 4 ---- .../drawing/engines/opengl/TextureCache.h | 20 ++++++++++--------- .../network/NetworkServerAdvertiser.cpp | 4 ++-- src/openrct2/network/network.cpp | 2 +- src/openrct2/network/network.h | 4 ++-- src/openrct2/object/ObjectRepository.cpp | 9 ++++----- 10 files changed, 44 insertions(+), 49 deletions(-) diff --git a/src/openrct2/core/FileScanner.cpp b/src/openrct2/core/FileScanner.cpp index 2189d15106..afce2fce62 100644 --- a/src/openrct2/core/FileScanner.cpp +++ b/src/openrct2/core/FileScanner.cpp @@ -58,8 +58,8 @@ struct DirectoryChild std::string Name; // Files only - uint64 Size; - uint64 LastModified; + uint64 Size = 0; + uint64 LastModified = 0; }; static uint32 GetPathChecksum(const utf8 * path); @@ -302,7 +302,7 @@ protected: void GetDirectoryChildren(std::vector &children, const std::string &path) override { struct dirent * * namelist; - sint32 count = scandir(path.c_str(), &namelist, FilterFunc, alphasort); + sint32 count = scandir(path.c_str(), &namelist, FilterFunc, alphasort); if (count > 0) { for (sint32 i = 0; i < count; i++) diff --git a/src/openrct2/drawing/engines/SoftwareDrawingEngine.cpp b/src/openrct2/drawing/engines/SoftwareDrawingEngine.cpp index 1ddb7aa5f1..a1a6a14f8e 100644 --- a/src/openrct2/drawing/engines/SoftwareDrawingEngine.cpp +++ b/src/openrct2/drawing/engines/SoftwareDrawingEngine.cpp @@ -58,16 +58,14 @@ private: static constexpr uint32 MaxRainPixels = 0xFFFE; - size_t _rainPixelsCapacity; - uint32 _rainPixelsCount; - RainPixel * _rainPixels; - rct_drawpixelinfo * _screenDPI; + size_t _rainPixelsCapacity = MaxRainPixels; + uint32 _rainPixelsCount = 0; + RainPixel * _rainPixels = nullptr; + rct_drawpixelinfo * _screenDPI = nullptr; public: RainDrawer() { - _rainPixelsCapacity = MaxRainPixels; - _rainPixelsCount = 0; _rainPixels = new RainPixel[_rainPixelsCapacity]; } @@ -161,8 +159,8 @@ public: class SoftwareDrawingContext final : public IDrawingContext { private: - SoftwareDrawingEngine * _engine; - rct_drawpixelinfo * _dpi; + SoftwareDrawingEngine * _engine = nullptr; + rct_drawpixelinfo * _dpi = nullptr; public: explicit SoftwareDrawingContext(SoftwareDrawingEngine * engine); diff --git a/src/openrct2/drawing/engines/opengl/OpenGLDrawingEngine.cpp b/src/openrct2/drawing/engines/opengl/OpenGLDrawingEngine.cpp index 82bfa8a3f8..725f484428 100644 --- a/src/openrct2/drawing/engines/opengl/OpenGLDrawingEngine.cpp +++ b/src/openrct2/drawing/engines/opengl/OpenGLDrawingEngine.cpp @@ -175,8 +175,8 @@ class OpenGLDrawingEngine; class OpenGLDrawingContext final : public IDrawingContext { private: - OpenGLDrawingEngine * _engine; - rct_drawpixelinfo * _dpi; + OpenGLDrawingEngine * _engine = nullptr; + rct_drawpixelinfo * _dpi = nullptr; DrawImageShader * _drawImageShader = nullptr; DrawLineShader * _drawLineShader = nullptr; @@ -184,12 +184,12 @@ private: TextureCache * _textureCache = nullptr; - sint32 _offsetX; - sint32 _offsetY; - sint32 _clipLeft; - sint32 _clipTop; - sint32 _clipRight; - sint32 _clipBottom; + sint32 _offsetX = 0; + sint32 _offsetY = 0; + sint32 _clipLeft = 0; + sint32 _clipTop = 0; + sint32 _clipRight = 0; + sint32 _clipBottom = 0; struct { std::vector rectangles; @@ -230,7 +230,7 @@ class OpenGLDrawingEngine : public IDrawingEngine { private: SDL_Window * _window = nullptr; - SDL_GLContext _context; + SDL_GLContext _context = nullptr; uint32 _width = 0; uint32 _height = 0; diff --git a/src/openrct2/drawing/engines/opengl/SwapFramebuffer.h b/src/openrct2/drawing/engines/opengl/SwapFramebuffer.h index 1ef93199cf..53c24d0890 100644 --- a/src/openrct2/drawing/engines/opengl/SwapFramebuffer.h +++ b/src/openrct2/drawing/engines/opengl/SwapFramebuffer.h @@ -33,12 +33,12 @@ class OpenGLFramebuffer; class SwapFramebuffer final { private: - sint32 _width; - sint32 _height; - uint8 _targetFramebufferIndex; - OpenGLFramebuffer * _targetFramebuffer; - OpenGLFramebuffer * _sourceFramebuffer; - OpenGLFramebuffer * _framebuffer[2]; + sint32 _width = 0; + sint32 _height = 0; + uint8 _targetFramebufferIndex = 0; + OpenGLFramebuffer * _targetFramebuffer = nullptr; + OpenGLFramebuffer * _sourceFramebuffer = nullptr; + OpenGLFramebuffer * _framebuffer[2] = { 0 }; CopyFramebufferShader * _copyFramebufferShader = nullptr; diff --git a/src/openrct2/drawing/engines/opengl/TextureCache.cpp b/src/openrct2/drawing/engines/opengl/TextureCache.cpp index 5a6cad5a05..b970bbebce 100644 --- a/src/openrct2/drawing/engines/opengl/TextureCache.cpp +++ b/src/openrct2/drawing/engines/opengl/TextureCache.cpp @@ -26,10 +26,6 @@ extern "C" #include "../../drawing.h" } -TextureCache::TextureCache() -{ -} - TextureCache::~TextureCache() { FreeTextures(); diff --git a/src/openrct2/drawing/engines/opengl/TextureCache.h b/src/openrct2/drawing/engines/opengl/TextureCache.h index a569cc0516..b79719f054 100644 --- a/src/openrct2/drawing/engines/opengl/TextureCache.h +++ b/src/openrct2/drawing/engines/opengl/TextureCache.h @@ -75,12 +75,14 @@ struct CachedTextureInfo class Atlas final { private: - GLuint _index; - sint32 _imageSize; - sint32 _atlasWidth, _atlasHeight; + GLuint _index = 0; + sint32 _imageSize = 0; + sint32 _atlasWidth = 0; + sint32 _atlasHeight = 0; std::vector _freeSlots; - sint32 _cols, _rows; + sint32 _cols = 0; + sint32 _rows = 0; public: Atlas(GLuint index, sint32 imageSize) @@ -187,10 +189,10 @@ class TextureCache final private: bool _atlasesTextureInitialised = false; - GLuint _atlasesTexture; - GLint _atlasesTextureDimensions; - GLuint _atlasesTextureIndices; - GLint _atlasesTextureIndicesLimit; + GLuint _atlasesTexture = 0; + GLint _atlasesTextureDimensions = 0; + GLuint _atlasesTextureIndices = 0; + GLint _atlasesTextureIndicesLimit = 0; std::vector _atlases; std::unordered_map _imageTextureMap; @@ -200,7 +202,7 @@ private: SDL_Color _palette[256]; public: - TextureCache(); + TextureCache() = default; ~TextureCache(); void SetPalette(const SDL_Color * palette); void InvalidateImage(uint32 image); diff --git a/src/openrct2/network/NetworkServerAdvertiser.cpp b/src/openrct2/network/NetworkServerAdvertiser.cpp index 09d59d1dc1..194c108019 100644 --- a/src/openrct2/network/NetworkServerAdvertiser.cpp +++ b/src/openrct2/network/NetworkServerAdvertiser.cpp @@ -100,7 +100,7 @@ private: _lastAdvertiseTime = SDL_GetTicks(); // Send the registration request - http_request_t request; + http_request_t request = { 0 }; request.tag = this; request.url = GetMasterServerUrl(); request.method = HTTP_METHOD_POST; @@ -130,7 +130,7 @@ private: void SendHeartbeat() { - http_request_t request; + http_request_t request = { 0 }; request.tag = this; request.url = GetMasterServerUrl(); request.method = HTTP_METHOD_PUT; diff --git a/src/openrct2/network/network.cpp b/src/openrct2/network/network.cpp index 34b427810a..ba227e0f7b 100644 --- a/src/openrct2/network/network.cpp +++ b/src/openrct2/network/network.cpp @@ -2203,7 +2203,7 @@ void game_command_modify_groups(sint32 *eax, sint32 *ebx, sint32 *ecx, sint32 *e uint8 groupid = (uint8)(*eax >> 8); uint8 nameChunkIndex = (uint8)(*eax >> 16); - char oldName[128]; + char oldName[128] = { 0 }; static char newName[128]; switch (action) diff --git a/src/openrct2/network/network.h b/src/openrct2/network/network.h index fcee9ff610..a0606f43a7 100644 --- a/src/openrct2/network/network.h +++ b/src/openrct2/network/network.h @@ -195,7 +195,7 @@ private: ITcpSocket * listening_socket = nullptr; uint16 listening_port = 0; NetworkConnection server_connection; - SOCKET_STATUS _lastConnectStatus; + SOCKET_STATUS _lastConnectStatus = SOCKET_STATUS_CLOSED; uint32 last_tick_sent_time = 0; uint32 last_ping_sent_time = 0; uint32 server_tick = 0; @@ -211,7 +211,7 @@ private: INetworkServerAdvertiser * _advertiser = nullptr; uint32 server_connect_time = 0; uint8 default_group = 0; - SDL_RWops *_chatLogStream; + SDL_RWops *_chatLogStream = nullptr; std::string _chatLogPath; void UpdateServer(); diff --git a/src/openrct2/object/ObjectRepository.cpp b/src/openrct2/object/ObjectRepository.cpp index 90d3d20201..362c6a2546 100644 --- a/src/openrct2/object/ObjectRepository.cpp +++ b/src/openrct2/object/ObjectRepository.cpp @@ -94,17 +94,16 @@ static void ReportMissingObject(const rct_object_entry * entry); class ObjectRepository final : public IObjectRepository { - IPlatformEnvironment * _env = nullptr; + const IPlatformEnvironment * _env = nullptr; std::vector _items; QueryDirectoryResult _queryDirectoryResult = { 0 }; ObjectEntryMap _itemMap; - uint16 _languageId = 0; - sint32 _numConflicts; + uint16 _languageId = 0; + sint32 _numConflicts = 0; public: - ObjectRepository(IPlatformEnvironment * env) + ObjectRepository(IPlatformEnvironment * env) : _env(env) { - _env = env; } ~ObjectRepository() final