Fix out-of-bounds check
Merge pull request #2935 from sipa/obounds

Fix out-of-bounds check