From fb8a3e4f6cf815a5108cbf31629bc9ed4abc828f Mon Sep 17 00:00:00 2001 From: Mirko Bonadei Date: Mon, 3 Jan 2022 16:02:19 +0100 Subject: [PATCH] Stricter sysconf(_SC_NPROCESSORS_ONLN) output check. While the output should never be 0, in case it is, DetectNumberOfCores() can crash because of an RTC_CHECK. Let's fall back on the default value of 1 instead. Bug: chromium:1282179 Change-Id: Ice083bff4222bbe7e92d789293a7c7b01b7fbd5d Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/244088 Reviewed-by: Niels Moller Commit-Queue: Mirko Bonadei Cr-Commit-Position: refs/heads/main@{#35614} --- system_wrappers/source/cpu_info.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/system_wrappers/source/cpu_info.cc b/system_wrappers/source/cpu_info.cc index 7288c67efd..eff720371a 100644 --- a/system_wrappers/source/cpu_info.cc +++ b/system_wrappers/source/cpu_info.cc @@ -32,7 +32,7 @@ static int DetectNumberOfCores() { number_of_cores = static_cast(si.dwNumberOfProcessors); #elif defined(WEBRTC_LINUX) || defined(WEBRTC_ANDROID) number_of_cores = static_cast(sysconf(_SC_NPROCESSORS_ONLN)); - if (number_of_cores < 0) { + if (number_of_cores <= 0) { RTC_LOG(LS_ERROR) << "Failed to get number of cores"; number_of_cores = 1; }