Skip to content

Commit

Permalink
Merge pull request #3483 from oanatitoc/coverity
Browse files Browse the repository at this point in the history
Coverity
  • Loading branch information
razvancrainea authored Oct 1, 2024
2 parents 207ec19 + c86d348 commit 20187fc
Show file tree
Hide file tree
Showing 10 changed files with 38 additions and 40 deletions.
8 changes: 4 additions & 4 deletions modules/presence/clustering.c
Original file line number Diff line number Diff line change
Expand Up @@ -236,11 +236,11 @@ static int bin_push_presentity(bin_packet_t *packet, presentity_t *pres)
goto error;
step++;

if (bin_push_int(packet, pres->expires) < 0)
if (bin_push_int(packet, (int)(unsigned long)pres->expires) < 0)
goto error;
step++;

if (bin_push_int(packet, pres->received_time) < 0)
if (bin_push_int(packet, (int)(unsigned long)pres->received_time) < 0)
goto error;
step++;

Expand Down Expand Up @@ -578,8 +578,8 @@ int pack_repl_presentity(bin_packet_t *packet, str *pres_uri, pres_ev_t *ev)
pres.new_etag.s = (char*)VAL_STRING(ROW_VALUES(RES_ROWS(res))+etag_col);
pres.new_etag.len = strlen(pres.new_etag.s);
pres.expires = VAL_INT(ROW_VALUES(RES_ROWS(res))+expires_col) -
(int)time(NULL);
pres.received_time = (int)time(NULL);
(int)(unsigned long)time(NULL);
pres.received_time = (int)(unsigned long)time(NULL);
if (!VAL_NULL(ROW_VALUES(RES_ROWS(res))+extra_hdrs_col)) {
s.s = (char*)VAL_STRING(ROW_VALUES(RES_ROWS(res))+extra_hdrs_col);
s.len = strlen(s.s);
Expand Down
1 change: 1 addition & 0 deletions modules/presence/event_list.c
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,7 @@ int search_event_params(event_t* ev, event_t* searched_ev)
{
if(p->name.len== ps->name.len &&
strncmp(p->name.s,ps->name.s, ps->name.len)== 0)
/* coverity[var_deref_model: FALSE] */
if((p->body.s== 0 && ps->body.s== 0) ||
(p->body.len== ps->body.len &&
strncmp(p->body.s,ps->body.s,ps->body.len)== 0))
Expand Down
4 changes: 2 additions & 2 deletions modules/presence/hash.c
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ int insert_shtable(shtable_t htable,unsigned int hash_code, subs_t* subs)
goto error;
}

new_rec->expires+= (int)time(NULL);
new_rec->expires+= (unsigned int)(unsigned long)time(NULL);
if(fallback2db)
new_rec->db_flag= NO_UPDATEDB_FLAG;
else
Expand Down Expand Up @@ -348,7 +348,7 @@ int update_shtable(shtable_t htable,unsigned int hash_code,

if(type & REMOTE_TYPE)
{
s->expires= subs->expires+ (int)time(NULL);
s->expires= subs->expires+ (unsigned int)(unsigned long)time(NULL);
s->remote_cseq= subs->remote_cseq;
}
else
Expand Down
14 changes: 7 additions & 7 deletions modules/presence/notify.c
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@ str* get_wi_notify_body(subs_t* subs, subs_t* watcher_subs)
{
s= s->next;

if(s->expires< (int)time(NULL))
if(s->expires< (unsigned int)(unsigned long)time(NULL))
{
LM_DBG("expired record\n");
continue;
Expand Down Expand Up @@ -1597,10 +1597,10 @@ int get_subs_db(str* pres_uri, pres_ev_t* event, str* sender,
s.event= event;
s.local_cseq = row_vals[cseq_col].val.int_val;

if(row_vals[expires_col].val.int_val < (int)time(NULL))
if(row_vals[expires_col].val.int_val < (int)(unsigned long)time(NULL))
s.expires = 0;
else
s.expires = row_vals[expires_col].val.int_val -(int)time(NULL);
s.expires = row_vals[expires_col].val.int_val -(int)(unsigned long)time(NULL);
s.version = row_vals[version_col].val.int_val;

s_new= mem_copy_subs(&s, PKG_MEM_TYPE);
Expand Down Expand Up @@ -1660,7 +1660,7 @@ int update_in_list(subs_t* s, subs_t* s_array, int new_rec_no, int n)
strncmp(ls->from_tag.s, s->from_tag.s, s->from_tag.len)== 0 )
{
ls->local_cseq= s->local_cseq;
ls->expires= s->expires- (int)time(NULL);
ls->expires= s->expires- (unsigned int)(unsigned long)time(NULL);
ls->version= s->version;
ls->status= s->status;
return 1;
Expand Down Expand Up @@ -1692,7 +1692,7 @@ int presentity_has_subscribers(str* pres_uri, pres_ev_t* event)
s= s->next;

/* expired & active ? */
if ( (s->expires<(int)now) || (s->status!=ACTIVE_STATUS) ||
if ( (s->expires<(unsigned int)(unsigned long)now) || (s->status!=ACTIVE_STATUS) ||
(s->reason.len!=0) )
continue;

Expand Down Expand Up @@ -1807,7 +1807,7 @@ subs_t* get_subs_dialog(str* pres_uri, pres_ev_t* event, str* sender,

printf_subs(s);

if(s->expires< (int)time(NULL))
if(s->expires< (unsigned int)(unsigned long)time(NULL))
{
LM_DBG("expired subs\n");
continue;
Expand All @@ -1829,7 +1829,7 @@ subs_t* get_subs_dialog(str* pres_uri, pres_ev_t* event, str* sender,
lock_release(&subs_htable[hash_code].lock);
goto error;
}
s_new->expires-= (int)time(NULL);
s_new->expires-= (unsigned int)(unsigned long)time(NULL);
s_new->next= s_array;
s_array= s_new;
i++;
Expand Down
2 changes: 1 addition & 1 deletion modules/presence/presence.c
Original file line number Diff line number Diff line change
Expand Up @@ -1477,7 +1477,7 @@ static int update_pw_dialogs(subs_t* subs, unsigned int hash_code, subs_t** subs
lock_release(&subs_htable[hash_code].lock);
return -1;
}
cs->expires-= (int)time(NULL);
cs->expires-= (unsigned int)(unsigned long)time(NULL);
cs->next= (*subs_array);
(*subs_array)= cs;
if(subs->status== TERMINATED_STATUS)
Expand Down
22 changes: 11 additions & 11 deletions modules/presence/presentity.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ int generate_ETag(int publ_count, str* etag)
memset(etag_buf, 0, ETAG_LEN);

etag->len = sprintf (etag_buf, "%c.%d.%d.%d.%d",
prefix, (int)startup_time, pid, counter, publ_count);
prefix, (int)(unsigned long)startup_time, pid, counter, publ_count);
if( etag->len <0 )
{
LM_ERR("unsuccessful sprintf\n");
Expand Down Expand Up @@ -457,7 +457,7 @@ int update_presentity(struct sip_msg* msg, presentity_t* presentity,

if(presentity->etag_new)
{
if (msg && publ_send200ok(msg, presentity->expires,
if (msg && publ_send200ok(msg, (int)(unsigned long)presentity->expires,
presentity->new_etag)<0)
{
LM_ERR("sending 200OK\n");
Expand Down Expand Up @@ -487,7 +487,7 @@ int update_presentity(struct sip_msg* msg, presentity_t* presentity,
query_vals[n_query_cols].type = DB_INT;
query_vals[n_query_cols].nul = 0;
query_vals[n_query_cols].val.int_val = presentity->expires+
(int)time(NULL);
(int)(unsigned long)time(NULL);
n_query_cols++;

query_cols[n_query_cols] = &str_sender_col;
Expand All @@ -514,7 +514,7 @@ int update_presentity(struct sip_msg* msg, presentity_t* presentity,
query_cols[n_query_cols] = &str_received_time_col;
query_vals[n_query_cols].type = DB_INT;
query_vals[n_query_cols].nul = 0;
query_vals[n_query_cols].val.int_val = presentity->received_time;
query_vals[n_query_cols].val.int_val = (int)(unsigned long)presentity->received_time;
n_query_cols++;

if(extra_hdrs)
Expand Down Expand Up @@ -622,7 +622,7 @@ int update_presentity(struct sip_msg* msg, presentity_t* presentity,
p = NULL;

lock_release(&pres_htable[hash_code].lock);
if(msg && publ_send200ok(msg, presentity->expires,
if(msg && publ_send200ok(msg, (int)(unsigned long)presentity->expires,
presentity->old_etag)<0)
{
LM_ERR("sending 200OK reply\n");
Expand Down Expand Up @@ -712,13 +712,13 @@ int update_presentity(struct sip_msg* msg, presentity_t* presentity,
update_vals[n_update_cols].type = DB_INT;
update_vals[n_update_cols].nul = 0;
update_vals[n_update_cols].val.int_val= presentity->expires +
(int)time(NULL);
(int)(unsigned long)time(NULL);
n_update_cols++;

update_keys[n_update_cols] = &str_received_time_col;
update_vals[n_update_cols].type = DB_INT;
update_vals[n_update_cols].nul = 0;
update_vals[n_update_cols].val.int_val= presentity->received_time;
update_vals[n_update_cols].val.int_val= (int)(unsigned long)presentity->received_time;
n_update_cols++;

update_keys[n_update_cols] = &str_sender_col;
Expand Down Expand Up @@ -796,7 +796,7 @@ int update_presentity(struct sip_msg* msg, presentity_t* presentity,
}

/* send 200OK */
if (msg && publ_send200ok(msg, presentity->expires,
if (msg && publ_send200ok(msg, (int)(unsigned long)presentity->expires,
presentity->new_etag)<0 )
{
LM_ERR("sending 200OK reply\n");
Expand Down Expand Up @@ -990,7 +990,7 @@ int pres_htable_restore(void)
continue;
}

if(row_vals[expires_col].val.int_val< (int)time(NULL))
if(row_vals[expires_col].val.int_val< (int)(unsigned long)time(NULL))
continue;

sphere= NULL;
Expand Down Expand Up @@ -1088,7 +1088,7 @@ int pres_expose_evi(pres_ev_t *ev, str *filter)
query_ops[nr_vals] = OP_GT;
query_vals[nr_vals].nul = 0;
query_vals[nr_vals].type = DB_INT;
query_vals[nr_vals].val.int_val = (int)time(NULL);
query_vals[nr_vals].val.int_val = (int)(unsigned long)time(NULL);
nr_vals++;
query_cols[nr_vals] = &str_event_col;
query_ops[nr_vals] = OP_EQ;
Expand Down Expand Up @@ -1159,7 +1159,7 @@ int pres_expose_evi(pres_ev_t *ev, str *filter)
}

/* not sure if this is needed */
if(row_vals[expires_col].val.int_val< (int)time(NULL))
if(row_vals[expires_col].val.int_val< (int)(unsigned long)time(NULL))
continue;

memset(&presentity, 0, sizeof(presentity_t));
Expand Down
7 changes: 2 additions & 5 deletions modules/presence/publish.c
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ void msg_presentity_clean(unsigned int ticks,void *interval)
db_ops[1] = OP_LT;
db_vals[1].type = DB_INT;
db_vals[1].nul = 0;
db_vals[1].val.int_val = (int)time(NULL) -10;
db_vals[1].val.int_val = (int)(unsigned long)time(NULL) -10;

last_expire_check = db_vals[1].val.int_val - 1;

Expand Down Expand Up @@ -359,9 +359,6 @@ void msg_presentity_clean(unsigned int ticks,void *interval)
}
}

if(result)
pa_dbf.free_result(pa_db, result);

/* now remove the expired records from DB ; just to be sure
* that the presentity was handled (as expired) on all presence
* servers (if DB is shared), remove from only presentities older
Expand Down Expand Up @@ -603,7 +600,7 @@ int handle_publish(struct sip_msg* msg, str* sender_uri)
presentity.sender= sender;
presentity.event= event;
presentity.expires = lexpire;
presentity.received_time= (int)time(NULL);
presentity.received_time= (int)(unsigned long)time(NULL);
if(extra_hdrs.s)
presentity.extra_hdrs = &extra_hdrs;
presentity.etag_new = etag_new;
Expand Down
16 changes: 8 additions & 8 deletions modules/presence/subscribe.c
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ int update_subs_db(subs_t* subs, int type)
update_keys[n_update_cols] = &str_expires_col;
update_vals[n_update_cols].type = DB_INT;
update_vals[n_update_cols].nul = 0;
update_vals[n_update_cols].val.int_val = subs->expires + (int)time(NULL);
update_vals[n_update_cols].val.int_val = subs->expires + (int)(unsigned long)time(NULL);
n_update_cols++;

update_keys[n_update_cols] = &str_remote_cseq_col;
Expand Down Expand Up @@ -488,7 +488,7 @@ void msg_watchers_clean(unsigned int ticks,void *param)
db_ops[0] = OP_LT;
db_vals[0].type = DB_INT;
db_vals[0].nul = 0;
db_vals[0].val.int_val = (int)time(NULL)- waiting_subs_time;
db_vals[0].val.int_val = (int)(unsigned long)time(NULL)- waiting_subs_time;

db_keys[1] = &str_status_col;
db_ops [1] = OP_EQ;
Expand Down Expand Up @@ -1543,7 +1543,7 @@ void update_db_subs(db_con_t *db,db_func_t *dbf, shtable_t hash_table,

/* collect and later delete (from memory) expired subscriptions,
* disregarding any clustering policy */
if(s->expires < (int)time(NULL))
if(s->expires < (unsigned int)(unsigned long)time(NULL))
{
LM_DBG("Found expired record\n");
del_s= s;
Expand Down Expand Up @@ -1676,7 +1676,7 @@ void update_db_subs(db_con_t *db,db_func_t *dbf, shtable_t hash_table,
update_cols[0]= &str_expires_col;
update_vals[0].type = DB_INT;
update_vals[0].nul = 0;
update_vals[0].val.int_val = (int)time(NULL);
update_vals[0].val.int_val = (int)(unsigned long)time(NULL);
update_ops[0] = OP_LT;

if (dbf->use_table(db, &active_watchers_table) < 0) {
Expand Down Expand Up @@ -1805,7 +1805,7 @@ int insert_subs_db(subs_t* s)
query_cols[n_query_cols] =&str_expires_col;
query_vals[n_query_cols].type = DB_INT;
query_vals[n_query_cols].nul = 0;
query_vals[n_query_cols].val.int_val = s->expires + (int)time(NULL);
query_vals[n_query_cols].val.int_val = s->expires + (int)(unsigned long)time(NULL);
n_query_cols++;

query_cols[n_query_cols] =&str_status_col;
Expand Down Expand Up @@ -1982,7 +1982,7 @@ int restore_db_subs(void)

expires= row_vals[expires_col].val.int_val;

if(expires< (int)time(NULL))
if(expires< (unsigned int)(unsigned long)time(NULL))
continue;

s.pres_uri.s= (char*)row_vals[pres_uri_col].val.string_val;
Expand Down Expand Up @@ -2058,7 +2058,7 @@ int restore_db_subs(void)
s.local_cseq= row_vals[local_cseq_col].val.int_val;
s.version= row_vals[version_col].val.int_val;

s.expires= expires- (int)time(NULL);
s.expires= expires- (unsigned int)(unsigned long)time(NULL);
s.status = row_vals[status_col].val.int_val;

if(!event->req_auth)
Expand Down Expand Up @@ -2352,7 +2352,7 @@ int insert_db_subs_auth(subs_t* subs)
db_keys[n_query_cols] = &str_inserted_time_col;
db_vals[n_query_cols].type = DB_INT;
db_vals[n_query_cols].nul = 0;
db_vals[n_query_cols].val.int_val= (int)time(NULL);
db_vals[n_query_cols].val.int_val= (int)(unsigned long)time(NULL);
n_query_cols++;

db_keys[n_query_cols] =&str_reason_col;
Expand Down
2 changes: 1 addition & 1 deletion modules/presence_callinfo/add_events.c
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ int do_callinfo_publish(struct sca_line *sca)
presentity.old_etag = etag;
presentity.event = callinfo_event;
presentity.expires = callinfo_event->default_expires;
presentity.received_time= (int)time(NULL);
presentity.received_time=time(NULL);
presentity.extra_hdrs = &ci_hdr;
presentity.etag_new = new_etag;
if ( pres.update_presentity( &presentity )<0 )
Expand Down
2 changes: 1 addition & 1 deletion modules/presence_xml/notify_body.c
Original file line number Diff line number Diff line change
Expand Up @@ -544,7 +544,7 @@ str* agregate_presence_xmls(str* pres_user, str* pres_domain, str** body_array,

for(i = 0; i < n; i++)
{
if(body_array[i] == NULL )
if(!body_array || !body_array[i])
continue;

xml_array[j] = NULL;
Expand Down

0 comments on commit 20187fc

Please sign in to comment.