llvm-project/clang-tools-extra/clang-tidy/bugprone
Tamás Zolnai 350da402ef [clang-tidy] new check: bugprone-signed-char-misuse
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
2020-01-06 18:21:26 +01:00
..
ArgumentCommentCheck.cpp Removed an incorred namespace-end comment 2019-09-23 12:07:10 +00:00
ArgumentCommentCheck.h Add a bugprone-argument-comment option: IgnoreSingleArgument. 2019-09-05 14:48:23 +00:00
AssertSideEffectCheck.cpp Simplify with llvm::is_contained. NFC 2019-07-13 07:23:12 +00:00
AssertSideEffectCheck.h [clang-tidy] Switch checks to #include "ClangTidyCheck.h" 2019-03-25 12:38:26 +00:00
BadSignalToKillThreadCheck.cpp [clang-tidy] Add bugprone-bad-signal-to-kill-thread check and its alias cert-pos44-c 2019-11-11 17:47:14 +01:00
BadSignalToKillThreadCheck.h [clang-tidy] Add bugprone-bad-signal-to-kill-thread check and its alias cert-pos44-c 2019-11-11 17:47:14 +01:00
BoolPointerImplicitConversionCheck.cpp Update the file headers across all of the LLVM projects in the monorepo 2019-01-19 08:50:56 +00:00
BoolPointerImplicitConversionCheck.h [clang-tidy] Switch checks to #include "ClangTidyCheck.h" 2019-03-25 12:38:26 +00:00
BranchCloneCheck.cpp [clang-tidy] Fix crash on end location inside macro 2019-07-17 17:22:43 +00:00
BranchCloneCheck.h [clang-tidy] new check: bugprone-branch-clone 2019-05-15 15:06:25 +00:00
BugproneTidyModule.cpp [clang-tidy] new check: bugprone-signed-char-misuse 2020-01-06 18:21:26 +01:00
CMakeLists.txt [clang-tidy] new check: bugprone-signed-char-misuse 2020-01-06 18:21:26 +01:00
CopyConstructorInitCheck.cpp Update the file headers across all of the LLVM projects in the monorepo 2019-01-19 08:50:56 +00:00
CopyConstructorInitCheck.h [clang-tidy] Switch checks to #include "ClangTidyCheck.h" 2019-03-25 12:38:26 +00:00
DanglingHandleCheck.cpp [clang-tidy][NFCI] DanglingHandleCheck: Remove a superflous IgnoreParenImpCasts 2019-02-17 18:21:54 +00:00
DanglingHandleCheck.h [clang-tidy] Switch checks to #include "ClangTidyCheck.h" 2019-03-25 12:38:26 +00:00
DynamicStaticInitializersCheck.cpp [clang-tidy] Check for dynamically initialized statics in headers. 2019-08-21 20:00:01 +00:00
DynamicStaticInitializersCheck.h [clang-tidy] Check for dynamically initialized statics in headers. 2019-08-21 20:00:01 +00:00
ExceptionEscapeCheck.cpp [clang-tidy] refactor ExceptionAnalyzer further to give ternary answer 2019-02-20 21:04:36 +00:00
ExceptionEscapeCheck.h [clang-tidy] Switch checks to #include "ClangTidyCheck.h" 2019-03-25 12:38:26 +00:00
FoldInitTypeCheck.cpp Update the file headers across all of the LLVM projects in the monorepo 2019-01-19 08:50:56 +00:00
FoldInitTypeCheck.h [clang-tidy] Switch checks to #include "ClangTidyCheck.h" 2019-03-25 12:38:26 +00:00
ForwardDeclarationNamespaceCheck.cpp NFC: Fix trivial typos in comments 2020-01-04 10:28:41 -05:00
ForwardDeclarationNamespaceCheck.h [clang-tidy] Switch checks to #include "ClangTidyCheck.h" 2019-03-25 12:38:26 +00:00
ForwardingReferenceOverloadCheck.cpp Simplify with llvm::is_contained. NFC 2019-07-13 07:23:12 +00:00
ForwardingReferenceOverloadCheck.h [clang-tidy] Switch checks to #include "ClangTidyCheck.h" 2019-03-25 12:38:26 +00:00
InaccurateEraseCheck.cpp Added an AST matcher for declarations that are in the `std` namespace 2019-05-03 12:50:00 +00:00
InaccurateEraseCheck.h [clang-tidy] Switch checks to #include "ClangTidyCheck.h" 2019-03-25 12:38:26 +00:00
IncorrectRoundingsCheck.cpp Update the file headers across all of the LLVM projects in the monorepo 2019-01-19 08:50:56 +00:00
IncorrectRoundingsCheck.h Remove \brief commands from doxygen comments. 2019-08-22 11:32:57 +00:00
InfiniteLoopCheck.cpp [clang-tidy] Fix for commits rL372706 and rL372711 2019-10-02 07:14:11 +00:00
InfiniteLoopCheck.h [clang-tidy] Add missing InfiniteLoopCheck.h, InfiniteLoopCheck.cpp and test from D64736 2019-09-24 09:06:31 +00:00
IntegerDivisionCheck.cpp Update the file headers across all of the LLVM projects in the monorepo 2019-01-19 08:50:56 +00:00
IntegerDivisionCheck.h [clang-tidy] Switch checks to #include "ClangTidyCheck.h" 2019-03-25 12:38:26 +00:00
LambdaFunctionNameCheck.cpp [clang-tools-extra] Migrate llvm::make_unique to std::make_unique 2019-08-14 23:52:23 +00:00
LambdaFunctionNameCheck.h [clang-tidy] Switch checks to #include "ClangTidyCheck.h" 2019-03-25 12:38:26 +00:00
MacroParenthesesCheck.cpp [Clang-Tidy] Quick fix for bug in bugprone-macro-parentheses 43804 2019-12-02 08:50:51 +01:00
MacroParenthesesCheck.h [clang-tidy] Switch checks to #include "ClangTidyCheck.h" 2019-03-25 12:38:26 +00:00
MacroRepeatedSideEffectsCheck.cpp Avoid including Builtins.h in Preprocessor.h 2019-11-15 16:45:16 -08:00
MacroRepeatedSideEffectsCheck.h [clang-tidy] Switch checks to #include "ClangTidyCheck.h" 2019-03-25 12:38:26 +00:00
MisplacedOperatorInStrlenInAllocCheck.cpp Update the file headers across all of the LLVM projects in the monorepo 2019-01-19 08:50:56 +00:00
MisplacedOperatorInStrlenInAllocCheck.h [clang-tidy] Switch checks to #include "ClangTidyCheck.h" 2019-03-25 12:38:26 +00:00
MisplacedWideningCastCheck.cpp Update the file headers across all of the LLVM projects in the monorepo 2019-01-19 08:50:56 +00:00
MisplacedWideningCastCheck.h [clang-tidy] Switch checks to #include "ClangTidyCheck.h" 2019-03-25 12:38:26 +00:00
MoveForwardingReferenceCheck.cpp Update the file headers across all of the LLVM projects in the monorepo 2019-01-19 08:50:56 +00:00
MoveForwardingReferenceCheck.h [clang-tidy] Switch checks to #include "ClangTidyCheck.h" 2019-03-25 12:38:26 +00:00
MultipleStatementMacroCheck.cpp Remove \brief commands from doxygen comments. 2019-08-22 11:32:57 +00:00
MultipleStatementMacroCheck.h [clang-tidy] Switch checks to #include "ClangTidyCheck.h" 2019-03-25 12:38:26 +00:00
NotNullTerminatedResultCheck.cpp Fix trivial typos in comments; NFC 2020-01-02 13:41:43 -05:00
NotNullTerminatedResultCheck.h [clang-tidy] New checker for not null-terminated result caused by strlen(), size() or equal length 2019-10-13 08:28:27 +00:00
ParentVirtualCallCheck.cpp Remove +x permission on some files 2019-11-16 14:47:20 +01:00
ParentVirtualCallCheck.h Remove +x permission on some files 2019-11-16 14:47:20 +01:00
PosixReturnCheck.cpp [clang-tidy] add checks to bugprone-posix-return 2019-09-16 21:43:56 +00:00
PosixReturnCheck.h [clang-tidy] add checks to bugprone-posix-return 2019-09-16 21:43:56 +00:00
SignedCharMisuseCheck.cpp [clang-tidy] new check: bugprone-signed-char-misuse 2020-01-06 18:21:26 +01:00
SignedCharMisuseCheck.h [clang-tidy] new check: bugprone-signed-char-misuse 2020-01-06 18:21:26 +01:00
SizeofContainerCheck.cpp Update the file headers across all of the LLVM projects in the monorepo 2019-01-19 08:50:56 +00:00
SizeofContainerCheck.h [clang-tidy] Switch checks to #include "ClangTidyCheck.h" 2019-03-25 12:38:26 +00:00
SizeofExpressionCheck.cpp [clang-tidy] Extend bugprone-sizeof-expression to check sizeof(pointers to structures) 2019-05-07 06:16:02 +00:00
SizeofExpressionCheck.h [clang-tidy] Switch checks to #include "ClangTidyCheck.h" 2019-03-25 12:38:26 +00:00
StringConstructorCheck.cpp [clang-tidy] Fix typo in bugprone-string-constructor. 2019-06-11 12:12:06 +00:00
StringConstructorCheck.h [clang-tidy] Switch checks to #include "ClangTidyCheck.h" 2019-03-25 12:38:26 +00:00
StringIntegerAssignmentCheck.cpp [clang-tidy] Fix more false positives for bugprone-string-integer-assignment 2019-03-25 08:18:00 +00:00
StringIntegerAssignmentCheck.h [clang-tidy] Switch checks to #include "ClangTidyCheck.h" 2019-03-25 12:38:26 +00:00
StringLiteralWithEmbeddedNulCheck.cpp NFC: Fix trivial typos in comments 2020-01-04 10:28:41 -05:00
StringLiteralWithEmbeddedNulCheck.h [clang-tidy] Switch checks to #include "ClangTidyCheck.h" 2019-03-25 12:38:26 +00:00
SuspiciousEnumUsageCheck.cpp Update the file headers across all of the LLVM projects in the monorepo 2019-01-19 08:50:56 +00:00
SuspiciousEnumUsageCheck.h [clang-tidy] Switch checks to #include "ClangTidyCheck.h" 2019-03-25 12:38:26 +00:00
SuspiciousMemsetUsageCheck.cpp Update the file headers across all of the LLVM projects in the monorepo 2019-01-19 08:50:56 +00:00
SuspiciousMemsetUsageCheck.h [clang-tidy] Switch checks to #include "ClangTidyCheck.h" 2019-03-25 12:38:26 +00:00
SuspiciousMissingCommaCheck.cpp Update the file headers across all of the LLVM projects in the monorepo 2019-01-19 08:50:56 +00:00
SuspiciousMissingCommaCheck.h [clang-tidy] Switch checks to #include "ClangTidyCheck.h" 2019-03-25 12:38:26 +00:00
SuspiciousSemicolonCheck.cpp [clang-tidy] Fix PR35824 2019-11-27 11:07:16 -08:00
SuspiciousSemicolonCheck.h [clang-tidy] Switch checks to #include "ClangTidyCheck.h" 2019-03-25 12:38:26 +00:00
SuspiciousStringCompareCheck.cpp Update the file headers across all of the LLVM projects in the monorepo 2019-01-19 08:50:56 +00:00
SuspiciousStringCompareCheck.h [clang-tidy] Switch checks to #include "ClangTidyCheck.h" 2019-03-25 12:38:26 +00:00
SwappedArgumentsCheck.cpp Remove \brief commands from doxygen comments. 2019-08-22 11:32:57 +00:00
SwappedArgumentsCheck.h [clang-tidy] Switch checks to #include "ClangTidyCheck.h" 2019-03-25 12:38:26 +00:00
TerminatingContinueCheck.cpp Update the file headers across all of the LLVM projects in the monorepo 2019-01-19 08:50:56 +00:00
TerminatingContinueCheck.h [clang-tidy] Switch checks to #include "ClangTidyCheck.h" 2019-03-25 12:38:26 +00:00
ThrowKeywordMissingCheck.cpp Update the file headers across all of the LLVM projects in the monorepo 2019-01-19 08:50:56 +00:00
ThrowKeywordMissingCheck.h [clang-tidy] Switch checks to #include "ClangTidyCheck.h" 2019-03-25 12:38:26 +00:00
TooSmallLoopVariableCheck.cpp Remove \brief commands from doxygen comments. 2019-08-22 11:32:57 +00:00
TooSmallLoopVariableCheck.h [clang-tidy] Add MagnitudeBitsUpperLimit option to bugprone-too-small-loop-variable 2019-04-14 12:47:48 +00:00
UndefinedMemoryManipulationCheck.cpp Update the file headers across all of the LLVM projects in the monorepo 2019-01-19 08:50:56 +00:00
UndefinedMemoryManipulationCheck.h [clang-tidy] Switch checks to #include "ClangTidyCheck.h" 2019-03-25 12:38:26 +00:00
UndelegatedConstructorCheck.cpp Update the file headers across all of the LLVM projects in the monorepo 2019-01-19 08:50:56 +00:00
UndelegatedConstructorCheck.h [clang-tidy] Switch checks to #include "ClangTidyCheck.h" 2019-03-25 12:38:26 +00:00
UnhandledSelfAssignmentCheck.cpp [clang-tidy]: Add cert-oop54-cpp alias for bugprone-unhandled-self-assignment 2019-05-23 20:29:04 +00:00
UnhandledSelfAssignmentCheck.h [clang-tidy]: Add cert-oop54-cpp alias for bugprone-unhandled-self-assignment 2019-05-23 20:29:04 +00:00
UnusedRaiiCheck.cpp Update the file headers across all of the LLVM projects in the monorepo 2019-01-19 08:50:56 +00:00
UnusedRaiiCheck.h [clang-tidy] Switch checks to #include "ClangTidyCheck.h" 2019-03-25 12:38:26 +00:00
UnusedReturnValueCheck.cpp Update the file headers across all of the LLVM projects in the monorepo 2019-01-19 08:50:56 +00:00
UnusedReturnValueCheck.h [clang-tidy] Switch checks to #include "ClangTidyCheck.h" 2019-03-25 12:38:26 +00:00
UseAfterMoveCheck.cpp [clang-tools-extra] Migrate llvm::make_unique to std::make_unique 2019-08-14 23:52:23 +00:00
UseAfterMoveCheck.h [clang-tidy] Switch checks to #include "ClangTidyCheck.h" 2019-03-25 12:38:26 +00:00
VirtualNearMissCheck.cpp Update the file headers across all of the LLVM projects in the monorepo 2019-01-19 08:50:56 +00:00
VirtualNearMissCheck.h Remove \brief commands from doxygen comments. 2019-08-22 11:32:57 +00:00