From 5b89b179ec97a0422363975be03987d97e16db68 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Sat, 28 Nov 2020 14:41:05 +0100 Subject: [PATCH] Detect syntax error when script is checked --- lib/tokenize.cpp | 4 ++++ test/testgarbage.cpp | 5 +++++ 2 files changed, 9 insertions(+) diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 2c868f034..eab9cf743 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -9563,6 +9563,10 @@ void Tokenizer::findGarbageCode() const } } + // array assignment + else if (Token::Match(tok, "%assign% [") && Token::simpleMatch(tok->linkAt(1), "] ;")) + syntaxError(tok, tok->str() + "[...];"); + // UNKNOWN_MACRO(return) if (tok->isKeyword() && Token::Match(tok, "throw|return )") && Token::Match(tok->linkAt(1)->previous(), "%name% (")) unknownMacroError(tok->linkAt(1)->previous()); diff --git a/test/testgarbage.cpp b/test/testgarbage.cpp index 814d2ac21..ced1b7671 100644 --- a/test/testgarbage.cpp +++ b/test/testgarbage.cpp @@ -245,6 +245,7 @@ private: TEST_CASE(garbageCode212); // #8765 TEST_CASE(garbageCode213); // #8758 TEST_CASE(garbageCode214); + TEST_CASE(garbageCode215); // daca@home script with extension .c TEST_CASE(garbageCodeFuzzerClientMode1); // test cases created with the fuzzer client, mode 1 @@ -1665,6 +1666,10 @@ private: checkCode("THIS FILE CONTAINS VARIOUS TEXT"); } + void garbageCode215() { // daca@home script with extension .c + ASSERT_THROW(checkCode("a = [1,2,3];"), InternalError); + } + void syntaxErrorFirstToken() { ASSERT_THROW(checkCode("&operator(){[]};"), InternalError); // #7818 ASSERT_THROW(checkCode("*(*const<> (size_t); foo) { } *(*const (size_t)() ; foo) { }"), InternalError); // #6858