[clang] [Clang][Sema] Add fortify warnings for fread, fwrite, and fgets (PR #204337)

Radovan Božić via cfe-commits cfe-commits at lists.llvm.org
Mon Sep 28 06:00:51 PDT 2026


================
@@ -1174,18 +1174,32 @@ class FortifiedBufferChecker {
     return NewIndex;
   }
 
-  std::optional<llvm::APSInt>
-  ComputeExplicitObjectSizeArgument(unsigned Index) {
+  /// Evaluate the argument at Index as an integer constant while preserving
+  /// its signedness, or return std::nullopt if it cannot be evaluated.
+  std::optional<llvm::APSInt> EvaluateIntegerArgument(unsigned Index) {
     std::optional<unsigned> IndexOptional = TranslateIndex(Index);
     if (!IndexOptional)
       return std::nullopt;
     unsigned NewIndex = *IndexOptional;
+
+    if (NewIndex >= TheCall->getNumArgs())
+      return std::nullopt;
----------------
bozicrHT wrote:

Done. Functions `ComputeSizeArgument` and `TranslateIndex` are updated.

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


More information about the cfe-commits mailing list