From 55577d0ac4a3fab2f5cdfcae31853432eb80a538 Mon Sep 17 00:00:00 2001 From: Ivan Savenko Date: Sat, 9 Nov 2013 13:49:36 +0000 Subject: [PATCH] - fixed missing DLL_LINKAGE - use precalculated checksum for zip files - UNUSED macro to silence some warnings --- AI/VCAI/VCAI.cpp | 1 + CMakeLists.txt | 2 +- Global.h | 3 +++ client/battle/CBattleAnimations.cpp | 1 + client/battle/CCreatureAnimation.cpp | 1 + lib/CCreatureSet.cpp | 1 + lib/CGameState.cpp | 3 +++ lib/CGeneralTextHandler.h | 22 +++++++++++----------- lib/CObstacleInstance.cpp | 2 +- lib/NetPacksLib.cpp | 3 +++ lib/filesystem/CInputStream.h | 1 + lib/filesystem/CZipLoader.cpp | 7 +++++++ lib/filesystem/CZipLoader.h | 3 ++- lib/logging/CLogger.cpp | 2 +- 14 files changed, 37 insertions(+), 15 deletions(-) diff --git a/AI/VCAI/VCAI.cpp b/AI/VCAI/VCAI.cpp index d3548fa32..6d790b64d 100644 --- a/AI/VCAI/VCAI.cpp +++ b/AI/VCAI/VCAI.cpp @@ -2774,6 +2774,7 @@ void SectorMap::makeParentBFS(crint3 source) toVisit.pop(); ui8 &sec = retreiveTile(curPos); assert(sec == mySector); //consider only tiles from the same sector + UNUSED(sec); //const TerrainTile *t = cb->getTile(curPos); foreach_neighbour(curPos, [&](crint3 neighPos) diff --git a/CMakeLists.txt b/CMakeLists.txt index a7dd8bfb5..0d630f007 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -96,7 +96,7 @@ if(CMAKE_COMPILER_IS_GNUCXX OR NOT WIN32) #so far all *nix compilers support suc if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") set(CLANG_SPECIFIC_FLAGS "-Wno-mismatched-tags") endif() - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x -Wall -Wextra -Wpointer-arith -Wno-switch -Wno-sign-compare -Wno-unused-parameter -Wno-overloaded-virtual ${CLANG_SPECIFIC_FLAGS}") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x -Wall -Wextra -Wpointer-arith -Wno-switch -Wno-sign-compare -Wno-unused-parameter -Wuninitialized -Wno-overloaded-virtual ${CLANG_SPECIFIC_FLAGS}") endif() if(WIN32) # on Win everything goes into H3 root directory diff --git a/Global.h b/Global.h index 34107f35c..79ef42bc4 100644 --- a/Global.h +++ b/Global.h @@ -219,6 +219,9 @@ typedef boost::lock_guard TLockGuardRec; template char (&_ArrayCountObj(const T (&)[N]))[N]; #define ARRAY_COUNT(arr) (sizeof(_ArrayCountObj(arr))) +// should be used for variables that becomes unused in release builds (e.g. only used for assert checks) +#define UNUSED(VAR) ((void)VAR) + /* ---------------------------------------------------------------------------- */ /* VCMI standard library */ /* ---------------------------------------------------------------------------- */ diff --git a/client/battle/CBattleAnimations.cpp b/client/battle/CBattleAnimations.cpp index b4b113907..9d7d5563d 100644 --- a/client/battle/CBattleAnimations.cpp +++ b/client/battle/CBattleAnimations.cpp @@ -141,6 +141,7 @@ CAttackAnimation::CAttackAnimation(CBattleInterface *_owner, const CStack *attac && owner->getCurrentPlayerInterface()->cb->battleHexToWallPart(_dest) >= 0; assert(attackedStack || isCatapultAttack); + UNUSED(isCatapultAttack); attackingStackPosBeforeReturn = attackingStack->position; } diff --git a/client/battle/CCreatureAnimation.cpp b/client/battle/CCreatureAnimation.cpp index e591b4944..99641253b 100644 --- a/client/battle/CCreatureAnimation.cpp +++ b/client/battle/CCreatureAnimation.cpp @@ -327,6 +327,7 @@ void CCreatureAnimation::nextFrameT(SDL_Surface * dest, bool rotate) const size_t baseOffset = reader.getStream()->tell(); assert(defType2 == 1); + UNUSED(defType2); auto specialPalette = genSpecialPalette(); diff --git a/lib/CCreatureSet.cpp b/lib/CCreatureSet.cpp index ec3a28b09..89cd0373e 100644 --- a/lib/CCreatureSet.cpp +++ b/lib/CCreatureSet.cpp @@ -338,6 +338,7 @@ void CCreatureSet::joinStack(SlotID slot, CStackInstance * stack) const CCreature *c = getCreature(slot); assert(c == stack->type); assert(c); + UNUSED(c); //TODO move stuff changeStackCount(slot, stack->count); diff --git a/lib/CGameState.cpp b/lib/CGameState.cpp index 723bf7eff..5b5f0012e 100644 --- a/lib/CGameState.cpp +++ b/lib/CGameState.cpp @@ -1368,7 +1368,10 @@ void CGameState::init(StartInfo * si) //Early check for #1444-like problems for(auto building : vti->builtBuildings) + { assert(vti->town->buildings[building]); + UNUSED(building); + } //town events for(CCastleEvent &ev : vti->events) diff --git a/lib/CGeneralTextHandler.h b/lib/CGeneralTextHandler.h index 3aa60bcd4..3107900e8 100644 --- a/lib/CGeneralTextHandler.h +++ b/lib/CGeneralTextHandler.h @@ -16,34 +16,34 @@ namespace Unicode { /// evaluates size of UTF-8 character - size_t getCharacterSize(ui8 firstByte); + size_t DLL_LINKAGE getCharacterSize(ui8 firstByte); /// test if character is a valid UTF-8 symbol /// maxSize - maximum number of bytes this symbol may consist from ( = remainer of string) - bool isValidCharacter(const ui8 *character, size_t maxSize); + bool DLL_LINKAGE isValidCharacter(const ui8 *character, size_t maxSize); /// test if text contains ASCII-string (no need for unicode conversion) - bool isValidASCII(const std::string & text); - bool isValidASCII(const char * data, size_t size); + bool DLL_LINKAGE isValidASCII(const std::string & text); + bool DLL_LINKAGE isValidASCII(const char * data, size_t size); /// test if text contains valid UTF-8 sequence - bool isValidString(const std::string & text); - bool isValidString(const char * data, size_t size); + bool DLL_LINKAGE isValidString(const std::string & text); + bool DLL_LINKAGE isValidString(const char * data, size_t size); /// converts text to unicode from specified encoding or from one specified in settings - std::string toUnicode(const std::string & text); - std::string toUnicode(const std::string & text, const std::string & encoding); + std::string DLL_LINKAGE toUnicode(const std::string & text); + std::string DLL_LINKAGE toUnicode(const std::string & text, const std::string & encoding); /// converts text from unicode to specified encoding or to one specified in settings /// NOTE: usage of these functions should be avoided if possible - std::string fromUnicode(const std::string & text); - std::string fromUnicode(const std::string & text, const std::string & encoding); + std::string DLL_LINKAGE fromUnicode(const std::string & text); + std::string DLL_LINKAGE fromUnicode(const std::string & text, const std::string & encoding); }; class CInputStream; /// Parser for any text files from H3 -class CLegacyConfigParser +class DLL_LINKAGE CLegacyConfigParser { std::unique_ptr data; char * curr; diff --git a/lib/CObstacleInstance.cpp b/lib/CObstacleInstance.cpp index 05a3ae0b2..bb9736000 100644 --- a/lib/CObstacleInstance.cpp +++ b/lib/CObstacleInstance.cpp @@ -37,7 +37,7 @@ const CObstacleInfo & CObstacleInstance::getInfo() const default: assert(0); } - + throw std::runtime_error("Unknown obstacle type in CObstacleInstance::getInfo()"); } std::vector CObstacleInstance::getBlockedTiles() const diff --git a/lib/NetPacksLib.cpp b/lib/NetPacksLib.cpp index 98ef61fb0..552b537ea 100644 --- a/lib/NetPacksLib.cpp +++ b/lib/NetPacksLib.cpp @@ -759,6 +759,7 @@ DLL_LINKAGE void RebalanceStacks::applyGs( CGameState *gs ) if(const CCreature *c = dst.army->getCreature(dst.slot)) //stack at dest -> merge { assert(c == srcType); + UNUSED(c); auto alHere = ArtifactLocation (src.getStack(), ArtifactPosition::CREATURE_SLOT); auto alDest = ArtifactLocation (dst.getStack(), ArtifactPosition::CREATURE_SLOT); auto artHere = alHere.getArt(); @@ -809,6 +810,7 @@ DLL_LINKAGE void RebalanceStacks::applyGs( CGameState *gs ) if(const CCreature *c = dst.army->getCreature(dst.slot)) //stack at dest -> rebalance { assert(c == srcType); + UNUSED(c); if (stackExp) { ui64 totalExp = srcCount * src.army->getStackExperience(src.slot) + dst.army->getStackCount(dst.slot) * dst.army->getStackExperience(dst.slot); @@ -875,6 +877,7 @@ DLL_LINKAGE void AssembledArtifact::applyGs( CGameState *gs ) const CArtifactInstance *transformedArt = al.getArt(); assert(transformedArt); assert(vstd::contains(transformedArt->assemblyPossibilities(artSet), builtArt)); + UNUSED(transformedArt); auto combinedArt = new CCombinedArtifactInstance(builtArt); gs->map->addNewArtifactInstance(combinedArt); diff --git a/lib/filesystem/CInputStream.h b/lib/filesystem/CInputStream.h index 6f58c321f..551f63ad3 100644 --- a/lib/filesystem/CInputStream.h +++ b/lib/filesystem/CInputStream.h @@ -72,6 +72,7 @@ public: seek(0); size_t readSize = read(data.get(), getSize()); assert(readSize == getSize()); + UNUSED(readSize); return std::make_pair(std::move(data), getSize()); } diff --git a/lib/filesystem/CZipLoader.cpp b/lib/filesystem/CZipLoader.cpp index 70c491c92..d35d6addd 100644 --- a/lib/filesystem/CZipLoader.cpp +++ b/lib/filesystem/CZipLoader.cpp @@ -39,6 +39,13 @@ si64 CZipStream::getSize() return info.uncompressed_size; } +ui32 CZipStream::calculateCRC32() +{ + unz_file_info info; + unzGetCurrentFileInfo (file, &info, nullptr, 0, nullptr, 0, nullptr, 0); + return info.crc; +} + CZipLoader::CZipLoader(const std::string & mountPoint, const std::string & archive): archiveName(archive), mountPoint(mountPoint), diff --git a/lib/filesystem/CZipLoader.h b/lib/filesystem/CZipLoader.h index d530e8bf0..397814814 100644 --- a/lib/filesystem/CZipLoader.h +++ b/lib/filesystem/CZipLoader.h @@ -31,7 +31,8 @@ public: CZipStream(const std::string & archive, unz_file_pos filepos); ~CZipStream(); - si64 getSize(); + si64 getSize() override; + ui32 calculateCRC32() override; protected: si64 readMore(ui8 * data, si64 size) override; diff --git a/lib/logging/CLogger.cpp b/lib/logging/CLogger.cpp index 1d526dd2c..b3a6f0617 100644 --- a/lib/logging/CLogger.cpp +++ b/lib/logging/CLogger.cpp @@ -374,7 +374,7 @@ EConsoleTextColor::EConsoleTextColor CColorMapping::getColorFor(const CLoggerDom break; } } - assert(0); + throw std::runtime_error("failed to find color for requested domain/level pair"); } CLogConsoleTarget::CLogConsoleTarget(CConsoleHandler * console) : console(console), threshold(ELogLevel::INFO), coloredOutputEnabled(true)