Fixed calculation of array size (#6487)

This commit is contained in:
PKEuS 2015-01-31 19:06:44 +01:00
parent ae4b86c231
commit 1f97e3001b
2 changed files with 6 additions and 3 deletions

View File

@ -2050,8 +2050,8 @@ void Tokenizer::simplifyDoublePlusAndDoubleMinus()
void Tokenizer::arraySize()
{
bool addlength = false;
for (Token *tok = list.front(); tok; tok = tok->next()) {
bool addlength = false;
if (Token::Match(tok, "%name% [ ] = { %str% } ;")) {
Token *t = tok->tokAt(3);
t->deleteNext();
@ -2061,9 +2061,8 @@ void Tokenizer::arraySize()
if (addlength || Token::Match(tok, "%name% [ ] = %str% ;")) {
tok = tok->next();
std::size_t sz = tok->strAt(3).length() - 1;
std::size_t sz = Token::getStrSize(tok->tokAt(3));
tok->insertToken(MathLib::toString((unsigned int)sz));
addlength = false;
tok = tok->tokAt(5);
}

View File

@ -717,6 +717,10 @@ private:
const char code3[] = "char str [ ] = \"\\0\";";
const char expected3[] = "char str [ 2 ] = \"\\0\" ;";
ASSERT_EQUALS(expected3, tok(code3));
const char code4[] = "char str [ ] = \"\\n\\n\";";
const char expected4[] = "char str [ 3 ] = \"\\n\\n\" ;";
ASSERT_EQUALS(expected4, tok(code4));
}
void dontRemoveIncrement() {