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.
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;
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) {