From: Kevin Day Date: Tue, 12 Dec 2023 02:18:03 +0000 (-0600) Subject: Update: Strip NULLs from the payload number converters. X-Git-Url: https://git.kevux.org/?a=commitdiff_plain;h=5277f5033d47830dd5283d31901a672c91ce6a29;p=fll Update: Strip NULLs from the payload number converters. Add logic to strip the NULLs from the numbers. The FSS functions use NULLs to reduce reallocations but the payload sends everything. Don't introduce unexpected NULLs when writing the numbers. I need to review the logic for any mistakes which I find is often best after sleeping on it. Even better, I should write some unit tests to expose any potential logic flaws more easily. --- diff --git a/level_1/fl_fss/c/fss/payload.c b/level_1/fl_fss/c/fss/payload.c index 601d562..2ec5c69 100644 --- a/level_1/fl_fss/c/fss/payload.c +++ b/level_1/fl_fss/c/fss/payload.c @@ -40,6 +40,40 @@ extern "C" { private_fl_fss_basic_write(F_false, *data->cache, 0, &internal->range, &internal->destinations->array[internal->destinations->used].value, state, (void * const) internal); if (F_status_is_error(state->status)) return F_true; + + // Strip NULLs that may have been introduced via private_fl_fss_basic_write(). + if (data->cache->used) { + f_number_unsigned_t i = data->cache->used; + f_number_unsigned_t j = 0; + f_number_unsigned_t total = 0; + + while (--i) { + + if (!data->cache->string[i]) { + total = 1; + + for (j = i - 1; j && !data->cache->string[j]; ++total, --j) { + // Do nothing. + } // for + + if (!j) { + if (!data->cache->string[j]) { + ++total; + } + else { + ++j; + } + } + + memmove(data->cache->string + j, data->cache->string + i + 1, total); + + data->cache->used -= total; + i = j; + + if (!i) break; + } + } // while + } } return F_false; @@ -79,6 +113,40 @@ extern "C" { private_fl_fss_basic_write(F_false, *data->cache, 0, &internal->range, &internal->destinations->array[internal->destinations->used].value, state, (void * const) internal); if (F_status_is_error(state->status)) return F_true; + + // Strip NULLs that may have been introduced via private_fl_fss_basic_write(). + if (data->cache->used) { + f_number_unsigned_t i = data->cache->used; + f_number_unsigned_t j = 0; + f_number_unsigned_t total = 0; + + while (--i) { + + if (!data->cache->string[i]) { + total = 1; + + for (j = i - 1; j && !data->cache->string[j]; ++total, --j) { + // Do nothing. + } // for + + if (!j) { + if (!data->cache->string[j]) { + ++total; + } + else { + ++j; + } + } + + memmove(data->cache->string + j, data->cache->string + i + 1, total); + + data->cache->used -= total; + i = j; + + if (!i) break; + } + } // while + } } return F_false;