From 96929c53c00475fbe94405891af7a7af77b0b075 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Sat, 1 Dec 2018 17:29:41 +0100 Subject: [PATCH] Fixed #8873 (Add syntaxError when there is no RHS for +-) --- lib/tokenize.cpp | 2 ++ test/testgarbage.cpp | 8 +++++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 54937388c..9e344ae8b 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -8533,6 +8533,8 @@ void Tokenizer::findGarbageCode() const syntaxError(tok); if (Token::Match(tok, "%cop%|= ]") && !(isCPP() && Token::Match(tok->previous(), "[|, &|= ]"))) syntaxError(tok); + if (Token::Match(tok, "[+-] [;,)]}]")) + syntaxError(tok); } // ternary operator without : diff --git a/test/testgarbage.cpp b/test/testgarbage.cpp index 52f344aac..278a59834 100644 --- a/test/testgarbage.cpp +++ b/test/testgarbage.cpp @@ -231,6 +231,7 @@ private: TEST_CASE(garbageCode198); // #8383 TEST_CASE(garbageCode199); // #8752 TEST_CASE(garbageCode200); // #8757 + TEST_CASE(garbageCode201); // #8873 TEST_CASE(garbageCodeFuzzerClientMode1); // test cases created with the fuzzer client, mode 1 @@ -1426,7 +1427,7 @@ private: } void garbageCode181() { - checkCode("int test() { int +; }"); + ASSERT_THROW(checkCode("int test() { int +; }"), InternalError); } // #4195 - segfault for "enum { int f ( ) { return = } r = f ( ) ; }" @@ -1551,6 +1552,11 @@ private: ASSERT_THROW(checkCode("(){e break,{(case)!{e:[]}}}"), InternalError); } + // #8873 + void garbageCode201() { + ASSERT_THROW(checkCode("void f() { std::string s=\"abc\"; return s + }"), InternalError); + } + void syntaxErrorFirstToken() { ASSERT_THROW(checkCode("&operator(){[]};"), InternalError); // #7818 ASSERT_THROW(checkCode("*(*const<> (size_t); foo) { } *(*const (size_t)() ; foo) { }"), InternalError); // #6858