iximeow / yaxpeax-x86

x86 decoders for the yaxpeax project
BSD Zero Clause License
129 stars 23 forks source link

replace unsafe hint function calls with panic-in-debug versions #16

Closed iximeow closed 2 years ago

iximeow commented 2 years ago

std::slice::get_unchecked is always unchecked, but its use in yaxpeax-x86 is as an optimization, not for load-bearing correctness. it would be helpful to panic if the expectation is violated in debug builds, instead of veering off into unknown states. the same applies for uses of unreachable_unchecked() in yaxpeax-x86.

for both hints, it would be good to have a wrapper that panics in debug builds, but is just the hint for release builds. maybe a debug_assert, maybe an cfg_if between two impls, either should be fine. but yaxpeax-x86 is well at the point that these unsafe hints should be designed to be caught by tests or fuzzing if they become erroneous.