No more infinite loops due to invalid file pointers