From f56f970bc2b0df1d26ebd6a0a86083b37017cd70 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20R=C3=BChsen?= Date: Wed, 14 Mar 2018 14:43:35 +0100 Subject: [PATCH] Fix some issues found by 'infer' --- src/ftp-basic.c | 11 ++++------- src/metalink.c | 14 ++++++-------- 2 files changed, 10 insertions(+), 15 deletions(-) diff --git a/src/ftp-basic.c b/src/ftp-basic.c index 4a112c97..bc129f6a 100644 --- a/src/ftp-basic.c +++ b/src/ftp-basic.c @@ -57,7 +57,7 @@ as that of the covered work. */ uerr_t ftp_response (int fd, char **ret_line) { - while (1) + for (;;) { char *p; char *line = fd_read_line (fd); @@ -65,12 +65,9 @@ ftp_response (int fd, char **ret_line) return FTPRERR; /* Strip trailing CRLF before printing the line, so that - quotting doesn't include bogus \012 and \015. */ - p = strchr (line, '\0'); - if (p > line && p[-1] == '\n') - *--p = '\0'; - if (p > line && p[-1] == '\r') - *--p = '\0'; + quoting doesn't include bogus \012 and \015. */ + if ((p = strpbrk(line , "\r\n"))) + *p = 0; if (opt.server_response) logprintf (LOG_NOTQUIET, "%s\n", diff --git a/src/metalink.c b/src/metalink.c index 93cc6159..2dc128fe 100644 --- a/src/metalink.c +++ b/src/metalink.c @@ -99,8 +99,8 @@ retrieve_from_metalink (const metalink_t* metalink) metalink_resource_t **mres_ptr; char *planname = NULL; char *trsrname = NULL; - char *filename = NULL; - char *basename = NULL; + char *filename; + char *basename; char *safename = NULL; char *destname = NULL; bool size_ok = false; @@ -709,8 +709,7 @@ retrieve_from_metalink (const metalink_t* metalink) gpgme_data_t gpgsigdata, gpgdata; gpgme_verify_result_t gpgres; gpgme_signature_t gpgsig; - gpgme_protocol_t gpgprot = GPGME_PROTOCOL_UNKNOWN; - int fd = -1; + int fd; /* Initialize the library - as name suggests. */ gpgme_check_version (NULL); @@ -751,16 +750,15 @@ retrieve_from_metalink (const metalink_t* metalink) msig->signature)); /* Check signature type. */ - if (!strcmp (msig->mediatype, "application/pgp-signature")) - gpgprot = GPGME_PROTOCOL_OpenPGP; - else /* Unsupported signature type. */ + if (strcmp (msig->mediatype, "application/pgp-signature")) { + /* Unsupported signature type. */ gpgme_release (gpgctx); gpgme_data_release (gpgdata); goto gpg_skip_verification; } - gpgerr = gpgme_set_protocol (gpgctx, gpgprot); + gpgerr = gpgme_set_protocol (gpgctx, GPGME_PROTOCOL_OpenPGP); if (gpgerr != GPG_ERR_NO_ERROR) { logprintf (LOG_NOTQUIET,