@@ -143,6 +143,7 @@ class TestClangImport : public TestFixture {
143143 TEST_CASE (crash);
144144 TEST_CASE (crash2);
145145 TEST_CASE (nullNodeInvalidLevel);
146+ TEST_CASE (invalidExtTokens);
146147 }
147148
148149 std::string parse (const char clang[]) {
@@ -1420,7 +1421,7 @@ class TestClangImport : public TestFixture {
14201421 // getSpelling() indexed mExtTokens[typeIndex - 1] without a lower-bound
14211422 // check, so a node whose line carries no ext tokens (typeIndex <= 0) read
14221423 // out of bounds.
1423- ( void ) parse (" `-RecordDecl " ); // don't crash
1424+ ASSERT_THROW_INTERNAL_EQUALS ( parse (" `-RecordDecl " ), AST , " invalid AST node: RecordDecl " );
14241425 }
14251426
14261427 void nullNodeInvalidLevel () {
@@ -1429,6 +1430,17 @@ class TestClangImport : public TestFixture {
14291430 " `-<<<NULL>>>\n " ;
14301431 ASSERT_EQUALS (" void foo ( ) ;" , parse (clang));
14311432 }
1433+
1434+ void invalidExtTokens () {
1435+ // nodes without the ext tokens the handlers read must not index out of bounds
1436+ ASSERT_THROW_INTERNAL_EQUALS (parse (" `-FunctionDecl 0x1 <a.cpp:1:1, col:20> col:5 f 'int ()'\n "
1437+ " `-CompoundStmt 0x2 <col:9, col:20>\n "
1438+ " `-ReturnStmt 0x3 <col:11, col:18>\n "
1439+ " `-IntegerLiteral \n " ), AST , " invalid AST node: IntegerLiteral" );
1440+ ASSERT_THROW_INTERNAL_EQUALS (parse (" `-EnumDecl " ), AST , " invalid AST node: EnumDecl" );
1441+ ASSERT_THROW_INTERNAL_EQUALS (parse (" `-VarDecl 0x1" ), AST , " invalid AST node: VarDecl" );
1442+ ASSERT_THROW_INTERNAL_EQUALS (parse (" `-FunctionDecl 0x1 <a.cpp:1:1, col:20> col:5 f 'int ()' prev" ), AST , " invalid AST node: FunctionDecl" );
1443+ }
14321444};
14331445
14341446REGISTER_TEST (TestClangImport)
0 commit comments