Skip to content

Commit

Permalink
Fix a variety of scan-build warnings.
Browse files Browse the repository at this point in the history
  • Loading branch information
ralight committed Mar 26, 2019
1 parent 67707b8 commit 9faad1e
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 24 deletions.
2 changes: 1 addition & 1 deletion src/conf.c
Original file line number Diff line number Diff line change
Expand Up @@ -758,7 +758,7 @@ int config__read_file_core(struct mosquitto__config *config, bool reload, struct
char *key;
struct mosquitto__listener *cur_listener = &config->default_listener;
int i;
int lineno_ext;
int lineno_ext = 0;

*lineno = 0;

Expand Down
5 changes: 2 additions & 3 deletions src/handle_connect.c
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,6 @@ int handle__connect(struct mosquitto_db *db, struct mosquitto *context)
}else if(rc == MOSQ_ERR_PROTOCOL){
if(context->protocol == mosq_p_mqtt31){
/* Password flag given, but no password. Ignore. */
password_flag = 0;
}else{
rc = MOSQ_ERR_PROTOCOL;
goto handle_connect_error;
Expand Down Expand Up @@ -480,7 +479,7 @@ int handle__connect(struct mosquitto_db *db, struct mosquitto *context)
}

#ifdef WITH_TLS
if(context->listener && context->listener->ssl_ctx && (context->listener->use_identity_as_username || context->listener->use_subject_as_username)){
if(context->listener->ssl_ctx && (context->listener->use_identity_as_username || context->listener->use_subject_as_username)){
/* Don't need the username or password if provided */
mosquitto__free(username);
username = NULL;
Expand Down Expand Up @@ -615,7 +614,7 @@ int handle__connect(struct mosquitto_db *db, struct mosquitto *context)
}
#endif

if(context->listener && context->listener->use_username_as_clientid){
if(context->listener->use_username_as_clientid){
if(context->username){
mosquitto__free(client_id);
client_id = mosquitto__strdup(context->username);
Expand Down
9 changes: 3 additions & 6 deletions src/loop.c
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,6 @@ int mosquitto_main_loop(struct mosquitto_db *db, mosq_sock_t *listensock, int li
time_t last_backup = mosquitto_time();
#endif
time_t now = 0;
time_t now_time;
int time_count;
int fdcount;
struct mosquitto *context, *ctxt_tmp;
Expand Down Expand Up @@ -216,8 +215,6 @@ int mosquitto_main_loop(struct mosquitto_db *db, mosq_sock_t *listensock, int li
}
#endif

now_time = time(NULL);

time_count = 0;
HASH_ITER(hh_sock, db->contexts_by_sock, context, ctxt_tmp){
if(time_count > 0){
Expand Down Expand Up @@ -469,16 +466,16 @@ int mosquitto_main_loop(struct mosquitto_db *db, mosq_sock_t *listensock, int li
}
}
#endif
now_time = time(NULL);
if(db->config->persistent_client_expiration > 0 && now_time > expiration_check_time){
now = time(NULL);
if(db->config->persistent_client_expiration > 0 && now > expiration_check_time){
HASH_ITER(hh_id, db->contexts_by_id, context, ctxt_tmp){
if(context->sock == INVALID_SOCKET && context->session_expiry_interval > 0 && context->session_expiry_interval != UINT32_MAX){
/* This is a persistent client, check to see if the
* last time it connected was longer than
* persistent_client_expiration seconds ago. If so,
* expire it and clean up.
*/
if(now_time > context->session_expiry_time){
if(now > context->session_expiry_time){
if(context->id){
id = context->id;
}else{
Expand Down
5 changes: 4 additions & 1 deletion src/mosquitto_passwd.c
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,10 @@ int main(int argc, char *argv[])

if(create_new){
rc = get_password(password, 1024);
if(rc) return rc;
if(rc){
free(password_file);
return rc;
}
fptr = fopen(password_file, "wt");
if(!fptr){
fprintf(stderr, "Error: Unable to open file %s for writing. %s.\n", password_file, strerror(errno));
Expand Down
1 change: 1 addition & 0 deletions src/net.c
Original file line number Diff line number Diff line change
Expand Up @@ -666,6 +666,7 @@ int net__socket_get_address(mosq_sock_t sock, char *buf, int len)
struct sockaddr_storage addr;
socklen_t addrlen;

memset(&addr, 0, sizeof(struct sockaddr_storage));
addrlen = sizeof(addr);
if(!getpeername(sock, (struct sockaddr *)&addr, &addrlen)){
if(addr.ss_family == AF_INET){
Expand Down
4 changes: 1 addition & 3 deletions src/persist_read.c
Original file line number Diff line number Diff line change
Expand Up @@ -271,15 +271,13 @@ static int persist__msg_store_chunk_restore(struct mosquitto_db *db, FILE *db_fp
chunk.topic, chunk.F.qos, chunk.F.payloadlen,
&chunk.payload, chunk.F.retain, &stored, message_expiry_interval, chunk.properties, chunk.F.store_id);

if(stored){
stored->source_listener = chunk.source.listener;
}
mosquitto__free(chunk.source.id);
mosquitto__free(chunk.source.username);
chunk.source.id = NULL;
chunk.source.username = NULL;

if(rc == MOSQ_ERR_SUCCESS){
stored->source_listener = chunk.source.listener;
load->db_id = stored->db_id;
load->store = stored;

Expand Down
3 changes: 2 additions & 1 deletion src/persist_read_v5.c
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,8 @@ int persist__chunk_msg_store_read_v5(FILE *db_fptr, struct P_msg_store *chunk, u
mosquitto_property *properties = NULL;
struct mosquitto__packet prop_packet;

memset(&prop_packet, 0, sizeof(struct mosquitto__packet));

read_e(db_fptr, &chunk->F, sizeof(struct PF_msg_store));
chunk->F.payloadlen = ntohl(chunk->F.payloadlen);
chunk->F.source_mid = ntohs(chunk->F.source_mid);
Expand Down Expand Up @@ -179,7 +181,6 @@ int persist__chunk_msg_store_read_v5(FILE *db_fptr, struct P_msg_store *chunk, u
}

if(length > 0){
memset(&prop_packet, 0, sizeof(struct mosquitto__packet));
prop_packet.remaining_length = length;
prop_packet.payload = mosquitto__malloc(length);
if(!prop_packet.payload){
Expand Down
13 changes: 4 additions & 9 deletions src/subs.c
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ static int subs__process(struct mosquitto_db *db, struct mosquitto__subhier *hie
}
}

rc2 = subs__shared_process(db, hier, topic, qos, retain, stored);
rc = subs__shared_process(db, hier, topic, qos, retain, stored);

leaf = hier->subs;
while(source_id && leaf){
Expand Down Expand Up @@ -307,9 +307,8 @@ static int sub__add_leaf(struct mosquitto *context, int qos, uint32_t identifier
}
leaf = leaf->next;
}
leaf = mosquitto__malloc(sizeof(struct mosquitto__subleaf));
leaf = mosquitto__calloc(1, sizeof(struct mosquitto__subleaf));
if(!leaf) return MOSQ_ERR_NOMEM;
leaf->next = NULL;
leaf->context = context;
leaf->qos = qos;
leaf->identifier = identifier;
Expand Down Expand Up @@ -413,7 +412,7 @@ static int sub__add_shared(struct mosquitto_db *db, struct mosquitto *context, i

static int sub__add_normal(struct mosquitto_db *db, struct mosquitto *context, int qos, uint32_t identifier, int options, struct mosquitto__subhier *subhier)
{
struct mosquitto__subleaf *newleaf;
struct mosquitto__subleaf *newleaf = NULL;
struct mosquitto__subhier **subs;
int i;
int rc;
Expand Down Expand Up @@ -668,7 +667,7 @@ struct mosquitto__subhier *sub__add_hier_entry(struct mosquitto__subhier *parent

assert(sibling);

child = mosquitto__malloc(sizeof(struct mosquitto__subhier));
child = mosquitto__calloc(1, sizeof(struct mosquitto__subhier));
if(!child){
log__printf(NULL, MOSQ_LOG_ERR, "Error: Out of memory.");
return NULL;
Expand All @@ -684,10 +683,6 @@ struct mosquitto__subhier *sub__add_hier_entry(struct mosquitto__subhier *parent
}else{
strncpy(child->topic, topic, child->topic_len+1);
}
child->subs = NULL;
child->shared = NULL;
child->children = NULL;
child->retained = NULL;

HASH_ADD_KEYPTR(hh, *sibling, child->topic, child->topic_len, child);

Expand Down

0 comments on commit 9faad1e

Please sign in to comment.