@@ -144,6 +144,7 @@ class TestClangImport : public TestFixture {
144144 TEST_CASE (crash2);
145145 TEST_CASE (crash3);
146146 TEST_CASE (nullNodeInvalidLevel);
147+ TEST_CASE (invalidExtTokens);
147148 }
148149
149150 std::string parse (const char clang[]) {
@@ -1421,7 +1422,7 @@ class TestClangImport : public TestFixture {
14211422 // getSpelling() indexed mExtTokens[typeIndex - 1] without a lower-bound
14221423 // check, so a node whose line carries no ext tokens (typeIndex <= 0) read
14231424 // out of bounds.
1424- ( void ) parse (" `-RecordDecl " ); // don't crash
1425+ ASSERT_THROW_INTERNAL_EQUALS ( parse (" `-RecordDecl " ), AST , " invalid AST node: RecordDecl " );
14251426 }
14261427
14271428 void nullNodeInvalidLevel () {
@@ -1442,6 +1443,17 @@ class TestClangImport : public TestFixture {
14421443 " `-CXXRecordDecl 0x2\n " ); // don't crash
14431444 (void )parse (" `-CXXRecordDecl 0x1" ); // don't crash
14441445 }
1446+
1447+ void invalidExtTokens () {
1448+ // nodes without the ext tokens the handlers read must not index out of bounds
1449+ ASSERT_THROW_INTERNAL_EQUALS (parse (" `-FunctionDecl 0x1 <a.cpp:1:1, col:20> col:5 f 'int ()'\n "
1450+ " `-CompoundStmt 0x2 <col:9, col:20>\n "
1451+ " `-ReturnStmt 0x3 <col:11, col:18>\n "
1452+ " `-IntegerLiteral \n " ), AST , " invalid AST node: IntegerLiteral" );
1453+ ASSERT_THROW_INTERNAL_EQUALS (parse (" `-EnumDecl " ), AST , " invalid AST node: EnumDecl" );
1454+ ASSERT_THROW_INTERNAL_EQUALS (parse (" `-VarDecl 0x1" ), AST , " invalid AST node: VarDecl" );
1455+ ASSERT_THROW_INTERNAL_EQUALS (parse (" `-FunctionDecl 0x1 <a.cpp:1:1, col:20> col:5 f 'int ()' prev" ), AST , " invalid AST node: FunctionDecl" );
1456+ }
14451457};
14461458
14471459REGISTER_TEST (TestClangImport)
0 commit comments