Skip to content

Commit 28a24a4

Browse files
authored
Merge pull request #3637 from martin-frbg/issue3636
Add fallback value for bogus sc_nprocessors_conf in getarch
2 parents 771dc6a + 14ae22b commit 28a24a4

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

getarch.c

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1693,17 +1693,20 @@ USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
16931693

16941694
static int get_num_cores(void) {
16951695

1696+
int count;
16961697
#ifdef OS_WINDOWS
16971698
SYSTEM_INFO sysinfo;
16981699
#elif defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__) || defined(__DragonFly__) || defined(__APPLE__)
1699-
int m[2], count;
1700+
int m[2];
17001701
size_t len;
17011702
#endif
17021703

17031704
#if defined(linux) || defined(__sun__)
17041705
//returns the number of processors which are currently online
1705-
return sysconf(_SC_NPROCESSORS_CONF);
1706-
1706+
count = sysconf(_SC_NPROCESSORS_CONF);
1707+
if (count <= 0) count = 2;
1708+
return count;
1709+
17071710
#elif defined(OS_WINDOWS)
17081711

17091712
GetSystemInfo(&sysinfo);
@@ -1714,13 +1717,15 @@ static int get_num_cores(void) {
17141717
m[1] = HW_NCPU;
17151718
len = sizeof(int);
17161719
sysctl(m, 2, &count, &len, NULL, 0);
1717-
1720+
if (count <= 0) count = 2;
1721+
17181722
return count;
17191723

17201724
#elif defined(AIX)
17211725
//returns the number of processors which are currently online
1722-
return sysconf(_SC_NPROCESSORS_ONLN);
1723-
1726+
count = sysconf(_SC_NPROCESSORS_ONLN);
1727+
if (count <= 0) count = 2;
1728+
17241729
#else
17251730
return 2;
17261731
#endif

0 commit comments

Comments
 (0)