HomePhabricator

[clang-tidy] Extend bugprone-sizeof-expression check to detect sizeof misuse in…

Description

[clang-tidy] Extend bugprone-sizeof-expression check to detect sizeof misuse in pointer arithmetic

Some programmers tend to forget that subtracting two pointers results in the
difference between them in number of elements of the pointee type instead of
bytes. This leads to codes such as size_t size = (p - q) / sizeof(int) where
p and q are of type int*. Or similarily, `if (p - q < buffer_size *
sizeof(int)) { ... }. This patch extends bugprone-sizeof-expression` to
detect such cases.

Differential Revision: https://reviews.llvm.org/D61422

Details

Committed
baloghadamsoftwareMay 6 2019, 3:41 AM
Differential Revision
D61422: [clang-tidy] Extend bugprone-sizeof-expression check to detect sizeof misuse in pointer arithmetic
Branches
Unknown
Tags
Unknown