Skip to content

Commit 75e700a

Browse files
committed
Check for errno explicitly on Windows which can be set if the command
interpreter was not found. Otherwise, check for the WEXITSTATUS and WTERMSIG macros which are only defined on POSIX-compliant systems. In all other cases, prefer failing at compile-time rather than using the value returned by the call to system().
1 parent 0071e1c commit 75e700a

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

tools/not.cpp

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,16 +67,24 @@ int main(int argc, const char **argv) {
6767
if (expectCrash && result == 3) {
6868
retcode = 3;
6969
signal = 1;
70+
} else if (errno) {
71+
// If the command interpreter was not found, errno will be set and 0 will
72+
// be returned. It is unlikely that this will happen in our use case, but
73+
// check anyway.
74+
retcode = 1;
75+
signal = 1;
7076
} else {
7177
// On Windows, result is the exit code, except for the special case above.
7278
retcode = result;
7379
signal = 0;
7480
}
75-
#else
76-
// On POSIX systems, result is a composite value of the exit code and,
77-
// potentially, the signal that caused termination of the command.
81+
#elif defined(WEXITSTATUS) && defined(WTERMSIG)
82+
// On POSIX systems and Solaris, result is a composite value of the exit code
83+
// and, potentially, the signal that caused termination of the command.
7884
retcode = WEXITSTATUS(result);
7985
signal = WTERMSIG(result);
86+
#else
87+
#error "Unsupported system"
8088
#endif
8189

8290
// If signal is non-zero, the command caused a crash, usually SIGABRT.

0 commit comments

Comments
 (0)