You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Flag any indexing expression on an expression or variable of array type (either static array or std::array) where the indexer is not a compile-time constant expression with a value between 0 and the upper bound of the array.
The check currently does nothing to infer something about the index, if it is not a compile-time constant.
E.g. (as per the example above):
voidbar(std::array<int, 5> arr, int X) {
arr[X&4]; // due to 'X', the index is not compile-time known -> FP warning
}
We could relatively easily check for such a pattern, and compare the constant in the & with the array size.
The question is what other kinds of patterns should be ignored. Something like a < N ? a : b where b < N could be one, or a parent if statement with a < N as the condition, and arr[a] in the body,... This quickly becomes a dataflow problem, and I think we should only ignore the a & C case for now.
Description
Why do we need to disable this check here (don't use
kCrc32Tab.at()
)?constants::kPreamble
==255
crc
==any number
&constants::kPreamble
<=255
- always, the laws of mathematics have not been repealedkCrc32Tab.size()
==256
, therefore themaximum index
==255
Conclusion: therefore this expression will always be within the array boundaries
Proposal
Improve
clang-tidy
so that it understands such patterns and does not give a warningThe text was updated successfully, but these errors were encountered: