Merge pull request #2449 from signalwire/fix_scan_build_mod_amrwb

[mod_amrwb] Fix scan-build 14
This commit is contained in:
Andrey Volk 2024-04-26 16:37:10 +03:00 committed by GitHub
commit 31cf32d91f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 9 additions and 5 deletions

View File

@ -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) 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_tocs[2] = {0x00, 0x00};
uint8_t *shift_buf; uint8_t *shift_buf;
memcpy(shift_tocs, encoded_buf, 2); memcpy(shift_tocs, encoded_buf, 2);
/* shift for BE */ /* shift for BE */
switch_amr_array_lshift(4, shift_tocs, 2); 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_buf = encoded_buf + 1; /* skip CMR */
/* shift for BE */ /* shift for BE */
switch_amr_array_lshift(2, shift_buf, encoded_len - 1); switch_amr_array_lshift(2, shift_buf, encoded_len - 1);
/* get frame size */ /* get frame size */
index = ((shift_tocs[0] >> 3) & 0x0f); index = ((shift_tocs[0] >> 3) & 0x0f);
if (index > 10 && index != 0xe && index != 0xf) { if (index > 10 && index != 0xe && index != 0xf) {
return SWITCH_FALSE; return SWITCH_FALSE;
} }
framesz = switch_amrwb_frame_sizes[index]; framesz = switch_amrwb_frame_sizes[index];
tmp[0] = shift_tocs[0]; /* save TOC */ tmp[0] = shift_tocs[0]; /* save TOC */
memcpy(&tmp[1], shift_buf, framesz); memcpy(&tmp[1], shift_buf, framesz);

View File

@ -191,6 +191,7 @@ static switch_status_t switch_amrwb_init(switch_codec_t *codec, switch_codec_fla
if (codec->fmtp_in) { if (codec->fmtp_in) {
codec->fmtp_out = switch_core_strdup(codec->memory_pool, codec->fmtp_in); codec->fmtp_out = switch_core_strdup(codec->memory_pool, codec->fmtp_in);
} }
return SWITCH_STATUS_SUCCESS; return SWITCH_STATUS_SUCCESS;
#else #else
struct amrwb_context *context = NULL; 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); decoding = (flags & SWITCH_CODEC_FLAG_DECODE);
if (!(encoding || decoding) || (!(context = switch_core_alloc(codec->memory_pool, sizeof(struct amrwb_context))))) { if (!(encoding || decoding) || (!(context = switch_core_alloc(codec->memory_pool, sizeof(struct amrwb_context))))) {
return SWITCH_STATUS_FALSE; return SWITCH_STATUS_FALSE;
} else { } else {
@ -296,6 +298,7 @@ static switch_status_t switch_amrwb_init(switch_codec_t *codec, switch_codec_fla
/* re-create mode-set */ /* re-create mode-set */
fmtptmp_pos = switch_snprintf(fmtptmp, sizeof(fmtptmp), "mode-set="); fmtptmp_pos = switch_snprintf(fmtptmp, sizeof(fmtptmp), "mode-set=");
for (i = 0; SWITCH_AMRWB_MODES-1 > i; ++i) { for (i = 0; SWITCH_AMRWB_MODES-1 > i; ++i) {
if (context->enc_modes & (1 << 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); 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) { 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); switch_test_flag(context, AMRWB_OPT_OCTET_ALIGN) ? 1 : 0);
} else { } 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); switch_test_flag(context, AMRWB_OPT_OCTET_ALIGN) ? 1 : 0);
} }
codec->fmtp_out = switch_core_strdup(codec->memory_pool, fmtptmp); codec->fmtp_out = switch_core_strdup(codec->memory_pool, fmtptmp);
context->encoder_state = NULL; context->encoder_state = NULL;