Skip to content

Commit

Permalink
Updated cppcheck script. Fixed several warnings.
Browse files Browse the repository at this point in the history
  • Loading branch information
heinermann committed Apr 28, 2017
1 parent 0a992d2 commit e35b0f9
Show file tree
Hide file tree
Showing 14 changed files with 20 additions and 32 deletions.
5 changes: 0 additions & 5 deletions bwapi/BWAPI/Source/BW/OrderTypes.cpp
Expand Up @@ -102,7 +102,6 @@ namespace BW
targets[targCount++] = UnitTarget(units[i]);
}
}
// cppcheck-suppress uninitMemberVar
Select::Select(const std::vector<BWAPI::Unit>& units)
: Select(static_cast<int>(units.size()), units.data())
{
Expand Down Expand Up @@ -136,7 +135,6 @@ namespace BW
break;
}
}
// cppcheck-suppress uninitMemberVar
MakeBuilding::MakeBuilding(int tileX, int tileY, BWAPI::UnitType type)
: MakeBuilding(BW::TilePosition(static_cast<s16>(tileX), static_cast<s16>(tileY)), type)
{
Expand All @@ -147,7 +145,6 @@ namespace BW
, type(static_cast<u16>(type))
{
}
// cppcheck-suppress uninitMemberVar
PlaceCOP::PlaceCOP(int x, int y, BWAPI::UnitType type)
: PlaceCOP(BW::TilePosition(static_cast<s16>(x), static_cast<s16>(y)), type)
{
Expand All @@ -168,7 +165,6 @@ namespace BW
, type(static_cast<u16>(type))
{
}
// cppcheck-suppress uninitMemberVar
MakeAddon::MakeAddon(int tileX, int tileY, BWAPI::UnitType type)
: MakeAddon(BW::TilePosition(static_cast<s16>(tileX), static_cast<s16>(tileY)), type)
{
Expand Down Expand Up @@ -227,7 +223,6 @@ namespace BW
, type(static_cast<u16>(type))
{
}
// cppcheck-suppress uninitMemberVar
Land::Land(int x, int y, BWAPI::UnitType type)
: Land(BW::TilePosition(static_cast<s16>(x), static_cast<s16>(y)), type)
{
Expand Down
2 changes: 1 addition & 1 deletion bwapi/BWAPI/Source/BWAPI/Command.h
Expand Up @@ -8,6 +8,6 @@ namespace BWAPI
class Command : public CommandTemp<BWAPI::UnitImpl,BWAPI::PlayerImpl>
{
public:
Command(UnitCommand command) : CommandTemp<BWAPI::UnitImpl,BWAPI::PlayerImpl>(command) {}
Command(const UnitCommand& command) : CommandTemp<BWAPI::UnitImpl,BWAPI::PlayerImpl>(command) {}
};
}
18 changes: 7 additions & 11 deletions bwapi/BWAPI/Source/BWAPI/CommandTemp.h
Expand Up @@ -13,24 +13,20 @@ namespace BWAPI
class CommandTemp
{
public :
CommandTemp(UnitCommand command);
CommandTemp(const UnitCommand& command);
void execute(int frame);
protected:
virtual ~CommandTemp() {};
private :
int getUnitID(Unit unit);
static int getUnitID(Unit unit);
UnitCommand command;
int savedExtra;
int savedExtra2;
PlayerImpl* player;
int savedExtra = -1;
int savedExtra2 = -1;
PlayerImpl* player = nullptr;
};
template <class UnitImpl, class PlayerImpl>
CommandTemp<UnitImpl, PlayerImpl>::CommandTemp(UnitCommand command) : command(command)
{
savedExtra = -1;
savedExtra2 = -1;
player = nullptr;
}
CommandTemp<UnitImpl, PlayerImpl>::CommandTemp(const UnitCommand& command) : command(command)
{}
template <class UnitImpl, class PlayerImpl>
int CommandTemp<UnitImpl, PlayerImpl>::getUnitID(Unit unit)
{
Expand Down
1 change: 0 additions & 1 deletion bwapi/BWAPI/Source/BWAPI/GameImpl.cpp
Expand Up @@ -309,7 +309,6 @@ namespace BWAPI
if ( newDistance < bestDistance )
{
pBestUnit = u;
// cppcheck-suppress unreadVariable
bestDistance = newDistance;
}
} } );
Expand Down
2 changes: 1 addition & 1 deletion bwapi/BWAPI/Source/BWAPI/Server.cpp
Expand Up @@ -263,7 +263,7 @@ namespace BWAPI
StrCopy(data->eventStrings[data->eventStringCount], text);
return data->eventStringCount++;
}
int Server::addEvent(BWAPI::Event e)
int Server::addEvent(const BWAPI::Event& e)
{
assert(data->eventCount < GameData::MAX_EVENTS);
BWAPIC::Event* e2 = &(data->events[data->eventCount++]);
Expand Down
2 changes: 1 addition & 1 deletion bwapi/BWAPI/Source/BWAPI/Server.h
Expand Up @@ -28,7 +28,7 @@ namespace BWAPI

void update();
bool isConnected() const;
int addEvent(BWAPI::Event e);
int addEvent(const BWAPI::Event& e);
int addString(const char* text);
void clearAll();

Expand Down
2 changes: 1 addition & 1 deletion bwapi/BWAPIClient/Source/Command.h
Expand Up @@ -9,6 +9,6 @@ namespace BWAPI
class Command : public CommandTemp<BWAPI::UnitImpl,BWAPI::PlayerImpl>
{
public:
Command(UnitCommand command) : CommandTemp<BWAPI::UnitImpl,BWAPI::PlayerImpl>(command) {}
Command(const UnitCommand& command) : CommandTemp<BWAPI::UnitImpl,BWAPI::PlayerImpl>(command) {}
};
}
1 change: 0 additions & 1 deletion bwapi/BWAPIClient/Source/GameImpl.cpp
Expand Up @@ -508,7 +508,6 @@ namespace BWAPI
if ( newDistance < bestDistance )
{
pBestUnit = u;
// cppcheck-suppress unreadVariable
bestDistance = newDistance;
}
} } );
Expand Down
4 changes: 0 additions & 4 deletions bwapi/BWAPILIBTest/positionTest.cpp
Expand Up @@ -237,9 +237,7 @@ namespace BWAPILIBTest
Assert::AreEqual(Position(0, 1), p2);
Assert::AreEqual(Position(0, 1), p3);

