Change order of array length check and array usage

the array should never be empty so the old code was probably fine, but
Clang Static Analyzer was complaining and this is safer anyway