diff options
4 files changed, 14 insertions, 0 deletions
diff --git a/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp b/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp index 231b6f988c0..a5b3d640b20 100644 --- a/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp +++ b/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp @@ -12,6 +12,7 @@ #include "../ClangTidyModuleRegistry.h" #include "CopyConstructorInitCheck.h" #include "IntegerDivisionCheck.h" +#include "MisplacedOperatorInStrlenInAllocCheck.h" #include "SuspiciousMemsetUsageCheck.h" #include "UndefinedMemoryManipulationCheck.h" @@ -26,6 +27,8 @@ public: "bugprone-copy-constructor-init"); CheckFactories.registerCheck<IntegerDivisionCheck>( "bugprone-integer-division"); + CheckFactories.registerCheck<MisplacedOperatorInStrlenInAllocCheck>( + "bugprone-misplaced-operator-in-strlen-in-alloc"); CheckFactories.registerCheck<SuspiciousMemsetUsageCheck>( "bugprone-suspicious-memset-usage"); CheckFactories.registerCheck<UndefinedMemoryManipulationCheck>( diff --git a/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt b/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt index 91327da34c4..46101c6037e 100644 --- a/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt +++ b/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt @@ -4,6 +4,7 @@ add_clang_library(clangTidyBugproneModule BugproneTidyModule.cpp CopyConstructorInitCheck.cpp IntegerDivisionCheck.cpp + MisplacedOperatorInStrlenInAllocCheck.cpp SuspiciousMemsetUsageCheck.cpp UndefinedMemoryManipulationCheck.cpp diff --git a/clang-tools-extra/docs/ReleaseNotes.rst b/clang-tools-extra/docs/ReleaseNotes.rst index 2ec26ee0197..0237787871e 100644 --- a/clang-tools-extra/docs/ReleaseNotes.rst +++ b/clang-tools-extra/docs/ReleaseNotes.rst @@ -85,6 +85,15 @@ Improvements to clang-tidy not intended to be subclassed. Includes a list of classes from Foundation and UIKit which are documented as not supporting subclassing. +- New `bugprone-misplaced-operator-in-strlen-in-alloc + <http://clang.llvm.org/extra/clang-tidy/checks/bugprone-misplaced-operator-in-strlen-in-alloc.html>`_ check + + Finds cases where ``1`` is added to the string in the argument to + ``strlen()``, ``strnlen()``, ``strnlen_s()``, ``wcslen()``, ``wcsnlen()``, and + ``wcsnlen_s()`` instead of the result and the value is used as an argument to + a memory allocation function (``malloc()``, ``calloc()``, ``realloc()``, + ``alloca()``). + - Renamed checks to use correct term "implicit conversion" instead of "implicit cast" and modified messages and option names accordingly: diff --git a/clang-tools-extra/docs/clang-tidy/checks/list.rst b/clang-tools-extra/docs/clang-tidy/checks/list.rst index 4fab7509aa4..8b5957af6c2 100644 --- a/clang-tools-extra/docs/clang-tidy/checks/list.rst +++ b/clang-tools-extra/docs/clang-tidy/checks/list.rst @@ -19,6 +19,7 @@ Clang-Tidy Checks boost-use-to-string bugprone-copy-constructor-init bugprone-integer-division + bugprone-misplaced-operator-in-strlen-in-alloc bugprone-suspicious-memset-usage bugprone-undefined-memory-manipulation cert-dcl03-c (redirects to misc-static-assert) <cert-dcl03-c> |