...
| Anchor | ||||
|---|---|---|---|---|
|
INT09-C-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 enumerator's value. This practice makes the intent clear to both human readers of the code and automated code analysis tools that detect violations of this guideline and would diagnose them otherwise. Note, however, that it does not make it possible to use such enumerators in contexts where unique values are required (such as in a
switch statement, as discussed earlier)....
Failing to ensure that constants within an enumeration have unique values can result in unexpected results.
Recommendation | Severity | Likelihood |
|---|
Detectable | Repairable | Priority | Level |
|---|---|---|---|
INT09-C | Low |
Probable |
Yes |
No | P4 | L3 |
Automated Detection
Tool | Version | Checker | Description | ||||||
|---|---|---|---|---|---|---|---|---|---|
| Astrée |
| enum-implicit-value | Fully checked | ||||||
| Axivion Bauhaus Suite |
| CertC-INT09 | |||||||
| CodeSonar |
| LANG.STRUCT.INIT.ENUM | Inconsistent Enumerator Initialization | ||||||
| Compass/ROSE |
| CC2.INT09 | Fully implemented | |||||||
| Helix QAC |
| C0724 | |||||||
| Klocwork |
| MISRA.ENUM.IMPLICIT.VAL.NON_UNIQUE.2012 | |||||||
| LDRA tool suite |
| 85 S, 630 S | Fully implemented |
0722
0723
| Parasoft C/C++test |
| CERT_C-INT09-a | In an enumerator list, the "=" construct shall not be used to explicitly initialise members other than the first, unless all items are explicitly initialised | ||||||
| PC-lint Plus |
| 488, 9148 | Partially supported | ||||||
| Polyspace Bug Finder |
| CERT C: Rec. INT09-C | Checks for situations where enumeration constants map to same value (rec. fully covered) | ||||||
| RuleChecker |
| enum-implicit-value | Fully checked |
Related Vulnerabilities
Search for vulnerabilities resulting from the violation of this rule on the CERT website.
Related Guidelines
| SEI CERT C++ |
| Coding Standard | VOID INT09-CPP. Ensure enumeration constants map to unique values |
| CERT Oracle Secure Coding Standard for Java |
| DCL56-J. Do not attach significance to the ordinal associated with an enum | |
| ISO/IEC TR 24772:2013 | Enumerator Issues [CCB] |
| MISRA C:2012 | Rule 8.12 (required) |
...
...