Skip to content

Commit bb9afcb

Browse files
[core] Coverity fixes
* [core] Coverity 1518099, 1518097, 1518098 (Unchecked return value from library) * [core] Coverity 1468551 Unchecked return value * [core] Coverity 1468293 Unchecked return value * [core] Coverity 1468274 Explicit null dereferenced * [core] Coverity 1395588 Unchecked return value * [core] Coverity 1395515 Logically dead code * [core] Coverity 1364984 Result is not floating-point * [core] Coverity 1395554, 1468440 Dereference before null check * [core] Coverity 1024487 Dereference after null check * [core] Coverity 1024872 Unchecked return value * [core] Coverity 1025822 Unchecked return value * [core] Coverity 1025823 Unchecked return value * [core] Coverity 1087637, 1346467, 1087638 Unchecked return value * [core] Coverity 1107607 Unchecked return value * [core] Coverity 1210777 Unchecked return value * [core] Coverity 1227670 Dereference before null check * [core] Coverity 1024551 Logically dead code * [core] Coverity 1024560 Logically dead code * [core] Coverity 1024664 Operands don't affect result * [core] Coverity 1364957 Dereference after null check * [core] Coverity 1395572 Logically dead code * [core] Coverity 1412459 Unchecked return value * [core] Coverity 1412490 Unchecked return value * [core] Coverity 1395515/2 Logically dead code * [core] Coverity cleanup
1 parent b6ccc27 commit bb9afcb

14 files changed

+142
-80
lines changed

