Change the extension detection

Correct a mistake where adding 1 to NULL.