[clang] [clang][analyzer] fix crash when modelling 'getline' function in checkers (PR #145229)

Baranov Victor via cfe-commits cfe-commits at lists.llvm.org
Tue Jun 24 08:59:17 PDT 2025


================
@@ -1518,14 +1518,18 @@ void MallocChecker::checkGetdelim(ProgramStateRef State, const CallEvent &Call,
   if (!CE)
     return;
 
-  const auto LinePtr =
-      getPointeeVal(Call.getArgSVal(0), State)->getAs<DefinedSVal>();
-  const auto Size =
-      getPointeeVal(Call.getArgSVal(1), State)->getAs<DefinedSVal>();
-  if (!LinePtr || !Size || !LinePtr->getAsRegion())
+  const auto LinePtrOpt = getPointeeVal(Call.getArgSVal(0), State);
+  const auto SizeOpt = getPointeeVal(Call.getArgSVal(1), State);
+  if (!LinePtrOpt || !SizeOpt)
     return;
 
-  State = setDynamicExtent(State, LinePtr->getAsRegion(), *Size);
+  const auto LinePtr = LinePtrOpt->getAs<DefinedSVal>();
+  const auto Size = SizeOpt->getAs<DefinedSVal>();
+  const MemRegion *LinePtrReg = LinePtr->getAsRegion();
+  if (!LinePtr || !Size || !LinePtrReg)
+    return;
----------------
vbvictor wrote:

Ah, yes, I can't think of a test that would have `nullptr` in `LinePtr->getAsRegion()`. For now, I used `isUnknownOrUndef()`

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


More information about the cfe-commits mailing list