MT#55283 fix media array building

The index j we get is not the position in the output array/list, but
rather the index into the source array. Simply append each new element
to the array in order.

Also make sure we don't skip over empty elements in the array when
building the JSON list, so that the order is preserved.

Change-Id: Id6577410e114f0ddbea745977118f1bab2e38fa9
(cherry picked from commit 64724284c1)
mr12.0.1
Richard Fuchs 3 years ago
parent 8710ccfc0c
commit 3441416f61

@ -1253,9 +1253,7 @@ static int rbpa_cb_simple(str *s, callback_arg_t pap, struct redis_list *list, v
GPtrArray *pa = pap.pa;
int j;
j = str_to_i(s, 0);
if (pa->len <= j)
g_ptr_array_set_size(pa, j + 1);
pa->pdata[j] = redis_list_get_idx_ptr(list, (unsigned) j);
g_ptr_array_add(pa, redis_list_get_idx_ptr(list, (unsigned) j));
return 0;
}
@ -2513,9 +2511,7 @@ char* redis_encode_json(struct call *c) {
json_builder_begin_array (builder);
for (unsigned int j = 0; j < ml->medias->len; j++) {
struct call_media *media = ml->medias->pdata[j];
if (!media)
continue;
JSON_ADD_STRING("%u", media->unique_id);
JSON_ADD_STRING("%u", media ? media->unique_id : -1);
}
json_builder_end_array(builder);

Loading…
Cancel
Save