You can do masking in the same way Linux does it. It prevents "branch code bypass" without using an explicit size:
cmp %bound, %ptr
jae bad_ptr
sbb %mask, %mask
and %mask, %ptr
Just two extra instructions. No need to memory map or hard code the size of bounds.See `array_index_mask_nospec` in https://github.com/torvalds/linux/blob/master/arch/x86/inclu...