From cfe694330f652b3bae685d39b6e8783b85278858 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Mon, 6 Sep 2010 21:34:51 +0200 Subject: [PATCH] Fixed #2024 (Internal Error on multiple append calls on same string object) --- lib/tokenize.cpp | 8 +++++++- test/testsimplifytokens.cpp | 20 ++++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index e69ab4f0c..f8d141b6b 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -3541,8 +3541,13 @@ void Tokenizer::simplifySizeof() else if (tok->next()->str() != "(") { // Add parenthesis around the sizeof + int parlevel = 0; for (Token *tempToken = tok->next(); tempToken; tempToken = tempToken->next()) { + if (tempToken->str() == "(") + ++parlevel; + else if (tempToken->str() == ")") + --parlevel; if (Token::Match(tempToken, "%var%")) { while (tempToken->next()->str() == "[") @@ -3568,8 +3573,9 @@ void Tokenizer::simplifySizeof() // nothing after this tempToken = tempToken->tokAt(2); } - else if (Token::simpleMatch(tempToken->next(), ") .")) + else if (parlevel > 0 && Token::simpleMatch(tempToken->next(), ") .")) { + --parlevel; tempToken = tempToken->tokAt(2); continue; } diff --git a/test/testsimplifytokens.cpp b/test/testsimplifytokens.cpp index 9a9cc6647..0322c1b39 100644 --- a/test/testsimplifytokens.cpp +++ b/test/testsimplifytokens.cpp @@ -82,6 +82,7 @@ private: TEST_CASE(sizeof17); TEST_CASE(sizeof18); TEST_CASE(sizeof19); // #1891 - sizeof 'x' + TEST_CASE(sizeof20); // #2024 - sizeof a) TEST_CASE(sizeofsizeof); TEST_CASE(casting); @@ -1322,6 +1323,25 @@ private: } } + void sizeof20() + { + // ticket #2024 - sizeof a) + const char code[] = "struct struct_a {\n" + " char a[20];\n" + "};\n" + "\n" + "void foo() {\n" + " struct_a a;\n" + " append(sizeof a).append();\n" + "}\n"; + ASSERT_EQUALS("struct struct_a { char a [ 20 ] ; } ; " + "void foo ( ) {" + " struct_a a ;" + " append ( 100 ) . append ( ) ; " + "}", tok(code)); + } + + void sizeofsizeof() { // ticket #1682