summaryrefslogtreecommitdiffstats
path: root/clang-tools-extra/clang-tidy/misc/MiscTidyModule.cpp
diff options
context:
space:
mode:
authorEtienne Bergeron <etienneb@google.com>2016-04-15 16:36:00 +0000
committerEtienne Bergeron <etienneb@google.com>2016-04-15 16:36:00 +0000
commit1f696b316c705ec7236b3a14e7f5b274de5535c7 (patch)
treec9b9d7696dcec3cb88f02c56838408b130403860 /clang-tools-extra/clang-tidy/misc/MiscTidyModule.cpp
parent3c5be6c9a72bad003348459a578b6b37678b075e (diff)
downloadbcm5719-llvm-1f696b316c705ec7236b3a14e7f5b274de5535c7.tar.gz
bcm5719-llvm-1f696b316c705ec7236b3a14e7f5b274de5535c7.zip
[clang-tidy] Add new checker for suspicious sizeof expressions
Summary: This check is finding suspicious cases of sizeof expression. Sizeof expression is returning the size (in bytes) of a type or an expression. Programmers often abuse or misuse this expression. This checker is adding common set of patterns to detect some of these bad constructs. Some examples found by this checker: R/packages/ifultools/ifultools/src/fra_neig.c ``` /* free buffer memory */ (void) mutil_free( dist_buff, sizeof( ctr * sizeof( double ) ) ); (void) mutil_free( nidx_buff, sizeof( ctr * sizeof( sint32 ) ) ); ``` graphviz/v2_20_2/lib/common/utils.c ``` static Dtdisc_t mapDisc = { offsetof(item, p), sizeof(2 * sizeof(void *)), offsetof(item, link), (Dtmake_f) newItem, (Dtfree_f) freeItem, (Dtcompar_f) cmpItem, NIL(Dthash_f), NIL(Dtmemory_f), NIL(Dtevent_f) }; ``` mDNSResponder/mDNSShared/dnsextd.c ``` context = ( TCPContext* ) malloc( sizeof( TCPContext ) ); require_action( context, exit, err = mStatus_NoMemoryErr; LogErr( "AcceptTCPConnection", "malloc" ) ); mDNSPlatformMemZero( context, sizeof( sizeof( TCPContext ) ) ); context->d = self; ``` Reviewers: alexfh Subscribers: malcolm.parsons, Eugene.Zelenko, cfe-commits Differential Revision: http://reviews.llvm.org/D19014 llvm-svn: 266451
Diffstat (limited to 'clang-tools-extra/clang-tidy/misc/MiscTidyModule.cpp')
-rw-r--r--clang-tools-extra/clang-tidy/misc/MiscTidyModule.cpp3
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 bbc0eb714e8..f4393c27351 100644
--- a/clang-tools-extra/clang-tidy/misc/MiscTidyModule.cpp
+++ b/clang-tools-extra/clang-tidy/misc/MiscTidyModule.cpp
@@ -31,6 +31,7 @@
#include "NonCopyableObjects.h"
#include "PointerAndIntegralOperationCheck.h"
#include "SizeofContainerCheck.h"
+#include "SizeofExpressionCheck.h"
#include "StaticAssertCheck.h"
#include "StringIntegerAssignmentCheck.h"
#include "StringLiteralWithEmbeddedNulCheck.h"
@@ -92,6 +93,8 @@ public:
CheckFactories.registerCheck<PointerAndIntegralOperationCheck>(
"misc-pointer-and-integral-operation");
CheckFactories.registerCheck<SizeofContainerCheck>("misc-sizeof-container");
+ CheckFactories.registerCheck<SizeofExpressionCheck>(
+ "misc-sizeof-expression");
CheckFactories.registerCheck<StaticAssertCheck>(
"misc-static-assert");
CheckFactories.registerCheck<StringIntegerAssignmentCheck>(
OpenPOWER on IntegriCloud