...
Code Block | ||||
---|---|---|---|---|
| ||||
enum enum_type {
E_A,
E_B
};
int int_var = -1;
enum_type enum_var = static_cast<enum_type>(int_var);
if (enum_var < E_A) {
// handle error
}
|
...
Code Block | ||||
---|---|---|---|---|
| ||||
enum enum_type {
E_A,
E_B
};
int int_var = -1;
if (int_var < E_A || int_var > E_B) {
// handle error
}
enum_type enum_var = static_cast<enum_type>(int_var);
|
...
Code Block | ||||
---|---|---|---|---|
| ||||
enum enum_type {
E_A,
E_B
};
int int_var = 5;
switch (static_cast<enum_type>(int_var)) {
case E_A:
// some action A
case E_B:
// some action B
default:
// handle error
}
|
...
Code Block | ||||
---|---|---|---|---|
| ||||
enum enum_type {
E_A = 1,
E_B,
E_C,
E_D,
E_E,
E_F,
E_G
};
for(enum_type enum_var = E_A; enum_var <= E_G; enum_var = static_cast<enum_var>(enum_var+1)) {
// some action
}
|
...
Code Block | ||||
---|---|---|---|---|
| ||||
enum enum_type {
E_A = 1,
E_B,
E_C,
E_D,
E_E,
E_F,
E_G
};
for(int i = E_A; i <= E_G; i = i+1) {
// some action
}
|
...
Rule | Severity | Likelihood | Remediation Cost | Priority | Level |
---|---|---|---|---|---|
INT36-CPP | high | probable | high | P6 | L2 |
Automated Detection
Tool | Version | Checker | Description | ||||||
| 3013 |
Bibliography
[Becker 2009] Section 7.2, "Enumeration declarations"
...
INT35INT18-CPP. Evaluate integer expressions in a larger size before comparing or assigning to that size 04. Integers (INT) 05. Floating Point Arithmetic (FLP)