From b5dd7de9b2a82018e53e512da19dad319edd0afa Mon Sep 17 00:00:00 2001 From: defanor Date: Wed, 22 Sep 2021 23:07:18 +0300 Subject: Fix a few GCC warnings --- src/Makefile.am | 9 +-------- src/rexmpp.c | 14 +++++++++----- src/rexmpp_jid.c | 2 +- src/rexmpp_openpgp.c | 2 +- 4 files changed, 12 insertions(+), 15 deletions(-) diff --git a/src/Makefile.am b/src/Makefile.am index 0ccdf5b..7acc57d 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -1,6 +1,5 @@ AM_CFLAGS = -Werror -Wall -Wextra -pedantic -std=gnu99 \ - -Wno-pointer-sign \ - -Wno-stringop-truncation -Wno-stringop-overflow -Wno-maybe-uninitialized + -Wno-pointer-sign # -Wno-pointer-sign is used to suppress libxml2-related warnings. # Since we only care about UTF-8, and in almost all cases just its @@ -8,12 +7,6 @@ AM_CFLAGS = -Werror -Wall -Wextra -pedantic -std=gnu99 \ # etc), it shouldn't matter. Later it would be nice to abstract XML # manipulations anyway, to allow libexpat as an alternative. -# -Wno-stringop-truncation, -Wno-stringop-overflow, and -# -Wno-maybe-uninitialized are added because newer GCC versions -# started complaining about the bits that are fine, though rewriting -# those bits in a way that doesn't make GCC unhappy may be useful for -# catching actual bugs with those warnings. - lib_LTLIBRARIES = librexmpp.la diff --git a/src/rexmpp.c b/src/rexmpp.c index acb4473..85f971a 100644 --- a/src/rexmpp.c +++ b/src/rexmpp.c @@ -796,8 +796,10 @@ rexmpp_err_t rexmpp_send_continue (rexmpp_t *s) } ssize_t ret; rexmpp_tls_err_t err; + int tls_was_active; while (1) { - if (s->tls_state == REXMPP_TLS_ACTIVE) { + tls_was_active = (s->tls_state == REXMPP_TLS_ACTIVE); + if (tls_was_active) { err = rexmpp_tls_send (s, s->send_buffer, s->send_buffer_len, @@ -829,7 +831,7 @@ rexmpp_err_t rexmpp_send_continue (rexmpp_t *s) } } } else { - if (s->tls_state == REXMPP_TLS_ACTIVE) { + if (tls_was_active) { if (err != REXMPP_TLS_E_AGAIN) { s->tls_state = REXMPP_TLS_ERROR; /* Assume a TCP error for now as well. */ @@ -1024,10 +1026,12 @@ rexmpp_err_t rexmpp_recv (rexmpp_t *s) { int sasl_err; rexmpp_tls_err_t recv_err; rexmpp_err_t err = REXMPP_SUCCESS; + int tls_was_active; /* Loop here in order to consume data from TLS buffers, which wouldn't show up on select(). */ do { - if (s->tls_state == REXMPP_TLS_ACTIVE) { + tls_was_active = (s->tls_state == REXMPP_TLS_ACTIVE); + if (tls_was_active) { recv_err = rexmpp_tls_recv(s, chunk_raw, 4096, &chunk_raw_len); } else { chunk_raw_len = recv(s->server_socket, chunk_raw, 4096, 0); @@ -1075,7 +1079,7 @@ rexmpp_err_t rexmpp_recv (rexmpp_t *s) { return err; } } else if (chunk_raw_len == 0) { - if (s->tls_state == REXMPP_TLS_ACTIVE) { + if (tls_was_active) { s->tls_state = REXMPP_TLS_CLOSED; rexmpp_log(s, LOG_INFO, "TLS disconnected"); } @@ -1089,7 +1093,7 @@ rexmpp_err_t rexmpp_recv (rexmpp_t *s) { s->tcp_state = REXMPP_TCP_CLOSED; } } else { - if (s->tls_state == REXMPP_TLS_ACTIVE) { + if (tls_was_active) { if (recv_err != REXMPP_TLS_E_AGAIN) { s->tls_state = REXMPP_TLS_ERROR; /* Assume a TCP error for now as well. */ diff --git a/src/rexmpp_jid.c b/src/rexmpp_jid.c index 659df3e..522a492 100644 --- a/src/rexmpp_jid.c +++ b/src/rexmpp_jid.c @@ -56,7 +56,7 @@ int rexmpp_jid_parse (const char *str, struct rexmpp_jid *jid) { } /* Copy all the parts. */ - strncpy(jid->full, str, full_len); + strncpy(jid->full, str, 3072); jid->full[full_len] = '\0'; strncpy(jid->bare, str, bare_len); jid->bare[bare_len] = '\0'; diff --git a/src/rexmpp_openpgp.c b/src/rexmpp_openpgp.c index fd22cf4..84b7537 100644 --- a/src/rexmpp_openpgp.c +++ b/src/rexmpp_openpgp.c @@ -783,7 +783,7 @@ char *rexmpp_openpgp_payload (rexmpp_t *s, } else if (mode == REXMPP_OX_CRYPT) { err = gpgme_op_encrypt(s->pgp_ctx, keys, GPGME_ENCRYPT_NO_ENCRYPT_TO, plain_dh, cipher_dh); - } else if (mode == REXMPP_OX_SIGN) { + } else { /* if (mode == REXMPP_OX_SIGN) */ err = gpgme_op_sign(s->pgp_ctx, plain_dh, cipher_dh, GPGME_SIG_MODE_NORMAL); } if (keys != NULL) { -- cgit v1.2.3