]> Kevux Git Server - fll/commitdiff
Bugfix: Failed to produce identical binary when passing appropriate parameters.
authorKevin Day <thekevinday@gmail.com>
Sat, 11 Dec 2021 20:54:11 +0000 (14:54 -0600)
committerKevin Day <thekevinday@gmail.com>
Sat, 11 Dec 2021 20:54:11 +0000 (14:54 -0600)
Taking a binary input with a binary output while passing +nq should result in a byte-for-byte duplicate binary.

Example: "utf8 -f /bin/bash -bB +nq -F /tmp/bash".

This is failing for two reasons:
1) Not using the original string data when printing detected invalid characters.
2) Performing the from codepoint check before checking the binary output check in the function utf8_print_character().

Also remove a redundant not zero check in the error print function utf8_print_character_invalid().
the function utf8_print_character_invalid() is a wrapper to utf8_print_character(), where that check is already performed.

level_3/utf8/c/private-print.c
level_3/utf8/c/private-utf8_binary.c
level_3/utf8/c/private-utf8_codepoint.c

index 8e87d65005328204f2c0ad077a3305eeaa92f8a6..f362bf6ce1e469bccbac9ab5a326507a2db94729 100644 (file)
@@ -18,12 +18,12 @@ extern "C" {
 
     if (!character.used) return;
 
-    if (data->mode & utf8_mode_from_codepoint_d) {
-      fl_print_format("%s%[%Q%]%s", data->file.stream, data->prepend, set, character, set, data->append);
-    }
-    else if (data->mode & utf8_mode_to_binary_d) {
+    if (data->mode & utf8_mode_to_binary_d) {
       fl_print_format("%s%[%r%]%s", data->file.stream, data->prepend, set, character, set, data->append);
     }
+    else if (data->mode & utf8_mode_from_codepoint_d) {
+      fl_print_format("%s%[%Q%]%s", data->file.stream, data->prepend, set, character, set, data->append);
+    }
     else {
       fl_print_format("%s%[0x", data->file.stream, data->prepend, set);
 
@@ -39,7 +39,6 @@ extern "C" {
 #ifndef _di_utf8_print_character_invalid_
   void utf8_print_character_invalid(utf8_data_t * const data, const f_string_static_t character) {
 
-    if (!character.used) return;
     if (data->main->parameters[utf8_parameter_strip_invalid].result == f_console_result_found) return;
     if (data->main->parameters[utf8_parameter_verify].result == f_console_result_found) return;
 
index 2a387b1a551a4fc70a9e045a22b3775715e2c57b..26e5edbb967db9c6728ee2f08058d674c043352c 100644 (file)
@@ -30,7 +30,7 @@ extern "C" {
       if (status == F_failure || status == F_utf || status == F_utf_fragment || status == F_valid_not) {
         valid_not = F_true;
 
-        utf8_print_character_invalid(data, data->text);
+        utf8_print_character_invalid(data, character);
       }
       else {
         status = F_status_set_error(status);
index fbe9fe4c44510207d5aaee7289a58a12c6ca93e9..601bc573fde32f1c6406111060928f0dcd4954eb 100644 (file)
@@ -41,7 +41,7 @@ extern "C" {
         if (status == F_failure || status == F_utf || status == F_utf_fragment || status == F_valid_not) {
           valid_not = F_true;
 
-          utf8_print_character_invalid(data, data->text);
+          utf8_print_character_invalid(data, character);
         }
         else {
           status = F_status_set_error(status);
@@ -76,7 +76,7 @@ extern "C" {
     else {
       status = F_none;
 
-      utf8_print_character_invalid(data, data->text);
+      utf8_print_character_invalid(data, character);
     }
 
     *mode = utf8_codepoint_mode_ready;