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

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


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

Fixes #79964

>From 77c9461b321fa82c82e3e4a1e29c825b912c8ed2 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= <tbaeder at redhat.com>
Date: Tue, 30 Jan 2024 17:04:23 +0100
Subject: [PATCH] [clang] Fix a possible out-of-bounds read

Fixes #79964
---
 clang/lib/Frontend/TextDiagnostic.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

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];
 



More information about the cfe-commits mailing list