git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] mailsplit.c: remove dead code

From
René Scharfe <l.s.r@web.de>
Date
Aug 12, 2014, 16:38 UTC
Message-ID
<53EA430E.8050905@web.de>
In-Reply-To
<1407791481-17410-1-git-send-email-stefanbeller@gmail.com>
Am 11.08.2014 um 23:11 schrieb Stefan Beller:
Show 5 quoted lines
> This was found by coverity. (Id: 290001)
>
> the variable 'output' is only assigned to a value inequal to NUL,
> after all gotos to the corrupt label.
> Therefore we can conclude the two removed lines are actually dead code.

After reading the above for the first time I thought it meant the opposite of what's actually going on. Perhaps it's the placement of "only", the comma or a flawed understanding of grammar on my part?

In any case, there is only one way to reach the label named corrupt, and the variable named output is always NULL if that branch is taken. That means the removed code was a no-op. With those two lines gone you also don't need to initialize output anymore, by the way.

And since there is only a single goto, you could move the three remaining error handling lines up to the if statement. Keeping condition and dependent code together would be an improvement, I think.

Show 19 quoted lines
> Signed-off-by: Stefan Beller <stefanbeller@gmail.com>
> ---
>   builtin/mailsplit.c | 2 --
>   1 file changed, 2 deletions(-)
>
> diff --git a/builtin/mailsplit.c b/builtin/mailsplit.c
> index 06296d4..b499014 100644
> --- a/builtin/mailsplit.c
> +++ b/builtin/mailsplit.c
> @@ -93,8 +93,6 @@ static int split_one(FILE *mbox, const char *name, int allow_bare)
>   	return status;
>
>    corrupt:
> -	if (output)
> -		fclose(output);
>   	unlink(name);
>   	fprintf(stderr, "corrupt mailbox\n");
>   	exit(1);
>
Previous: Stefan BellerNext: Stefan Beller
Message 2 of 9 in “mailsplit.c: remove dead code”
  1. mailsplit.c: remove dead codeStefan Beller, Aug 11, 2014
  2. René ScharfeAug 12, 2014
  3. mailsplit.c: remove dead codeStefan Beller, Aug 12, 2014
  4. Matthieu MoyAug 12, 2014
  5. Junio C HamanoAug 12, 2014
  6. Junio C HamanoAug 12, 2014
  7. Matthieu MoyAug 12, 2014
  8. Jonathan NiederAug 12, 2014
  9. Jeff KingAug 17, 2014

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.