]> Kevux Git Server - fll/commitdiff
Regression: The trailing Unicode sequences don't always show correctly for sequences...
authorKevin Day <thekevinday@gmail.com>
Fri, 15 Apr 2022 21:56:11 +0000 (16:56 -0500)
committerKevin Day <thekevinday@gmail.com>
Fri, 15 Apr 2022 21:56:11 +0000 (16:56 -0500)
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

index 54451ae3d0a3797d679adb918cca4ee85829a1cb..174e852b38d88e6452858aae49bb780fa1e39902 100644 (file)
@@ -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) {