Add overflow checks for error message printing.