Fixed #4390 (False alarm 'Object pointed by an auto_ptr is destroyed using operator delete. You should not use auto_ptr for pointers obtained with operator new[].')

This commit is contained in:
Daniel Marjamäki 2013-05-01 11:11:57 +02:00
parent b2798e929d
commit 287782a679
2 changed files with 29 additions and 23 deletions

View File

@ -1308,13 +1308,12 @@ void CheckStl::checkAutoPointer()
(Token::simpleMatch(tok->tokAt(-3), "< std :: auto_ptr") && Token::Match(tok->tokAt(-4), STL_CONTAINER_LIST))) { (Token::simpleMatch(tok->tokAt(-3), "< std :: auto_ptr") && Token::Match(tok->tokAt(-4), STL_CONTAINER_LIST))) {
autoPointerContainerError(tok); autoPointerContainerError(tok);
} else { } else {
const Token *tok2 = tok->tokAt(2); const Token *tok2 = tok->linkAt(1);
while (tok2) {
if (Token::Match(tok2, "> %var%")) { if (Token::Match(tok2, "> %var%")) {
const Token *tok3 = tok2->tokAt(2); const Token *tok3 = tok2->tokAt(2);
if (Token::Match(tok3, "( new %type%") && hasArrayEndParen(tok3)) { if (Token::Match(tok3, "( new %type%") && hasArrayEndParen(tok3)) {
autoPointerArrayError(tok2->next()); autoPointerArrayError(tok2->next());
break;
} }
while (tok3 && tok3->str() != ";") { while (tok3 && tok3->str() != ";") {
tok3 = tok3->next(); tok3 = tok3->next();
@ -1332,11 +1331,8 @@ void CheckStl::checkAutoPointer()
if (tok2->next()->varId()) { if (tok2->next()->varId()) {
autoPtrVarId.insert(tok2->next()->varId()); autoPtrVarId.insert(tok2->next()->varId());
} }
break;
} }
} }
tok2 = tok2->next();
}
} }
} else { } else {
if (Token::Match(tok, "%var% = %var% ;")) { if (Token::Match(tok, "%var% = %var% ;")) {

View File

@ -2145,6 +2145,16 @@ private:
// ticket #2967 (segmentation fault) // ticket #2967 (segmentation fault)
check("auto_ptr<x>\n"); check("auto_ptr<x>\n");
ASSERT_EQUALS("", errout.str()); ASSERT_EQUALS("", errout.str());
// ticket #4390
check("auto_ptr<ConnectionStringReadStorage> CreateRegistryStringStorage() {\n"
" return auto_ptr<ConnectionStringReadStorage>(new RegistryConnectionStringStorage());\n"
"}\n"
"\n"
"void LookupWindowsUserAccountName() {\n"
" auto_ptr_array<char> domainName(new char[42]);\n"
"}");
ASSERT_EQUALS("", errout.str());
} }
void uselessCalls() { void uselessCalls() {