From: Stefan Beller <stefanbeller@gmail.com>
To: l.s.r@web.de, gitster@pobox.com, git@vger.kernel.org
Cc: Stefan Beller <stefanbeller@gmail.com>
Subject: [PATCH] mailsplit.c: remove dead code
Date: Tue, 12 Aug 2014 23:21:27 +0200 [thread overview]
Message-ID: <1407878487-23530-1-git-send-email-stefanbeller@gmail.com> (raw)
In-Reply-To: <53EA430E.8050905@web.de>
This was found by coverity. (Id: 290001)
The variable 'output' is assigned to a value
after all gotos to the corrupt label.
Remove the goto by moving the errorhandling code to the
condition, which detects the error.
Signed-off-by: Stefan Beller <stefanbeller@gmail.com>
Helped-by: René Scharfe <l.s.r@web.de>
---
builtin/mailsplit.c | 17 ++++++-----------
1 file changed, 6 insertions(+), 11 deletions(-)
If I understood correctly, this is what you had in mind?
Thanks,
Stefan
diff --git a/builtin/mailsplit.c b/builtin/mailsplit.c
index 06296d4..763cda0 100644
--- a/builtin/mailsplit.c
+++ b/builtin/mailsplit.c
@@ -53,14 +53,16 @@ static int keep_cr;
*/
static int split_one(FILE *mbox, const char *name, int allow_bare)
{
- FILE *output = NULL;
+ FILE *output;
int fd;
int status = 0;
int is_bare = !is_from_line(buf.buf, buf.len);
- if (is_bare && !allow_bare)
- goto corrupt;
-
+ if (is_bare && !allow_bare) {
+ unlink(name);
+ fprintf(stderr, "corrupt mailbox\n");
+ exit(1);
+ }
fd = open(name, O_WRONLY | O_CREAT | O_EXCL, 0666);
if (fd < 0)
die_errno("cannot open output file '%s'", name);
@@ -91,13 +93,6 @@ static int split_one(FILE *mbox, const char *name, int allow_bare)
}
fclose(output);
return status;
-
- corrupt:
- if (output)
- fclose(output);
- unlink(name);
- fprintf(stderr, "corrupt mailbox\n");
- exit(1);
}
static int populate_maildir_list(struct string_list *list, const char *path)
--
2.1.0.rc2
next prev parent reply other threads:[~2014-08-12 21:21 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-08-11 21:11 [PATCH] mailsplit.c: remove dead code Stefan Beller
2014-08-12 16:38 ` René Scharfe
2014-08-12 21:21 ` Stefan Beller [this message]
2014-08-12 21:37 ` Matthieu Moy
2014-08-12 21:38 ` Junio C Hamano
2014-08-12 21:50 ` Junio C Hamano
2014-08-12 21:56 ` Matthieu Moy
2014-08-12 22:58 ` Jonathan Nieder
2014-08-17 8:14 ` Jeff King
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1407878487-23530-1-git-send-email-stefanbeller@gmail.com \
--to=stefanbeller@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=l.s.r@web.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).