Skip to content

Commit

Permalink
Fix several cppcheck warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
bcsanches committed Nov 9, 2022
1 parent 28ce75b commit f454178
Show file tree
Hide file tree
Showing 16 changed files with 45 additions and 28 deletions.
9 changes: 8 additions & 1 deletion check.cppcheck
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="1">
<builddir>check-cppcheck-build-dir</builddir>
<platform>Unspecified</platform>
<platform>unknown</platform>
<analyze-all-vs-configs>false</analyze-all-vs-configs>
<check-headers>true</check-headers>
<check-unused-templates>false</check-unused-templates>
<max-ctu-depth>10</max-ctu-depth>
<max-template-recursion>100</max-template-recursion>
<paths>
<dir name="src"/>
</paths>
<libraries>
<library>wxwidgets</library>
</libraries>
<tools>
<tool>clang-tidy</tool>
</tools>
</project>
6 changes: 3 additions & 3 deletions src/ArduinoLib/avr/pgmspace.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,17 @@ class __FlashStringHelper;

inline size_t strlen_P(const __FlashStringHelper *fstr)
{
return strlen((const char *)fstr);
return strlen(reinterpret_cast<const char *>(fstr));
}

inline int strncmp_P(const char *str1, const __FlashStringHelper *fstr2, size_t maxCount)
{
return strncmp(str1, (const char *)fstr2, maxCount);
return strncmp(str1, reinterpret_cast<const char *>(fstr2), maxCount);
}

inline char *strncpy_P(char *dest, const __FlashStringHelper *fsrc, size_t count)
{
return strncpy(dest, (const char *)fsrc, count);
return strncpy(dest, reinterpret_cast<const char *>(fsrc), count);
}

