Prevent the array accesses to undefined positions