This case is not worth optimising, because the index should be size_t just like the original size. Then the compiler knows it won't overflow, and doesn't have to check.
And, the fix is easy: just use types of the same width for the counter and the boundary. Using a narrower counter is just begging for errors to happen. This is not a good coding style, and there is no point in having the compiler condoning it.
Compiling it and making it run? Sure. Bending over backwards to ensure it runs fast? Hell no.
Compiling it and making it run? Sure. Bending over backwards to ensure it runs fast? Hell no.