#define F(x) (reinterpret_cast<const __FlashStringHelper *>(x))
2 changes: 1 addition & 1 deletion src/BrokerLib/DccLiteService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ namespace dcclite::broker
const rapidjson::Value &params
)
{
auto decoder = TryCreateDecoder(className.c_str(), address, name, *this, dev, params);
auto decoder = TryCreateDecoder(className, address, name, *this, dev, params);
if (!decoder)
{
throw std::runtime_error(fmt::format("[DccLiteService::Device_CreateDecoder] Error: failed to instantiate decoder {} - {} [{}]", name, address, className));
Expand Down
4 changes: 1 addition & 3 deletions src/BrokerLib/DccppService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -539,9 +539,7 @@ namespace dcclite::broker
goto ERROR_RESPONSE;
}
else
{
std::stringstream response;

{
auto sensorDecoders = m_rclSystem.FindAllSensorDecoders();
m_clMessenger.Send(m_clAddress, CreateSensorStateRespnse(sensorDecoders));
}
Expand Down
6 changes: 3 additions & 3 deletions src/BrokerLib/EventHub.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ namespace dcclite::broker
class ObjectPool
{
public:
ObjectPool(uint32_t size):
explicit ObjectPool(uint32_t size):
m_u32Size{size},
m_upPool{new std::byte[size]}
{
Expand Down Expand Up @@ -73,8 +73,8 @@ namespace dcclite::broker
std::unique_ptr<std::byte[]> m_upPool;

#ifdef DEBUG
uint32_t m_uAllocCount;
uint32_t m_uUsedMem;
uint32_t m_uAllocCount = 0;
uint32_t m_uUsedMem = 0;
#endif

};
Expand Down
8 changes: 3 additions & 5 deletions src/BrokerLib/LocationManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ namespace dcclite::broker
{
public:
Location(std::string name, std::string prefix, const DccAddress beginAddress, const DccAddress endAddress):
Object(name),
Object(std::move(name)),
m_strPrefix(std::move(prefix)),
m_tBeginAddress(beginAddress),
m_tEndAddress(endAddress)
Expand Down Expand Up @@ -54,8 +54,6 @@ namespace dcclite::broker
{
auto index = GetDecoderIndex(dec);

bool foundIt = m_vecDecoders[index] == &dec;

m_vecDecoders[index] = nullptr;
}

Expand Down Expand Up @@ -143,12 +141,12 @@ namespace dcclite::broker

for(auto &sectorData : sectorsData.GetArray())
{
auto name = sectorData["name"].GetString();
auto dname = sectorData["name"].GetString();
auto prefix = sectorData["prefix"].GetString();
auto beginAddress = DccAddress{static_cast<uint16_t>(sectorData["begin"].GetInt())};
auto endAddress = DccAddress{ static_cast<uint16_t>(sectorData["end"].GetInt())};

auto location = this->AddChild(std::make_unique<Location>(name, prefix, beginAddress, endAddress));
auto location = this->AddChild(std::make_unique<Location>(dname, prefix, beginAddress, endAddress));

m_vecIndex.push_back(static_cast<Location *>(location));
}
Expand Down
3 changes: 1 addition & 2 deletions src/BrokerLib/NetworkDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -605,8 +605,7 @@ namespace dcclite::broker
packet.ReadBitPack(states);

bool sensorStateRefresh = false;
bool stateRefresh = false;


for (unsigned i = 0; i < changedStates.size(); ++i)
{
if (!changedStates[i])
Expand Down
6 changes: 3 additions & 3 deletions src/BrokerLib/NetworkDevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ namespace dcclite::broker

void TaskServices_SendPacket(dcclite::Packet &packet) override;

bool IsConnectionStable() const noexcept;
bool IsConnectionStable() const noexcept override;

void TaskServices_ForgetTask(NetworkTask &task) override;

Expand Down Expand Up @@ -235,7 +235,7 @@ namespace dcclite::broker

struct SyncState: State
{
SyncState(NetworkDevice &self);
explicit SyncState(NetworkDevice &self);

void OnPacket(
dcclite::Packet &packet,
Expand Down Expand Up @@ -286,7 +286,7 @@ namespace dcclite::broker
class TimeoutController
{
public:
TimeoutController(NetworkDevice &owner);
explicit TimeoutController(NetworkDevice &owner);

void Enable(const dcclite::Clock::TimePoint_t time);

Expand Down
2 changes: 1 addition & 1 deletion src/BrokerLib/PinManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ namespace dcclite::broker
std::vector<PinInfo> m_vecPins;

public:
PinManager(ArduinoBoards board);
explicit PinManager(ArduinoBoards board);

void RegisterPin(const RemoteDecoder &decoder, dcclite::BasicPin pin, const char *usage);
void UnregisterPin(const RemoteDecoder &decoder, dcclite::BasicPin pin);
Expand Down
4 changes: 2 additions & 2 deletions src/BrokerLib/SignalDecoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ namespace dcclite::broker

SignalDecoder::SignalDecoder(
const DccAddress &address,
const std::string &name,
const std::string &decoderName,
IDccLite_DecoderServices &owner,
IDevice_DecoderServices &dev,
const rapidjson::Value &params
) :
Decoder(address, name, owner, dev, params)
Decoder(address, decoderName, owner, dev, params)
{
auto headsData = params.FindMember("heads");
if ((headsData == params.MemberEnd()) || (!headsData->value.IsObject()))
Expand Down
4 changes: 2 additions & 2 deletions src/BrokerLib/SignalDecoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ namespace dcclite::broker

struct State
{
State(SignalDecoder &owner):
explicit State(SignalDecoder &owner):
m_rclOwner{ owner }
{
//empty
Expand All @@ -113,7 +113,7 @@ namespace dcclite::broker

struct State_WaitTurnOff: State
{
State_WaitTurnOff(SignalDecoder &self);
explicit State_WaitTurnOff(SignalDecoder &self);

void GotoNextState();

Expand Down
9 changes: 9 additions & 0 deletions src/Common/LogUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,15 @@
namespace dcclite
{
static std::shared_ptr<spdlog::logger> g_spLogger;

void LogFinalize()
{
g_spLogger.reset();

spdlog::drop("dcclite");

spdlog::shutdown();
}

void LogInit(const char *fileName)
{
Expand Down
2 changes: 2 additions & 0 deletions src/Common/LogUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ namespace dcclite

extern void LogInit(const char *fileName);

extern void LogFinalize();

extern void LogReplace(Logger_t log);

extern Logger_t LogGetDefault();
Expand Down
2 changes: 1 addition & 1 deletion src/Common/Socket.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ namespace dcclite
//empty
}

inline IpAddress(std::uint_fast32_t address) noexcept:
inline explicit IpAddress(std::uint_fast32_t address) noexcept:
m_uAddress{ address }
{

Expand Down
4 changes: 3 additions & 1 deletion src/UnitTest/EventHubTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
class EventTargetMockup : public dcclite::broker::EventHub::IEventTarget
{
public:
EventTargetMockup(std::string_view name):
explicit EventTargetMockup(std::string_view name):
m_svDebugName{name}
{
//empty
Expand Down Expand Up @@ -197,6 +197,8 @@ TEST(EventHub, BadAlloc)
//memory is free
dcclite::broker::EventHub::PostEvent<MyTestEvent>(std::ref(t1), [&called] { ++called; });

dcclite::LogFinalize();

return;
}

Expand Down
2 changes: 2 additions & 0 deletions src/UnitTest/SignalDecoderTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,8 @@ TEST(SignalDecoderTest, Basic)
ASSERT_TRUE(VectorHasStr(aspects[3].m_vecOffHeads, "STC_HY12"));
ASSERT_TRUE(VectorHasStr(aspects[3].m_vecOffHeads, "STC_HG12"));
ASSERT_TRUE(VectorHasStr(aspects[3].m_vecOffHeads, "STC_BLA"));

dcclite::LogFinalize();
}

static std::string ExtractSignalExceptionString(const char *json)
Expand Down

0 comments on commit f454178

Please sign in to comment.