Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix CodeQL warnings in SVDConv and PackChk #682

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion tools/packchk/include/GatherCompilers.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ class GatherCompilersVisitor : public RteVisitor

std::map<std::string, std::string> EMPTY_MAP;
std::map<std::string, compiler_s> m_compilerMap;
RteTarget m_target; // for expression evaluation
RteModel m_filteredModel; // needed to test conditions
RteTarget m_target; // for expression evaluation
};

#endif //GATHERCOMPILERS_H
22 changes: 10 additions & 12 deletions tools/packchk/src/PackOptions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -283,20 +283,18 @@ const string CPackOptions::GetHeader()
*/
string CPackOptions::GetCurrentDateTime()
{
string text;

char buffer[128] = { "0000-00-00" };

time_t rawtime;
time(&rawtime);
struct tm* timeinfo = localtime(&rawtime);
if(timeinfo) {
strftime(buffer, sizeof(buffer), "%A %Y-%m-%d %H:%M:%S (%z)", timeinfo); // https://de.wikipedia.org/wiki/ISO_8601
time_t result = time(nullptr);
const char* timeAsc = asctime(std::localtime(&result));
string timeText { "<unknown>" };
if(timeAsc) {
timeText = timeAsc;

if(*timeText.rbegin() == '\n') {
timeText.pop_back(); // erase '\n'
}
}

text = buffer;

return text;
return timeText;
}

/**
Expand Down
22 changes: 10 additions & 12 deletions tools/svdconv/SVDConv/src/SvdOptions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -187,20 +187,18 @@ string SvdOptions::GetHeader()
*/
string SvdOptions::GetCurrentDateTime()
{
string text;

char buffer[128] = { "0000-00-00" };

time_t rawtime;
time(&rawtime);
struct tm* timeinfo = localtime(&rawtime);
if(timeinfo) {
strftime(buffer, sizeof(buffer), "%A %Y-%m-%d %H:%M:%S (%z)", timeinfo); // https://de.wikipedia.org/wiki/ISO_8601
time_t result = time(nullptr);
const char* timeAsc = asctime(std::localtime(&result));
string timeText { "<unknown>" };
if(timeAsc) {
timeText = timeAsc;

if(*timeText.rbegin() == '\n') {
timeText.pop_back(); // erase '\n'
}
}

text = buffer;

return text;
return timeText;
}

/**
Expand Down
4 changes: 2 additions & 2 deletions tools/svdconv/SVDModel/include/SvdItem.h
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ bool SvdItem::GetDeriveItem(T *&item, const std::list<std::string>& searchName,
}

if(parent && parent->FindChild(child, name)) {
bool found = false;
found = false;
// go down the levels
for(const auto& searchN : searchName) {
const auto& childs = parent->GetChildren();
Expand All @@ -307,7 +307,7 @@ bool SvdItem::GetDeriveItem(T *&item, const std::list<std::string>& searchName,
if(parent && parent->FindChild(parent->GetChildren(), child, searchN)) {
parent = child;
found = true;
}
}
else {
found = false;
break;
Expand Down
22 changes: 11 additions & 11 deletions tools/svdconv/SVDModel/include/SvdTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ struct CpuFeature {
const uint16_t NUMEXTIRQ;
public:
CpuFeature(const bool vtor, const bool mpu, const bool fpu, const bool fpudp,
const bool icache, const bool dcache, const bool itcm, const bool dtcm,
const bool icache, const bool dcache, const bool itcm, const bool dtcm,
const bool sau, const bool dsp, const bool pmu, const bool mve, const bool mvefp,
const uint16_t numExtIrq)
const uint16_t numExtIrq)
: VTOR(vtor), MPU(mpu), FPU(fpu), FPUDP(fpudp), ICACHE(icache), DCACHE(dcache),
ITCM(itcm), DTCM(dtcm), SAU(sau), DSP(dsp), PMU(pmu), MVE(mve), MVEFP(mvefp),
NUMEXTIRQ(numExtIrq)
Expand All @@ -53,19 +53,19 @@ struct CpuTypeFeature {
const CpuFeature cpuFeature;

public:
CpuTypeFeature(const char *t, const char *n,
CpuTypeFeature(const char *t, const char *n,
const bool irqVals0, const bool irqVals1, const bool irqVals2, const bool irqVals3,
const bool irqVals4, const bool irqVals5, const bool irqVals6, const bool irqVals7,
const bool irqVals8, const bool irqVals9, const bool irqVals10, const bool irqVals11,
const bool irqVals12, const bool irqVals13, const bool irqVals14, const bool irqVals15,
const bool cpuF0, const bool cpuF1, const bool cpuF2, const bool cpuF3,
const bool cpuF4, const bool cpuF5, const bool cpuF6, const bool cpuF7,
const bool cpuF8, const bool cpuF9, const bool cpuF10, const bool cpuF11,
const bool cpuF4, const bool cpuF5, const bool cpuF6, const bool cpuF7,
const bool cpuF8, const bool cpuF9, const bool cpuF10, const bool cpuF11,
const bool cpuF12,
const uint16_t numExtIrq
)
: type(t), name(n),
cpuFeature(cpuF0,cpuF1,cpuF2,cpuF3,cpuF4,cpuF5,cpuF6,cpuF7,cpuF8,cpuF9,cpuF10,cpuF11,cpuF12, numExtIrq)
cpuFeature(cpuF0,cpuF1,cpuF2,cpuF3,cpuF4,cpuF5,cpuF6,cpuF7,cpuF8,cpuF9,cpuF10,cpuF11,cpuF12, numExtIrq)
{
uint32_t i = 0;
irq[i++] = irqVals0;
Expand Down Expand Up @@ -103,7 +103,7 @@ class SvdTypes {
enum class EnumUsage { UNDEF = 0, READ, WRITE, READWRITE };
enum class SvdConvV2accType { EMPTY = 0, READ, READONLY, WRITE, WRITEONLY, READWRITE, UNDEF };
enum class CpuIrqNum { IRQ0 = 0, IRQ1, IRQ2, IRQ3, IRQ4, IRQ5, IRQ6, IRQ7, IRQ8, IRQ9, IRQ10, IRQ11, IRQ12, IRQ13, IRQ14, IRQ15, IRQ_END, IRQ_RESERVED, IRQ_UNDEF };

#define CPUTYPE(enumType, name) enumType,
enum class CpuType {
#include "EnumStringTables.h"
Expand All @@ -115,7 +115,7 @@ class SvdTypes {
#include "EnumStringTables.h"
};
#undef MODIFWRV

struct CmsisCfgForce {
uint32_t bMpuPresent : 1;
uint32_t bFpuPresent : 1;
Expand All @@ -131,7 +131,7 @@ class SvdTypes {
uint32_t bMvePresent : 1;
uint32_t bMveFP : 1;
};

static const std::string& GetExpressionType (Expression exprType);
static const std::string& GetAccessType (Access accType);
static const std::string& GetAccessTypeSfd (Access accType);
Expand All @@ -145,8 +145,8 @@ class SvdTypes {
static const std::string& GetCortexMInterruptName (SvdTypes::CpuIrqNum num);
static const std::string& GetCortexMInterruptDescription (SvdTypes::CpuIrqNum num);
static const std::string& GetEnumUsage (EnumUsage enumUsage);
static const bool GetCortexMInterruptAvailable (CpuType cpuType, SvdTypes::CpuIrqNum num);
static const bool GetCortexMInterrupt (CpuType cpuType, SvdTypes::CpuIrqNum num, std::string &name, std::string &descr);
static bool GetCortexMInterruptAvailable (CpuType cpuType, SvdTypes::CpuIrqNum num);
static bool GetCortexMInterrupt (CpuType cpuType, SvdTypes::CpuIrqNum num, std::string &name, std::string &descr);
static const CpuFeature& GetCpuFeatures (CpuType cpuType);

private:
Expand Down
20 changes: 10 additions & 10 deletions tools/svdconv/SVDModel/src/SvdCExpression.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,27 +77,27 @@ bool SvdCExpression::LinkSymbols(SvdItem* item, const SvdCExpressionParser::Toke

auto& regList = device->GetExpressionRegistersList();

for(auto& symbol : m_symbolsList) {
switch(symbol.token.type) {
for(auto& foundSymbol : m_symbolsList) {
switch(foundSymbol.token.type) {
case SvdCExpressionParser::xme_identi: {
SvdItem* from = 0;
string lastSearchName;
item->GetDeriveItem(from, symbol.searchname, L_UNDEF, lastSearchName);
item->GetDeriveItem(from, foundSymbol.searchname, L_UNDEF, lastSearchName);
if(!from) {
LogMsg("M244", NAME(lastSearchName), MSG(errText), lineNo);
return false;
}
symbol.svdItem = from;
foundSymbol.svdItem = from;

string name = symbol.svdItem->GetHierarchicalNameResulting();
string name = foundSymbol.svdItem->GetHierarchicalNameResulting();
if(!name.empty()) {
if(symbol.svdItem->GetSvdLevel() == L_Register) {
regList[name] = symbol.svdItem;
if(foundSymbol.svdItem->GetSvdLevel() == L_Register) {
regList[name] = foundSymbol.svdItem;
}
else if(symbol.svdItem->GetSvdLevel() == L_Field) {
SvdItem* item = symbol.svdItem->GetParent()->GetParent();
else if(foundSymbol.svdItem->GetSvdLevel() == L_Field) {
SvdItem* symbolItem = foundSymbol.svdItem->GetParent()->GetParent();
if(item) {
regList[name] = item;
regList[name] = symbolItem;
}
}
else {
Expand Down
11 changes: 7 additions & 4 deletions tools/svdconv/SVDModel/src/SvdDerivedFrom.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,17 +83,17 @@ bool SvdDerivedFrom::CalculateDerivedFrom()
do {
auto it = name.find("%");
if(it == string::npos) {
break;
break;
}
name.erase(it, 1);
} while(1);

const auto lineNo = GetLineNumber();
LogMsg("M206", NAME(name), lineNo);
Invalidate();
auto parent = GetParent();
if(parent) {
parent->Invalidate();
auto invalidParent = GetParent();
if(invalidParent) {
invalidParent->Invalidate();
}
}

Expand All @@ -103,6 +103,9 @@ bool SvdDerivedFrom::CalculateDerivedFrom()
bool SvdDerivedFrom::DeriveItem(SvdItem *from)
{
const auto parent = GetParent();
if(!parent) {
return true;
}

// If there are already any childs, the item is changed from it's derivedFrom item
if(parent->GetChildCount()) {
Expand Down
12 changes: 6 additions & 6 deletions tools/svdconv/SVDModel/src/SvdDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,7 @@ bool SvdDevice::AddToMap(SvdCluster *clust)
if(enumCont) {
AddToMap(enumCont);
}

return true;
}

Expand Down Expand Up @@ -622,8 +622,8 @@ bool SvdDevice::CheckPeripherals(const list<SvdItem*>& childs)
// ClusterNames must be unique to peripherals
const auto regs = peri->GetRegisterContainer();
if(regs) {
const auto& childs = regs->GetChildren();
AddClusterNames(childs);
const auto& children = regs->GetChildren();
AddClusterNames(children);
}
}
}
Expand Down Expand Up @@ -787,12 +787,12 @@ bool SvdDevice::CheckForItemsRegister(SvdRegister* reg)
if(dim) {
const auto& dimChilds = dim->GetChildren();
for(const auto dimChild : dimChilds) {
const auto reg = dynamic_cast<SvdRegister*>(dimChild);
if(!reg || !reg->IsValid()) {
const auto dimReg = dynamic_cast<SvdRegister*>(dimChild);
if(!dimReg || !dimReg->IsValid()) {
continue;
}

itemCnt += CheckForItemsRegister(reg);
itemCnt += CheckForItemsRegister(dimReg);
}
return true;
}
Expand Down
50 changes: 33 additions & 17 deletions tools/svdconv/SVDModel/src/SvdDimension.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,23 +125,26 @@ bool SvdDimension::Construct(XMLTreeElement* xmlElement)
SetLineNumber(xmlElement->GetLineNumber());

if(GetTag().empty()) {
string tag { "Dim data: " };
string thisTag { "Dim data: " };
auto parent = GetParent();
if(parent) {
tag += parent->GetTag();
thisTag += parent->GetTag();
}
else {
tag += "???";
thisTag += "???";
}
SetTag(tag);
SetTag(thisTag);
}

if(!IsTagAllowed(tag)) {
const auto parent = GetParent();
const auto lineNo = xmlElement->GetLineNumber();
const auto svdLevel = parent->GetSvdLevel();
LogMsg("M240", TAG(tag), THISLEVEL(), LEVEL2(GetSvdLevelStr(svdLevel)), lineNo);
parent->Invalidate();
if(parent) {
const auto lineNo = xmlElement->GetLineNumber();
const auto svdLevel = parent->GetSvdLevel();
LogMsg("M240", TAG(tag), THISLEVEL(), LEVEL2(GetSvdLevelStr(svdLevel)), lineNo);
parent->Invalidate();
}

return true;
}

Expand Down Expand Up @@ -343,7 +346,7 @@ bool SvdDimension::CalculateNameFromExpression()
if(!item) {
return true;
}

const auto& itemName = item->GetName();
string name;
uint32_t insertPos = 0;
Expand All @@ -361,9 +364,11 @@ bool SvdDimension::CalculateNameFromExpression()
}

const auto expr = GetExpression();
expr->SetName(name);
expr->SetType(exprType);
expr->SetNameInsertPos(insertPos);
if(expr) {
expr->SetName(name);
expr->SetType(exprType);
expr->SetNameInsertPos(insertPos);
}

return true;
}
Expand Down Expand Up @@ -392,8 +397,10 @@ bool SvdDimension::CalculateDisplayNameFromExpression()
}

const auto expr = GetExpression();
expr->SetDisplayName (name);
expr->SetDisplayNameInsertPos (insertPos);
if(expr) {
expr->SetDisplayName (name);
expr->SetDisplayNameInsertPos (insertPos);
}

return true;
}
Expand Down Expand Up @@ -422,8 +429,10 @@ bool SvdDimension::CalculateDescriptionFromExpression()
}

const auto expr = GetExpression();
expr->SetDescription (descr);
expr->SetDescriptionInsertPos (insertPos);
if(expr) {
expr->SetDescription (descr);
expr->SetDescriptionInsertPos (insertPos);
}

return true;
}
Expand Down Expand Up @@ -521,8 +530,11 @@ bool SvdDimension::CopyItem(SvdItem *from)
bool SvdDimension::AddToMap(const string& dimIndex)
{
const auto parent = GetParent();
const auto lineNo = parent->GetLineNumber();
if(!parent) {
return true;
}

const auto lineNo = parent->GetLineNumber();
auto found = m_dimIndexSet.find(dimIndex);
if(found != m_dimIndexSet.end()) {
LogMsg("M336", LEVEL("<dimIndex>"), NAME(dimIndex), LINE2(lineNo), lineNo);
Expand All @@ -541,6 +553,10 @@ bool SvdDimension::CheckItem()
}

const auto parent = GetParent();
if(!parent) {
return true;
}

const auto name = parent->GetNameCalculated();
const auto lineNo = parent->GetLineNumber();

Expand Down
Loading