Fix crash in arraySize() (#4556)

* Fix  #11355 FN: arrayIndexOutOfBounds

* Fix

* Fix crash in arraySize()
This commit is contained in:
chrchr-github 2022-10-19 19:19:01 +02:00 committed by GitHub
parent 49f1282ce1
commit 192c30ab1d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 2 additions and 1 deletions

View File

@ -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% [ ] =")) {

View File

@ -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() {