Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Need some clarification of "Bounds.1: Don't use pointer arithmetic" for static analysis #299

Closed
mgehre opened this issue Oct 6, 2015 · 2 comments
Labels

Comments

@mgehre
Copy link

mgehre commented Oct 6, 2015

While discussing my patch for this rule to clang-tidy (http://reviews.llvm.org/D13311), the following example code was presented:

void f(int ar[], size_t s) {
  a[1] = 0;
}
  1. Is the access to ar considered "pointer arithmetic" and thus forbidden under this rule?

My current patch flags all operators +, -, +=, -=, ++ and -- that yield a pointer type. In addition, it flags the use of operator [] on pointer types. Clearly, using operator [] on an array with known size is okay under this rule (and subject to rule Bounds.2).
2) Are any other operations considered "pointer arithmetic" and thus forbidden under this rule?

Please add the details to the "Enforcement" part of this rule.

@AaronBallman
Copy link

I believe the access to ar is pointer arithmetic due to array to pointer decay. However, I would also suggest that this may be a reasonable way to silence the diagnostic for legacy code that cannot make use of array_view (for instance, due to ABI issues).

@gdr-at-ms
Copy link
Contributor

The use is pointer arithmetic because the parameter ar is a pointer, not an array -- there is no concept of array parameter in C or C++. This is a typical case where we recommend people use array_view.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants
@mgehre @AaronBallman @gdr-at-ms and others