Fixed #625 (cppcheck dumps core on valid code)

This commit is contained in:
danmar 2009-08-28 12:57:29 +02:00
parent bb2bda0be4
commit 4f6b79b761
2 changed files with 20 additions and 12 deletions

View File

@ -2160,6 +2160,8 @@ bool Tokenizer::simplifyQuestionMark()
bool Tokenizer::simplifyCasts()
{
createLinks();
bool ret = false;
for (Token *tok = _tokens; tok; tok = tok->next())
{

View File

@ -39,8 +39,7 @@ private:
void run()
{
TEST_CASE(cast0);
TEST_CASE(cast1);
TEST_CASE(cast);
TEST_CASE(iftruefalse);
TEST_CASE(combine_strings);
TEST_CASE(double_plus);
@ -122,19 +121,26 @@ private:
return ret;
}
void cast0()
void cast()
{
const char code1[] = " if ( p == (char *)0 ) ";
const char code2[] = " if ( p == 0 ) ";
ASSERT_EQUALS(tok(code1), tok(code2));
ASSERT_EQUALS("if ( p == 0 )", tok("if (p == (char *)0)"));
ASSERT_EQUALS("return str ;", tok("return (char *)str;"));
{
const char code[] = "static void crash()\n"
"{\n"
" goto err_exit;\n"
"err_exit:\n"
" (void)foo();\n"
"}\n";
const char expected[] = "static void crash ( ) "
"{ foo ( ) ; }";
ASSERT_EQUALS(expected, tok(code));
}
}
void cast1()
{
const char code[] = "return (unsigned char *)str;";
const char expected[] = "return str;";
ASSERT_EQUALS(tok(expected), tok(code));
}
void iftruefalse()
{