diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index a6676579a..be13fa6e5 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -3161,7 +3161,7 @@ void Tokenizer::arraySize() { auto getStrTok = [](Token* tok, bool addLength, Token** endStmt) -> Token* { if (addLength) { - *endStmt = tok->tokAt(6); + *endStmt = tok->tokAt(5); return tok->tokAt(4); } if (Token::Match(tok, "%var% [ ] =")) { diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index 16a3695b4..a20a6b667 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -4013,6 +4013,7 @@ private: ASSERT_EQUALS("; int a [ 3 ] = { [ 2 ] = 5 } ;", tokenizeAndStringify(";int a[]={ [2] = 5 };")); ASSERT_EQUALS("; int a [ 5 ] = { 1 , 2 , [ 2 ] = 5 , 3 , 4 } ;", tokenizeAndStringify(";int a[]={ 1, 2, [2] = 5, 3, 4 };")); ASSERT_EQUALS("; int a [ ] = { 1 , 2 , [ x ] = 5 , 3 , 4 } ;", tokenizeAndStringify(";int a[]={ 1, 2, [x] = 5, 3, 4 };")); + ASSERT_EQUALS("; const char c [ 4 ] = \"abc\" ;", tokenizeAndStringify(";const char c[] = { \"abc\" };")); } void labels() {