]> Kevux Git Server - fll/commitdiff
Bugfix: Fix bugs in console parameter processing exposed by unit tests.
authorKevin Day <kevin@kevux.org>
Tue, 18 Apr 2023 03:57:54 +0000 (22:57 -0500)
committerKevin Day <kevin@kevux.org>
Tue, 18 Apr 2023 03:57:54 +0000 (22:57 -0500)
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
level_0/f_console/c/private-console.c

index 89e207d587e396258cf74982e59f78c43a4ae52b..b476b86578ce303e043f507be856325307ae06ae 100644 (file)
@@ -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, &parameters->array[i].locations);
           if (F_status_is_error(state->status)) break;
 
index c0af986d69c3a6af6fa781c20a20fa06c2a2436f..05e0fabd4dea50c6448766f5e15d4810dc3dbb57 100644 (file)
@@ -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;
       }
     }