Fix FP mismatchAllocDealloc, uninitdata for new with initializer (#5106)

This commit is contained in:
chrchr-github 2023-06-02 13:01:55 +02:00 committed by GitHub
parent 9810bad869
commit 52c0f10fa1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 1 deletions

View File

@ -417,7 +417,7 @@ bool CheckLeakAutoVar::checkScope(const Token * const startToken,
changeAllocStatusIfRealloc(alloctype, fTok, varTok);
} else if (mTokenizer->isCPP() && Token::Match(varTok->tokAt(2), "new !!(")) {
const Token* tok2 = varTok->tokAt(2)->astOperand1();
const bool arrayNew = (tok2 && (tok2->str() == "[" || (tok2->str() == "(" && tok2->astOperand1() && tok2->astOperand1()->str() == "[")));
const bool arrayNew = (tok2 && (tok2->str() == "[" || (Token::Match(tok2, "(|{") && tok2->astOperand1() && tok2->astOperand1()->str() == "[")));
VarInfo::AllocInfo& varAlloc = alloctype[varTok->varId()];
varAlloc.type = arrayNew ? NEW_ARRAY : NEW;
varAlloc.status = VarInfo::ALLOC;

View File

@ -2101,6 +2101,12 @@ private:
" }\n"
"}\n", true);
ASSERT_EQUALS("", errout.str());
check("void f(int i) {\n"
" int* a = new int[i] {};\n"
" delete[] a;\n"
"}\n", /*cpp*/ true);
ASSERT_EQUALS("", errout.str());
}
void smartPointerDeleter() {