From: Kevin Day Date: Sun, 5 Mar 2023 20:51:19 +0000 (-0600) Subject: Bugfix: Dead code in return status handling. X-Git-Tag: 0.6.4~22 X-Git-Url: https://git.kevux.org/?a=commitdiff_plain;h=86d3a14483202cea61464e43cc4b214a9523c10f;p=fll Bugfix: Dead code in return status handling. 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. --- diff --git a/level_3/fake/c/private-make-operate_process.c b/level_3/fake/c/private-make-operate_process.c index 941910c..11acaf1 100644 --- a/level_3/fake/c/private-make-operate_process.c +++ b/level_3/fake/c/private-make-operate_process.c @@ -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_ diff --git a/level_3/fake/c/private-make-operate_process.h b/level_3/fake/c/private-make-operate_process.h index aa04bc4..e4a72dc 100644 --- a/level_3/fake/c/private-make-operate_process.h +++ b/level_3/fake/c/private-make-operate_process.h @@ -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_ /** diff --git a/level_3/fake/c/private-make-operate_process_type.c b/level_3/fake/c/private-make-operate_process_type.c index ff6cac4..9218884 100644 --- a/level_3/fake/c/private-make-operate_process_type.c +++ b/level_3/fake/c/private-make-operate_process_type.c @@ -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 index 0000000..e6da3ba --- /dev/null +++ b/level_3/fake/data/projects/example/return_code.fakefile @@ -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