[PATCH] D130974: [analyzer] Fix for the crash in #56873

Balázs Benics via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Aug 9 04:54:05 PDT 2022


steakhal added a comment.

Some checker should have caught the uninitialized value earlier than the `defaultEvalCall()`.
I guess, the `MallocCkecher` could have checked for it in `PreStmt<CXXNewExpr>`.
Or alternatively, the `CallAndMessageChecker::preCall()` already does something like this in the `PreVisitProcessArg()`. I know that `CXXNewExpr` is not a //call//, but you get the idea.
WDYT, worth catching it?

Other than that, I think it's a good practice to not rely on some checkers to catch things to prevent crashes; so this 'fix' seems reasonable to me.



================
Comment at: clang/lib/StaticAnalyzer/Core/ExprEngineCallAndReturn.cpp:768
+      if (Size.isUndef())
+        Size = UnknownVal();
+
----------------
I'm not a fan of mutating values like this.
Alternatively we could have used something like this at the point of use:
`Size.getAs<DefinedOrUnknownSVal>().getValueOr(UnknownVal{})`
I'm not sure if it's more readable :D


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D130974/new/

https://reviews.llvm.org/D130974



More information about the cfe-commits mailing list