Fix pointer arithmetic undefined behavior.

Reported by Denis Denisov.