[PATCH] D19014: [clang-tidy] Add new checker for suspicious sizeof expressions
Etienne Bergeron via cfe-commits
cfe-commits at lists.llvm.org
Tue Apr 12 08:30:39 PDT 2016
etienneb created this revision.
etienneb added a reviewer: alexfh.
etienneb added a subscriber: cfe-commits.
This check found suspicious cases of sizeof expression.
Sizeof expression is retuning the size (in bytes) of a type or an
expression. Programmers often abuse of 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;
```
http://reviews.llvm.org/D19014
Files:
clang-tidy/misc/CMakeLists.txt
clang-tidy/misc/MiscTidyModule.cpp
clang-tidy/misc/SizeofExpressionCheck.cpp
clang-tidy/misc/SizeofExpressionCheck.h
docs/clang-tidy/checks/list.rst
docs/clang-tidy/checks/misc-sizeof-expression.rst
test/clang-tidy/misc-sizeof-expression.cpp
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D19014.53405.patch
Type: text/x-patch
Size: 28092 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20160412/0e047381/attachment-0001.bin>
More information about the cfe-commits
mailing list