Skip to content

Commit

Permalink
Solve another things reported by splint
Browse files Browse the repository at this point in the history
  • Loading branch information
claucece committed Oct 6, 2018
1 parent 0238e8a commit eda970e
Show file tree
Hide file tree
Showing 13 changed files with 36 additions and 27 deletions.
3 changes: 0 additions & 3 deletions .splintrc
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,13 @@
+charint
+matchanyintegral
+voidabstract
-boolops
-branchstate
-compdef
-compdestroy
-compmempass
-exportlocal
-fcnuse
-fixedformalarray
-formatcode
-globstate
-immediatetrans
-incondefs
Expand All @@ -61,7 +59,6 @@
-nullret
-nullstate
-observertrans
-predboolothers
-retvalother
-shiftnegative
-statictrans
Expand Down
4 changes: 2 additions & 2 deletions src/alloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ INTERNAL /*@only@*/ /*@notnull@*/ void *otrng_xmalloc(size_t size) {
if (oom_handler != NULL) {
oom_handler();
}
fprintf(stderr, "fatal: memory exhausted (xmalloc of %zu bytes).\n", size);
fprintf(stderr, "fatal: memory exhausted (xmalloc of %lu bytes).\n", size);

This comment has been minimized.

Copy link
@olabini

olabini Oct 6, 2018

Contributor

This makes me a bit sad... %zu is proper C99 code and is what you're supposed to use to printf a size_t. But yeah, splint doesn't like it...

This comment has been minimized.

Copy link
@claucece

claucece Oct 7, 2018

Author Member

Yeah.. it is very weird.

exit(EXIT_FAILURE);
}

Expand All @@ -59,7 +59,7 @@ otrng_xrealloc(/*@only@*/ /*@null@*/ void *ptr, size_t size) {
if (oom_handler != NULL) {
oom_handler();
}
fprintf(stderr, "fatal: memory exhausted (xrealloc of %zu bytes).\n", size);
fprintf(stderr, "fatal: memory exhausted (xrealloc of %lu bytes).\n", size);
exit(EXIT_FAILURE);
}

