Skip to content

Commit 48942c2

Browse files
committed
avoid some unchecked pointer dereferences
1 parent ad8a8f5 commit 48942c2

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

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
@@ -1128,7 +1128,7 @@ void Tokenizer::simplifyTypedefCpp()
11281128
return;
11291129

11301130
if (maxTime > 0 && std::time(nullptr) > maxTime) {
1131-
if (mSettings->debugwarnings) {
1131+
if (mErrorLogger && mSettings->debugwarnings) {
11321132
ErrorMessage::FileLocation loc;
11331133
loc.setfile(list.getFiles()[0]);
11341134
ErrorMessage errmsg({std::move(loc)},
@@ -3354,6 +3354,7 @@ bool Tokenizer::simplifyTokens1(const std::string &configuration)
33543354
const bool doValueFlow = !disableValueflowEnv || (std::strcmp(disableValueflowEnv, "1") != 0);
33553355

33563356
if (doValueFlow) {
3357+
assert(mErrorLogger);
33573358
if (mTimerResults) {
33583359
Timer t("Tokenizer::simplifyTokens1::ValueFlow", mSettings->showtime, mTimerResults);
33593360
ValueFlow::setValues(list, *mSymbolDatabase, *mErrorLogger, mSettings, mTimerResults);
@@ -5895,7 +5896,8 @@ void Tokenizer::dump(std::ostream &out) const
58955896
}
58965897
out << " </tokenlist>" << std::endl;
58975898

5898-
mSymbolDatabase->printXml(out);
5899+
if (mSymbolDatabase)
5900+
mSymbolDatabase->printXml(out);
58995901

59005902
containers.erase(nullptr);
59015903
if (!containers.empty()) {

0 commit comments

Comments
 (0)