Improved error checking in is_empty C code