From: Kevin Day Date: Tue, 6 Dec 2022 00:33:44 +0000 (-0600) Subject: Bugfix: Invalid print of character when a placeholder should be printed in byte_dump. X-Git-Tag: 0.6.2~61 X-Git-Url: https://git.kevux.org/?a=commitdiff_plain;h=159cb22bb16f90f0e1370b343959ac506470a007;p=fll Bugfix: Invalid print of character when a placeholder should be printed in byte_dump. The following is happening: # clear ; echo -n "xa" | byte_dump -wt 2 && echo -n "∩" | byte_dump -wt 2 && echo -n "∩xa" | byte_dump -wt 2 Piped Byte Dump: (in Hexidecimal) 0000000000000000 78 61 | x a | Piped Byte Dump: (in Hexidecimal) 0000000000000000 e2 88 | ∩ | 0000000000000001 a9 | ∩ | Piped Byte Dump: (in Hexidecimal) 0000000000000000 e2 88 | ∩ | 0000000000000001 a9 78 | x | 0000000000000002 61 | a | In the second case the line 0000000000000001 should not print the string '| ∩ |'. This is happening because the character is not being properly reset in the situation where the overflow happens at the end of input. With this change the results should now be: # clear ; echo -n "xa" | byte_dump -wt 2 && echo -n "∩" | byte_dump -wt 2 && echo -n "∩xa" | byte_dump -wt 2 Piped Byte Dump: (in Hexidecimal) 0000000000000000 78 61 | x a | Piped Byte Dump: (in Hexidecimal) 0000000000000000 e2 88 | ∩ | 0000000000000001 a9 | | Piped Byte Dump: (in Hexidecimal) 0000000000000000 e2 88 | ∩ | 0000000000000001 a9 78 | x | 0000000000000002 61 | a | Perform a trivial cleanup/optimization where inverse of bytes is being checked for. This is pointless when there is an else block. Reverse the order and remove the "not" operator. --- diff --git a/level_3/byte_dump/c/private-byte_dump.c b/level_3/byte_dump/c/private-byte_dump.c index 156b206..c85cc99 100644 --- a/level_3/byte_dump/c/private-byte_dump.c +++ b/level_3/byte_dump/c/private-byte_dump.c @@ -70,7 +70,15 @@ extern "C" { byte_get = getc(file.stream); - if (byte_get < 0) break; + if (byte_get < 0) { + if (width_utf == -1 && character_reset) { + sequence.used = 0; + character_reset = F_false; + memset(&invalid, 0, sizeof(f_char_t) * data->width); + } + + break; + } byte = (f_char_t) byte_get; @@ -560,14 +568,14 @@ extern "C" { cell->column = 0; ++cell->row; - if (!bytes) { - previous->bytes = 0; - previous->invalid = 0; - } - else { + if (bytes) { previous->bytes = bytes; previous->invalid = invalid[current]; } + else { + previous->bytes = 0; + previous->invalid = 0; + } } else { if (data->main->parameters.array[byte_dump_parameter_unicode_e].result == f_console_result_found_e) {