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

Takuya Shimizu via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Aug 23 18:23:32 PDT 2023


hazohelet added a comment.

Gcc can diagnose wider cases of overflow/truncation by specifying a higher level for it, like `-Wformat-overflow=2` (https://godbolt.org/z/n5facjW1c).
 The current clang counterpart only diagnoses when the format string is //always// larger than the buffer size. If we are going to implement more general warnings like gcc's, I think we should separate these counterparts into their own warning flags (`-Wformat-overflow/truncation`).



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


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

https://reviews.llvm.org/D158562



More information about the cfe-commits mailing list