]> Kevux Git Server - fll/commitdiff
Bugfix: Dead code in return status handling.
authorKevin Day <kevin@kevux.org>
Sun, 5 Mar 2023 20:51:19 +0000 (14:51 -0600)
committerKevin Day <kevin@kevux.org>
Sun, 5 Mar 2023 23:26:03 +0000 (17:26 -0600)
The fake_make_operate_process_return() has dead code where it checks for the inverse of the return_code in two spots.
The first of which always returns.
The second case can never be reached.

Redesign the function.
This success/failure behavior should be preserved with this change.

Add a simple example fakefile for testing the return code value.

level_3/fake/c/private-make-operate_process.c
level_3/fake/c/private-make-operate_process.h
level_3/fake/c/private-make-operate_process_type.c
level_3/fake/data/projects/example/return_code.fakefile [new file with mode: 0644]

index 941910c76976e3b19f79a9ea563961b1312fc1a6..11acaf166d3d9d6769c1e63fff6efa085d318b12 100644 (file)
@@ -387,72 +387,68 @@ extern "C" {
       }
     }
 
-    return fake_make_operate_process_return(data_make, return_code);
+    return fake_make_operate_process_return(data_make, return_code, status);
   }
 #endif // _di_fake_make_operate_process_execute_
 
 #ifndef _di_fake_make_operate_process_return_
