forked from OSchip/llvm-project
350da402ef
Summary: This check searches for signed char -> integer conversions which might indicate programming error, because of the misinterpretation of char values. A signed char might store the non-ASCII characters as negative values. The human programmer probably expects that after an integer conversion the converted value matches with the character code (a value from [0..255]), however, the actual value is in [-128..127] interval. See also: STR34-C. Cast characters to unsigned char before converting to larger integer sizes <https://wiki.sei.cmu.edu/confluence/display/c/STR34-C.+Cast+characters+to+unsigned+char+before+converting+to+larger+integer+sizes> By now this check is limited to assignment / variable declarations. If we would catch all signed char -> integer conversion, then it would produce a lot of findings and also false positives. So I added only this use case now, but this check can be extended with additional use cases later. The CERT documentation mentions another use case when the char is used for array subscript. Next to that a third use case can be the signed char - unsigned char comparison, which also a use case where things happen unexpectedly because of conversion to integer. Reviewers: alexfh, hokein, aaron.ballman Reviewed By: aaron.ballman Subscribers: sylvestre.ledru, whisperity, Eugene.Zelenko, mgorny, xazax.hun, cfe-commits Tags: #clang, #clang-tools-extra Differential Revision: https://reviews.llvm.org/D71174 |
||
---|---|---|
.. | ||
abseil | ||
android | ||
boost | ||
bugprone | ||
cert | ||
cppcoreguidelines | ||
darwin | ||
fuchsia | ||
hicpp | ||
linuxkernel | ||
llvm | ||
misc | ||
modernize | ||
mpi | ||
objc | ||
openmp | ||
performance | ||
plugin | ||
portability | ||
readability | ||
tool | ||
utils | ||
zircon | ||
CMakeLists.txt | ||
ClangTidy.cpp | ||
ClangTidy.h | ||
ClangTidyCheck.cpp | ||
ClangTidyCheck.h | ||
ClangTidyDiagnosticConsumer.cpp | ||
ClangTidyDiagnosticConsumer.h | ||
ClangTidyForceLinker.h | ||
ClangTidyModule.cpp | ||
ClangTidyModule.h | ||
ClangTidyModuleRegistry.h | ||
ClangTidyOptions.cpp | ||
ClangTidyOptions.h | ||
ClangTidyProfiling.cpp | ||
ClangTidyProfiling.h | ||
ExpandModularHeadersPPCallbacks.cpp | ||
ExpandModularHeadersPPCallbacks.h | ||
GlobList.cpp | ||
GlobList.h | ||
add_new_check.py | ||
rename_check.py |