Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

The There are three character types: char, signed char, and unsigned char are collectively called the character types. Compilers have the latitude to define char to have the same range, representation, and behavior as either signed char or unsigned char. Irrespective of the choice made, char is a separate type from the other two and is not compatible with either.

...

In most cases, the only portable operators on plain char types are assignment and equality operators (=, ==, != ). An exception is the translation to and from digits.   For example, if the char c is a digit, c - '0' is a value between 0 and 9.

...

The following noncompliant code example simply shows calling the standard string handling function strlen() being called with a plain character string, a signed character string, and an unsigned character string. The strlen() functions takes a single argument of type const char *.

...

Wiki Markup
Compiling at high warning levels in compliance with guideline [MSC00-C. Compile cleanly at high warning levels] causes warnings to be issued when converting from {{unsigned char\[\]}} to {{const char *}} when {{char}} is signed and from {{signed char\[\]}} to {{const char *}} when {{char}} is defined to be unsigned.  Casts are required to eliminate these warnings, but excessive casts can make code difficult to read and hide legitimate warning messages.

...

Conversions are not required, and the code compiles cleanly at high warning levels without casts.

...

Recommendation

Severity

Likelihood

Remediation Cost

Priority

Level

STR04-C

low

unlikely

low

P3

L3

Automated Detection

Tool

Version

Checker

Description

Section

Fortify SCA

...

Section

V. 5.0

 

Section

can detect violations of this rule with CERT C Rule Pack

...

, except cases involving signed char

...

Section

...

EDG Front End to Compass

...

/ROSE

 

 

 

Section

Compass/ROSE

...

 

 

 

Related Vulnerabilities

Search for vulnerabilities resulting from the violation of this rule on the CERT website.

Other Languages

Related Guidelines

This rule appears in the C++ Secure Coding Standard as : STR04-CPP. Use plain char for characters in the basic character set.

Bibliography

Wiki Markup
\[[ISO/IEC 9899:1999|AA. Bibliography#ISO/IEC 9899-1999]\] Section 6.2.5, "Types"
\[[MISRA 042004|AA. Bibliography#MISRA 04]\] Rule 6.1, "The plain char type shall be used only for the storage and use of character values"

...