Before this commit, error message output containing multibyte characters
would be displayed incorrectly for en_US.ISO-88591, en_US.UTF-8, and
other standard locales.
The characters were being split because the character count only
increased by one at the end of a loop iteration. It is necessary to
account for characters that are 2, 3, or 4 bytes wide, and this commit
(mostly) fixes that problem.
Note that this is a temporary workaround. Eventually, we should use
routines that are not locale-dependent, since the only information we
need is the size of each UTF-8 character.