diff options
author | Etienne Bergeron <etienneb@google.com> | 2016-04-21 17:19:36 +0000 |
---|---|---|
committer | Etienne Bergeron <etienneb@google.com> | 2016-04-21 17:19:36 +0000 |
commit | bae829ede5b164eb7bf139167846fb06b60afe27 (patch) | |
tree | c77530b6d7930800d6a8ab67d072ae4dd2829aa4 /clang-tools-extra/clang-tidy/misc/MiscTidyModule.cpp | |
parent | 1a299eab32acd4858e8651550b185be0767f7c70 (diff) | |
download | bcm5719-llvm-bae829ede5b164eb7bf139167846fb06b60afe27.tar.gz bcm5719-llvm-bae829ede5b164eb7bf139167846fb06b60afe27.zip |
[clang-tidy] Add new checker for comparison with runtime string functions.
Summary:
This checker is validating suspicious usage of string compare functions.
Example:
```
if (strcmp(...)) // Implicitly compare to zero
if (!strcmp(...)) // Won't warn
if (strcmp(...) != 0) // Won't warn
```
This patch was checked over large amount of code.
There is three checks:
[*] Implicit comparator to zero (coding-style, many warnings found),
[*] Suspicious implicit cast to non-integral (bugs!?, almost none found),
[*] Comparison to suspicious constant (bugs!?, found two cases),
Example:
[[https://github.com/kylepjohnson/sigma/blob/master/sigma/native-installers/debian/dependencies/files/opt/sigma/E/HEURISTICS/che_to_precgen.c |
https://github.com/kylepjohnson/sigma/blob/master/sigma/native-installers/debian/dependencies/files/opt/sigma/E/HEURISTICS/che_to_precgen.c]]
```
else if(strcmp(id, "select") == 0)
{
array->array[i].key1 = 25;
}
else if(strcmp(id, "sk") == 28) // BUG!?
{
array->array[i].key1 = 20;
}
```
Reviewers: alexfh
Subscribers: Eugene.Zelenko, cfe-commits
Differential Revision: http://reviews.llvm.org/D18703
llvm-svn: 267009
Diffstat (limited to 'clang-tools-extra/clang-tidy/misc/MiscTidyModule.cpp')
-rw-r--r-- | clang-tools-extra/clang-tidy/misc/MiscTidyModule.cpp | 3 |
1 files changed, 3 insertions, 0 deletions
diff --git a/clang-tools-extra/clang-tidy/misc/MiscTidyModule.cpp b/clang-tools-extra/clang-tidy/misc/MiscTidyModule.cpp index 1d667b50161..aaeddeded21 100644 --- a/clang-tools-extra/clang-tidy/misc/MiscTidyModule.cpp +++ b/clang-tools-extra/clang-tidy/misc/MiscTidyModule.cpp @@ -37,6 +37,7 @@ #include "StringLiteralWithEmbeddedNulCheck.h" #include "SuspiciousMissingCommaCheck.h" #include "SuspiciousSemicolonCheck.h" +#include "SuspiciousStringCompareCheck.h" #include "SwappedArgumentsCheck.h" #include "ThrowByValueCatchByReferenceCheck.h" #include "UndelegatedConstructor.h" @@ -106,6 +107,8 @@ public: "misc-suspicious-missing-comma"); CheckFactories.registerCheck<SuspiciousSemicolonCheck>( "misc-suspicious-semicolon"); + CheckFactories.registerCheck<SuspiciousStringCompareCheck>( + "misc-suspicious-string-compare"); CheckFactories.registerCheck<SwappedArgumentsCheck>( "misc-swapped-arguments"); CheckFactories.registerCheck<ThrowByValueCatchByReferenceCheck>( |