[clang] [NFC][Clang][FixitUtil] Check optional value before dereference. (PR #184867)
Rohan Jacob-Rao via cfe-commits
cfe-commits at lists.llvm.org
Thu Mar 5 11:53:40 PST 2026
https://github.com/rohanjr created https://github.com/llvm/llvm-project/pull/184867
This prevents a crash if the range text is invalid.
>From 5d8c0407b3c7fee22cb5c9c66ff17b3d86841296 Mon Sep 17 00:00:00 2001
From: Rohan Jacob-Rao <rohanjr at google.com>
Date: Thu, 5 Mar 2026 19:51:15 +0000
Subject: [PATCH] [NFC][Clang][FixitUtil] Check optional value before
dereference.
This prevents a crash if the range text is invalid.
---
clang/lib/Analysis/FixitUtil.cpp | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/clang/lib/Analysis/FixitUtil.cpp b/clang/lib/Analysis/FixitUtil.cpp
index 4ac3f3acd8c62..ec1924f9c3e10 100644
--- a/clang/lib/Analysis/FixitUtil.cpp
+++ b/clang/lib/Analysis/FixitUtil.cpp
@@ -89,8 +89,12 @@ clang::getPointeeTypeText(const DeclaratorDecl *VD, const SourceManager &SM,
// `PteTy` via source ranges.
*QualifiersToAppend = PteTy.getQualifiers();
}
- return getRangeText({PteTyLoc.getBeginLoc(), PteEndOfTokenLoc}, SM, LangOpts)
- ->str();
+
+ std::optional<StringRef> RangeText =
+ getRangeText({PteTyLoc.getBeginLoc(), PteEndOfTokenLoc}, SM, LangOpts);
+ if (!RangeText)
+ return std::nullopt;
+ return RangeText->str();
}
// returns text of pointee to pointee (T*&)
More information about the cfe-commits
mailing list