From 192c30ab1d3ec97ae7c6955d8953fac133b8e4ff Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Wed, 19 Oct 2022 19:19:01 +0200 Subject: [PATCH] Fix crash in arraySize() (#4556) * Fix #11355 FN: arrayIndexOutOfBounds * Fix * Fix crash in arraySize() --- lib/tokenize.cpp | 2 +- test/testtokenize.cpp | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) 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() {