[PATCH] D132294: [clang-tidy] Add check of sprintf with fixed size buffer
Eugene Zelenko via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Sat Aug 20 06:34:36 PDT 2022
Eugene.Zelenko added inline comments.
================
Comment at: clang-tools-extra/clang-tidy/bugprone/SprintfWithFixedSizeBufferCheck.cpp:13
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+
+#include "clang/Lex/Lexer.h"
----------------
Unnecessary newline.
================
Comment at: clang-tools-extra/clang-tidy/bugprone/SprintfWithFixedSizeBufferCheck.cpp:34
+ const MatchFinder::MatchResult &Result) {
+ const DeclRefExpr *CA = Result.Nodes.getNodeAs<DeclRefExpr>("ConstantArray");
+ const CallExpr *Call = Result.Nodes.getNodeAs<CallExpr>("sprintf");
----------------
`const auto *` could be used because type is spelled in same statement.
================
Comment at: clang-tools-extra/clang-tidy/bugprone/SprintfWithFixedSizeBufferCheck.cpp:35
+ const DeclRefExpr *CA = Result.Nodes.getNodeAs<DeclRefExpr>("ConstantArray");
+ const CallExpr *Call = Result.Nodes.getNodeAs<CallExpr>("sprintf");
+
----------------
Ditto.
================
Comment at: clang-tools-extra/clang-tidy/bugprone/SprintfWithFixedSizeBufferCheck.h:29
+ void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
+};
+
----------------
Please add `isLanguageVersionSupported` (C and C++).
================
Comment at: clang-tools-extra/docs/ReleaseNotes.rst:105
+
+ FIXME: add release notes.
+
----------------
Please use first statement in documentation.
================
Comment at: clang-tools-extra/docs/clang-tidy/checks/bugprone/sprintf-with-fixed-size-buffer.rst:6
+
+The check finds usage of `sprintf`, which write output string into a fixed-size
+array. It will suggest `snprintf` instead.
----------------
Please omit `The check` and use double back-ticks for `sprintf` (language construct).
================
Comment at: clang-tools-extra/docs/clang-tidy/checks/bugprone/sprintf-with-fixed-size-buffer.rst:7
+The check finds usage of `sprintf`, which write output string into a fixed-size
+array. It will suggest `snprintf` instead.
+
----------------
Ditto for `snprintf`.
================
Comment at: clang-tools-extra/docs/clang-tidy/checks/bugprone/sprintf-with-fixed-size-buffer.rst:14
+Example:
+.. code-block:: c++
+ void f(){
----------------
Please separate with newline.
================
Comment at: clang-tools-extra/docs/clang-tidy/checks/bugprone/sprintf-with-fixed-size-buffer.rst:21
+Becomes:
+.. code-block:: c++
+ void f(){
----------------
Ditto.
================
Comment at: clang-tools-extra/docs/clang-tidy/checks/bugprone/sprintf-with-fixed-size-buffer.rst:26
+ }
\ No newline at end of file
----------------
Please fix.
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D132294/new/
https://reviews.llvm.org/D132294
More information about the cfe-commits
mailing list