]> Kevux Git Server - fll/commitdiff
Update: Strip NULLs from the payload number converters.
authorKevin Day <thekevinday@gmail.com>
Tue, 12 Dec 2023 02:18:03 +0000 (20:18 -0600)
committerKevin Day <thekevinday@gmail.com>
Tue, 12 Dec 2023 02:18:03 +0000 (20:18 -0600)
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.

level_1/fl_fss/c/fss/payload.c

index 601d5624ec4c01a370b83589aba4183de5854d03..2ec5c6956e5ecddb0f292410b9a5767d7d37f727 100644 (file)
@@ -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;