...
Of these three options, the first — firstâ”"provide no explicit integer assignments" — is â”is the simplest, and consequently the preferred, approach unless the first enumerator must have non-zero value.
...
| Anchor | ||||
|---|---|---|---|---|
|
INT09-EX1: In cases where defining an enumeration with two or more enumerators with the same value is intended the constant expression used to define the value of the duplicate enumerator should reference the enumerator rather than the original enumerators value. This makes the intent clear to both human readers of the code, as well as automated code analysis tools that detect violations of this guideline and would diagnose them otherwise. Note, however, that this does not make it possible to use such enumerators in contexts where unique values are required (such as in a
switch statement as discussed above)....
Recommendation | Severity | Likelihood | Remediation Cost | Priority | Level |
|---|---|---|---|---|---|
INT09-C | low | probable | medium | P4 | L3 |
Automated Detection
...
Tool | Version | Checker | Description |
|---|---|---|---|
|
...
|
|
| ||||||||
|
|
|
|
...
Related Vulnerabilities
Search for vulnerabilities resulting from the violation of this rule on the CERT website.
Other Languages
Related Guidelines
This rule appears in the C++ Secure Coding Standard as : INT09-CPP. Ensure enumeration constants map to unique values.
Bibliography
| Wiki Markup |
|---|
\[[ISO/IEC 9899:1999|AA. Bibliography#ISO/IEC 9899-1999]\] Section 6.7.2.2, "Enumeration specifiers" \[[ISO/IEC PDTR 24772|AA. Bibliography#ISO/IEC PDTR 24772]\] "CCB Enumerator issues" \[[MISRA 042004|AA. Bibliography#MISRA 04]\] Rule 9.3 |
...