Fix undefined behavior: don't perform array indexing through a potentially null