Fix #1065 (Internal error - incrementing single char in char array)

http://sourceforge.net/apps/trac/cppcheck/ticket/1065
This commit is contained in:
Reijo Tomperi 2009-12-07 23:42:30 +02:00
parent e5c507dc02
commit bd024b7a2d
2 changed files with 21 additions and 9 deletions

View File

@ -3676,7 +3676,8 @@ bool Tokenizer::simplifyKnownVariables()
ret = true;
}
if (Token::Match(tok3->next(), "++|-- %varid% !!.", varid))
if (Token::Match(tok3->next(), "++|-- %varid%", varid) &&
!Token::Match(tok3->tokAt(3), "[.[]"))
{
incdec(value, tok3->strAt(1));
tok2->tokAt(2)->str(value);

View File

@ -515,14 +515,25 @@ private:
void removePreIncrement()
{
const char code[] = "void f()\n"
"{\n"
" unsigned int c = 0;\n"
" ++c;\n"
" if (c>0) { ++c; }\n"
" ++c;\n"
"}\n";
ASSERT_EQUALS("void f ( ) { int c ; c = 3 ; ; { ; } ; }", tok(code));
{
const char code[] = "void f()\n"
"{\n"
" unsigned int c = 0;\n"
" ++c;\n"
" if (c>0) { ++c; }\n"
" ++c;\n"
"}\n";
ASSERT_EQUALS("void f ( ) { int c ; c = 3 ; ; { ; } ; }", tok(code));
}
{
const char code[] = "void f()\n"
"{\n"
" char a[] = \"p\";\n"
" ++a[0];\n"
"}\n";
ASSERT_EQUALS("void f ( ) { char * a ; a = \"p\" ; ++ a [ 0 ] ; }", tok(code));
}
}