[PATCH] D158562: [clang][Sema] Add truncation warning on fortified snprintf

Nick Desaulniers via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Aug 23 08:53:15 PDT 2023


nickdesaulniers added a comment.

Thanks for the patch!



================
Comment at: clang/lib/Sema/SemaChecking.cpp:1134
   };
+  auto ProcessFormatStringLiteral =
+      [&](const Expr *FormatExpr, StringRef &FormatStrRef, size_t &StrLen) {
----------------
naive question, so will we create a lambda with capture even though a few cases in the switch below will never use it?


================
Comment at: clang/lib/Sema/SemaChecking.cpp:1324
     SourceSize = ComputeExplicitObjectSizeArgument(1);
     DestinationSize = ComputeSizeArgument(0);
+    const auto *FormatExpr = TheCall->getArg(/*Arg=*/2)->IgnoreParenImpCasts();
----------------
Can `DestinationSize` be calculated later, after the `if (SourceSize && ...`? Seems it's not needed unless that condition is false?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D158562



More information about the cfe-commits mailing list