[core] fix array_copy_array() sorted[]

fix array_copy_array() sorted[]
(current use appears to be only on value lists; not user-visible issue)

Some time back, sorted[] was a set of indexes into data[],
and therefore sorted[] could be copied when copying array.
Now that sorted[] is a list of pointers, the sorted[] list
must be rebuilt.  If copied, it continued to point to
(data_unset *) from the original src array, not the dst array.
Glenn Strauss 2020-12-15 20:01:23 -05:00
parent 20b54fa918
commit fefdf7f097
1 changed files with 2 additions and 9 deletions

View File

@ -45,16 +45,9 @@ void array_copy_array(array * const dst, const array * const src) {
if (0 == src->size) return;
dst->used = src->used;
dst->size = src->size;
dst->data = calloc(src->size, sizeof(*src->data));
force_assert(NULL != dst->data);
dst->sorted = malloc(sizeof(*src->sorted) * src->size);
force_assert(NULL != dst->sorted);
memcpy(dst->sorted, src->sorted, sizeof(*src->sorted) * src->used);
array_extend(dst, src->size);
for (uint32_t i = 0; i < src->used; ++i) {
dst->data[i] = src->data[i]->fn->copy(src->data[i]);
array_insert_unique(dst, src->data[i]->fn->copy(src->data[i]));