[llvm] [llvm][Support] Fix an off-by-1 bug in YAML parser (PR #186731)

via llvm-commits llvm-commits at lists.llvm.org
Sun Mar 15 20:40:36 PDT 2026


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-llvm-support

Author: owenca (owenca)

<details>
<summary>Changes</summary>

Closes #<!-- -->171620

---
Full diff: https://github.com/llvm/llvm-project/pull/186731.diff


2 Files Affected:

- (modified) llvm/lib/Support/YAMLParser.cpp (+2-2) 
- (modified) llvm/unittests/Support/YAMLIOTest.cpp (+1-1) 


``````````diff
diff --git a/llvm/lib/Support/YAMLParser.cpp b/llvm/lib/Support/YAMLParser.cpp
index 6734877802caf..2ee104aa2be60 100644
--- a/llvm/lib/Support/YAMLParser.cpp
+++ b/llvm/lib/Support/YAMLParser.cpp
@@ -1840,14 +1840,14 @@ bool Scanner::fetchMoreTokens() {
   if (Column == 0 && *Current == '%')
     return scanDirective();
 
-  if (Column == 0 && Current + 4 <= End
+  if (Column == 0 && Current + 3 <= End
       && *Current == '-'
       && *(Current + 1) == '-'
       && *(Current + 2) == '-'
       && (Current + 3 == End || isBlankOrBreak(Current + 3)))
     return scanDocumentIndicator(true);
 
-  if (Column == 0 && Current + 4 <= End
+  if (Column == 0 && Current + 3 <= End
       && *Current == '.'
       && *(Current + 1) == '.'
       && *(Current + 2) == '.'
diff --git a/llvm/unittests/Support/YAMLIOTest.cpp b/llvm/unittests/Support/YAMLIOTest.cpp
index 7446c07ccb9a8..ff5744bc7fa54 100644
--- a/llvm/unittests/Support/YAMLIOTest.cpp
+++ b/llvm/unittests/Support/YAMLIOTest.cpp
@@ -78,7 +78,7 @@ namespace yaml {
 TEST(YAMLIO, TestMapRead) {
   FooBar doc;
   {
-    Input yin("---\nfoo:  3\nbar:  5\n...\n");
+    Input yin("---\nfoo:  3\nbar:  5\n...");
     yin >> doc;
 
     EXPECT_FALSE(yin.error());

``````````

</details>


https://github.com/llvm/llvm-project/pull/186731


More information about the llvm-commits mailing list