Hacker News new | ask | show | jobs
by wtetzner 2169 days ago
If you want to omit a bounds check, the compiler needs to know that the length of the array covers the upper bound of the loop, right?
1 comments

If the array length is known to be strictly less than 255 then there is definitely an out-of-bounds access inside the loop, but since this is a panic rather than undefined behavior it could matter how many loop iterations are executed before the out of bounds access occurs, so the check can't be omitted.

If the array size is definitely greater than or equal to 255 then all the array accesses in the loop will be in bounds and no further bounds check is required.

Oh, right.