[PATCH] D53974: [clang-tidy] new checker: bugprone-too-small-loop-variable
Tamás Zolnai via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Thu Nov 1 06:07:16 PDT 2018
ztamas created this revision.
Herald added subscribers: cfe-commits, xazax.hun, mgorny.
The new checker searches for those for loops which has a loop variable
with a "too small" type which means this type can't represent all values
which are part of the iteration range.
For example:
int main() {
long size = 300000;
for( short int i = 0; i < size; ++i) {}
}
The short type leads to infinite loop here because it can't store all
values in the [0..size] interval. In a real use case, size means a
container's size which depends on the user input. Which means for small
amount of objects the algorithm works, but with a larger user input the
software will freeze.
The idea of the checker comes from the LibreOffice project, where the
same check was implemented as a clang compiler plugin, called
LoopVarTooSmall (LLVM licensed).
The idea is the same behind this check, but the code is different because
of the different framework.
Repository:
rCTE Clang Tools Extra
https://reviews.llvm.org/D53974
Files:
clang-tidy/bugprone/BugproneTidyModule.cpp
clang-tidy/bugprone/CMakeLists.txt
clang-tidy/bugprone/TooSmallLoopVariableCheck.cpp
clang-tidy/bugprone/TooSmallLoopVariableCheck.h
docs/ReleaseNotes.rst
docs/clang-tidy/checks/bugprone-too-small-loop-variable.rst
docs/clang-tidy/checks/list.rst
test/clang-tidy/bugprone-too-small-loop-variable.cpp
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D53974.172111.patch
Type: text/x-patch
Size: 17012 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20181101/c382aad0/attachment-0001.bin>
More information about the cfe-commits
mailing list