aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/CodeGen/CodeGenModule.cpp
diff options
context:
space:
mode:
authorZoltán Porkoláb <zporky@gmail.com>2024-09-17 16:42:58 +0200
committerGitHub <noreply@github.com>2024-09-17 16:42:58 +0200
commit267ad430fc54d6d548cd7d25c7e59c3b6b650097 (patch)
tree5c9108c672f0a0a83e331e9e1b1af5333d5865f6 /clang/lib/CodeGen/CodeGenModule.cpp
parentf4172f6659ef14cbc235e3d690957de068cd55d4 (diff)
downloadllvm-267ad430fc54d6d548cd7d25c7e59c3b6b650097.zip
llvm-267ad430fc54d6d548cd7d25c7e59c3b6b650097.tar.gz
llvm-267ad430fc54d6d548cd7d25c7e59c3b6b650097.tar.bz2
[clang-tidy] Extend `bugprone-sizeof-expression` with matching `P +- sizeof(T)` and `P +- N */ sizeof(T)` cases, add `cert-arr39-c` alias (#106061)
Improved `bugprone-sizeof-expression` check to find suspicious pointer arithmetic calculations where the pointer is offset by an `alignof()`, `offsetof()`, or `sizeof()` expression. Pointer arithmetic expressions implicitly scale the offset added to or subtracted from the address by the size of the pointee type. Using an offset expression that is already scaled by the size of the underlying type effectively results in a squared offset, which is likely an invalid pointer that points beyond the end of the intended array. ```c void printEveryEvenIndexElement(int *Array, size_t N) { int *P = Array; while (P <= Array + N * sizeof(int)) { // Suspicious pointer arithmetics using sizeof()! printf("%d ", *P); P += 2 * sizeof(int); // Suspicious pointer arithmetics using sizeof()! } } ``` --------- Co-authored-by: Whisperity <whisperity@gmail.com>
Diffstat (limited to 'clang/lib/CodeGen/CodeGenModule.cpp')
0 files changed, 0 insertions, 0 deletions