...
Code Block | ||||
---|---|---|---|---|
| ||||
void f(char const *str, int slen) {
char *p = const_cast<char*>(str);
int i;
for (i = 0; i < slen && str[i]; i++) {
if (str[i] != ' ') *p++ = str[i];
}
}
|
...
Code Block | ||||
---|---|---|---|---|
| ||||
void f(char *str, int slen) {
char *p = str;
int i;
for (i = 0; i < slen && str[i]; i++) {
if (str[i] != ' ') *p++ = str[i];
}
}
|
...
Code Block | ||||
---|---|---|---|---|
| ||||
int const vals[] = {3, 4, 5};
memset((int*) vals, 0, sizeof(vals));
|
...
Code Block | ||||
---|---|---|---|---|
| ||||
int vals[] = {3, 4, 5};
memset(vals, 0, sizeof(vals));
|
...
EXP05-EX1: An exception to this rule is allowed when it is necessary to cast away const
when invoking a legacy API that does not accept a const
argument, provided the function does not attempt to modify the referenced variable. For example, the following code casts away the const
qualification of INVFNAME
in the call to the audit_log()
function.
Code Block |
---|
/* Legacy function defined elsewhere - cannot be modified */
void audit_log(char *errstr) {
fprintf(stderr, "Error: %s.\n", errstr);
}
/* ... */
const char INVFNAME[] = "Invalid file name.";
audit_log(const_cast<char*>(INVFNAME)); /* EXP05-EX1 */
/* ... */
|
...
Tool | Version | Checker | Description | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 7.6.0 |
|
| ||||||||||
|
|
|
| ||||||||||
|
|
|
| ||||||||||
Section | |
|
| section CP1.EXP35 | Fully Implementedimplemented |
Related Vulnerabilities
Search for vulnerabilities resulting from the violation of this rule on the CERT website.
...