[BoundsChecking] Clamp trap ID if it would overflow (#175103)
This was exposed by a83c89495ba6fe0134dcaa02372c320cc7ff0dbf. We were
trying to create 8-bit integers to represent the size of the function,
which might be larger than what can fit in an 8-bit integer. This patch
clamps the argument and adds a regression test.