[PATCH] D48866: [clang-tidy] Add incorrect-pointer-cast checker

Gábor Horváth via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Jul 3 00:24:06 PDT 2018


hgabii created this revision.
Herald added subscribers: cfe-commits, mgorny.

This checker warns for cases when pointer is cast and the pointed to type is incompatible with allocated memory area type.
This may lead to access memory based on invalid memory layout.

Warn for cases when the pointed to type is wider than the allocated type. 
For example char vs integer, long vs char etc.
Also warn for cases when the pointed to type layout is different from the allocated type layout, like different structs, integer vs float/double, different signedness.

Allows pointer casts if the pointed to struct type is "part" of the allocated type.
Which means the allocated type contains the pointed to type member by member.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D48866

Files:
  clang-tidy/misc/CMakeLists.txt
  clang-tidy/misc/IncorrectPointerCastCheck.cpp
  clang-tidy/misc/IncorrectPointerCastCheck.h
  clang-tidy/misc/MiscTidyModule.cpp
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/list.rst
  docs/clang-tidy/checks/misc-incorrect-pointer-cast.rst
  test/clang-tidy/misc-incorrect-pointer-cast.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D48866.153866.patch
Type: text/x-patch
Size: 13218 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20180703/e8314f5b/attachment-0001.bin>


More information about the cfe-commits mailing list