Skip to content

Commit 6afc89e

Browse files
authored
Check the returns of WIFSIGNALED and WIFEXITED (#144)
Need to check WIFSIGNALED and WIFEXTED before using the return values of WTERMSIG and WEXITSTATUS respectively to update variables
1 parent a73e05c commit 6afc89e

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

tools/not.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,11 +92,14 @@ int main(int argc, char* const* argv) {
9292
retcode = result;
9393
signal = 0;
9494
}
95-
#elif defined(WEXITSTATUS) && defined(WTERMSIG)
95+
#elif defined(WIFEXITED) && defined(WEXITSTATUS) && defined(WIFSIGNALED) && \
96+
defined(WTERMSIG)
9697
// On POSIX systems and Solaris, result is a composite value of the exit code
9798
// and, potentially, the signal that caused termination of the command.
98-
retcode = WEXITSTATUS(result);
99-
signal = WTERMSIG(result);
99+
if (WIFEXITED(result))
100+
retcode = WEXITSTATUS(result);
101+
if (WIFSIGNALED(result))
102+
signal = WTERMSIG(result);
100103
#else
101104
#error "Unsupported system"
102105
#endif

0 commit comments

Comments
 (0)