[clang] [clang][analyzer] Model allocation behavior or getdelim/geline (PR #83138)

via cfe-commits cfe-commits at lists.llvm.org
Wed Mar 6 03:56:26 PST 2024


Alejandro =?utf-8?q?Álvarez_Ayllón?Message-ID:
In-Reply-To: <llvm.org/llvm/llvm-project/pull/83138 at github.com>


================
@@ -1423,6 +1435,46 @@ void MallocChecker::checkGMallocN0(const CallEvent &Call,
   C.addTransition(State);
 }
 
+void MallocChecker::preGetdelim(const CallEvent &Call,
+                                CheckerContext &C) const {
+  if (!Call.isGlobalCFunction())
+    return;
+
+  ProgramStateRef State = C.getState();
+  const auto LinePtr = getPointeeDefVal(Call.getArgSVal(0), State);
+  if (!LinePtr)
+    return;
+
+  bool IsKnownToBeAllocated = false;
----------------
NagyDonat wrote:

So if I understand it correctly, you declare this `bool` because `FreeMemAux` needs a reference that'll be use as an out parameter; but you don't actually use the value that's returned in it.

Consider adding a comment that explains this, because out-parameters are not that common and the fact that this acts as an out-parameter is not marked (unlike the older style when out-parameters are implemented with pointers and when `&TargetVariable` is passed to a function you can guess that it's an out-parameter). Originally I thought that this is an in-parameter and you put it into a named variable to explain its purpose (as an alternative to the comment `/*IsKnownToBeAllocated=*/`).

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


More information about the cfe-commits mailing list