]> Kevux Git Server - fll/commitdiff
Bugfix: Trailing Unicode sequences that get cut off before the encoding is completed...
authorKevin Day <thekevinday@gmail.com>
Fri, 15 Apr 2022 20:36:25 +0000 (15:36 -0500)
committerKevin Day <thekevinday@gmail.com>
Fri, 15 Apr 2022 20:36:25 +0000 (15:36 -0500)
Detect when this kind of underflow happens.
Print remaining characters without trying to print missing characters.
Reset and perform remaining data to print at end.

level_3/byte_dump/c/private-byte_dump.c

index e7689448909d8579f7a327a65a12941a4857dfe6..e9c54e4bb4fe3ccd96feff635824c50389036a15 100644 (file)
@@ -191,8 +191,49 @@ extern "C" {
 
     // Print placeholders to fill out the remaining line and then optionally print the text block.
     if (cell.column && cell.column < data->width) {
-      previous.bytes = 0;
-      previous.invalid = 0;
+      const uint8_t width_missing = width_utf - width_count;
+      const uint8_t column_offset = data->width - cell.column;
+      width_count = 0;
+
+      // Handle incomplete character at the end of the stream.
+      if (width_count < width_utf) {
+        found_invalid_utf = F_true;
+        invalid[character_current] = width_utf;
+
+        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, 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, 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);
+
+          previous.bytes = column_offset;
+          previous.invalid = previous.bytes;
+        }
+        else {
+          previous.bytes = 0;
+          previous.invalid = 0;
+        }
+      }
 
       while (cell.column < data->width) {