Skip to content

Commit

Permalink
avoid some unchecked pointer dereferences
Browse files Browse the repository at this point in the history
  • Loading branch information
firewave committed Mar 9, 2024
1 parent 0fa10b1 commit db87503
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
4 changes: 2 additions & 2 deletions lib/symboldatabase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2135,7 +2135,7 @@ void SymbolDatabase::validateExecutableScopes() const
for (std::size_t i = 0; i < functions; ++i) {
const Scope* const scope = functionScopes[i];
const Function* const function = scope->function;
if (scope->isExecutable() && !function) {
if (mErrorLogger && scope->isExecutable() && !function) {
const std::list<const Token*> callstack(1, scope->classDef);
const std::string msg = std::string("Executable scope '") + scope->classDef->str() + "' with unknown function.";
const ErrorMessage errmsg(callstack, &mTokenizer.list, Severity::debug,
Expand Down Expand Up @@ -2202,7 +2202,7 @@ void SymbolDatabase::debugSymbolDatabase() const
for (const Token* tok = mTokenizer.list.front(); tok != mTokenizer.list.back(); tok = tok->next()) {
if (tok->astParent() && tok->astParent()->getTokenDebug() == tok->getTokenDebug())
continue;
if (tok->getTokenDebug() == TokenDebug::ValueType) {
if (mErrorLogger && tok->getTokenDebug() == TokenDebug::ValueType) {

std::string msg = "Value type is ";
ErrorPath errorPath;
Expand Down
6 changes: 4 additions & 2 deletions lib/tokenize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1149,7 +1149,7 @@ void Tokenizer::simplifyTypedefCpp()
return;

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

if (doValueFlow) {
assert(mErrorLogger);
if (mTimerResults) {
Timer t("Tokenizer::simplifyTokens1::ValueFlow", mSettings.showtime, mTimerResults);
ValueFlow::setValues(list, *mSymbolDatabase, *mErrorLogger, mSettings, mTimerResults);
Expand Down Expand Up @@ -6066,7 +6067,8 @@ void Tokenizer::dump(std::ostream &out) const
out << outs;
outs.clear();

mSymbolDatabase->printXml(out);
if (mSymbolDatabase)
mSymbolDatabase->printXml(out);

containers.erase(nullptr);
if (!containers.empty()) {
Expand Down

0 comments on commit db87503

Please sign in to comment.