From d02c099206d81f81167ee97c7a80c6b264dd14bb Mon Sep 17 00:00:00 2001 From: Richard Fuchs Date: Tue, 7 Nov 2023 13:33:31 -0500 Subject: [PATCH] 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 --- daemon/redis.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/daemon/redis.c b/daemon/redis.c index 66671cb65..28ec972df 100644 --- a/daemon/redis.c +++ b/daemon/redis.c @@ -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);