Fix an infinite loop with the message box

Still need a more general fix for things setting endindex to INT32_MAX.