[clang] [clang] Fix a possible out-of-bounds read (PR #80023)

via cfe-commits cfe-commits at lists.llvm.org
Tue Jan 30 08:05:59 PST 2024


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clang

Author: Timm Baeder (tbaederr)

<details>
<summary>Changes</summary>

Fixes #<!-- -->79964

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


1 Files Affected:

- (modified) clang/lib/Frontend/TextDiagnostic.cpp (+1-1) 


``````````diff
diff --git a/clang/lib/Frontend/TextDiagnostic.cpp b/clang/lib/Frontend/TextDiagnostic.cpp
index 291d71f6db61f..627a7641308a1 100644
--- a/clang/lib/Frontend/TextDiagnostic.cpp
+++ b/clang/lib/Frontend/TextDiagnostic.cpp
@@ -1251,7 +1251,7 @@ highlightLines(StringRef FileData, unsigned StartLineNumber,
     unsigned LineLength = 0;
     for (unsigned I = 0; I <= Spelling.size(); ++I) {
       // This line is done.
-      if (isVerticalWhitespace(Spelling[I]) || I == Spelling.size()) {
+      if (I == Spelling.size() || isVerticalWhitespace(Spelling[I])) {
         SmallVector<TextDiagnostic::StyleRange> &LineRanges =
             SnippetRanges[L - StartLineNumber];
 

``````````

</details>


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


More information about the cfe-commits mailing list