The existing check accepts the number of array elements as a valid index. That's clearly wrong for zero based indexing, and would result in a buffer overflow.