[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: timeout.c warning about returning undefined value
From: |
Pádraig Brady |
Subject: |
Re: timeout.c warning about returning undefined value |
Date: |
Mon, 31 Aug 2009 17:05:28 +0100 |
User-agent: |
Thunderbird 2.0.0.6 (X11/20071008) |
Jim Meyering wrote:
> Hi Pádraig,
>
> clang reports this:
>
> timeout.c:330:9: warning: Uninitialized or undefined value returned to
> caller.
> return status;
> ^
>
> Even if it really can't happen (which the comment suggests), please
> initialize "status" or ensure that we get a diagnostic and exit nonzero
> if/when wait ever fails.
I'll check something like this in later when I've a chance to test.
diff --git a/src/timeout.c b/src/timeout.c
index 20efddd..c47069c 100644
--- a/src/timeout.c
+++ b/src/timeout.c
@@ -317,12 +317,18 @@ main (int argc, char **argv)
child exits, not on this process receiving a signal. Also we're not
passing WUNTRACED | WCONTINUED to a waitpid() call and so will not get
indication that the child has stopped or continued. */
- wait (&status);
-
- if (WIFEXITED (status))
- status = WEXITSTATUS (status);
- else if (WIFSIGNALED (status))
- status = WTERMSIG (status) + 128; /* what sh does at least. */
+ if (wait (&status) == -1)
+ {
+ error (0, errno, _("error waiting for command"));
+ status = EXIT_CANCELED;
+ }
+ else
+ {
+ if (WIFEXITED (status))
+ status = WEXITSTATUS (status);
+ else if (WIFSIGNALED (status))
+ status = WTERMSIG (status) + 128; /* what sh does at least. */
+ }
if (timed_out)
return EXIT_TIMEDOUT;