From c0c7715d6def574887fb360472e425fa295e2564 Mon Sep 17 00:00:00 2001 From: Kevin Day Date: Mon, 17 Apr 2023 22:57:54 -0500 Subject: [PATCH] Bugfix: Fix bugs in console parameter processing exposed by unit tests. The f_console_identify() function is incorrectly assigning the bits for short alone values. The mistake is a missing pipe character and as a result the flags are being assigned rather than being bitwise-or appended. The short.used and long.used string checks should skip when the string is empty. This is not happening due to an AND comparitor in the string. This then causes a false positive and the unit tests identify invalid data. The process found check outside of the loop that depends on the iterator "i" should also check that i is less than the total array length. --- level_0/f_console/c/console.c | 11 +++++++---- level_0/f_console/c/private-console.c | 2 +- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/level_0/f_console/c/console.c b/level_0/f_console/c/console.c index 89e207d..b476b86 100644 --- a/level_0/f_console/c/console.c +++ b/level_0/f_console/c/console.c @@ -273,7 +273,8 @@ extern "C" { if (parameters->array[i].flag & f_console_flag_disable_e) continue; if ((process.result & f_console_result_normal_e) && !(parameters->array[i].flag & f_console_flag_normal_e)) continue; if ((process.result & f_console_result_inverse_e) && !(parameters->array[i].flag & f_console_flag_inverse_e)) continue; - if (!parameters->array[i].match_short.used && !parameters->array[i].match_short.string) continue; + if (!parameters->array[i].match_short.used) continue; + if (!parameters->array[i].match_short.string) continue; if (arguments.argv[process.location][process.location_sub] != *parameters->array[i].match_short.string) continue; process.width = macro_f_utf_byte_width_is(arguments.argv[process.location][process.location_sub]); @@ -392,7 +393,8 @@ extern "C" { if (parameters->array[i].flag & f_console_flag_disable_e) continue; if ((process.result & f_console_result_normal_e) && !(parameters->array[i].flag & f_console_flag_normal_e)) continue; if ((process.result & f_console_result_inverse_e) && !(parameters->array[i].flag & f_console_flag_inverse_e)) continue; - if (!parameters->array[i].match_short.used && !parameters->array[i].match_short.string) continue; + if (!parameters->array[i].match_short.used) continue; + if (!parameters->array[i].match_short.string) continue; if (arguments.argv[process.location][process.location_sub] != *parameters->array[i].match_short.string) continue; if (parameters->callback) { @@ -493,7 +495,8 @@ extern "C" { if (parameters->array[i].flag & f_console_flag_disable_e) continue; if ((process.result & f_console_result_normal_e) && !(parameters->array[i].flag & f_console_flag_normal_e)) continue; if ((process.result & f_console_result_inverse_e) && !(parameters->array[i].flag & f_console_flag_inverse_e)) continue; - if (!parameters->array[i].match_long.used && !parameters->array[i].match_long.string) continue; + if (!parameters->array[i].match_long.used) continue; + if (!parameters->array[i].match_long.string) continue; if (strncmp(&arguments.argv[process.location][process.location_sub], parameters->array[i].match_long.string, parameters->array[i].match_long.used + 1)) continue; if (parameters->callback) { @@ -581,7 +584,7 @@ extern "C" { continue; } - if (state->status == F_process && process.found) { + if (state->status == F_process && process.found && i < parameters->used) { state->status = f_array_lengths_increase(state->step_small, ¶meters->array[i].locations); if (F_status_is_error(state->status)) break; diff --git a/level_0/f_console/c/private-console.c b/level_0/f_console/c/private-console.c index c0af986..05e0fab 100644 --- a/level_0/f_console/c/private-console.c +++ b/level_0/f_console/c/private-console.c @@ -51,7 +51,7 @@ extern "C" { } } else { - *result = f_console_result_short_e | f_console_result_alone_e; + *result |= f_console_result_short_e | f_console_result_alone_e; } } -- 1.8.3.1