[PATCH] D132294: [clang-tidy] Add check of sprintf with fixed size buffer

Nathan James via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Sat Aug 20 13:57:29 PDT 2022


njames93 added a comment.

Why are we only targeting sprintf, vsprintf would also suffer from the same pitfalls.
Is there any hard reason that this check always suggests `snprintf` instead of `sprintf_s`, maybe have that dynamically controlled with an option.



================
Comment at: clang-tools-extra/clang-tidy/bugprone/SprintfWithFixedSizeBufferCheck.cpp:36
+
+  std::string ReplacementText = "snprintf(";
+  auto arg = Call->getArgs();
----------------
Prefer small little edits instead of one big replacement.
So create a fix it that turns `sprintf` into `snprintf`, then create a fix it that inserts `, sizeof(Buff)` after the first argument.


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

https://reviews.llvm.org/D132294



More information about the cfe-commits mailing list