[PATCH] D71001: [clang-tidy] New check: bugprone-misplaced-pointer-arithmetic-in-alloc

Balogh, Ádám via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Dec 6 08:29:38 PST 2019


baloghadamsoftware marked 5 inline comments as done.
baloghadamsoftware added inline comments.


================
Comment at: clang-tools-extra/clang-tidy/bugprone/MisplacedPointerArithmeticInAllocCheck.cpp:81-82
+  diag(PtrArith->getBeginLoc(),
+       "pointer arithmetic is applied to the result of %0() instead of its "
+       "argument")
+      << Func->getName() << Hint;
----------------
whisperity wrote:
> If I put the `+ b` on `X` as in `malloc(X + b)` instead of `malloc(X) + b`, then it's not //pointer// arithmetic anymore, but (hopefully unsigned) arithmetic. Should the warning message really start with "pointer arithmetic"?
> 
> Maybe you could consider the check saying
> 
>     arithmetic operation applied to pointer result of ...() instead of size-like argument
> 
> optionally, I'd clarify it further by putting at the end:
> 
>     resulting in ignoring a prefix of the buffer.
> 
> considering you specifically match on the std(-like) allocations. (At least for now.)
"resulting in ignoring a prefix of the buffer" <- this is only true for addition. What should we write for subtraction?


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D71001/new/

https://reviews.llvm.org/D71001





More information about the cfe-commits mailing list