fix #2967 (segmentation fault of cppcheck ( auto_ptr< x >))

This commit is contained in:
Robert Reif 2011-08-05 18:18:30 -04:00
parent fd01a7555a
commit fa82d43562
2 changed files with 7 additions and 2 deletions

View File

@ -1122,7 +1122,8 @@ void CheckStl::checkAutoPointer()
{ {
if (Token::simpleMatch(tok, "auto_ptr <")) if (Token::simpleMatch(tok, "auto_ptr <"))
{ {
if ((tok->previous()->str() == "<" && Token::Match(tok->tokAt(-2), STL_CONTAINER_LIST)) || (Token::Match(tok->tokAt(-3), "< std :: auto_ptr") && Token::Match(tok->tokAt(-4), STL_CONTAINER_LIST))) if ((tok->previous() && tok->previous()->str() == "<" && Token::Match(tok->tokAt(-2), STL_CONTAINER_LIST)) ||
(Token::Match(tok->tokAt(-3), "< std :: auto_ptr") && Token::Match(tok->tokAt(-4), STL_CONTAINER_LIST)))
{ {
autoPointerContainerError(tok); autoPointerContainerError(tok);
} }

View File

@ -1424,9 +1424,13 @@ private:
"}\n"); "}\n");
ASSERT_EQUALS("[test.cpp:4]: (error) Object pointed by an 'auto_ptr' is destroyed using operator 'delete'. You should not use 'auto_ptr' for pointers obtained with operator 'new[]'.\n", errout.str()); ASSERT_EQUALS("[test.cpp:4]: (error) Object pointed by an 'auto_ptr' is destroyed using operator 'delete'. You should not use 'auto_ptr' for pointers obtained with operator 'new[]'.\n", errout.str());
// ticket #1887 infinite loop // ticket #2887 (infinite loop)
check("A::A(std::auto_ptr<X> e){}\n"); check("A::A(std::auto_ptr<X> e){}\n");
ASSERT_EQUALS("", errout.str()); ASSERT_EQUALS("", errout.str());
// ticket #2967 (segmentation fault)
check("auto_ptr<x>\n");
ASSERT_EQUALS("", errout.str());
} }