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
rfuchs/dataport-mr11.5
Richard Fuchs 3 years ago
parent 8df04209a7
commit bd6c6ceaf2

@ -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;
}
@ -2529,9 +2527,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