diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 67699d4cd..ba0ca8e01 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -2597,8 +2597,8 @@ void Tokenizer::setVarId() if (!scopeStack.top().isExecutable) newFunctionDeclEnd = isFunctionHead(tok, "{:;"); else { - Token const * tokenLinkNext = tok->link()->next(); - if (tokenLinkNext->str() == "{") // might be for- or while-loop or if-statement + Token const * const tokenLinkNext = tok->link()->next(); + if (tokenLinkNext && tokenLinkNext->str() == "{") // might be for- or while-loop or if-statement newFunctionDeclEnd = tokenLinkNext; } if (newFunctionDeclEnd && diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index 1a931d874..5aa543a77 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -402,6 +402,8 @@ private: // a = b = 0; TEST_CASE(multipleAssignment); + TEST_CASE(setVarId) // #6660 - crash + TEST_CASE(platformWin); TEST_CASE(platformWin32); TEST_CASE(platformWin32A); @@ -8711,6 +8713,19 @@ private: ASSERT_EQUALS("sizeof ( a [ 2 ] . b ) + 3 ;", tokenizeAndStringify("sizeof a[2].b+3;")); ASSERT_EQUALS("f ( 0 , sizeof ( ptr . bar ) ) ;", tokenizeAndStringify("f(0, sizeof ptr->bar );")); } + + void setVarId() { + const char * code = "CS_PLUGIN_NAMESPACE_BEGIN(csparser)\n" + "{\n" + " struct foo\n" + " {\n" + " union\n" + " {};\n" + " } halo;\n" + "}\n" + "CS_PLUGIN_NAMESPACE_END(csparser)\n"; + tokenizeAndStringify(code, true); + } }; REGISTER_TEST(TestTokenizer)