From 2334192bff774e4070111283dc18345ae681835e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Tue, 12 Oct 2010 21:52:02 +0200 Subject: [PATCH] Fixed #2087 (False positive: Array 'str[1]' index 1 out of bounds) --- lib/tokenize.cpp | 6 ++++++ test/testsimplifytokens.cpp | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index da3bfcddc..80ece70fb 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -2095,6 +2095,12 @@ void Tokenizer::arraySize() { for (Token *tok = _tokens; tok; tok = tok->next()) { + if (Token::Match(tok, "%var% [ ] = { %str% }")) + { + tok->tokAt(4)->deleteThis(); + tok->tokAt(5)->deleteThis(); + } + if (Token::Match(tok, "%var% [ ] = {")) { unsigned int sz = 1; diff --git a/test/testsimplifytokens.cpp b/test/testsimplifytokens.cpp index 1fc813a69..0adc5e81f 100644 --- a/test/testsimplifytokens.cpp +++ b/test/testsimplifytokens.cpp @@ -934,6 +934,12 @@ private: ASSERT_EQUALS("; const char str [ 1 ] = { '1' } ; 1 ;", sizeof_(code)); } + { + // Ticket #2087 + const char code[] = "; const char str[] = {\"abc\"}; sizeof(str);"; + ASSERT_EQUALS("; const char str [ 4 ] = \"abc\" ; 4 ;", sizeof_(code)); + } + // ticket #716 - sizeof string { std::ostringstream expected;