Prevent infinite loop when input file is empty