MISRA C++:2023 Rule 24.5.1
The character handling functions from <cctype>
and
<cwctype>
shall not be used
Since R2024b
Description
Rule Definition
The character handling functions from <cctype>
and
<cwctype>
shall not be used. 1
Rationale
The functions from <cctype>
and
<cwctype>
are locale-dependent. Therefore, in some locales, these
character handling functions do not handle extended character sets or unicode characters
properly, or they can have inconsistent behavior in programs intended to run in multiple
locales. These functions can also produce undefined behavior if the input character is not
representable as unsigned char
or is not equal to the value of the macro
EOF
.
Functions from the standard template library <locale>
are safer to
use because they correctly handle character classification and case conversion based on the
locale you specify.
Polyspace Implementation
The rule checker reports a violation whenever the code uses functions from
<cctype>
or <cwctype>
, such as
islower()
or iswdigit()
.
Troubleshooting
If you expect a rule violation but Polyspace® does not report it, see Diagnose Why Coding Standard Violations Do Not Appear as Expected.
Examples
Check Information
Group: Strings Library |
Category: Required |
Version History
Introduced in R2024b
1 All MISRA coding rules and directives are © Copyright The MISRA Consortium Limited 2021.
The MISRA coding standards referenced in the Polyspace Bug Finder™ documentation are from the following MISRA standards:
MISRA C:2004
MISRA C:2012
MISRA C:2023
MISRA C++:2008
MISRA C++:2023
MISRA and MISRA C are registered trademarks of The MISRA Consortium Limited 2021.