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

Whisperity via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Dec 9 02:05:04 PST 2019


whisperity 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;
----------------
baloghadamsoftware wrote:
> 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?
You are right about subtraction. I think this message is concise as is.


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

https://reviews.llvm.org/D71001





More information about the cfe-commits mailing list