Skip to content

Commit db87503

Browse files
committed
avoid some unchecked pointer dereferences
1 parent 0fa10b1 commit db87503

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
@@ -2135,7 +2135,7 @@ void SymbolDatabase::validateExecutableScopes() const
21352135
for (std::size_t i = 0; i < functions; ++i) {
21362136
const Scope* const scope = functionScopes[i];
21372137
const Function* const function = scope->function;
2138-
if (scope->isExecutable() && !function) {
2138+
if (mErrorLogger && scope->isExecutable() && !function) {
21392139
const std::list<const Token*> callstack(1, scope->classDef);
21402140
const std::string msg = std::string("Executable scope '") + scope->classDef->str() + "' with unknown function.";
21412141
const ErrorMessage errmsg(callstack, &mTokenizer.list, Severity::debug,
@@ -2202,7 +2202,7 @@ void SymbolDatabase::debugSymbolDatabase() const
22022202
for (const Token* tok = mTokenizer.list.front(); tok != mTokenizer.list.back(); tok = tok->next()) {
22032203
if (tok->astParent() && tok->astParent()->getTokenDebug() == tok->getTokenDebug())
22042204
continue;
2205-
if (tok->getTokenDebug() == TokenDebug::ValueType) {
2205+
if (mErrorLogger && tok->getTokenDebug() == TokenDebug::ValueType) {
22062206

22072207
std::string msg = "Value type is ";
22082208
ErrorPath errorPath;

lib/tokenize.cpp

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

11511151
if (maxTime > 0 && std::time(nullptr) > maxTime) {
1152-
if (mSettings.debugwarnings) {
1152+
if (mErrorLogger && mSettings.debugwarnings) {
11531153
ErrorMessage::FileLocation loc;
11541154
loc.setfile(list.getFiles()[0]);
11551155
ErrorMessage errmsg({std::move(loc)},
@@ -3405,6 +3405,7 @@ bool Tokenizer::simplifyTokens1(const std::string &configuration)
34053405
const bool doValueFlow = !disableValueflowEnv || (std::strcmp(disableValueflowEnv, "1") != 0);
34063406

34073407
if (doValueFlow) {
3408+
assert(mErrorLogger);
34083409
if (mTimerResults) {
34093410
Timer t("Tokenizer::simplifyTokens1::ValueFlow", mSettings.showtime, mTimerResults);
34103411
ValueFlow::setValues(list, *mSymbolDatabase, *mErrorLogger, mSettings, mTimerResults);
@@ -6066,7 +6067,8 @@ void Tokenizer::dump(std::ostream &out) const
60666067
out << outs;
60676068
outs.clear();
60686069

6069-
mSymbolDatabase->printXml(out);
6070+
if (mSymbolDatabase)
6071+
mSymbolDatabase->printXml(out);
60706072

60716073
containers.erase(nullptr);
60726074
if (!containers.empty()) {

0 commit comments

Comments
 (0)