Skip to content

Commit 264f85c

Browse files
committed
avoid some unchecked pointer dereferences
1 parent f48b05f commit 264f85c

2 files changed

Lines changed: 6 additions & 4 deletions

File tree

lib/symboldatabase.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1991,7 +1991,7 @@ void SymbolDatabase::validateExecutableScopes() const
19911991
for (std::size_t i = 0; i < functions; ++i) {
19921992
const Scope* const scope = functionScopes[i];
19931993
const Function* const function = scope->function;
1994-
if (scope->isExecutable() && !function) {
1994+
if (mErrorLogger && scope->isExecutable() && !function) {
19951995
const std::list<const Token*> callstack(1, scope->classDef);
19961996
const std::string msg = std::string("Executable scope '") + scope->classDef->str() + "' with unknown function.";
19971997
const ErrorMessage errmsg(callstack, &mTokenizer.list, Severity::debug,
@@ -2058,7 +2058,7 @@ void SymbolDatabase::debugSymbolDatabase() const
20582058
for (const Token* tok = mTokenizer.list.front(); tok != mTokenizer.list.back(); tok = tok->next()) {
20592059
if (tok->astParent() && tok->astParent()->getTokenDebug() == tok->getTokenDebug())
20602060
continue;
2061-
if (tok->getTokenDebug() == TokenDebug::ValueType) {
2061+
if (mErrorLogger && tok->getTokenDebug() == TokenDebug::ValueType) {
20622062

20632063
std::string msg = "Value type is ";
20642064
ErrorPath errorPath;

lib/tokenize.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1135,7 +1135,7 @@ void Tokenizer::simplifyTypedefCpp()
11351135
return;
11361136

11371137
if (maxTime > 0 && std::time(nullptr) > maxTime) {
1138-
if (mSettings->debugwarnings) {
1138+
if (mErrorLogger && mSettings->debugwarnings) {
11391139
ErrorMessage::FileLocation loc;
11401140
loc.setfile(list.getFiles()[0]);
11411141
ErrorMessage errmsg({std::move(loc)},
@@ -3359,6 +3359,7 @@ bool Tokenizer::simplifyTokens1(const std::string &configuration)
33593359
const bool doValueFlow = !disableValueflowEnv || (std::strcmp(disableValueflowEnv, "1") != 0);
33603360

33613361
if (doValueFlow) {
3362+
assert(mErrorLogger);
33623363
if (mTimerResults) {
33633364
Timer t("Tokenizer::simplifyTokens1::ValueFlow", mSettings->showtime, mTimerResults);
33643365
ValueFlow::setValues(list, *mSymbolDatabase, *mErrorLogger, mSettings, mTimerResults);
@@ -5900,7 +5901,8 @@ void Tokenizer::dump(std::ostream &out) const
59005901
}
59015902
out << " </tokenlist>" << std::endl;
59025903

5903-
mSymbolDatabase->printXml(out);
5904+
if (mSymbolDatabase)
5905+
mSymbolDatabase->printXml(out);
59045906

59055907
containers.erase(nullptr);
59065908
if (!containers.empty()) {

0 commit comments

Comments
 (0)