Re: [PATCH] Fix compiler warning by properly initialize failed_errno
- From
Junio C Hamano <gitster@pobox.com>
- Date
- Aug 4, 2009, 06:07 UTC
- Message-ID
- <7vmy6g6rj1.fsf@alter.siamese.dyndns.org>
- In-Reply-To
- <1249241675-77329-1-git-send-email-sn_@gmx.net>
David Soria Parra <sn_@gmx.net> writes:
Show 22 quoted lines
> From: David Soria Parra <dsp@php.net>
>
> Initilize failed_error in start_command to avoid compiler warnings
>
> Signed-off-by: David Soria Parra <dsp@php.net>
> ---
> run-command.c | 2 +-
> 1 files changed, 1 insertions(+), 1 deletions(-)
>
> diff --git a/run-command.c b/run-command.c
> index dc09433..510349b 100644
> --- a/run-command.c
> +++ b/run-command.c
> @@ -19,7 +19,7 @@ int start_command(struct child_process *cmd)
> {
> int need_in, need_out, need_err;
> int fdin[2], fdout[2], fderr[2];
> - int failed_errno;
> + int failed_errno = 0;
>
> /*
> * In case of errors we must keep the promise to close FDsWe would want to be able to distinguish between a workaround for a compiler that is not clever/careful enough, and a necessary initialization. In this particular case, it is the former, and we should say
int failed_errno = failed_errno;
instead.
The potentially uninitialized use your compiler is worried about is inside if (cmd->pid < 0) after #ifdef/#else/#endif.
(1) if not on MINGW32, we would have already assigned to failed_errno
after fork() returns negative value to cmd->pid; (2) if on MINGW32, we would have assigned to failed_errno unconditionally
after calling mingw_spawnvpe().so its worry is unfounded.