From b8cb2d5cf5c2beb5de175a0b6a95502a54d3e936 Mon Sep 17 00:00:00 2001 From: Mamadou DIOP Date: Fri, 26 Feb 2016 01:38:27 +0100 Subject: Fix codec priority setting issue. The codec is removed when the priority value is > the total number of registered codecs. This happens when few codecs are registered --- tinyDAV/src/tdav.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'tinyDAV') diff --git a/tinyDAV/src/tdav.c b/tinyDAV/src/tdav.c index 0fa72e8..e264f2b 100755 --- a/tinyDAV/src/tdav.c +++ b/tinyDAV/src/tdav.c @@ -473,14 +473,15 @@ int tdav_codec_set_priority(tdav_codec_id_t codec_id, int priority) { tsk_size_t i; - if(priority < 0) { + if (priority < 0) { TSK_DEBUG_ERROR("Invalid parameter"); return -1; } - for(i = 0; i < __codec_plugins_all_count && __codec_plugins_all[i]; ++i) { + for (i = 0; i < __codec_plugins_all_count && __codec_plugins_all[i]; ++i) { if(__codec_plugins_all[i]->codec_id == codec_id) { const struct tmedia_codec_plugin_def_s *codec_decl_1, *codec_decl_2; - priority = TSK_MIN(priority, (int)__codec_plugins_all_count-1); + tsk_size_t max = tmedia_codec_plugin_registered_count(__codec_plugins_all, __codec_plugins_all_count); + priority = TSK_CLAMP(0, priority, (int)(max > 0 ? (max - 1) : 0)); codec_decl_1 = __codec_plugins_all[priority]; codec_decl_2 = __codec_plugins_all[i]; -- cgit v1.1