...
The intent is that an implementation should identify the nature of, and where possible localize, each violation. Of course, an implementation is free to produce any number of diagnostics as long as a valid program is still correctly translated. It may also successfully translate an invalid program.
Any constraint violation is a violation of this rule because it can result in an invalid program. .
Noncompliant Code Example (inline, Internal Linkage)
The Using inline as the example, the Constraints clause in 6.7.4 paragraph 3, states:
...
That is, if a function has an external and inline definition, implementations are free to choose which definition to invoke (two distinct invocations of the function may call different definitions, one the external definition, the other the inline definition). Therefore, issues can arise when these definitions reference internally linked objects, or mutable objects with static or thread storage duration.
...
This noncompliant code example refers to a file scope static variable with internal linkage from within an external inline function:
...
| Code Block | ||||
|---|---|---|---|---|
| ||||
/* file2.c */
/* Static inline definition of get_random function */
static inline unsigned int get_random() {
/* Initialize the seeds
* No more constraint violation, our inline function is now
* internally linked.
*/
static unsigned int m_z = 0xdeadbeef;
static unsigned int m_w = 0xbaddecaf;
/* Compute the next random value and update the seeds */
m_z = 36969 * (m_z & 65535) + (m_z >> 16);
m_w = 18000 * (m_w & 65535) + (m_w >> 16);
return (m_z << 16) + m_w;
}
int main(void) {
/* Generate random numbers using get_random()... */
return 0;
}
|
Risk Assessment
Constraint violations are a very broad category of error that can result in unexpected control flow and corrupted data.
Recommendation | Severity | Likelihood | Remediation Cost | Priority | Level |
|---|---|---|---|---|---|
MSC25-C | Low | Unlikely | Medium | P2 | L3 |
...