rspec/rules/S1260/cfamily/rule.adoc

34 lines
841 B
Plaintext
Raw Normal View History

== Why is this an issue?
----
void foo(const int* x)
{
int* y;
y = (int*)x; //Noncompliant
}
int main()
{
const int a = 10;
int b;
b = (int)a; //Noncompliant
return(0);
}
----
Converting const to non-const can undermine the data integrity by allowing values to change that are assumed to be constant. This practice also reduces the readability of the code, since you cannot assume const variables to be constant
== Resources
* https://www.securecoding.cert.org/confluence/x/gAU[CERT, EXP40-C.] - Do not modify constant objects
* https://www.securecoding.cert.org/confluence/x/ZYAyAQ[CERT, EXP55-CPP.] - Do not access a cv-qualified object through a cv-unqualified type
ifdef::env-github,rspecator-view[]
'''
== Comments And Links
(visible only on this page)
=== duplicates: S859
endif::env-github,rspecator-view[]