Browse Source

[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.
master
Glenn Strauss 6 months ago
parent
commit
fefdf7f097
  1. 11
      src/array.c

11
src/array.c

@ -45,16 +45,9 @@ void array_copy_array(array * const dst, const array * const src) {
array_free_data(dst);
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]));
}
}

Loading…
Cancel
Save