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 <nisse@webrtc.org>
Commit-Queue: Mirko Bonadei <mbonadei@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#35614}
This commit is contained in:
Mirko Bonadei 2022-01-03 16:02:19 +01:00 committed by WebRTC LUCI CQ
parent 7336422fe3
commit fb8a3e4f6c

View file

@ -32,7 +32,7 @@ static int DetectNumberOfCores() {
number_of_cores = static_cast<int>(si.dwNumberOfProcessors);
#elif defined(WEBRTC_LINUX) || defined(WEBRTC_ANDROID)
number_of_cores = static_cast<int>(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;
}