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 1/2] 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 From d0423ff8acbafa0b7bd99d668a42851bdf4a74e6 Mon Sep 17 00:00:00 2001 From: Reijo Tomperi Date: Mon, 6 Sep 2010 22:39:02 +0300 Subject: [PATCH 2/2] Set encoding to UTF-8 for some files. --- cli/cmdlineparser.cpp | 2 +- cli/cmdlineparser.h | 2 +- lib/timer.cpp | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/cli/cmdlineparser.cpp b/cli/cmdlineparser.cpp index 89f1e50bd..090b812fc 100644 --- a/cli/cmdlineparser.cpp +++ b/cli/cmdlineparser.cpp @@ -1,6 +1,6 @@ /* * Cppcheck - A tool for static C/C++ code analysis - * Copyright (C) 2007-2010 Daniel Marjamäki and Cppcheck team. + * Copyright (C) 2007-2010 Daniel Marjamäki and Cppcheck team. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/cli/cmdlineparser.h b/cli/cmdlineparser.h index 7a02a1475..fa726be61 100644 --- a/cli/cmdlineparser.h +++ b/cli/cmdlineparser.h @@ -1,6 +1,6 @@ /* * Cppcheck - A tool for static C/C++ code analysis - * Copyright (C) 2007-2010 Daniel Marjamäki and Cppcheck team. + * Copyright (C) 2007-2010 Daniel Marjamäki and Cppcheck team. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/lib/timer.cpp b/lib/timer.cpp index 626fdcb7b..598fa3952 100644 --- a/lib/timer.cpp +++ b/lib/timer.cpp @@ -1,6 +1,6 @@ /* * Cppcheck - A tool for static C/C++ code analysis - * Copyright (C) 2007-2010 Daniel Marjamäki and Cppcheck team. + * Copyright (C) 2007-2010 Daniel Marjamäki and Cppcheck team. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by