// cppcheck-suppress zerodiv
p2 = p1 / 0;
// cppcheck-suppress zerodiv
p3 /= 0;
Assert::AreEqual(Positions::Invalid, p2);
Assert::AreEqual(Positions::Invalid, p3);
Expand All @@ -259,9 +257,7 @@ namespace BWAPILIBTest
Assert::AreEqual(Position(1, 0), p2);
Assert::AreEqual(Position(0, 0), p3);

// cppcheck-suppress zerodiv
p2 = p1 % 0;
// cppcheck-suppress zerodiv
p3 %= 0;
Assert::AreEqual(Positions::Invalid, p2);
Assert::AreEqual(Positions::Invalid, p3);
Expand Down
2 changes: 1 addition & 1 deletion bwapi/Util/Source/Util/MemoryFrame.cpp
Expand Up @@ -75,7 +75,7 @@ namespace Util
//----------------------- IS EMPTY -----------------------------------
bool MemoryFrame::isEmpty() const
{
return this->frameSize <= 0;
return this->frameSize == 0;
}
//----------------------- IS MULTIPLE OF -----------------------------
bool MemoryFrame::isMultipleOf(unsigned int bytes) const
Expand Down
6 changes: 3 additions & 3 deletions bwapi/Util/Source/Util/SharedMemory.h
Expand Up @@ -65,16 +65,16 @@ namespace Util
template<typename T>
T *unpack(Pointer<T> p) const // to process address space
{
if(!(int)this->bufferBase)
if(this->bufferBase == nullptr)
return NULL;
return (T*)(this->bufferBase + p.offset);
return reinterpret_cast<T*>(reinterpret_cast<decltype(retval.offset)>(this->bufferBase) + p.offset);
}

