Fix incorrect bound enforcement due to truncation
This commit is contained in:
parent
3dfc9c84f3
commit
f17bc1a8bc
2 changed files with 16 additions and 2 deletions
|
|
@ -223,12 +223,12 @@ absl::optional<T> readFloat_(OpcodeSpec<T> spec, absl::string_view v)
|
||||||
if (spec.flags & kWrapPhase)
|
if (spec.flags & kWrapPhase)
|
||||||
returnedValue = wrapPhase(returnedValue);
|
returnedValue = wrapPhase(returnedValue);
|
||||||
|
|
||||||
if (returnedValue > static_cast<int64_t>(spec.bounds.getEnd())) {
|
if (returnedValue > spec.bounds.getEnd()) {
|
||||||
if (spec.flags & kEnforceUpperBound)
|
if (spec.flags & kEnforceUpperBound)
|
||||||
return spec.bounds.getEnd();
|
return spec.bounds.getEnd();
|
||||||
else if (!(spec.flags & kPermissiveUpperBound))
|
else if (!(spec.flags & kPermissiveUpperBound))
|
||||||
return absl::nullopt;
|
return absl::nullopt;
|
||||||
} else if (returnedValue < static_cast<int64_t>(spec.bounds.getStart())) {
|
} else if (returnedValue < spec.bounds.getStart()) {
|
||||||
if (spec.flags & kEnforceLowerBound)
|
if (spec.flags & kEnforceLowerBound)
|
||||||
return spec.bounds.getStart();
|
return spec.bounds.getStart();
|
||||||
else if (!(spec.flags & kPermissiveLowerBound))
|
else if (!(spec.flags & kPermissiveLowerBound))
|
||||||
|
|
|
||||||
|
|
@ -335,6 +335,20 @@ TEST_CASE("[Opcode] opcode read (uint8_t)")
|
||||||
REQUIRE( opcode.read(spec) == 20 );
|
REQUIRE( opcode.read(spec) == 20 );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SECTION("Clamp upper (real)")
|
||||||
|
{
|
||||||
|
Opcode opcode { "", "101" };
|
||||||
|
OpcodeSpec<float> spec { 0.0f, Range<float>(0.0f, 100.5f), kEnforceUpperBound };
|
||||||
|
REQUIRE( opcode.read(spec) == 100.5f );
|
||||||
|
}
|
||||||
|
|
||||||
|
SECTION("Clamp lower (real)")
|
||||||
|
{
|
||||||
|
Opcode opcode { "", "19" };
|
||||||
|
OpcodeSpec<float> spec { 0.0f, Range<float>(19.5f, 100.0f), kEnforceLowerBound };
|
||||||
|
REQUIRE( opcode.read(spec) == 19.5f );
|
||||||
|
}
|
||||||
|
|
||||||
SECTION("Floating point")
|
SECTION("Floating point")
|
||||||
{
|
{
|
||||||
Opcode opcode { "", "10.5" };
|
Opcode opcode { "", "10.5" };
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue