Belt and suspenders when calling sysconf
llvm-svn: 174642
Cr-Mirrored-From: sso://chromium.googlesource.com/_direct/external/github.com/llvm/llvm-project
Cr-Mirrored-Commit: 0749262a1148a73d110885602b4d9e9017a3f04d
diff --git a/src/thread.cpp b/src/thread.cpp
index 184d81e..447eca7 100644
--- a/src/thread.cpp
+++ b/src/thread.cpp
@@ -69,7 +69,9 @@
long result = sysconf(_SC_NPROCESSORS_ONLN);
// sysconf returns -1 if the name is invalid, the option does not exist or
// does not have a definite limit.
- if (result == -1)
+ // if sysconf returns some other negative number, we have no idea
+ // what is going on. Default to something safe.
+ if (result < 0)
return 0;
return static_cast<unsigned>(result);
#else // defined(CTL_HW) && defined(HW_NCPU)