From c952a025dde75069e6d87ec98c2eec9bb1fbb3d9 Mon Sep 17 00:00:00 2001 From: Andrey Volk Date: Fri, 12 Jul 2019 20:52:25 +0400 Subject: [PATCH] FS-11903: Fix errors reported by PVS-Studio Static Code Analyzer for mod_spandsp --- .../applications/mod_spandsp/mod_spandsp.c | 6 +++++- .../mod_spandsp/mod_spandsp_codecs.c | 2 +- .../mod_spandsp/mod_spandsp_fax.c | 19 +++++++++++-------- .../mod_spandsp/mod_spandsp_modem.c | 2 -- src/mod/applications/mod_spandsp/udptl.c | 2 +- 5 files changed, 18 insertions(+), 13 deletions(-) diff --git a/src/mod/applications/mod_spandsp/mod_spandsp.c b/src/mod/applications/mod_spandsp/mod_spandsp.c index 7d8c0d1e63..c8802ed15d 100644 --- a/src/mod/applications/mod_spandsp/mod_spandsp.c +++ b/src/mod/applications/mod_spandsp/mod_spandsp.c @@ -282,6 +282,8 @@ SWITCH_STANDARD_API(start_tone_detect_api) puuid = strdup((char *)cmd); + switch_assert(puuid); + if ((descriptor = strchr(puuid, ' '))) { *descriptor++ = '\0'; } @@ -367,7 +369,7 @@ SWITCH_STANDARD_API(start_tdd_detect_api) return SWITCH_STATUS_SUCCESS; } - spandsp_tdd_decode_session(psession); + status = spandsp_tdd_decode_session(psession); if (status == SWITCH_STATUS_SUCCESS) { stream->write_function(stream, "+OK started\n"); @@ -413,6 +415,8 @@ SWITCH_STANDARD_API(start_send_tdd_api) puuid = strdup((char *)cmd); + switch_assert(puuid); + if ((text = strchr(puuid, ' '))) { *text++ = '\0'; } diff --git a/src/mod/applications/mod_spandsp/mod_spandsp_codecs.c b/src/mod/applications/mod_spandsp/mod_spandsp_codecs.c index a4c6ba2223..93f4462230 100644 --- a/src/mod/applications/mod_spandsp/mod_spandsp_codecs.c +++ b/src/mod/applications/mod_spandsp/mod_spandsp_codecs.c @@ -463,7 +463,7 @@ static switch_status_t switch_g726_init(switch_codec_t *codec, switch_codec_flag return SWITCH_STATUS_FALSE; } - if ((flags & SWITCH_CODEC_FLAG_AAL2 || strstr(codec->implementation->iananame, "AAL2"))) { + if (flags & SWITCH_CODEC_FLAG_AAL2 || strstr(codec->implementation->iananame, "AAL2")) { packing = G726_PACKING_LEFT; } diff --git a/src/mod/applications/mod_spandsp/mod_spandsp_fax.c b/src/mod/applications/mod_spandsp/mod_spandsp_fax.c index b75ac89423..2931f7414c 100644 --- a/src/mod/applications/mod_spandsp/mod_spandsp_fax.c +++ b/src/mod/applications/mod_spandsp/mod_spandsp_fax.c @@ -824,9 +824,7 @@ static switch_status_t spanfax_init(pvt_t *pvt, transport_mode_t trans_mode) /* add to timer thread processing */ if (!add_pvt(pvt)) { - if (channel) { - switch_channel_hangup(channel, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER); - } + switch_channel_hangup(channel, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER); } span_log_set_message_handler(t38_terminal_get_logging_state(t38), mod_spandsp_log_message, pvt->session); @@ -1027,12 +1025,17 @@ static switch_status_t spanfax_destroy(pvt_t *pvt) static t38_mode_t configure_t38(pvt_t *pvt) { - switch_core_session_t *session = pvt->session; - switch_channel_t *channel = switch_core_session_get_channel(session); - switch_t38_options_t *t38_options = switch_channel_get_private(channel, "t38_options"); + switch_core_session_t *session; + switch_channel_t *channel; + switch_t38_options_t *t38_options; int method = 2; - if (!t38_options || !pvt || !pvt->t38_core) { + switch_assert(pvt && pvt->session); + session = pvt->session; + channel = switch_core_session_get_channel(session); + t38_options = switch_channel_get_private(channel, "t38_options"); + + if (!t38_options || !pvt->t38_core) { pvt->t38_mode = T38_MODE_REFUSED; return pvt->t38_mode; } @@ -2364,7 +2367,7 @@ switch_status_t spandsp_fax_detect_session(switch_core_session_t *session, return SWITCH_STATUS_FALSE; } - if (!cont && !(cont = switch_core_session_alloc(session, sizeof(*cont)))) { + if (!(cont = switch_core_session_alloc(session, sizeof(*cont)))) { return SWITCH_STATUS_MEMERR; } diff --git a/src/mod/applications/mod_spandsp/mod_spandsp_modem.c b/src/mod/applications/mod_spandsp/mod_spandsp_modem.c index 21c4296871..5613b4aa4c 100644 --- a/src/mod/applications/mod_spandsp/mod_spandsp_modem.c +++ b/src/mod/applications/mod_spandsp/mod_spandsp_modem.c @@ -744,8 +744,6 @@ static switch_status_t channel_receive_message(switch_core_session_t *session, s case SWITCH_MESSAGE_INDICATE_RINGING: break; case SWITCH_MESSAGE_INDICATE_BRIDGE: - mod_spandsp_indicate_data(session, SWITCH_FALSE, SWITCH_TRUE); - break; case SWITCH_MESSAGE_INDICATE_UNBRIDGE: mod_spandsp_indicate_data(session, SWITCH_FALSE, SWITCH_TRUE); break; diff --git a/src/mod/applications/mod_spandsp/udptl.c b/src/mod/applications/mod_spandsp/udptl.c index 4244c1a519..6b414924e2 100644 --- a/src/mod/applications/mod_spandsp/udptl.c +++ b/src/mod/applications/mod_spandsp/udptl.c @@ -363,7 +363,7 @@ int udptl_rx_packet(udptl_state_t *s, const uint8_t buf[], int len) int udptl_build_packet(udptl_state_t *s, uint8_t buf[], const uint8_t msg[], int msg_len) { - uint8_t fec[LOCAL_FAX_MAX_DATAGRAM]; + uint8_t fec[LOCAL_FAX_MAX_DATAGRAM] = { 0 }; int i; int j; int seq;