Fix Undefined behavior

The value of a pointer to an object whose lifetime has ended is used (C99p6.2.4).
Prevent reading past an array.