Expand Down
4 changes: 3 additions & 1 deletion src/client.c
Original file line number Diff line number Diff line change
Expand Up @@ -585,7 +585,9 @@ otrng_client_build_prekey_messages(uint8_t num_messages,
for (i = 0; i < num_messages; i++) {
ecdh_keypair_s ecdh;
dh_keypair_s dh;
otrng_generate_ephemeral_keys(&ecdh, &dh);
if (!otrng_generate_ephemeral_keys(&ecdh, &dh)) {
return NULL;
}

messages[i] = otrng_prekey_message_build(instance_tag, &ecdh, &dh);
if (!messages[i]) {
Expand Down
2 changes: 1 addition & 1 deletion src/client_profile.c
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ tstatic uint32_t client_profile_body_serialize_pre_transitional_signature(
num_fields++;

/* DSA key */
if (client_profile->dsa_key && client_profile->dsa_key_len) {
if ((client_profile->dsa_key != NULL) && (client_profile->dsa_key_len != 0)) {
w += otrng_serialize_uint16(dst + w, OTRNG_CLIENT_PROFILE_FIELD_DSA_KEY);
w += otrng_serialize_bytes_array(dst + w, client_profile->dsa_key,
client_profile->dsa_key_len);
Expand Down
2 changes: 1 addition & 1 deletion src/fingerprint.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ INTERNAL otrng_result otrng_serialize_fingerprint(otrng_fingerprint fp,

memset(ser, 0, ED448_POINT_BYTES);

if (!fp) {
if (fp == NULL) { // TODO: unsure about this check. This is an array
return OTRNG_ERROR;
}

Expand Down
4 changes: 2 additions & 2 deletions src/fragment.c
Original file line number Diff line number Diff line change
Expand Up @@ -327,8 +327,8 @@ INTERNAL otrng_result otrng_expire_fragments(time_t now,
fragment_context_s *ctx = current->data;

list_element_s *to_free = NULL;
if (ctx &&
difftime(now, ctx->last_fragment_received_at) < expiration_time) {
if ((ctx != NULL) &&
(difftime(now, ctx->last_fragment_received_at) < expiration_time)) {
*contexts = otrng_list_remove_element(current, *contexts);
otrng_fragment_context_free(ctx);
to_free = current;
Expand Down
2 changes: 1 addition & 1 deletion src/instance_tag.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ API otrng_bool otrng_instag_get(otrng_instag_s *otrng_instag,
OtrlInsTag *tmp_instag;
OtrlUserState us = otrl_userstate_create();

if (!us) {
if (us == NULL) { // TODO: unsure about this check
return otrng_false;
}

Expand Down
2 changes: 1 addition & 1 deletion src/list.c
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ otrng_list_get(const void *wanted, list_element_s *head,
list_element_s *cursor = head;

while (cursor) {
if (fn && fn(cursor->data, wanted)) {
if ((fn != NULL) && fn(cursor->data, wanted)) {
return cursor;
}

Expand Down
16 changes: 10 additions & 6 deletions src/otrng.c
Original file line number Diff line number Diff line change
Expand Up @@ -335,12 +335,14 @@ tstatic otrng_result message_to_display_without_tag(otrng_response_s *response,
}

tstatic void set_running_version_from_tag(otrng_s *otr, const string_p msg) {
if (allow_version(otr, OTRNG_ALLOW_V4) && strstr(msg, tag_version_v4)) {
if (allow_version(otr, OTRNG_ALLOW_V4) &&
(strstr(msg, tag_version_v4) != NULL)) {
otr->running_version = OTRNG_PROTOCOL_VERSION_4;
return;
}

if (allow_version(otr, OTRNG_ALLOW_V3) && strstr(msg, tag_version_v3)) {
if (allow_version(otr, OTRNG_ALLOW_V3) &&
(strstr(msg, tag_version_v3) != NULL)) {
otr->running_version = OTRNG_PROTOCOL_VERSION_3;
return;
}
Expand All @@ -355,9 +357,9 @@ tstatic otrng_bool message_is_query(const string_p msg) {

tstatic void set_running_version_from_query_message(otrng_s *otr,
const string_p msg) {
if (allow_version(otr, OTRNG_ALLOW_V4) && strstr(msg, "4")) {
if (allow_version(otr, OTRNG_ALLOW_V4) && (strstr(msg, "4") != NULL)) {
otr->running_version = OTRNG_PROTOCOL_VERSION_4;
} else if (allow_version(otr, OTRNG_ALLOW_V3) && strstr(msg, "3")) {
} else if (allow_version(otr, OTRNG_ALLOW_V3) && (strstr(msg, "3") != NULL)) {
otr->running_version = OTRNG_PROTOCOL_VERSION_3;
}
}
Expand Down Expand Up @@ -1225,7 +1227,8 @@ tstatic otrng_bool verify_non_interactive_auth_message(
free(t);
t = NULL;

if (initiator.exp_client_profile && initiator.exp_prekey_profile) {
if ((initiator.exp_client_profile != NULL) &&
(initiator.exp_prekey_profile != NULL)) {
/* the fallback */
if (!build_fallback_non_interactive_rsign_tag(
&t, &t_len, &initiator, &responder,
Expand Down Expand Up @@ -2251,7 +2254,8 @@ static otrng_result receive_defragmented_message(otrng_response_s *response,
response->to_display = NULL;

/* A DH-Commit sets our running version to 3 */
if (allow_version(otr, OTRNG_ALLOW_V3) && strstr(msg, "?OTR:AAMC")) {
if (allow_version(otr, OTRNG_ALLOW_V3) &&
(strstr(msg, "?OTR:AAMC") != NULL)) {
otr->running_version = OTRNG_PROTOCOL_VERSION_3;
}

Expand Down
5 changes: 3 additions & 2 deletions src/persistence.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ static char *otrng_client_get_storage_id(const otrng_client_s *client) {
return NULL;
}

if (account_name && protocol_name) {
if ((account_name != NULL) && (protocol_name != NULL)) {
size_t n = strlen(protocol_name) + strlen(account_name) + 2;
key = otrng_xmalloc(n);

Expand Down Expand Up @@ -296,7 +296,8 @@ INTERNAL otrng_result
otrng_client_instance_tag_read_from(otrng_client_s *client, FILE *instagf) {
gcry_error_t ret;

if (!client->global_state->user_state_v3) {
if (client->global_state->user_state_v3 ==
NULL) { // TODO: unsure about this check. It is not a pointer
return OTRNG_ERROR;
}

Expand Down
8 changes: 5 additions & 3 deletions src/protocol.c
Original file line number Diff line number Diff line change
Expand Up @@ -222,9 +222,11 @@ tstatic otrng_result send_data_message(string_p *to_send, const uint8_t *msg,
memset(enc_key, 0, ENC_KEY_BYTES);
memset(mac_key, 0, MAC_KEY_BYTES);

otrng_key_manager_derive_chain_keys(enc_key, mac_key, otr->keys, NULL,
otr->client->max_stored_msg_keys, 0, 's',
warn);
if (!otrng_key_manager_derive_chain_keys(enc_key, mac_key, otr->keys, NULL,
otr->client->max_stored_msg_keys, 0,
's', warn)) {
return OTRNG_ERROR;
}

data_msg = generate_data_message(otr, ratchet_id);
if (!data_msg) {
Expand Down
5 changes: 4 additions & 1 deletion src/smp_protocol.c
Original file line number Diff line number Diff line change
Expand Up @@ -1196,7 +1196,10 @@ INTERNAL otrng_smp_event otrng_reply_with_smp_message_2(tlv_s **to_send,

*to_send = NULL;

generate_smp_message_2(&msg_2, smp->message1, smp);
if (!generate_smp_message_2(&msg_2, smp->message1, smp)) {
return OTRNG_SMP_EVENT_ERROR;
}

if (!smp_message_2_serialize(&buffer, &buff_len, &msg_2)) {
return OTRNG_SMP_EVENT_ERROR;
}
Expand Down
6 changes: 3 additions & 3 deletions src/v3.c
Original file line number Diff line number Diff line change
Expand Up @@ -712,7 +712,7 @@ INTERNAL otrng_result otrng_v3_receive_message(char **to_send,

*to_send = otrng_v3_retrieve_injected_message(conn);

if (to_display && new_msg) {
if ((to_display != NULL) && (new_msg != NULL)) {
*to_display = otrng_xstrdup(new_msg);
}

Expand Down Expand Up @@ -777,7 +777,7 @@ INTERNAL otrng_result otrng_v3_smp_start(char **to_send,
size_t secretlen,
otrng_v3_conn_s *conn) {
char *q = NULL;
if (question && q_len > 0) {
if ((question != NULL) && q_len > 0) {
q = otrng_xmalloc(q_len + 1);
q = memcpy(q, question, q_len);
q[q_len] = 0;
Expand Down Expand Up @@ -822,7 +822,7 @@ tstatic void otrng_v3_store_injected_message(const char *msg,

// TODO: @client This is where we should ADD a new element to the list.
// We are just ignoring for now.
if (conn->injected_message && msg) {
if ((conn->injected_message != NULL) && (msg != NULL)) {
free(conn->injected_message);
}

Expand Down

0 comments on commit eda970e

Please sign in to comment.