simplify some logic in scanf and remove redundant invalid-format check