...
Code Block | ||
---|---|---|
| ||
size_t len; char cstr[] = "char string"; signed char scstr[] = "signed char string"; unsigned char ucstr[] = "unsigned char string"; len = strlen(cstr); len = strlen(scstr); /* warns when char is unsigned */ len = strlen(ucstr); /* warns when char is signed */ |
Compiling at high warning levels in compliance with guideline [recommendation MSC00-C. Compile cleanly at high warning levels] causes warnings to be issued when when Wiki Markup
Wiki Markup converting from {{unsigned char\[\]}} to {{const char *}} when {{char}} is signed
...
Wiki Markup converting 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.
Wiki Markup |
---|
If this C code were compiled using a C+\+ compiler, conversions from {{unsigned char\[\]}} to {{const char *}} and from {{signed char\[\]}} to {{const char *}} would be flagged as errors requiring casts. |
...
Search for vulnerabilities resulting from the violation of this rule on the CERT website.
Related Guidelines
CERT C++ Secure Coding Standard: STR04-CPP. Use plain char for characters in the basic character set
Bibliography
unmigrated-wiki-markup
\[[ISO/IEC 9899:1999|AA. Bibliography#ISO/IEC 9899-1999]\] Section 6.2.5, "Types" \[[MISRA 2004|AA. Bibliography#MISRA 04]\] Rule
MISRA Rule 6.1, "The plain char type shall be used only for the storage and use of character values"
Bibliography
...
STR03-C. Do not inadvertently truncate a null-terminated byte string 07. Characters and Strings (STR)