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 alerts #451

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 libs/errlog/src/ErrLog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ ErrLog::~ErrLog ()
m_ErrOutputter = nullptr;
}

delete m_outBuf;
delete[] m_outBuf;
}

void ErrLog::InitMessageTable()
Expand Down
90 changes: 50 additions & 40 deletions libs/xmlreader/src/XML_Reader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ Err XML_Reader::Close()
size_t XML_Reader::ReadLine()
{
if(!m_InputSourceReader->IsValid()) {
LogMsg("M410", GetLineNumber()); //fprintf(stderr, "Lost xml file stream at line %d.\n", GetLineNumber());
LogMsg("M410", GetLineNumber());
return 0;
}

Expand Down Expand Up @@ -401,51 +401,61 @@ UTFCode XML_Reader::CheckUTF(const string& text)

UTFCode utfDetected = UTFCode::UTF_NULL;
switch (*str++) {
case (char)0xEF: {
switch (*str++) {
case (char)0xBB: {
case (char)0xEF: {
switch (*str++) {
case (char)0xBF: {
utfDetected = UTFCode::UTF8;
} break;
case (char)0xBB: {
switch (*str++) {
case (char)0xBF: {
utfDetected = UTFCode::UTF8;
} break;
default:
break;
}
} break;
default:
break;
}
} break;
}
} break;

case (char)0xFE: {
switch (*str++) {
case (char)0xFF: {
utfDetected = UTFCode::UTF16_BE;
case (char)0xFE: {
switch (*str++) {
case (char)0xFF: {
utfDetected = UTFCode::UTF16_BE;
} break;
default:
break;
}
} break;
}
} break;

case (char)0xFF: {
switch (*str++) {
case (char)0xFE: {
utfDetected = UTFCode::UTF16_LE;
case (char)0xFF: {
switch (*str++) {
case (char)0xFE: {
utfDetected = UTFCode::UTF16_LE;
} break;
default:
break;
}
} break;
}
} break;
default:
break;
}

if (utfDetected != UTFCode::UTF_NULL) {
string text = "UTF Error";
string txt = "UTF Error";

auto find = m_UTFCodeText.find(utfDetected);
if (find != m_UTFCodeText.end()) {
text = find->second;
txt = find->second;
}

LogMsg("M411", VAL("UTF", text)); //printf("\nUnicode: Preamble for %s should not be used, already specified via '<?xml'");
LogMsg("M411", VAL("UTF", txt)); //"\nUnicode: Preamble for %s should not be used, already specified via '<?xml'"
if (utfDetected != UTFCode::UTF8) {
LogMsg("M413", VAL("UTF", text)); // printf("\nUTF Format not supported: %s", UTFCode_str[isUtf]);
LogMsg("M413", VAL("UTF", txt)); // "\nUTF Format not supported: %s", UTFCode_str[isUtf]
}
}

if (*str) {
LogMsg("M412", VAL("STR", str)); //printf("\nUnicode: Unsupported format or extra characters found before '<?xml': \"%s\"\n", str);
LogMsg("M412", VAL("STR", str)); //"\nUnicode: Unsupported format or extra characters found before '<?xml': \"%s\"\n", str
}

return utfDetected;
Expand Down Expand Up @@ -539,13 +549,13 @@ bool XML_Reader::ReadNext()
specialChar += c;

if (c == '/' && c_prev == '<') { // probably found an error
LogMsg("M414", VAL("SPECIALCHAR", specialChar), MSG("Found END Tag!"), GetLineNumber()); // printf("Line %d: Problem while parsing XML special characters: '%s'. Found END Tag!\n", GetLineNumber(), m_xmlData.specialChar);
LogMsg("M414", VAL("SPECIALCHAR", specialChar), MSG("Found END Tag!"), GetLineNumber()); // "Line %d: Problem while parsing XML special characters: '%s'. Found END Tag!\n", GetLineNumber(), m_xmlData.specialChar
CorrectCnt(-1 * (int)specialChar.length());
break;
}

if (specialChar.length() > 32) {
LogMsg("M414", VAL("SPECIALCHAR", specialChar), MSG("String too long!"), GetLineNumber()); // printf("Line %d: Problem while parsing XML special characters: '%s'. String too uint32_t!\n", GetLineNumber(), m_xmlData.specialChar);
LogMsg("M414", VAL("SPECIALCHAR", specialChar), MSG("String too long!"), GetLineNumber()); // "Line %d: Problem while parsing XML special characters: '%s'. String too uint32_t!\n", GetLineNumber(), m_xmlData.specialChar
CorrectCnt(-1 * (int)specialChar.length());
break;
}
Expand Down Expand Up @@ -710,7 +720,7 @@ void XML_Reader::PrintTagStack()
msg += tag;
}

LogMsg("M406", MSG(msg)); // printf("XML Stack: ");
LogMsg("M406", MSG(msg)); // "XML Stack: "
}

bool XML_Reader::NextEntry ()
Expand All @@ -734,29 +744,29 @@ bool XML_Reader::NextEntry ()
PopTag(xmlTag);

if(!m_bPrevTagIsSingle && (xmlTag != m_xmlData.tagData)) {
LogMsg("M417", GetLineNumber()); // printf("Line %d: Inconsistent XML Structure\n", GetLineNumber());
LogMsg("M417", GetLineNumber()); // "Line %d: Inconsistent XML Structure\n", GetLineNumber()
PushTag(xmlTag);
PrintTagStack();
PopTag(xmlTag);

if(doTryAgain) {
if(!xmlTag.empty()) {
LogMsg("M401", VAL("TAG", xmlTag)); // printf("Line %d: Did you mean '%s' ?\n", GetLineNumber(), xmlTag);
LogMsg("M401", VAL("TAG", xmlTag)); // "Line %d: Did you mean '%s' ?\n", GetLineNumber(), xmlTag
m_xmlData.tagData = xmlTag;
}
}
}
else if(m_bPrevTagIsSingle) {
m_bPrevTagIsSingle = false;
if(xmlTag != m_xmlData.tagData) {
LogMsg("M417", GetLineNumber()); // printf("Line %d: Inconsistent XML Structure\n", GetLineNumber());
LogMsg("M417", GetLineNumber()); // "Line %d: Inconsistent XML Structure\n", GetLineNumber()
PushTag(xmlTag);
PrintTagStack();
PopTag(xmlTag);

if(doTryAgain) {
if(!xmlTag.empty() && (xmlTag != m_xmlData.tagData)) {
LogMsg("M401", VAL("TAG", xmlTag)); // printf("Line %d: Did you mean '%s' ?\n", GetLineNumber(), xmlTag);
LogMsg("M401", VAL("TAG", xmlTag)); // "Line %d: Did you mean '%s' ?\n", GetLineNumber(), xmlTag
m_xmlData.tagData = xmlTag;
}
}
Expand All @@ -765,11 +775,11 @@ bool XML_Reader::NextEntry ()
}
else if(m_xmlData.type == TagType::TAG_BEGIN) {
if(!PushTag(m_xmlData.tagData)) {
LogMsg("M418", GetLineNumber()); // printf("Line %d: XML Stack deeper than 30 Items! Giving up...\n", GetLineNumber());
LogMsg("M418", GetLineNumber()); // "Line %d: XML Stack deeper than 30 Items! Giving up...\n", GetLineNumber()
return 0;
}
if(m_bIsPrevText) {
LogMsg("M419", GetLineNumber()); // printf("Line %d: Begin Tag follows Text. Missing End Tag?\n", GetLineNumber());
LogMsg("M419", GetLineNumber()); // "Line %d: Begin Tag follows Text. Missing End Tag?\n", GetLineNumber()
m_bIsPrevText = false;
string xmlTag;
PopTag(xmlTag); // correct stack
Expand Down Expand Up @@ -801,7 +811,7 @@ bool XML_Reader::Recover()
uint32_t recoverCnt=0;

errorTag = m_xmlData.tagData;
LogMsg("M407", GetLineNumber()); // printf("\nLine %d: Recover from Error\n", GetLineNumber());
LogMsg("M407", GetLineNumber()); // "\nLine %d: Recover from Error\n", GetLineNumber()

if(m_bFirstTry) { // try to read a statement then return
bool bOk = ReadNext();
Expand Down Expand Up @@ -839,14 +849,14 @@ bool XML_Reader::Recover()
}

if(m_xmlData.tagData == errorTag) { // found end of unknown tag
LogMsg("M409", VAL("TAG", errorTag), GetLineNumber()); // printf("Line %d: Skipping unknown Tag: '%s'\n", GetLineNumber(), errorTag);
LogMsg("M409", VAL("TAG", errorTag), GetLineNumber()); // "Line %d: Skipping unknown Tag: '%s'\n", GetLineNumber(), errorTag
break;
}
}

recoverCnt++;
if(recoverCnt > 100) {
LogMsg("M408", GetLineNumber()); // printf("\nLine %d: Recover from Error: giving up after 100 tries...\n", GetLineNumber());
LogMsg("M408", GetLineNumber()); // "\nLine %d: Recover from Error: giving up after 100 tries...\n", GetLineNumber()
break;
}
} while(bOk);
Expand Down Expand Up @@ -917,13 +927,13 @@ bool XML_Reader::ReadNextAttribute(bool bInorePrefixes)
specialChar += c;

if(c == '/' && cPrev == '<') { // probably found an error
LogMsg("M414", VAL("SPECIALCHAR", specialChar), MSG("Found END Tag!"), GetLineNumber()); // printf("Line %d: Problem while parsing XML special characters: '%s'. Found END Tag!\n", GetLineNumber(), m_xmlData.specialChar);
LogMsg("M414", VAL("SPECIALCHAR", specialChar), MSG("Found END Tag!"), GetLineNumber()); // "Line %d: Problem while parsing XML special characters: '%s'. Found END Tag!\n", GetLineNumber(), m_xmlData.specialChar
CorrectCnt(-1 * (int)specialChar.length());
break;
}

if (specialChar.length() > 32) {
LogMsg("M414", VAL("SPECIALCHAR", specialChar), MSG("String too uint32_t!"), GetLineNumber()); // printf("Line %d: Problem while parsing XML special characters: '%s'. String too uint32_t!\n", GetLineNumber(), m_xmlData.specialChar);
LogMsg("M414", VAL("SPECIALCHAR", specialChar), MSG("String too uint32_t!"), GetLineNumber()); // "Line %d: Problem while parsing XML special characters: '%s'. String too uint32_t!\n", GetLineNumber(), m_xmlData.specialChar
CorrectCnt(-1 * (int)specialChar.length());
break;
}
Expand Down
4 changes: 2 additions & 2 deletions tools/packchk/src/CheckComponents.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ bool CheckComponent::CheckComp(RteItem* item)
if(pKg) {
RteGeneratorContainer* genCont = pKg->GetGenerators();
if(genCont) {
for(auto item : genCont->GetChildren()) {
RteGenerator* generator = dynamic_cast<RteGenerator*>(item);
for(auto itm : genCont->GetChildren()) {
RteGenerator* generator = dynamic_cast<RteGenerator*>(itm);
if(!generator) {
continue;
}
Expand Down
6 changes: 3 additions & 3 deletions tools/packchk/src/CheckConditions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,9 @@ void UsedConditionsVisitor::GetUsedSubConditions(RteCondition* cond)
m_Conditions->AddUsedCondition(cond);

for(auto expression : cond->GetChildren()) {
RteCondition* cond = expression->GetCondition();
if(cond) {
GetUsedSubConditions(cond);
RteCondition* c = expression->GetCondition();
if(c) {
GetUsedSubConditions(c);
}
else {
m_Conditions->TestSubConditions(expression);
Expand Down
4 changes: 3 additions & 1 deletion tools/packchk/src/CheckFiles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,9 @@ const string& CheckFiles::GetFolder(RteItem* item) const
}
else if(tag == "environment") {
RteItem* parent = item->GetParent();
return parent->GetAttribute("folder");
if(parent) {
return parent->GetAttribute("folder");
}
}

return RteUtils::EMPTY_STRING;
Expand Down
6 changes: 4 additions & 2 deletions tools/packchk/src/ValidateSemantic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -730,8 +730,10 @@ bool ValidateSemantic::TestComponentDependencies()
}
else if(api) {
RtePackage* apiPkg = api->GetPackage();
const string& packName = apiPkg->GetPackageFileName();
LogMsg("M378", CCLASS(compClass), CGROUP(compGroup), CSUB(compSub), CVER(compVer), NAME(packName), lineNo);
if(apiPkg) {
const string& packN = apiPkg->GetPackageFileName();
LogMsg("M378", CCLASS(compClass), CGROUP(compGroup), CSUB(compSub), CVER(compVer), NAME(packN), lineNo);
}
}

RteDependencyResult dependencyResult;
Expand Down
31 changes: 15 additions & 16 deletions tools/packchk/src/ValidateSyntax.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -220,10 +220,10 @@ bool ValidateSyntax::CheckInfo(RtePackage* pKg)
LogMsg("M305");
bInfoComplete = false;
}
for(auto release : releases) {
const string& rVer = release->GetVersionString();
const string& rDescr = release->GetDescription();
int lineNo = release->GetLineNumber();
for(auto rel : releases) {
const string& rVer = rel->GetVersionString();
const string& rDescr = rel->GetDescription();
int lineNo = rel->GetLineNumber();

if(rVer.empty() && !rDescr.empty()) {
LogMsg("M328", VAL("DESCR", rDescr), lineNo);
Expand Down Expand Up @@ -673,13 +673,13 @@ bool ValidateSyntax::CheckFeatureDevice(RteDeviceProperty* prop, const string& d
}
else {
ok = false;
auto itexisting = m_featureTableDeviceLowerCase.find(typeLower);
if(itexisting != m_featureTableDeviceLowerCase.end()) {
existingFeature = &(itexisting->second->second);
auto itexist = m_featureTableDeviceLowerCase.find(typeLower);
if(itexist != m_featureTableDeviceLowerCase.end()) {
existingFeature = &(itexist->second->second);
}

if(existingFeature) {
LogMsg("M372", MCU(devName), SECTION("Device"), VAL("FEATURE", type), VAL("KNOWNFEATURE", itexisting->second->first), VAL("DESCR", existingFeature->defaultName), lineNo);
LogMsg("M372", MCU(devName), SECTION("Device"), VAL("FEATURE", type), VAL("KNOWNFEATURE", itexist->second->first), VAL("DESCR", existingFeature->defaultName), lineNo);
}
else {
LogMsg("M371", MCU(devName), SECTION("Device"), VAL("FEATURE", type), lineNo);
Expand Down Expand Up @@ -719,13 +719,13 @@ bool ValidateSyntax::CheckFeatureBoard(RteItem* prop, const string& boardName)
}
else {
ok = false;
auto itexisting = m_featureTableBoardLowerCase.find(typeLower);
if(itexisting != m_featureTableBoardLowerCase.end()) {
existingFeature = &(itexisting->second->second);
auto itexist = m_featureTableBoardLowerCase.find(typeLower);
if(itexist != m_featureTableBoardLowerCase.end()) {
existingFeature = &(itexist->second->second);
}

if(existingFeature) {
LogMsg("M372", MCU(boardName), SECTION("Board"), VAL("FEATURE", type), VAL("KNOWNFEATURE", itexisting->second->first), VAL("DESCR", existingFeature->defaultName), lineNo);
LogMsg("M372", MCU(boardName), SECTION("Board"), VAL("FEATURE", type), VAL("KNOWNFEATURE", itexist->second->first), VAL("DESCR", existingFeature->defaultName), lineNo);
}
else {
LogMsg("M371", MCU(boardName), SECTION("Board"), VAL("FEATURE", type), lineNo);
Expand Down Expand Up @@ -1096,15 +1096,14 @@ bool ValidateSyntax::CheckBoardProperties(RteItem* boardItem, map<string, RteIte
map<string, RteItem*> properties;
map<string, RteItem*> allProperties = prevProperties; // copy from previous recursion step

for(auto boardItem : boardItem->GetChildren()) {
RteItem* item = dynamic_cast<RteItem*>(boardItem);
for(auto item : boardItem->GetChildren()) {
if(!item) {
continue;
}

const string& tag = item->GetTag();
if(tag == "feature") {
CheckAddBoardProperty(item, properties, boardItem->GetName());
CheckAddBoardProperty(item, properties, item->GetName());
}
}

Expand Down Expand Up @@ -1919,7 +1918,7 @@ bool ValidateSyntax::CheckRequirements_Packages(RteItem* requirement)
}

const string& pkName = pk->GetName();
const string& pkVendor = pk->GetAttribute("vendor"); //GetVendorName();
const string& pkVendor = pk->GetAttribute("vendor");
const string& pkVersion = pk->GetVersionString();

msg += "\n ";
Expand Down