Skip to content

Commit d8058d0

Browse files
committed
avoid some unchecked pointer dereferences
1 parent 3c011fe commit d8058d0

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

22052205
std::string msg = "Value type is ";
22062206
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)},
@@ -3408,6 +3408,7 @@ bool Tokenizer::simplifyTokens1(const std::string &configuration)
34083408
const bool doValueFlow = !disableValueflowEnv || (std::strcmp(disableValueflowEnv, "1") != 0);
34093409

34103410
if (doValueFlow) {
3411+
assert(mErrorLogger);
34113412
if (mTimerResults) {
34123413
Timer t("Tokenizer::simplifyTokens1::ValueFlow", mSettings.showtime, mTimerResults);
34133414
ValueFlow::setValues(list, *mSymbolDatabase, *mErrorLogger, mSettings, mTimerResults);
@@ -6069,7 +6070,8 @@ void Tokenizer::dump(std::ostream &out) const
60696070
out << outs;
60706071
outs.clear();
60716072

6072-
mSymbolDatabase->printXml(out);
6073+
if (mSymbolDatabase)
6074+
mSymbolDatabase->printXml(out);
60736075

60746076
containers.erase(nullptr);
60756077
if (!containers.empty()) {

0 commit comments

Comments
 (0)