minibar: represent bytes as 0xNN and valid Unicode code points as U+NNNN

An invalid UTF-8 starter byte should not be represented in the same way
as a valid Unicode character.

This fixes https://savannah.gnu.org/bugs/?59832.

Bug existed since two weeks ago, since the mini-bar code was merged.
This commit is contained in:
Benno Schulenberg 2021-01-06 15:02:15 +01:00
parent 5129e718d7
commit 0693d6974a
1 changed files with 6 additions and 4 deletions

View File

@ -2138,14 +2138,16 @@ void minibar(void)
char *this_position = openfile->current->data + openfile->current_x;
if (*this_position == '\0')
sprintf(hexadecimal, openfile->current->next ? "U+000A" : "------");
sprintf(hexadecimal, openfile->current->next ? " 0x0A" : "------");
else if (*this_position == '\n')
sprintf(hexadecimal, "U+0000");
else if ((unsigned char)*this_position > 0xC1 &&
sprintf(hexadecimal, " 0x00");
#ifdef ENABLE_UTF8
else if ((unsigned char)*this_position > 0xC1 && using_utf8() &&
mbtowc(&widecode, this_position, MAXCHARLEN) >= 0)
sprintf(hexadecimal, "U+%04X", widecode);
#endif
else
sprintf(hexadecimal, "U+%04X", (unsigned char)*this_position);
sprintf(hexadecimal, " 0x%02X", (unsigned char)*this_position);
mvwaddstr(bottomwin, 0, COLS - 23, hexadecimal);
}