Add protection for zero-length array.