...
The following noncompliant code example simply shows the standard string-handling function strlen()
being called with a plain character string, a signed character string, and an unsigned character string. The strlen()
function takes a single argument of type const char
*.:
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 */ |
...
The compliant solution uses plain char
for character data.:
Code Block | ||||
---|---|---|---|---|
| ||||
size_t len; char cstr[] = "char string"; len = strlen(cstr); |
...
Tool | Version | Checker | Description | ||||||
---|---|---|---|---|---|---|---|---|---|
Compass/ROSE |
|
|
| ||||||
ECLAIR |
| charsgnd | Fully implemented. | ||||||
EDG |
|
|
| ||||||
Fortify SCA | 5.0 |
| Can detect violations of this rule with CERT C Rule Pack, except cases involving | ||||||
PRQA QA-C |
| 0432 (C) | Partially implemented |
...
CERT C++ Secure Coding Standard | STR04-CPP. Use plain char for characters in the basic character set |
MISRA - C:2012 | Rule 610.1 through Rule 10.4 (required) |
...