[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:41:46 PDT 2026


github-actions[bot] wrote:

<!--LLVM CODE FORMAT COMMENT: {clang-format}-->


:warning: C/C++ code formatter, clang-format found issues in your code. :warning:

<details>
<summary>
You can test this locally with the following command:
</summary>

``````````bash
git-clang-format --diff origin/main HEAD --extensions cpp -- llvm/lib/Support/YAMLParser.cpp llvm/unittests/Support/YAMLIOTest.cpp --diff_from_common_commit
``````````

:warning:
The reproduction instructions above might return results for more than one PR
in a stack if you are using a stacked PR workflow. You can limit the results by
changing `origin/main` to the base branch/commit you want to compare against.
:warning:

</details>

<details>
<summary>
View the diff from clang-format here.
</summary>

``````````diff
diff --git a/llvm/lib/Support/YAMLParser.cpp b/llvm/lib/Support/YAMLParser.cpp
index 2ee104aa2..5df8e6b23 100644
--- a/llvm/lib/Support/YAMLParser.cpp
+++ b/llvm/lib/Support/YAMLParser.cpp
@@ -1840,18 +1840,14 @@ bool Scanner::fetchMoreTokens() {
   if (Column == 0 && *Current == '%')
     return scanDirective();
 
-  if (Column == 0 && Current + 3 <= End
-      && *Current == '-'
-      && *(Current + 1) == '-'
-      && *(Current + 2) == '-'
-      && (Current + 3 == End || isBlankOrBreak(Current + 3)))
+  if (Column == 0 && Current + 3 <= End && *Current == '-' &&
+      *(Current + 1) == '-' && *(Current + 2) == '-' &&
+      (Current + 3 == End || isBlankOrBreak(Current + 3)))
     return scanDocumentIndicator(true);
 
-  if (Column == 0 && Current + 3 <= End
-      && *Current == '.'
-      && *(Current + 1) == '.'
-      && *(Current + 2) == '.'
-      && (Current + 3 == End || isBlankOrBreak(Current + 3)))
+  if (Column == 0 && Current + 3 <= End && *Current == '.' &&
+      *(Current + 1) == '.' && *(Current + 2) == '.' &&
+      (Current + 3 == End || isBlankOrBreak(Current + 3)))
     return scanDocumentIndicator(false);
 
   if (*Current == '[')

``````````

</details>


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


More information about the llvm-commits mailing list