fix off-by-one index check

Change-Id: I6d6461eec24895e9aa0e77deccd39210958b7e2c
Reviewed-by: Andy Shaw <andy.shaw@digia.com>
(cherry picked from qtbase/96a22ed926cfd706c1b5aca1881f124bc9624f2f)