[clang-tidy] Extend bugprone-sizeof-expression check to detect sizeof misuse in point...
authorAdam Balogh <adam.balogh@ericsson.com>
Mon, 6 May 2019 10:41:37 +0000 (10:41 +0000)
committerAdam Balogh <adam.balogh@ericsson.com>
Mon, 6 May 2019 10:41:37 +0000 (10:41 +0000)
commit62468003ef97cdf4ea47b8646fe76bc33dfc073a
treef8fc3d61025df93c62380cb3eb248a1575f600cd
parent97fbc2abfeceabf05cc339b5079d96f25fa380d7
[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

llvm-svn: 360032
clang-tools-extra/clang-tidy/bugprone/SizeofExpressionCheck.cpp
clang-tools-extra/test/clang-tidy/bugprone-sizeof-expression.cpp