-  f_status_t fake_make_operate_process_return(fake_make_data_t * const data_make, const int return_code) {
+  f_status_t fake_make_operate_process_return(fake_make_data_t * const data_make, const int return_code, const f_status_t status) {
 
-    f_status_t status = F_none;
+    f_status_t result = F_none;
 
     data_make->setting_make.parameter.array[0].value.array[0].used = 0;
 
-    if (!return_code) {
-      if (F_status_is_error(status)) {
-        status = f_string_dynamic_append(f_string_ascii_1_s, &data_make->setting_make.parameter.array[0].value.array[0]);
-      }
-      else {
-        status = f_string_dynamic_append(f_string_ascii_0_s, &data_make->setting_make.parameter.array[0].value.array[0]);
-      }
-
-      if (F_status_is_error(status)) {
-        fll_error_print(data_make->error, F_status_set_fine(status), "f_string_dynamic_append", F_true);
-      }
-
-      return status;
-    }
-
     if (return_code) {
       f_string_dynamic_t number = f_string_dynamic_t_initialize;
 
-      status = f_conversion_number_signed_to_string(WEXITSTATUS(return_code), f_conversion_data_base_10_c, &number);
+      result = f_conversion_number_signed_to_string(WEXITSTATUS(return_code), f_conversion_data_base_10_c, &number);
 
-      if (F_status_is_error(status)) {
-        fll_error_print(data_make->error, F_status_set_fine(status), "f_conversion_number_signed_to_string", F_true);
+      if (F_status_is_error(result)) {
+        fll_error_print(data_make->error, F_status_set_fine(result), "f_conversion_number_signed_to_string", F_true);
 
         f_string_dynamic_resize(0, &number);
 
-        return status;
+        return result;
       }
 
-      status = f_string_dynamic_append(number, &data_make->setting_make.parameter.array[0].value.array[0]);
+      result = f_string_dynamic_append(number, &data_make->setting_make.parameter.array[0].value.array[0]);
 
       f_string_dynamic_resize(0, &number);
-    }
-    else {
-      status = f_string_dynamic_append(f_string_ascii_0_s, &data_make->setting_make.parameter.array[0].value.array[0]);
-    }
 
-    if (F_status_is_error(status)) {
-      fll_error_print(data_make->error, F_status_set_fine(status), "f_string_dynamic_append", F_true);
+      if (F_status_is_error(result)) {
+        fll_error_print(data_make->error, F_status_set_fine(result), "f_string_dynamic_append", F_true);
 
-      return status;
-    }
+        return result;
+      }
 
-    if (data_make->error.verbosity != f_console_verbosity_quiet_e && data_make->error.to.stream) {
-      flockfile(data_make->error.to.stream);
+      if (data_make->error.verbosity != f_console_verbosity_quiet_e && data_make->error.to.stream) {
+        flockfile(data_make->error.to.stream);
+
+        fl_print_format("%r%[%QFailed with return code %]", data_make->error.to.stream, f_string_eol_s, data_make->error.context, data_make->error.prefix, data_make->error.context);
+        fl_print_format("%[%i%]", data_make->error.to.stream, data_make->error.notable, return_code, data_make->error.notable);
+        fl_print_format("%[.%]%r", data_make->error.to.stream, data_make->error.context, data_make->error.context, f_string_eol_s);
+
+        funlockfile(data_make->error.to.stream);
+      }
 
-      fl_print_format("%r%[%QFailed with return code %]", data_make->error.to.stream, f_string_eol_s, data_make->error.context, data_make->error.prefix, data_make->error.context);
-      fl_print_format("%[%i%]", data_make->error.to.stream, data_make->error.notable, return_code, data_make->error.notable);
-      fl_print_format("%[.%]%r", data_make->error.to.stream, data_make->error.context, data_make->error.context, f_string_eol_s);
+      return data_make->setting_make.fail == fake_make_operation_fail_type_exit_e ? F_status_set_error(F_failure) : F_failure;
+    }
 
-      funlockfile(data_make->error.to.stream);
+    if (F_status_is_error(status)) {
+      result = f_string_dynamic_append(f_string_ascii_1_s, &data_make->setting_make.parameter.array[0].value.array[0]);
+    }
+    else {
+      result = f_string_dynamic_append(f_string_ascii_0_s, &data_make->setting_make.parameter.array[0].value.array[0]);
     }
 
-    if (data_make->setting_make.fail == fake_make_operation_fail_type_exit_e) return F_status_set_error(F_failure);
+    if (F_status_is_error(result)) {
+      fll_error_print(data_make->error, F_status_set_fine(result), "f_string_dynamic_append", F_true);
+    }
+    else {
+      result = F_none;
+    }
 
-    return F_failure;
+    return result;
   }
 #endif // _di_fake_make_operate_process_return_
 
index aa04bc4e74a460836e51a1a7143e561e6f458799..e4a72dc6c1bd734f30aa94d96d021aebf9507ca0 100644 (file)
@@ -120,6 +120,8 @@ extern "C" {
  *   All make related setting data, including data from the fakefile and the build settings file.
  * @param return_code
  *   The return code to process.
+ * @param status
+ *   The status immediately prior to this operation.
  *
  * @return
  *   F_none on success.
@@ -136,7 +138,7 @@ extern "C" {
  * @see f_string_dynamic_append()
  */
 #ifndef _di_fake_make_operate_process_return_
-  extern f_status_t fake_make_operate_process_return(fake_make_data_t * const data_make, const int return_code) F_attribute_visibility_internal_d;
+  extern f_status_t fake_make_operate_process_return(fake_make_data_t * const data_make, const int return_code, const f_status_t status) F_attribute_visibility_internal_d;
 #endif // _di_fake_make_operate_process_return_
 
 /**
index ff6cac442a00f99e33a5c8f1c00601c556994667..92188844680c55f05bf8d48aad243215a666e899 100644 (file)
@@ -49,7 +49,7 @@ extern "C" {
     const f_status_t status = fake_build_operate(data_make->data, data_make->cache_arguments.used ? &data_make->cache_arguments : 0, F_false);
     if (F_status_set_fine(status) == F_interrupt) return status;
 
-    return fake_make_operate_process_return(data_make, F_status_is_error(status) ? 1 : 0);
+    return fake_make_operate_process_return(data_make, F_status_is_error(status) ? 1 : 0, status);
   }
 #endif // _di_fake_make_operate_process_type_build_
 
@@ -59,7 +59,7 @@ extern "C" {
     const f_status_t status = fake_clean_operate(data_make->data);
     if (F_status_set_fine(status) == F_interrupt) return status;
 
-    return fake_make_operate_process_return(data_make, F_status_is_error(status) ? 1 : 0);
+    return fake_make_operate_process_return(data_make, F_status_is_error(status) ? 1 : 0, status);
   }
 #endif // _di_fake_make_operate_process_type_clean_
 
@@ -75,7 +75,7 @@ extern "C" {
       return result;
     }
 
-    *status = fake_make_operate_process_return(data_make, result);
+    *status = fake_make_operate_process_return(data_make, result, *status);
 
     return 0;
   }
@@ -1301,7 +1301,7 @@ extern "C" {
 
     if (*status == F_child) return result;
 
-    *status = fake_make_operate_process_return(data_make, result);
+    *status = fake_make_operate_process_return(data_make, result, *status);
 
     return 0;
   }
@@ -1790,7 +1790,7 @@ extern "C" {
     const f_status_t status = fake_skeleton_operate(data_make->data);
     if (F_status_set_fine(status) == F_interrupt) return status;
 
-    return fake_make_operate_process_return(data_make, F_status_is_error(status) ? 1 : 0);
+    return fake_make_operate_process_return(data_make, F_status_is_error(status) ? 1 : 0, status);
   }
 #endif // _di_fake_make_operate_process_type_skeleton_
 
diff --git a/level_3/fake/data/projects/example/return_code.fakefile b/level_3/fake/data/projects/example/return_code.fakefile
new file mode 100644 (file)
index 0000000..e6da3ba
--- /dev/null
@@ -0,0 +1,29 @@
+# fss-0005 iki-0002
+#
+# This is an example showing the return status code results.
+# This simulates a success and a failure return result.
+#
+
+setting:
+  # Set failure to "warng" to not exit (options are "exit" (default), "warn", and "ignore".
+  fail warn
+
+main:
+  print
+  print "Simulating Success Return:"
+
+  # The fake program probably exists, so use it for success.
+  run fake +v
+
+  print "Return code is 'parameter:"return"'."
+
+
+  print
+  print "Simulating Failure Return:"
+
+  # Trigger an error, if "exit" doesn't exist then this is an error but if it does then exit with value 1 to represent an error.
+  shell exit 1
+
+  print "Return code is 'parameter:"return"'."
+
+  exit success