Index: clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp =================================================================== --- clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp +++ clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp @@ -48,6 +48,7 @@ #include "StringConstructorCheck.h" #include "StringIntegerAssignmentCheck.h" #include "StringLiteralWithEmbeddedNulCheck.h" +#include "StrlenInArrayIndexCheck.h" #include "SuspiciousEnumUsageCheck.h" #include "SuspiciousIncludeCheck.h" #include "SuspiciousMemsetUsageCheck.h" @@ -149,6 +150,8 @@ "bugprone-string-integer-assignment"); CheckFactories.registerCheck( "bugprone-string-literal-with-embedded-nul"); + CheckFactories.registerCheck( + "bugprone-strlen-in-array-index"); CheckFactories.registerCheck( "bugprone-suspicious-enum-usage"); CheckFactories.registerCheck( Index: clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt =================================================================== --- clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt +++ clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt @@ -43,6 +43,7 @@ StringConstructorCheck.cpp StringIntegerAssignmentCheck.cpp StringLiteralWithEmbeddedNulCheck.cpp + StrlenInArrayIndexCheck.cpp SuspiciousEnumUsageCheck.cpp SuspiciousIncludeCheck.cpp SuspiciousMemsetUsageCheck.cpp Index: clang-tools-extra/clang-tidy/cert/CERTTidyModule.cpp =================================================================== --- clang-tools-extra/clang-tidy/cert/CERTTidyModule.cpp +++ clang-tools-extra/clang-tidy/cert/CERTTidyModule.cpp @@ -14,6 +14,7 @@ #include "../bugprone/SignalHandlerCheck.h" #include "../bugprone/SignedCharMisuseCheck.h" #include "../bugprone/SpuriouslyWakeUpFunctionsCheck.h" +#include "../bugprone/StrlenInArrayIndexCheck.h" #include "../bugprone/UnhandledSelfAssignmentCheck.h" #include "../google/UnnamedNamespaceInHeaderCheck.h" #include "../misc/NewDeleteOverloadsCheck.h" Index: clang-tools-extra/docs/ReleaseNotes.rst =================================================================== --- clang-tools-extra/docs/ReleaseNotes.rst +++ clang-tools-extra/docs/ReleaseNotes.rst @@ -117,6 +117,14 @@ Finds condition variables in nested ``if`` statements that were also checked in the outer ``if`` statement and were not changed. +- New :doc:`bugprone-strlen-in-array-index + ` check. + + Finds strlen function calls if they are used on an array within the array's + own index operator []. This could cause out-of-bounds memory access in + some special scenarios. + + - New :doc:`concurrency-mt-unsafe ` check. @@ -140,6 +148,13 @@ Flags functions with Cognitive Complexity metric exceeding the configured limit. +New check aliases +^^^^^^^^^^^^^^^^^ +- New alias :doc:`cert-fio37-c + ` to + :doc:`bugprone-strlen-in-array-index + ` was added. + Changes in existing checks ^^^^^^^^^^^^^^^^^^^^^^^^^^