Fix 10718: Crash in CheckOther::checkDuplicateExpression (#3713)

This commit is contained in:
Paul Fultz II 2022-01-16 05:34:20 -06:00 committed by GitHub
parent 4af98f21d6
commit 89bc226738
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 15 additions and 1 deletions

View File

@ -1721,7 +1721,7 @@ bool isUniqueExpression(const Token* tok)
if (f.type != Function::eFunction)
continue;
const std::string freturnType = f.retType ? f.retType->name() : f.retDef->stringifyList(f.tokenDef);
const std::string freturnType = f.retType ? f.retType->name() : f.retDef->stringifyList(f.returnDefEnd());
if (f.argumentList.size() == fun->argumentList.size() &&
returnType == freturnType &&
f.name() != fun->name()) {

View File

@ -1258,6 +1258,9 @@ std::string Token::stringifyList(const stringifyOptions& options, const std::vec
unsigned int fileIndex = options.files ? ~0U : mImpl->mFileIndex;
std::map<int, unsigned int> lineNumbers;
for (const Token *tok = this; tok != end; tok = tok->next()) {
assert(tok && "end precedes token");
if (!tok)
return ret;
bool fileChange = false;
if (tok->mImpl->mFileIndex != fileIndex) {
if (fileIndex != ~0U) {

View File

@ -6179,6 +6179,17 @@ private:
"}");
ASSERT_EQUALS("", errout.str());
// #10718
// Should probably not be inconclusive
check("struct a {\n"
" int b() const;\n"
" auto c() -> decltype(0) {\n"
" a d;\n"
" int e = d.b(), f = d.b();\n"
" return e + f;\n"
" }\n"
"};\n");
ASSERT_EQUALS("[test.cpp:5] -> [test.cpp:5]: (style, inconclusive) Same expression used in consecutive assignments of 'e' and 'f'.\n", errout.str());
}
void multiConditionSameExpression() {