If stopIndex+startIndex is greater than the greatest integer allowed by the language, then (stopIndex + startIndex) will overflow.
One way to fix this is to rewrite the average as:
(stopIndex + startIndex)/2 == startIndex + (stopIndex - startIndex)/2
startIndex + (stopIndex - startIndex)/2 never overflows, as it is always strictly less than stopIndex and so is any intermediate result of the computation.
Fix "integer overflow" bug.
It still might be worth changing for teaching purposes since it is a bug in C/C++/Java/etc.
If you add a comment above it explaining why you're doing it this way, I'll merge it in.