From b7b055e8856c19c992516f43b42907be017a1865 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Wed, 28 Jan 2009 17:38:32 +0000 Subject: [PATCH] tokenizer: fixed TestTokenizer::sizeof1 --- src/tokenize.cpp | 14 +++++++++++++- test/testbufferoverrun.cpp | 2 +- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/tokenize.cpp b/src/tokenize.cpp index 80b61b21f..5eeec97f9 100644 --- a/src/tokenize.cpp +++ b/src/tokenize.cpp @@ -675,7 +675,19 @@ void Tokenizer::simplifyTokenList() else if (Token::Match(tok, "sizeof ( * %var% )")) { - tok->str("100"); + // Some default value.. + int sz = 100; + + // Try to locate variable declaration.. + const Token *decltok = Token::findmatch(_tokens, (std::string("%type% ") + tok->strAt(3) + " [").c_str()); + if (decltok) + { + sz = SizeOfType(decltok->strAt(0)); + } + + std::ostringstream ostr; + ostr << sz; + tok->str(ostr.str().c_str()); for (int i = 0; i < 4; ++i) tok->deleteNext(); } diff --git a/test/testbufferoverrun.cpp b/test/testbufferoverrun.cpp index f7850a4e2..24d211c34 100644 --- a/test/testbufferoverrun.cpp +++ b/test/testbufferoverrun.cpp @@ -67,7 +67,7 @@ private: TEST_CASE(noerr2); TEST_CASE(noerr3); TEST_CASE(noerr4); - + TEST_CASE(sizeof1); TEST_CASE(array_index_1);