]> Kevux Git Server - fll/commitdiff
Bugfix: Error handling should not exit for certain errors.
authorKevin Day <thekevinday@gmail.com>
Sat, 11 Dec 2021 03:57:44 +0000 (21:57 -0600)
committerKevin Day <thekevinday@gmail.com>
Sat, 11 Dec 2021 04:24:04 +0000 (22:24 -0600)
When a process signal is being received, F_signal is being set with the error bit.
This should not have the error bit set.

Move the conditional logic inside the appropriate printing functions.
Add utf8_print_character_invalid() for printing an error character.

Invalid UTF-8 fragments should not result in an exit on error.
Instead, these should be handled by either appropriate printing or by setting the is valid property on exit.

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

index 23b75c575448959f289ef797ff33731ed1c957ce..70b17950cad7b26c10b1aebcaaa151b005e6e3e3 100644 (file)
@@ -33,6 +33,17 @@ extern "C" {
   }
 #endif // _di_utf8_print_character_
 
+#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;
+
+    utf8_print_character(data, character, data->valid_not);
+  }
+#endif // _di_utf8_print_character_invalid_
+
 #ifndef _di_utf8_print_codepoint_
   void utf8_print_codepoint(utf8_data_t * const data, const uint32_t codepoint) {
 
@@ -52,6 +63,8 @@ extern "C" {
   void utf8_print_error_decode(utf8_data_t * const data, const f_status_t status, const f_string_static_t character) {
 
     if (data->main->error.verbosity == f_console_verbosity_quiet) 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;
 
     fl_print_format("%c%[%SFailed to decode character code '%]", data->main->error.to.stream, f_string_eol_s[0], data->main->context.set.error, data->main->error.prefix, data->main->context.set.error);
 
@@ -68,6 +81,9 @@ extern "C" {
     if (F_status_set_fine(status) == F_utf) {
       fl_print_format("%[', not a valid UTF-8 character sequence.%]%c", data->main->error.to.stream, data->main->context.set.error, data->main->context.set.error, f_string_eol_s[0]);
     }
+    else if (F_status_set_fine(status) == F_utf_fragment) {
+      fl_print_format("%[', invalid UTF-8 fragment.%]%c", data->main->error.to.stream, data->main->context.set.error, data->main->context.set.error, f_string_eol_s[0]);
+    }
     else {
       fl_print_format("%[', error status code%] ", data->main->error.to.stream, data->main->context.set.error, data->main->context.set.error, f_string_eol_s[0]);
       fl_print_format("%[%ui%]", data->main->error.to.stream, data->main->context.set.notable, F_status_set_fine(status), data->main->context.set.notable);
index bcf1bcdc42fa12834d5b03cdf068edb879080199..18f462d9069c52111441a884ae65a8475b7eb895 100644 (file)
@@ -40,6 +40,20 @@ extern "C" {
 #endif // _di_utf8_print_character_
 
 /**
+ * Print an invalid character either as a Unicode codeblock or as a binary.
+ *
+ * This handles whether or not the invalid character should be printed or not based on program parameters.
+ *
+ * @param data
+ *   The program data.
+ * @param character
+ *   The character block to print.
+ */
+#ifndef _di_utf8_print_character_invalid_
+  extern void utf8_print_character_invalid(utf8_data_t * const data, const f_string_static_t character) F_attribute_visibility_internal_d;
+#endif // _di_utf8_print_character_invalid_
+
+/**
  * Print the codepoint number as a codepoint string (such as U+8C78).
  *
  * @param data
index dae939cb887509138ce21b3498d22c9aa69b4f14..2a387b1a551a4fc70a9e045a22b3775715e2c57b 100644 (file)
@@ -25,17 +25,17 @@ extern "C" {
     }
 
     if (F_status_is_error(status)) {
-      if (F_status_set_fine(status) == F_failure || F_status_set_fine(status) == F_utf || F_status_set_fine(status) == F_valid_not) {
+      status = F_status_set_fine(status);
+
+      if (status == F_failure || status == F_utf || status == F_utf_fragment || status == F_valid_not) {
         valid_not = F_true;
 
-        if (data->main->parameters[utf8_parameter_strip_invalid].result == f_console_result_none && data->main->parameters[utf8_parameter_verify].result == f_console_result_none) {
-          utf8_print_character(data, character, data->valid_not);
-        }
+        utf8_print_character_invalid(data, data->text);
       }
       else {
-        if (data->main->parameters[utf8_parameter_strip_invalid].result == f_console_result_none && data->main->parameters[utf8_parameter_verify].result == f_console_result_none) {
-          utf8_print_error_decode(data, status, character);
-        }
+        status = F_status_set_error(status);
+
+        utf8_print_error_decode(data, status, character);
 
         return status;
       }
@@ -84,7 +84,7 @@ extern "C" {
           if (utf8_signal_received(data)) {
             utf8_print_signal_received(data, status);
 
-            status = F_status_set_error(F_signal);
+            status = F_signal;
             break;
           }
         }
@@ -149,7 +149,7 @@ extern "C" {
 
     data->buffer.used = 0;
 
-    if (F_status_is_error(status)) {
+    if (F_status_is_error(status) || status == F_signal) {
       return status;
     }
 
index 79c12b95d8765d4f595a5d06e4bcdcb10402d8f6..fbe9fe4c44510207d5aaee7289a58a12c6ca93e9 100644 (file)
@@ -36,17 +36,17 @@ extern "C" {
       status = f_utf_unicode_string_to(data->text.string, data->text.used, &codepoint);
 
       if (F_status_is_error(status)) {
-        if (F_status_set_fine(status) == F_failure || F_status_set_fine(status) == F_utf || F_status_set_fine(status) == F_valid_not) {
+        status = F_status_set_fine(status);
+
+        if (status == F_failure || status == F_utf || status == F_utf_fragment || status == F_valid_not) {
           valid_not = F_true;
 
-          if (data->main->parameters[utf8_parameter_strip_invalid].result == f_console_result_none && data->main->parameters[utf8_parameter_verify].result == f_console_result_none) {
-            fl_print_format("%s%[%r%]%s", data->file.stream, data->prepend, data->valid_not, data->text, data->valid_not, data->append);
-          }
+          utf8_print_character_invalid(data, data->text);
         }
         else {
-          if (data->main->parameters[utf8_parameter_strip_invalid].result == f_console_result_none && data->main->parameters[utf8_parameter_verify].result == f_console_result_none) {
-            utf8_print_error_decode(data, status, character);
-          }
+          status = F_status_set_error(status);
+
+          utf8_print_error_decode(data, status, character);
 
           return status;
         }
@@ -76,9 +76,7 @@ extern "C" {
     else {
       status = F_none;
 
-      if (data->main->parameters[utf8_parameter_verify].result == f_console_result_none) {
-        fl_print_format("%s%[%r%]%s", data->file.stream, data->prepend, data->valid_not, data->text, data->valid_not, data->append);
-      }
+      utf8_print_character_invalid(data, data->text);
     }
 
     *mode = utf8_codepoint_mode_ready;
@@ -110,7 +108,15 @@ extern "C" {
     }
     else if (macro_f_utf_byte_width_is(*character.string)) {
       status = f_utf_is_whitespace(character.string, 4);
-      if (F_status_is_error(status)) return status;
+
+      if (F_status_is_error(status)) {
+        if (F_status_set_fine(status) == F_utf_fragment) {
+          status = F_valid_not;
+        }
+        else {
+          return status;
+        }
+      }
 
       if (status == F_true) {
         status = F_space;
@@ -121,9 +127,16 @@ extern "C" {
     }
     else {
       if (character.string[0] < 0x30 || character.string[0] > 0x39 && character.string[0] < 0x41 || character.string[0] > 0x46 && character.string[0] < 0x61 || character.string[0] > 0x66) {
-
         status = f_utf_is_whitespace(character.string, 4);
-        if (F_status_is_error(status)) return status;
+
+        if (F_status_is_error(status)) {
+          if (F_status_set_fine(status) == F_utf_fragment) {
+            status = F_valid_not;
+          }
+          else {
+            return status;
+          }
+        }
 
         if (status == F_true) {
           status = F_space;
@@ -207,7 +220,7 @@ extern "C" {
           if (utf8_signal_received(data)) {
             utf8_print_signal_received(data, status);
 
-            status = F_status_set_error(F_signal);
+            status = F_signal;
             break;
           }
         }
@@ -272,7 +285,7 @@ extern "C" {
 
     data->buffer.used = 0;
 
-    if (F_status_is_error(status)) {
+    if (F_status_is_error(status) || status == F_signal) {
       return status;
     }
 
index 7c521e8cef92649b56dfdfd574b4ebabfb187979..eaae881bb0d4252685818260dec4a664621b9f06 100644 (file)
@@ -361,7 +361,7 @@ extern "C" {
           status = utf8_process_file_codepoint(&data, file);
         }
 
-        if (F_status_is_error(status)) {
+        if (F_status_is_error(status) && F_status_set_fine(status) != F_utf_fragment) {
           fll_error_file_print(main->error, F_status_set_fine(status), data.mode & utf8_mode_from_binary_d ? "utf8_process_file_binary" : "utf8_process_file_codepoint", F_true, 0, utf8_string_process_s, fll_error_file_type_pipe);
         }
       }
@@ -410,7 +410,7 @@ extern "C" {
             }
           }
 
-          if (F_status_is_error(status)) {
+          if (F_status_is_error(status) && F_status_set_fine(status) != F_utf_fragment) {
             fll_error_file_print(main->error, F_status_set_fine(status), data.mode & utf8_mode_from_binary_d ? "utf8_process_file_binary" : "utf8_process_file_codepoint", F_true, arguments->argv[index], utf8_string_process_s, fll_error_file_type_file);
 
             break;
@@ -449,7 +449,7 @@ extern "C" {
     }
 
     if (main->output.verbosity != f_console_verbosity_quiet && main->parameters[utf8_parameter_verify].result == f_console_result_none) {
-      if (F_status_set_fine(status) == F_interrupt) {
+      if (status == F_signal) {
         fflush(data.file.stream);
 
         if (data.file.stream != main->output.to.stream) {
@@ -463,7 +463,7 @@ extern "C" {
     utf8_data_delete(&data);
     utf8_main_delete(main);
 
-    if (F_status_is_error(status)) {
+    if (F_status_is_error(status) || status == F_signal) {
       return status;
     }