From 84ab90895ab53cbbf60f0f214f4ca2c025d085e7 Mon Sep 17 00:00:00 2001 From: Jakub Karolczyk Date: Fri, 26 Apr 2024 13:11:54 +0000 Subject: [PATCH] [mod_amrwb] Fix scan-build 14 --- src/mod/codecs/mod_amrwb/amrwb_be.c | 6 +++--- src/mod/codecs/mod_amrwb/mod_amrwb.c | 8 ++++++-- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/mod/codecs/mod_amrwb/amrwb_be.c b/src/mod/codecs/mod_amrwb/amrwb_be.c index 7b43b2b583..e8f45cf7d7 100644 --- a/src/mod/codecs/mod_amrwb/amrwb_be.c +++ b/src/mod/codecs/mod_amrwb/amrwb_be.c @@ -95,23 +95,23 @@ extern switch_bool_t switch_amrwb_pack_be(unsigned char *shift_buf, int n) extern switch_bool_t switch_amrwb_unpack_be(unsigned char *encoded_buf, uint8_t *tmp, int encoded_len) { - int framesz, index, ft; + int framesz, index; uint8_t shift_tocs[2] = {0x00, 0x00}; uint8_t *shift_buf; memcpy(shift_tocs, encoded_buf, 2); /* shift for BE */ switch_amr_array_lshift(4, shift_tocs, 2); - ft = shift_tocs[0] >> 3; - ft &= ~(1 << 5); /* Frame Type*/ shift_buf = encoded_buf + 1; /* skip CMR */ /* shift for BE */ switch_amr_array_lshift(2, shift_buf, encoded_len - 1); /* get frame size */ index = ((shift_tocs[0] >> 3) & 0x0f); if (index > 10 && index != 0xe && index != 0xf) { + return SWITCH_FALSE; } + framesz = switch_amrwb_frame_sizes[index]; tmp[0] = shift_tocs[0]; /* save TOC */ memcpy(&tmp[1], shift_buf, framesz); diff --git a/src/mod/codecs/mod_amrwb/mod_amrwb.c b/src/mod/codecs/mod_amrwb/mod_amrwb.c index 4ac3f25f37..d89ec5d62b 100644 --- a/src/mod/codecs/mod_amrwb/mod_amrwb.c +++ b/src/mod/codecs/mod_amrwb/mod_amrwb.c @@ -191,6 +191,7 @@ static switch_status_t switch_amrwb_init(switch_codec_t *codec, switch_codec_fla if (codec->fmtp_in) { codec->fmtp_out = switch_core_strdup(codec->memory_pool, codec->fmtp_in); } + return SWITCH_STATUS_SUCCESS; #else struct amrwb_context *context = NULL; @@ -204,6 +205,7 @@ static switch_status_t switch_amrwb_init(switch_codec_t *codec, switch_codec_fla decoding = (flags & SWITCH_CODEC_FLAG_DECODE); if (!(encoding || decoding) || (!(context = switch_core_alloc(codec->memory_pool, sizeof(struct amrwb_context))))) { + return SWITCH_STATUS_FALSE; } else { @@ -296,6 +298,7 @@ static switch_status_t switch_amrwb_init(switch_codec_t *codec, switch_codec_fla /* re-create mode-set */ fmtptmp_pos = switch_snprintf(fmtptmp, sizeof(fmtptmp), "mode-set="); + for (i = 0; SWITCH_AMRWB_MODES-1 > i; ++i) { if (context->enc_modes & (1 << i)) { fmtptmp_pos += switch_snprintf(fmtptmp + fmtptmp_pos, sizeof(fmtptmp) - fmtptmp_pos, fmtptmp_pos > strlen("mode-set=") ? ",%d" : "%d", i); @@ -312,12 +315,13 @@ static switch_status_t switch_amrwb_init(switch_codec_t *codec, switch_codec_fla } if (!globals.volte) { - fmtptmp_pos += switch_snprintf(fmtptmp + fmtptmp_pos, sizeof(fmtptmp) - fmtptmp_pos, ";octet-align=%d", + switch_snprintf(fmtptmp + fmtptmp_pos, sizeof(fmtptmp) - fmtptmp_pos, ";octet-align=%d", switch_test_flag(context, AMRWB_OPT_OCTET_ALIGN) ? 1 : 0); } else { - fmtptmp_pos += switch_snprintf(fmtptmp + fmtptmp_pos, sizeof(fmtptmp) - fmtptmp_pos, ";octet-align=%d;max-red=0;mode-change-capability=2", + switch_snprintf(fmtptmp + fmtptmp_pos, sizeof(fmtptmp) - fmtptmp_pos, ";octet-align=%d;max-red=0;mode-change-capability=2", switch_test_flag(context, AMRWB_OPT_OCTET_ALIGN) ? 1 : 0); } + codec->fmtp_out = switch_core_strdup(codec->memory_pool, fmtptmp); context->encoder_state = NULL;