Fix #1065 (Internal error - incrementing single char in char array)
http://sourceforge.net/apps/trac/cppcheck/ticket/1065
This commit is contained in:
parent
e5c507dc02
commit
bd024b7a2d
|
@ -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);
|
||||
|
|
|
@ -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));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue