os/os.h: Improve cpus_configured()
authorBart Van Assche <bvanassche@acm.org>
Sun, 13 Nov 2022 23:10:10 +0000 (15:10 -0800)
committerBart Van Assche <bvanassche@acm.org>
Sun, 13 Nov 2022 23:19:56 +0000 (15:19 -0800)
Fix the following Coverity complaint:

1. negative_return: Calling sysconf, which might return a negative value.
2. return_negative_fn: Returning the return value of sysconf, which might be negative.

Signed-off-by: Bart Van Assche <bvanassche@acm.org>
os/os.h

diff --git a/os/os.h b/os/os.h
index a6fde1fd27f6cab60020b4eb71af1ebe4363a7ff..c428260ca4b80132da47f4ab26f84d21dd3409f6 100644 (file)
--- a/os/os.h
+++ b/os/os.h
@@ -355,7 +355,9 @@ static inline unsigned long long get_fs_free_size(const char *path)
 #ifndef FIO_HAVE_CPU_CONF_SYSCONF
 static inline unsigned int cpus_configured(void)
 {
-       return sysconf(_SC_NPROCESSORS_CONF);
+       int nr_cpus = sysconf(_SC_NPROCESSORS_CONF);
+
+       return nr_cpus >= 1 ? nr_cpus : 1;
 }
 #endif