Skip to content

Commit

Permalink
Check the returns of WIFSIGNALED and WIFEXITED (llvm#144)
Browse files Browse the repository at this point in the history
Need to check WIFSIGNALED and WIFEXTED before using the return values of WTERMSIG and WEXITSTATUS respectively to update variables
  • Loading branch information
kkwli authored Jul 23, 2024
1 parent a73e05c commit 6afc89e
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions tools/not.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,14 @@ int main(int argc, char* const* argv) {
retcode = result;
signal = 0;
}
#elif defined(WEXITSTATUS) && defined(WTERMSIG)
#elif defined(WIFEXITED) && defined(WEXITSTATUS) && defined(WIFSIGNALED) && \
defined(WTERMSIG)
// On POSIX systems and Solaris, result is a composite value of the exit code
// and, potentially, the signal that caused termination of the command.
retcode = WEXITSTATUS(result);
signal = WTERMSIG(result);
if (WIFEXITED(result))
retcode = WEXITSTATUS(result);
if (WIFSIGNALED(result))
signal = WTERMSIG(result);
#else
#error "Unsupported system"
#endif
Expand Down

0 comments on commit 6afc89e

Please sign in to comment.