mirror of
https://github.com/ThrowTheSwitch/Unity.git
synced 2026-01-27 02:11:36 +01:00
Add a value to FLOAT_TRAIT enum to enforce use of default case in switches
Revert the previous commit. Add tests for extended enum cases. Fix crash due to accessing 'trait_names' array out of bounds. Adding an extra invalid value to the end of an enum causes '-Wswitch' flag to warn unless there is a switch default case - also enabled by '-Wall'.
This commit is contained in:
11
src/unity.c
11
src/unity.c
@@ -35,6 +35,7 @@ const char UnityStrInf[] = "Infinity";
|
||||
const char UnityStrNegInf[] = "Negative Infinity";
|
||||
const char UnityStrNaN[] = "NaN";
|
||||
const char UnityStrDet[] = "Determinate";
|
||||
const char UnityStrInvalidFloatTrait[] = "Invalid Float Trait";
|
||||
const char UnityStrErrFloat[] = "Unity Floating Point Disabled";
|
||||
const char UnityStrErrDouble[] = "Unity Double Precision Disabled";
|
||||
const char UnityStrErr64[] = "Unity 64-bit Support Disabled";
|
||||
@@ -775,7 +776,9 @@ void UnityAssertFloatSpecial(const _UF actual,
|
||||
break;
|
||||
|
||||
default:
|
||||
/*break // unreachable code */;
|
||||
trait_index = 0;
|
||||
trait_names[0] = UnityStrInvalidFloatTrait;
|
||||
break;
|
||||
}
|
||||
|
||||
if (is_trait != should_be_trait)
|
||||
@@ -905,7 +908,7 @@ void UnityAssertDoubleSpecial(const _UD actual,
|
||||
const char* trait_names[] = { UnityStrInf, UnityStrNegInf, UnityStrNaN, UnityStrDet };
|
||||
_U_SINT should_be_trait = ((_U_SINT)style & 1);
|
||||
_U_SINT is_trait = !should_be_trait;
|
||||
_U_SINT trait_index = style >> 1;
|
||||
_U_SINT trait_index = (_U_SINT)(style >> 1);
|
||||
|
||||
UNITY_SKIP_EXECUTION;
|
||||
|
||||
@@ -938,7 +941,9 @@ void UnityAssertDoubleSpecial(const _UD actual,
|
||||
break;
|
||||
|
||||
default:
|
||||
/*break // unreachable code*/;
|
||||
trait_index = 0;
|
||||
trait_names[0] = UnityStrInvalidFloatTrait;
|
||||
break;
|
||||
}
|
||||
|
||||
if (is_trait != should_be_trait)
|
||||
|
||||
Reference in New Issue
Block a user