From f31cef3fd7ef5b4183664b4505c34ed4abc72ffb Mon Sep 17 00:00:00 2001 From: Kevin Day Date: Fri, 15 Apr 2022 16:56:11 -0500 Subject: [PATCH] Regression: The trailing Unicode sequences don't always show correctly for sequences ending normally. The commit 85df83a6d846d575657016682c7014a09ac8af4e didn't handle all of the cases it needed to. I forgot to check the normal behavior and ended up breaking normal behavior while fixing the exception cases. The width_utf might be -1 for ASCII and performing the subtracting without handling -1 (and then casting it to unsigned) results in bad behavior. Only handle incomplete character at the end of the stream when the character is actually incomplete. --- level_3/byte_dump/c/private-byte_dump.c | 47 ++++++++++++++++++++------------- 1 file changed, 28 insertions(+), 19 deletions(-) diff --git a/level_3/byte_dump/c/private-byte_dump.c b/level_3/byte_dump/c/private-byte_dump.c index 54451ae..174e852 100644 --- a/level_3/byte_dump/c/private-byte_dump.c +++ b/level_3/byte_dump/c/private-byte_dump.c @@ -191,48 +191,57 @@ extern "C" { // Print placeholders to fill out the remaining line and then optionally print the text block. if (cell.column && cell.column < data->width) { - const uint8_t width_missing = width_utf - width_count; - const uint8_t column_offset = data->width - cell.column; - width_count = 0; + const uint8_t width_missing = width_utf == -1 ? 0 : width_utf - width_count; - // Handle incomplete character at the end of the stream. - found_invalid_utf = F_true; - invalid[character_current] = width_utf; + if (width_missing) { + const uint8_t column_offset = data->width - cell.column; + width_count = 0; - if (byte_dump_print_character_fragment(data, characters, invalid, width_utf, 1, &previous, &cell, &offset) == F_true) { - character_reset = F_true; - } + // Handle incomplete character at the end of the stream. + found_invalid_utf = F_true; + invalid[character_current] = width_utf; - if (++width_count < width_missing) { - if (byte_dump_print_character_fragment(data, characters, invalid, width_utf, 2, &previous, &cell, &offset) == F_true) { + if (byte_dump_print_character_fragment(data, characters, invalid, width_utf, 1, &previous, &cell, &offset) == F_true) { character_reset = F_true; } if (++width_count < width_missing) { - if (byte_dump_print_character_fragment(data, characters, invalid, width_utf, 3, &previous, &cell, &offset) == F_true) { + if (byte_dump_print_character_fragment(data, characters, invalid, width_utf, 2, &previous, &cell, &offset) == F_true) { character_reset = F_true; } if (++width_count < width_missing) { - if (byte_dump_print_character_fragment(data, characters, invalid, width_utf, 4, &previous, &cell, &offset) == F_true) { + if (byte_dump_print_character_fragment(data, characters, invalid, width_utf, 3, &previous, &cell, &offset) == F_true) { character_reset = F_true; } + + if (++width_count < width_missing) { + if (byte_dump_print_character_fragment(data, characters, invalid, width_utf, 4, &previous, &cell, &offset) == F_true) { + character_reset = F_true; + } + } } } - } - if (character_reset) { - characters.used = 0; - memset(&invalid, 0, sizeof(f_char_t) * data->width); + if (character_reset) { + characters.used = 0; + memset(&invalid, 0, sizeof(f_char_t) * data->width); - previous.bytes = column_offset; - previous.invalid = previous.bytes; + previous.bytes = column_offset; + previous.invalid = previous.bytes; + } + else { + previous.bytes = 0; + previous.invalid = 0; + } } else { previous.bytes = 0; previous.invalid = 0; } + } + if (cell.column && cell.column < data->width) { while (cell.column < data->width) { if (data->main->parameters.array[byte_dump_parameter_unicode_e].result == f_console_result_found_e) { -- 1.8.3.1