浏览代码

cmRST: Fix crash on empty markup block

Brad King 6 年之前
父节点
当前提交
a9b38a1757
共有 3 个文件被更改,包括 14 次插入0 次删除
  1. 6 0
      Source/cmRST.cxx
  2. 4 0
      Tests/CMakeLib/testRST.expect
  3. 4 0
      Tests/CMakeLib/testRST.rst

+ 6 - 0
Source/cmRST.cxx

@@ -457,6 +457,12 @@ void cmRST::UnindentLines(std::vector<std::string>& lines)
   size_t trailingEmpty =
   size_t trailingEmpty =
     std::distance(rit, cmFindNot(cmReverseRange(lines), std::string()));
     std::distance(rit, cmFindNot(cmReverseRange(lines), std::string()));
 
 
+  if ((leadingEmpty + trailingEmpty) >= lines.size()) {
+    // All lines are empty.  The markup block is empty.  Leave only one.
+    lines.resize(1);
+    return;
+  }
+
   std::vector<std::string>::iterator contentEnd = cmRotate(
   std::vector<std::string>::iterator contentEnd = cmRotate(
     lines.begin(), lines.begin() + leadingEmpty, lines.end() - trailingEmpty);
     lines.begin(), lines.begin() + leadingEmpty, lines.end() - trailingEmpty);
   lines.erase(contentEnd, lines.end());
   lines.erase(contentEnd, lines.end());

+ 4 - 0
Tests/CMakeLib/testRST.expect

@@ -83,6 +83,10 @@ or after a paragraph ending in two colons::
 but not after a line ending in two colons::
 but not after a line ending in two colons::
 in the middle of a paragraph.
 in the middle of a paragraph.
 
 
+A literal block can be empty::
+
+
+
 .. productionlist::
 .. productionlist::
  grammar: `production`
  grammar: `production`
  production: "content rendered"
  production: "content rendered"

+ 4 - 0
Tests/CMakeLib/testRST.rst

@@ -90,6 +90,10 @@ or after a paragraph ending in two colons::
 but not after a line ending in two colons::
 but not after a line ending in two colons::
 in the middle of a paragraph.
 in the middle of a paragraph.
 
 
+A literal block can be empty::
+
+
+
 .. productionlist::
 .. productionlist::
  grammar: `production`
  grammar: `production`
  production: "content rendered"
  production: "content rendered"