This is failing for two reasons:
1) Not using the original string data when printing detected invalid characters.
2) Performing the from codepoint check before checking the binary output check in the function utf8_print_character().
Also remove a redundant not zero check in the error print function utf8_print_character_invalid().
the function utf8_print_character_invalid() is a wrapper to utf8_print_character(), where that check is already performed.