File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -431,6 +431,8 @@ std::string clangimport::AstNode::getSpelling() const
431431 if (typeIndex <= 0 )
432432 return " " ;
433433 }
434+ if (typeIndex <= 0 )
435+ return " " ;
434436 const std::string &str = mExtTokens [typeIndex - 1 ];
435437 if (startsWith (str," col:" ))
436438 return " " ;
Original file line number Diff line number Diff line change @@ -139,6 +139,7 @@ class TestClangImport : public TestFixture {
139139 TEST_CASE (valueType2);
140140
141141 TEST_CASE (crash);
142+ TEST_CASE (crash2);
142143 }
143144
144145 std::string parse (const char clang[]) {
@@ -1372,6 +1373,13 @@ class TestClangImport : public TestFixture {
13721373 " `-CompoundStmt 0x5603791b5700 <col:54, col:55>\n " ;
13731374 (void )parse (clang); // don't crash
13741375 }
1376+
1377+ void crash2 () {
1378+ // getSpelling() indexed mExtTokens[typeIndex - 1] without a lower-bound
1379+ // check, so a node whose line carries no ext tokens (typeIndex <= 0) read
1380+ // out of bounds.
1381+ (void )parse (" `-RecordDecl " ); // don't crash
1382+ }
13751383};
13761384
13771385REGISTER_TEST (TestClangImport)
You can’t perform that action at this time.
0 commit comments