Skip to content

Commit 83ac6bf

Browse files
Fix crash when calling estimateSize() (f'up to #12139) (#5628)
1 parent 966a89d commit 83ac6bf

2 files changed

Lines changed: 15 additions & 1 deletion

File tree

lib/checkother.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2887,7 +2887,8 @@ void CheckOther::checkRedundantCopy()
28872887
if (fScope && fScope->bodyEnd && Token::Match(fScope->bodyEnd->tokAt(-3), "return %var% ;")) {
28882888
const Token* varTok = fScope->bodyEnd->tokAt(-2);
28892889
if (varTok->variable() && !varTok->variable()->isGlobal() &&
2890-
(!varTok->variable()->type() || estimateSize(varTok->variable()->type(), mSettings, symbolDatabase) > 2 * mSettings->platform.sizeof_pointer))
2890+
(!varTok->variable()->type() || !varTok->variable()->type()->classScope ||
2891+
estimateSize(varTok->variable()->type(), mSettings, symbolDatabase) > 2 * mSettings->platform.sizeof_pointer))
28912892
redundantCopyError(startTok, startTok->str());
28922893
}
28932894
}

test/cfg/qt.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -580,3 +580,16 @@ namespace {
580580
Q_PROPERTY(QHash<QString, int> hash READ hash WRITE setHash)
581581
};
582582
}
583+
584+
struct SEstimateSize {
585+
inline const QString& get() const { return m; }
586+
QString m;
587+
};
588+
589+
class QString;
590+
591+
void dontCrashEstimateSize(const SEstimateSize& s) {
592+
// cppcheck-suppress redundantCopyLocalConst
593+
QString q = s.get();
594+
if (!q.isNull()) {}
595+
}

0 commit comments

Comments
 (0)