[PATCH] D158562: [clang][Sema] Add truncation warning on fortified snprintf
Timm Bäder via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Wed Aug 23 02:25:24 PDT 2023
tbaeder added a comment.
Can't say much about the rest of the patch so I'd defer to someone else. Since gcc has `-Wformat-truncation`, can we disable this warning in clang as well? Can you add a test for that?
================
Comment at: clang/lib/Sema/SemaChecking.cpp:1136-1137
+ [&](const Expr *FormatExpr, StringRef &FormatStrRef, size_t &StrLen) {
+ if (auto *Format = dyn_cast<StringLiteral>(FormatExpr)) {
+ if (!Format->isOrdinary() && !Format->isUTF8())
+ return false;
----------------
================
Comment at: clang/lib/Sema/SemaChecking.cpp:1325
DestinationSize = ComputeSizeArgument(0);
+ const auto *FormatExpr = TheCall->getArg(/*Arg=*/2)->IgnoreParenImpCasts();
+ StringRef FormatStrRef;
----------------
(Really not a fan of this, it adds nothing).
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