From: Kevin Day Date: Mon, 31 May 2021 04:07:18 +0000 (-0500) Subject: Bugfix: FLL/FSS Identifier problems. X-Git-Tag: 0.5.4~17 X-Git-Url: https://git.kevux.org/?a=commitdiff_plain;h=f377109ca2b27f05964c7139d11726cec6e4eb20;p=fll Bugfix: FLL/FSS Identifier problems. The strtol() function is being incorrectly used. Redesign the code to accomodate the particular nature of that function. Instead of doing math, just create a special structure that is friendly for strtol() and read str The status is being incorrectly checked against F_false when the check should be against F_true (oops!). Make sure the id->used is correctly calculated. The calculation is truncating the name because the i variable is incremented in a start/stop range and not in a buffer used (start/stop ranges are inclusive and a buffer.used more akin to exclusive). I forgot to allocate the FLL Identifiers array. There are some cases where found_fss is not and should be tested for. The ids->used should instead be ids->used - 1. Minor syntax fixes. --- diff --git a/level_1/fl_string/c/string.c b/level_1/fl_string/c/string.c index dfbd933..8a2a89a 100644 --- a/level_1/fl_string/c/string.c +++ b/level_1/fl_string/c/string.c @@ -560,7 +560,7 @@ extern "C" { // skip past all leading NULLs. for (; range->start <= range->stop; ++range->start) { if (buffer[range->start]) break; - } + } // for if (range->start > range->stop) { return F_data_not; @@ -677,8 +677,9 @@ extern "C" { { f_array_length_t j = 0; + char number[5] = { 0, 0, 0, 0, 0 }; - for (; range->start <= range->stop && j < 5; ++range->start, ++j) { + for (++range->start; range->start <= range->stop && j < 4; ++range->start, ++j) { // The hexidecimal representing the number may only be ASCII. if (macro_f_utf_byte_width_is(buffer[range->start])) { @@ -703,40 +704,21 @@ extern "C" { } if (isxdigit(buffer[range->start])) { - if (id) { - if (j) { - id->type *= 16; - id->type += strtol(buffer + range->start, 0, 16); - } - else { - id->type = strtol(buffer + range->start, 0, 16); - } - } + number[j] = buffer[range->start]; } else { if (!buffer[range->start]) continue; - // Increment until stop, while taking into consideration UTF-8 character widths. - for (; range->start <= range->stop; ) { - - if (buffer[range->start] == f_string_eol_s[0]) { - ++range->start; - - break; - } - - range->start += macro_f_utf_byte_width(buffer[range->start]); - } // for - - if (id) { - id->type = 0; - } - - return F_found_not; + break; } } // for - if (j != 5) { + if (j == 4) { + if (id) { + id->type = strtol(number, 0, 16); + } + } + else { // Increment until stop, while taking into consideration UTF-8 character widths. for (; range->start <= range->stop; ) { @@ -761,7 +743,7 @@ extern "C" { // skip past all NULLs. for (; range->start <= range->stop; ++range->start) { if (buffer[range->start]) break; - } + } // for // The end of line, whitespace, or range stop point are the only valid stop points. if (range->start <= range->stop) { @@ -775,7 +757,7 @@ extern "C" { return status; } - if (status == F_true) { + if (status == F_false) { // Increment until stop, while taking into consideration UTF-8 character widths. for (; range->start <= range->stop; ) { @@ -811,11 +793,11 @@ extern "C" { ++i; } // for - if (i < 64) { - id->name[i] = 0; - } + id->used = i + 1; - id->used = i; + if (id->used < 64) { + id->name[id->used] = 0; + } } return F_found; diff --git a/level_2/fll_fss/c/fss.c b/level_2/fll_fss/c/fss.c index 1f51a13..b262696 100644 --- a/level_2/fll_fss/c/fss.c +++ b/level_2/fll_fss/c/fss.c @@ -119,10 +119,15 @@ extern "C" { bool found_fss = F_false; do { + if (ids && ids->used + 1 > ids->size) { + status = f_type_fll_ids_increase(f_fss_default_allocation_step_small, ids); + } - status = fl_string_fll_identify(buffer, range, ids ? &ids->array[ids->used] : &id); + if (F_status_is_error_not(status)) { + status = fl_string_fll_identify(buffer, range, ids ? &ids->array[ids->used] : &id); + } - if (F_status_is_error(status) || status == F_found_not) { + if (F_status_is_error(status) || (status == F_found_not && !found_fss)) { if (ids) { ids->used = 0; } @@ -132,7 +137,7 @@ extern "C" { if (!found_fss) { if (ids) { - if (ids->array[ids->used].used == 3 && ids->array[ids->used].name[0] == f_fss_f_s[0] && ids->array[ids->used].name[0] == f_fss_s_s[0] && ids->array[ids->used].name[0] == f_fss_s_s[0]) { + if (ids->used && ids->array[ids->used - 1].used == 3 && ids->array[ids->used - 1].name[0] == f_fss_f_s[0] && ids->array[ids->used - 1].name[0] == f_fss_s_s[0] && ids->array[ids->used - 1].name[0] == f_fss_s_s[0]) { found_fss = F_true; } }