From 4f6b79b761bb164efe23331f0c05b9c6efb062f4 Mon Sep 17 00:00:00 2001 From: danmar Date: Fri, 28 Aug 2009 12:57:29 +0200 Subject: [PATCH] Fixed #625 (cppcheck dumps core on valid code) --- src/tokenize.cpp | 2 ++ test/testsimplifytokens.cpp | 30 ++++++++++++++++++------------ 2 files changed, 20 insertions(+), 12 deletions(-) diff --git a/src/tokenize.cpp b/src/tokenize.cpp index 99e6ba9e9..628825055 100644 --- a/src/tokenize.cpp +++ b/src/tokenize.cpp @@ -2160,6 +2160,8 @@ bool Tokenizer::simplifyQuestionMark() bool Tokenizer::simplifyCasts() { + createLinks(); + bool ret = false; for (Token *tok = _tokens; tok; tok = tok->next()) { diff --git a/test/testsimplifytokens.cpp b/test/testsimplifytokens.cpp index 93a64c5d9..7ac14b58c 100644 --- a/test/testsimplifytokens.cpp +++ b/test/testsimplifytokens.cpp @@ -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() {