Fix crash when calling estimateSize() (f'up to #12139) (#5628)

This commit is contained in:
chrchr-github 2023-11-06 15:22:59 +01:00 committed by GitHub
parent 966a89d5f4
commit 83ac6bfa0f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 1 deletions

View File

@ -2887,7 +2887,8 @@ void CheckOther::checkRedundantCopy()
if (fScope && fScope->bodyEnd && Token::Match(fScope->bodyEnd->tokAt(-3), "return %var% ;")) {
const Token* varTok = fScope->bodyEnd->tokAt(-2);
if (varTok->variable() && !varTok->variable()->isGlobal() &&
(!varTok->variable()->type() || estimateSize(varTok->variable()->type(), mSettings, symbolDatabase) > 2 * mSettings->platform.sizeof_pointer))
(!varTok->variable()->type() || !varTok->variable()->type()->classScope ||
estimateSize(varTok->variable()->type(), mSettings, symbolDatabase) > 2 * mSettings->platform.sizeof_pointer))
redundantCopyError(startTok, startTok->str());
}
}

View File

@ -580,3 +580,16 @@ namespace {
Q_PROPERTY(QHash<QString, int> hash READ hash WRITE setHash)
};
}
struct SEstimateSize {
inline const QString& get() const { return m; }
QString m;
};
class QString;
void dontCrashEstimateSize(const SEstimateSize& s) {
// cppcheck-suppress redundantCopyLocalConst
QString q = s.get();
if (!q.isNull()) {}
}