[clang] [analyzer] Check the correct first and last elements in cstring.UninitializedRead (PR #95408)

DonĂ¡t Nagy via cfe-commits cfe-commits at lists.llvm.org
Thu Jun 13 08:32:09 PDT 2024


================
@@ -393,6 +401,173 @@ ProgramStateRef CStringChecker::checkNonNull(CheckerContext &C,
   return stateNonNull;
 }
 
+static std::optional<NonLoc> getIndex(ProgramStateRef State,
+                                      const ElementRegion *ER, CharKind CK) {
+  SValBuilder &SValBuilder = State->getStateManager().getSValBuilder();
+  ASTContext &Ctx = SValBuilder.getContext();
+
+  if (CK == CharKind::Regular) {
+    if (ER->getValueType() != Ctx.CharTy)
+      return {};
+    return ER->getIndex();
+  }
+
+  if (ER->getValueType() != Ctx.WideCharTy)
+    return {};
+
+  QualType SizeTy = Ctx.getSizeType();
+  NonLoc WideSize =
+      SValBuilder
+          .makeIntVal(Ctx.getTypeSizeInChars(Ctx.WideCharTy).getQuantity(),
----------------
NagyDonat wrote:

Normal person: "2"
Programmer: "`Ctx.getTypeSizeInChars(Ctx.WideCharTy).getQuantity()`"
;-)

(No action expected, we're programmers...)

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


More information about the cfe-commits mailing list