Use of plain char type for numeric value (BAD_PLAIN_CHAR_USE)
R2026bPlain char variable in arithmetic operation without explicit
signedness
Description
This defect occurs when char variables without explicit signedness
are used in these ways:
To store non-
charconstants.In an arithmetic operation when the
charis:A negative value.
The result of a sign changing overflow.
As a buffer offset.
char variables without a signed or
unsigned qualifier can be signed or unsigned depending on your
compiler.
Risk
Operations on a plain char can result in unexpected numerical values. If the char is used as an offset, the char can cause buffer overflow or underflow.
Fix
When initializing a char variable, to avoid implementation-defined confusion, explicitly state whether the char is signed or unsigned.
Extend Checker
A default Bug Finder analysis might not raise this defect when the input values are unknown and only a subset of inputs cause an issue. To check for defects caused by specific system input values, run a stricter Bug Finder analysis. See Extend Bug Finder Checkers to Find Defects from Specific System Input Values.
Examples
Result Information
| Group: Numerical |
| Language: C | C++ |
| Default: Off |
Command-Line Syntax:
BAD_PLAIN_CHAR_USE
|
| Impact: Medium |
PQL Name:
std.defects.BAD_PLAIN_CHAR_USE
|
Version History
Introduced in R2016b
See Also
Topics
- Interpret Polyspace Bug Finder Results in Polyspace Platform User Interface
- Interpret Bug Finder Results in Polyspace Access Web Interface (Polyspace Access)
- Address Polyspace Results Through Bug Fixes or Justifications
- Address Results in Polyspace Access Through Bug Fixes or Justifications (Polyspace Access)