From a3b2076ba0b398523c3e0428c2400184e83c4f62 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Sat, 2 Mar 2013 21:19:28 +0300 Subject: Last fixes after Coverity checks. --- src/client.cpp | 11 ++++++----- src/graphics.cpp | 28 ++++++++++++++++++++-------- src/graphics.h | 5 ++++- src/main.cpp | 1 + src/map.cpp | 6 ++---- src/units.cpp | 1 + src/utils/translation/poparser.cpp | 2 ++ 7 files changed, 36 insertions(+), 18 deletions(-) (limited to 'src') diff --git a/src/client.cpp b/src/client.cpp index 7493257fd..5a0733e92 100644 --- a/src/client.cpp +++ b/src/client.cpp @@ -284,6 +284,12 @@ Client::Client(const Options &options) : mButtonSpacing(3) { mInstance = this; + + // Initialize frame limiting + mFpsManager.framecount = 0; + mFpsManager.rateticks = 0; + mFpsManager.lastticks = 0; + mFpsManager.rate = 0; } void Client::testsInit() @@ -652,11 +658,6 @@ void Client::gameInit() const int fpsLimit = config.getIntValue("fpslimit"); mLimitFps = fpsLimit > 0; - // Initialize frame limiting - mFpsManager.framecount = 0; - mFpsManager.rateticks = 0; - mFpsManager.lastticks = 0; - mFpsManager.rate = 0; SDL_initFramerate(&mFpsManager); setFramerate(fpsLimit); diff --git a/src/graphics.cpp b/src/graphics.cpp index 0e3f19544..e220775a7 100644 --- a/src/graphics.cpp +++ b/src/graphics.cpp @@ -659,10 +659,15 @@ bool Graphics::calcImageRect(ImageVertexes *const vert, } calcTile(vert, topLeft, x, y); - calcTile(vert, topRight, x + w - topRight->getWidth(), y); - calcTile(vert, bottomLeft, x, y + h - bottomLeft->getHeight()); - calcTile(vert, bottomRight, x + w - bottomRight->getWidth(), - y + h - bottomRight->getHeight()); + if (topRight) + calcTile(vert, topRight, x + w - topRight->getWidth(), y); + if (bottomLeft) + calcTile(vert, bottomLeft, x, y + h - bottomLeft->getHeight()); + if (bottomRight) + { + calcTile(vert, bottomRight, x + w - bottomRight->getWidth(), + y + h - bottomRight->getHeight()); + } // popClipArea(); BLOCK_END("Graphics::calcImageRect") @@ -711,6 +716,10 @@ void Graphics::calcImagePattern(ImageVertexes* const vert, { vert->sdl.push_back(r); } + else + { + delete r; + } } } } @@ -989,11 +998,14 @@ int Graphics::SDL_FakeUpperBlit(const SDL_Surface *const src, if (w > 0 && h > 0) { - srcrect->x = static_cast(srcx); - srcrect->y = static_cast(srcy); - srcrect->w = static_cast(w); + if (srcrect) + { + srcrect->x = static_cast(srcx); + srcrect->y = static_cast(srcy); + srcrect->w = static_cast(w); + srcrect->h = static_cast(h); + } dstrect->w = static_cast(w); - srcrect->h = static_cast(h); dstrect->h = static_cast(h); return 1; diff --git a/src/graphics.h b/src/graphics.h index b9d4cc53b..12a6c3a77 100644 --- a/src/graphics.h +++ b/src/graphics.h @@ -61,7 +61,10 @@ class ImageRect final { public: ImageRect() - { } + { + for (int f = 0; f < 9; f ++) + grid[f] = nullptr; + } A_DELETE_COPY(ImageRect) diff --git a/src/main.cpp b/src/main.cpp index e9e09e9b7..a6d311b0b 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -186,6 +186,7 @@ static void parseOptions(const int argc, char *const argv[], break; case 'a': options.chatLogDir = std::string(optarg); + break; case 'i': options.screenshotDir = optarg; break; diff --git a/src/map.cpp b/src/map.cpp index c3338f6d4..76947ad7d 100644 --- a/src/map.cpp +++ b/src/map.cpp @@ -1252,12 +1252,10 @@ void Map::addPortal(const std::string &name, const int type, void Map::addPortalTile(const std::string &name, const int type, const int x, const int y) { - MapItem *item = new MapItem(type, name, x, y); if (mSpecialLayer) - mSpecialLayer->setTile(x, y, item); + mSpecialLayer->setTile(x, y, new MapItem(type, name, x, y)); - item = new MapItem(type, name, x, y); - mMapPortals.push_back(item); + mMapPortals.push_back(new MapItem(type, name, x, y)); } void Map::updatePortalTile(const std::string &name, const int type, diff --git a/src/units.cpp b/src/units.cpp index 4931f416b..73b05005c 100644 --- a/src/units.cpp +++ b/src/units.cpp @@ -234,6 +234,7 @@ static std::string formatUnit(const int value, const int type) } else { + ul.round = 0; for (unsigned int i = 0; i < ud.levels.size(); i++) { ul = ud.levels[i]; diff --git a/src/utils/translation/poparser.cpp b/src/utils/translation/poparser.cpp index d4426a2e3..dc201d4b3 100644 --- a/src/utils/translation/poparser.cpp +++ b/src/utils/translation/poparser.cpp @@ -41,6 +41,8 @@ PoParser::PoParser() : void PoParser::openFile(std::string name) { const ResourceManager *const resman = ResourceManager::getInstance(); + if (!resman) + return; int size; char *buf = static_cast(resman->loadFile(getFileName(name), size)); -- cgit v1.2.3-60-g2f50