2023-05-03 11:06:20 +02:00
== Why is this an issue?
2021-06-08 14:23:48 +02:00
----
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
2023-05-03 11:06:20 +02:00
== Resources
2021-06-08 14:23:48 +02:00
* 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[]
2021-06-08 15:52:13 +02:00
'''
2021-06-08 14:23:48 +02:00
== Comments And Links
(visible only on this page)
2023-05-25 14:18:12 +02:00
=== duplicates: S859
2021-06-08 14:23:48 +02:00
endif::env-github,rspecator-view[]