1
0
Fork 0
mirror of https://github.com/Neargye/magic_enum.git synced 2026-01-10 23:44:29 +00:00
magic_enum/test
Alexander Karatarakis 41c916432b
Fix underflow in out of range check (#88)
* Special case bool in cmp_less to avoid msvc's warnings

* Fix underflow in out of range check

The previous fix addressed bool but it seems that was not the heart
of the issue.

The problem is that (lhs - 1) can underflow.

Another example of the check trigger when it shouldn't is:
uint8_t with min_value set to 0 and a value of uint8_t::max
lhs-1 would underflow and find max (see added test).

The issue happens when lhs == rhs. To avoid that situation: flip the if-else!
`cmp_less(rhs, lhs)`means that rhs is strictly less than lhs, so
the check will not trigger when lhs == rhs.

Also, cleanup the bool special-case, as it is no longer necessary.

Note: for the bug to manifest, it is important that the min
of the enums is customized to be 0, so corresponding enum_range
specializations need to be present in the regression tests.
2021-06-25 15:00:54 +03:00
..
3rdparty/Catch2 update catch2 2021-04-14 14:06:52 +03:00
CMakeLists.txt chore: update catch2 to 2.13.4 for Apple Silicon support (#75) 2021-02-22 18:10:47 +02:00
test.cpp Fix underflow in out of range check (#88) 2021-06-25 15:00:54 +03:00
test_flags.cpp chore: update catch2 to 2.13.4 for Apple Silicon support (#75) 2021-02-22 18:10:47 +02:00