From ab296fa93f207a94e0e4227c0f80d4096e4526c3 Mon Sep 17 00:00:00 2001 From: Alexander Mai Date: Sun, 8 Nov 2015 13:45:55 +0100 Subject: [PATCH] 7111 segmentation fault (invalid code) in Tokenizer::simplifyRedundantParentheses --- lib/tokenize.cpp | 2 +- test/testgarbage.cpp | 5 +++++ tools/dmake.cpp | 2 +- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index d3a53a253..b01b46e9b 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -6897,7 +6897,7 @@ bool Tokenizer::simplifyRedundantParentheses() } while (Token::simpleMatch(tok, "( (") && - tok->link()->previous() == tok->next()->link()) { + tok->link() && tok->link()->previous() == tok->next()->link()) { // We have "(( *something* ))", remove the inner // parentheses tok->deleteNext(); diff --git a/test/testgarbage.cpp b/test/testgarbage.cpp index a92ed1ff1..d6f3a56d2 100644 --- a/test/testgarbage.cpp +++ b/test/testgarbage.cpp @@ -201,6 +201,7 @@ private: TEST_CASE(garbageCode150); // #7089 TEST_CASE(garbageCode151); // #4175 TEST_CASE(garbageCode152); // travis after 9c7271a5 + TEST_CASE(garbageCode153); TEST_CASE(garbageValueFlow); @@ -1213,6 +1214,10 @@ private: checkCode(code); } + void garbageCode153() { + ASSERT_THROW(checkCode("enum { X = << { X } } { X X } enum { X = << { ( X ) } } { } X */"), InternalError); + } + void garbageValueFlow() { // #6089 const char* code = "{} int foo(struct, x1, struct x2, x3, int, x5, x6, x7)\n" diff --git a/tools/dmake.cpp b/tools/dmake.cpp index 08fc54ef4..20773f439 100644 --- a/tools/dmake.cpp +++ b/tools/dmake.cpp @@ -328,7 +328,7 @@ int main(int argc, char **argv) // -Wsign-conversion : too many warnings // -Wunreachable-code : some GCC versions report lots of warnings makeConditionalVariable(fout, "CXXFLAGS", - "-std=c++0x " + "-std=c++0x " "-include lib/cxx11emu.h " "-pedantic " "-Wall "