From 64724284c19b2b825252882b174d249e5eb60f95 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 fe6994e24..fe5c1a417 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; } @@ -2518,9 +2516,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);