[PATCH] D132294: [clang-tidy] Add check of sprintf with fixed size buffer
方程 via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Sat Aug 20 06:26:34 PDT 2022
Yoorkin created this revision.
Yoorkin added a reviewer: clang-tools-extra.
Yoorkin added a project: clang-tools-extra.
Herald added subscribers: carlosgalvezp, xazax.hun, mgorny.
Herald added a project: All.
Yoorkin requested review of this revision.
Herald added a subscriber: cfe-commits.
Hi, I have added a clang-tidy check which proposed in this issue <https://github.com/llvm/llvm-project/issues/40511>.
The check can finds sprintf usage like:
char buff[50];
sprintf(buff,"Hello, %s!\n","world");
And suggest counted version function instead:
warning: string to be written may exceeds the size of buffer; use snprintf instead [bugprone-sprintf-with-fixed-size-buffer]
sprintf(buff,"Hello, %s!\n","world");
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
snprintf(buff, sizeof(buff), "Hello, %s!\n", "world")
https://reviews.llvm.org/D132294
Files:
clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
clang-tools-extra/clang-tidy/bugprone/SprintfWithFixedSizeBufferCheck.cpp
clang-tools-extra/clang-tidy/bugprone/SprintfWithFixedSizeBufferCheck.h
clang-tools-extra/docs/ReleaseNotes.rst
clang-tools-extra/docs/clang-tidy/checks/bugprone/sprintf-with-fixed-size-buffer.rst
clang-tools-extra/docs/clang-tidy/checks/list.rst
clang-tools-extra/test/clang-tidy/checkers/bugprone/sprintf-with-fixed-size-buffer.cpp
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D132294.454202.patch
Type: text/x-patch
Size: 9631 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220820/bf0a0fbb/attachment-0001.bin>
More information about the cfe-commits
mailing list