template<typename T>
Pointer<T> pack(T *pt) const // to shared address space
{
Pointer<T> retval;
retval.offset = (int)pt - (int)this->bufferBase;
retval.offset = reinterpret_cast<decltype(retval.offset)>(pt) - reinterpret_cast<decltype(retval.offset)>(this->bufferBase);
}

MemoryFrame getMemory() const;
Expand Down
3 changes: 3 additions & 0 deletions bwapi/Util/Source/Util/StringUtil.h
Expand Up @@ -23,6 +23,7 @@ inline std::string to_upper_copy(const std::string& s) {
}

// Trims the left side of str, using predicate to decide trimming (while true)
// cppcheck-suppress passedByValue
inline void trim_left(std::string& str, std::function<bool(char)> pred) {
auto it = str.begin();
auto it_end = str.end();
Expand All @@ -35,6 +36,7 @@ inline void trim_left(std::string& str, std::function<bool(char)> pred) {
}

// Trims the right side of str, using pred to decide trimming (while true)
// cppcheck-suppress passedByValue
inline void trim_right(std::string& str, std::function<bool(char)> pred) {
auto it = str.rbegin();
auto it_end = str.rend();
Expand All @@ -48,6 +50,7 @@ inline void trim_right(std::string& str, std::function<bool(char)> pred) {

// Trims left and right side of str, using predicate to check if the character
// stays (false) or will be trimmed (true)
// cppcheck-suppress passedByValue
inline void trim(std::string& str, std::function<bool(char)> pred) {
trim_left(str, pred);
trim_right(str, pred);
Expand Down
2 changes: 1 addition & 1 deletion bwapi/include/BWAPI/Client/GameImpl.h
Expand Up @@ -65,7 +65,7 @@ namespace BWAPI
Playerset _enemies;
Playerset _observers;
mutable Error lastError;
Text::Size::Enum textSize;
Text::Size::Enum textSize = Text::Size::Default;

public :
Event makeEvent(BWAPIC::Event e);
Expand Down
2 changes: 1 addition & 1 deletion cppcheck_script.bat
@@ -1 +1 @@
cppcheck --enable=all --library=std.cfg --library=windows.cfg --platform=win32A --suppress=unusedFunction --suppress=variableHidingTypedef --inline-suppr -I \"bwapi/include/\" -I \"bwapi/Util/Source/\" -I \"bwapi/BWAPI/Source/\" -I \"bwapi/Storm/\" -I \"bwapi/Shared/\" -USWIG -U_MAC -Umax -UAPSTUDIO_INVOKED -UAPSTUDIO_READONLY_SYMBOLS --inconclusive --xml --xml-version=2 -i "bwapi/BWScriptEmulator" -i "bwapi/libReplayTool" -i "bwapi/libReplayToolTest" -i "bwapi/Replay_Tool" --verbose bwapi/ 2> cppcheck.xml
cppcheck --enable=all --library=std.cfg --library=windows.cfg --platform=win32A --suppress=unusedFunction --suppress=purgedConfiguration --suppress=noExplicitConstructor --inline-suppr -I \"bwapi/include/\" -I \"bwapi/Util/Source/\" -I \"bwapi/BWAPI/Source/\" -I \"bwapi/Storm/\" -I \"bwapi/Shared/\" -USWIG -U_MAC -Umax -UAPSTUDIO_INVOKED -UAPSTUDIO_READONLY_SYMBOLS --inconclusive --xml --xml-version=2 -i "bwapi/BWScriptEmulator" -i "bwapi/libReplayTool" -i "bwapi/libReplayToolTest" -i "bwapi/Replay_Tool" -i "bwapi\include\swig_wrap.cxx" --verbose bwapi/ 2> cppcheck.xml

0 comments on commit e35b0f9

Please sign in to comment.