src/cJSON.c

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1104,34 +1104,32 @@ static unsigned char *print(const cJSON * const item, cJSON_bool format, const i
11041104
buffer->length = default_buffer_size;
11051105
buffer->format = format;
11061106
buffer->hooks = *hooks;
1107-
if (buffer->buffer == NULL)
1108-
{
1107+
1108+
if (buffer->buffer == NULL) {
11091109
goto fail;
11101110
}
11111111

11121112
/* print the value */
1113-
if (!print_value(item, buffer))
1114-
{
1113+
if (!print_value(item, buffer)) {
11151114
goto fail;
11161115
}
1116+
11171117
update_offset(buffer);
11181118

11191119
/* check if reallocate is available */
1120-
if (hooks->reallocate != NULL)
1121-
{
1120+
if (hooks->reallocate != NULL) {
11221121
printed = (unsigned char*) hooks->reallocate(buffer->buffer, buffer->offset + 1);
11231122
if (printed == NULL) {
11241123
goto fail;
11251124
}
1125+
11261126
buffer->buffer = NULL;
1127-
}
1128-
else /* otherwise copy the JSON over to a new buffer */
1129-
{
1127+
} else { /* otherwise copy the JSON over to a new buffer */
11301128
printed = (unsigned char*) hooks->allocate(buffer->offset + 1);
1131-
if (printed == NULL)
1132-
{
1129+
if (printed == NULL) {
11331130
goto fail;
11341131
}
1132+
11351133
memcpy(printed, buffer->buffer, cjson_min(buffer->length, buffer->offset + 1));
11361134
printed[buffer->offset] = '\0'; /* just to be sure */
11371135

@@ -1142,16 +1140,10 @@ static unsigned char *print(const cJSON * const item, cJSON_bool format, const i
11421140
return printed;
11431141

11441142
fail:
1145-
if (buffer->buffer != NULL)
1146-
{
1143+
if (buffer->buffer != NULL) {
11471144
hooks->deallocate(buffer->buffer);
11481145
}
11491146

1150-
if (printed != NULL)
1151-
{
1152-
hooks->deallocate(printed);
1153-
}
1154-
11551147
return NULL;
11561148
}
11571149

@@ -1942,33 +1934,41 @@ static cJSON_bool add_item_to_object(cJSON * const object, const char * const st
19421934

19431935
CJSON_PUBLIC(void) cJSON_AddItemToObject(cJSON *object, const char *string, cJSON *item)
19441936
{
1945-
add_item_to_object(object, string, item, &global_hooks, false);
1937+
cJSON_bool res = add_item_to_object(object, string, item, &global_hooks, false);
1938+
(void)res;
19461939
}
19471940

19481941
/* Add an item to an object with constant string as key */
19491942
CJSON_PUBLIC(void) cJSON_AddItemToObjectCS(cJSON *object, const char *string, cJSON *item)
19501943
{
1951-
add_item_to_object(object, string, item, &global_hooks, true);
1944+
cJSON_bool res = add_item_to_object(object, string, item, &global_hooks, true);
1945+
(void)res;
19521946
}
19531947

19541948
CJSON_PUBLIC(void) cJSON_AddItemReferenceToArray(cJSON *array, cJSON *item)
19551949
{
1950+
cJSON_bool res;
1951+
19561952
if (array == NULL)
19571953
{
19581954
return;
19591955
}
19601956

1961-
add_item_to_array(array, create_reference(item, &global_hooks));
1957+
res = add_item_to_array(array, create_reference(item, &global_hooks));
1958+
(void)res;
19621959
}
19631960

19641961
CJSON_PUBLIC(void) cJSON_AddItemReferenceToObject(cJSON *object, const char *string, cJSON *item)
19651962
{
1963+
cJSON_bool res;
1964+
19661965
if ((object == NULL) || (string == NULL))
19671966
{
19681967
return;
19691968
}
19701969

1971-
add_item_to_object(object, string, create_reference(item, &global_hooks), &global_hooks, false);
1970+
res = add_item_to_object(object, string, create_reference(item, &global_hooks), &global_hooks, false);
1971+
(void)res;
19721972
}
19731973

19741974
CJSON_PUBLIC(cJSON*) cJSON_AddNullToObject(cJSON * const object, const char * const name)

src/switch_core_media.c

Lines changed: 26 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -722,13 +722,10 @@ SWITCH_DECLARE(payload_map_t *) switch_core_media_add_payload_map(switch_core_se
722722
exists = (type == pmap->type && !strcasecmp(name, pmap->iananame) && pmap->pt == pt && (!pmap->rate || rate == pmap->rate) && (!pmap->ptime || pmap->ptime == ptime));
723723
break;
724724
case SWITCH_MEDIA_TYPE_VIDEO:
725-
if (sdp_type == SDP_TYPE_RESPONSE) {
726-
exists = (pmap->sdp_type == SDP_TYPE_REQUEST && type == pmap->type && !strcasecmp(name, pmap->iananame));
727-
} else {
728-
exists = (type == pmap->type && !strcasecmp(name, pmap->iananame));
729-
}
725+
exists = (pmap->sdp_type == SDP_TYPE_REQUEST && type == pmap->type && !strcasecmp(name, pmap->iananame));
726+
730727
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG1, "CHECK PMAP %s:%s %d %s:%s %d ... %d\n",
731-
name, sdp_type == SDP_TYPE_REQUEST ? "REQ" : "RES", pt,
728+
name, "RES", pt,
732729
pmap->iananame, pmap->sdp_type == SDP_TYPE_REQUEST ? "REQ" : "RES", pmap->pt, exists);
733730

734731

@@ -2524,7 +2521,7 @@ static void check_jb_sync(switch_core_session_t *session)
25242521
}
25252522

25262523
if (!jb_sync_msec && frames) {
2527-
jb_sync_msec = (double)(1000 / fps) * frames;
2524+
jb_sync_msec = ((double)1000 / fps) * frames;
25282525
}
25292526

25302527
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session),
@@ -4624,9 +4621,10 @@ static void check_stream_changes(switch_core_session_t *session, const char *r_s
46244621
{
46254622
switch_core_session_t *other_session = NULL;
46264623
switch_core_session_message_t *msg;
4624+
switch_status_t status = SWITCH_STATUS_SUCCESS;
46274625

4628-
switch_core_session_get_partner(session, &other_session);
4629-
4626+
status = switch_core_session_get_partner(session, &other_session);
4627+
(void)status;
46304628

46314629
if (switch_channel_test_flag(session->channel, CF_STREAM_CHANGED)) {
46324630
switch_channel_clear_flag(session->channel, CF_STREAM_CHANGED);
@@ -4662,13 +4660,15 @@ static void check_stream_changes(switch_core_session_t *session, const char *r_s
46624660
if (switch_channel_test_flag(other_session->channel, CF_AWAITING_STREAM_CHANGE)) {
46634661
uint8_t proceed = 1;
46644662
const char *sdp_in, *other_ep;
4663+
uint8_t res = 0;
46654664

46664665
if ((other_ep = switch_channel_get_variable(session->channel, "ep_codec_string"))) {
46674666
switch_channel_set_variable(other_session->channel, "codec_string", other_ep);
46684667
}
46694668

46704669
sdp_in = switch_channel_get_variable(other_session->channel, SWITCH_R_SDP_VARIABLE);
4671-
switch_core_media_negotiate_sdp(other_session, sdp_in, &proceed, SDP_TYPE_REQUEST);
4670+
res = switch_core_media_negotiate_sdp(other_session, sdp_in, &proceed, SDP_TYPE_REQUEST);
4671+
(void)res;
46724672
switch_core_media_activate_rtp(other_session);
46734673
msg = switch_core_session_alloc(other_session, sizeof(*msg));
46744674
msg->message_id = SWITCH_MESSAGE_INDICATE_RESPOND;
@@ -13587,6 +13587,7 @@ static void switch_core_media_set_r_sdp_codec_string(switch_core_session_t *sess
1358713587
if (zstr(attr->a_name)) {
1358813588
continue;
1358913589
}
13590+
1359013591
if (!strcasecmp(attr->a_name, "ptime")) {
1359113592
dptime = atoi(attr->a_value);
1359213593
break;
@@ -13599,22 +13600,27 @@ static void switch_core_media_set_r_sdp_codec_string(switch_core_session_t *sess
1359913600
if ((m->m_type == sdp_media_audio || m->m_type == sdp_media_video) && m->m_port) {
1360013601
for (map = m->m_rtpmaps; map; map = map->rm_next) {
1360113602
int found = 0;
13603+
1360213604
for (attr = m->m_attributes; attr && found < 2; attr = attr->a_next) {
1360313605
if (zstr(attr->a_name)) {
1360413606
continue;
1360513607
}
13608+
1360613609
if (!strcasecmp(attr->a_name, "ptime") && attr->a_value) {
1360713610
ptime = atoi(attr->a_value);
1360813611
found++;
1360913612
}
13613+
1361013614
if (!strcasecmp(attr->a_name, "rtcp-mux")) {
1361113615
if (switch_channel_var_true(channel, "rtcp_mux_auto_detect")) {
1361213616
switch_log_printf(SWITCH_CHANNEL_CHANNEL_LOG(channel), SWITCH_LOG_DEBUG, "setting rtcp-mux from sdp\n");
1361313617
switch_channel_set_variable(channel, "rtcp_mux", "true");
1361413618
}
13619+
1361513620
found++;
1361613621
}
1361713622
}
13623+
1361813624
switch_core_media_add_payload_map(session,
1361913625
m->m_type == sdp_media_audio ? SWITCH_MEDIA_TYPE_AUDIO : SWITCH_MEDIA_TYPE_VIDEO,
1362013626
map->rm_encoding,
@@ -13640,11 +13646,13 @@ static void switch_core_media_set_r_sdp_codec_string(switch_core_session_t *sess
1364013646
if (zstr(attr->a_name)) {
1364113647
continue;
1364213648
}
13649+
1364313650
if (!strcasecmp(attr->a_name, "ptime") && attr->a_value) {
1364413651
ptime = atoi(attr->a_value);
1364513652
break;
1364613653
}
1364713654
}
13655+
1364813656
connection = sdp->sdp_connection;
1364913657
if (m->m_connections) {
1365013658
connection = m->m_connections;
@@ -13658,7 +13666,7 @@ static void switch_core_media_set_r_sdp_codec_string(switch_core_session_t *sess
1365813666
if (switch_channel_direction(channel) == SWITCH_CALL_DIRECTION_INBOUND || prefer_sdp) {
1365913667
for (map = m->m_rtpmaps; map; map = map->rm_next) {
1366013668

13661-
if (map->rm_pt > 127 || already_did[map->rm_pt]) {
13669+
if (already_did[map->rm_pt]) {
1366213670
continue;
1366313671
}
1366413672

@@ -13679,19 +13687,20 @@ static void switch_core_media_set_r_sdp_codec_string(switch_core_session_t *sess
1367913687
if (match) {
1368013688
add_audio_codec(map, imp, ptime, buf, sizeof(buf));
1368113689
}
13682-
1368313690
}
1368413691
}
1368513692

1368613693
} else {
1368713694
for (i = 0; i < num_codecs; i++) {
1368813695
const switch_codec_implementation_t *imp = codecs[i];
13696+
1368913697
if (imp->codec_type != SWITCH_CODEC_TYPE_AUDIO || imp->ianacode > 127 || already_did[imp->ianacode]) {
1369013698
continue;
1369113699
}
13700+
1369213701
for (map = m->m_rtpmaps; map; map = map->rm_next) {
1369313702

13694-
if (map->rm_pt > 127 || already_did[map->rm_pt]) {
13703+
if (already_did[map->rm_pt]) {
1369513704
continue;
1369613705
}
1369713706

@@ -13724,11 +13733,10 @@ static void switch_core_media_set_r_sdp_codec_string(switch_core_session_t *sess
1372413733
break;
1372513734
}
1372613735

13727-
1372813736
if (switch_channel_direction(channel) == SWITCH_CALL_DIRECTION_INBOUND || prefer_sdp) {
1372913737
for (map = m->m_rtpmaps; map; map = map->rm_next) {
1373013738

13731-
if (map->rm_pt > 127 || already_did[map->rm_pt]) {
13739+
if (already_did[map->rm_pt]) {
1373213740
continue;
1373313741
}
1373413742

@@ -13752,11 +13760,11 @@ static void switch_core_media_set_r_sdp_codec_string(switch_core_session_t *sess
1375213760
} else {
1375313761
switch_snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), ",%s.%s", imp->modname, imp->iananame);
1375413762
}
13763+
1375513764
already_did[imp->ianacode] = 1;
1375613765
}
1375713766
}
1375813767
}
13759-
1376013768
} else {
1376113769
for (i = 0; i < num_codecs; i++) {
1376213770
const switch_codec_implementation_t *imp = codecs[i];
@@ -13772,7 +13780,7 @@ static void switch_core_media_set_r_sdp_codec_string(switch_core_session_t *sess
1377213780

1377313781
for (map = m->m_rtpmaps; map; map = map->rm_next) {
1377413782

13775-
if (map->rm_pt > 127 || already_did[map->rm_pt]) {
13783+
if (already_did[map->rm_pt]) {
1377613784
continue;
1377713785
}
1377813786

@@ -13793,6 +13801,7 @@ static void switch_core_media_set_r_sdp_codec_string(switch_core_session_t *sess
1379313801
} else {
1379413802
switch_snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), ",%s.%s", imp->modname, imp->iananame);
1379513803
}
13804+
1379613805
already_did[imp->ianacode] = 1;
1379713806
}
1379813807
}

src/switch_core_memory.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -501,9 +501,12 @@ SWITCH_DECLARE(switch_status_t) switch_core_perform_destroy_memory_pool(switch_m
501501
#if APR_POOL_DEBUG
502502
fspr_pool_destroy_debug(tmp_pool, func);
503503
#else
504-
fspr_pool_destroy(tmp_pool);
504+
if (tmp_pool) {
505+
fspr_pool_destroy(tmp_pool);
506+
}
505507
#endif
506508
#ifdef USE_MEM_LOCK
509+
507510
switch_mutex_unlock(memory_manager.mem_lock);
508511
#endif
509512
}

src/switch_core_sqldb.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2065,6 +2065,7 @@ static uint32_t do_trans(switch_sql_queue_manager_t *qm)
20652065
switch_status_t status;
20662066
uint32_t ttl = 0;
20672067
uint32_t i;
2068+
switch_status_t res;
20682069

20692070
if (!zstr(qm->pre_trans_execute)) {
20702071
switch_cache_db_execute_sql_real(qm->event_db, qm->pre_trans_execute, &errmsg);
@@ -2126,7 +2127,8 @@ static uint32_t do_trans(switch_sql_queue_manager_t *qm)
21262127

21272128
for (i = 0; (qm->max_trans == 0 || ttl <= qm->max_trans) && (i < qm->numq); i++) {
21282129
switch_mutex_lock(qm->mutex);
2129-
switch_queue_trypop(qm->sql_queue[i], &pop);
2130+
res = switch_queue_trypop(qm->sql_queue[i], &pop);
2131+
(void)res;
21302132
switch_mutex_unlock(qm->mutex);
21312133
if (pop) break;
21322134
}
@@ -2138,6 +2140,7 @@ static uint32_t do_trans(switch_sql_queue_manager_t *qm)
21382140
switch_mutex_unlock(qm->mutex);
21392141
ttl++;
21402142
}
2143+
21412144
switch_safe_free(pop);
21422145
if (status != SWITCH_STATUS_SUCCESS) break;
21432146
} else {
@@ -2153,7 +2156,6 @@ static uint32_t do_trans(switch_sql_queue_manager_t *qm)
21532156
}
21542157
}
21552158

2156-
21572159
end:
21582160

21592161
switch(qm->event_db->type) {
@@ -2190,11 +2192,11 @@ static uint32_t do_trans(switch_sql_queue_manager_t *qm)
21902192
}
21912193
}
21922194

2193-
21942195
switch_mutex_lock(qm->mutex);
21952196
for (i = 0; i < qm->numq; i++) {
21962197
qm->written[i] = qm->pre_written[i];
21972198
}
2199+
21982200
switch_mutex_unlock(qm->mutex);
21992201

22002202
return ttl;

src/switch_cpp.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -98,21 +98,24 @@ SWITCH_DECLARE(Event *) EventConsumer::pop(int block, int timeout)
9898
void *pop = NULL;
9999
Event *ret = NULL;
100100
switch_event_t *event;
101+
switch_status_t res;
101102

102103
if (!ready) {
103104
return NULL;
104105
}
105106

106107
if (block) {
107108
if (timeout > 0) {
108-
switch_queue_pop_timeout(events, &pop, (switch_interval_time_t) timeout * 1000); // millisec rather than microsec
109+
res = switch_queue_pop_timeout(events, &pop, (switch_interval_time_t) timeout * 1000); // millisec rather than microsec
109110
} else {
110-
switch_queue_pop(events, &pop);
111+
res = switch_queue_pop(events, &pop);
111112
}
112113
} else {
113-
switch_queue_trypop(events, &pop);
114+
res = switch_queue_trypop(events, &pop);
114115
}
115116

117+
(void)res;
118+
116119
if ((event = (switch_event_t *) pop)) {
117120
ret = new Event(event, 1);
118121
}
@@ -138,9 +141,7 @@ SWITCH_DECLARE(void) EventConsumer::cleanup()
138141

139142
node_index = 0;
140143

141-
if (events) {
142-
switch_queue_interrupt_all(events);
143-
}
144+
switch_queue_interrupt_all(events);
144145

145146
while(switch_queue_trypop(events, &pop) == SWITCH_STATUS_SUCCESS) {
146147
switch_event_t *event = (switch_event_t *) pop;

0 commit comments

Comments
 (0)