btrfs-progs: image: fix bogus check after cpu on-line detection
authorDavid Sterba <dsterba@suse.com>
Fri, 30 Oct 2015 14:34:55 +0000 (15:34 +0100)
committerDavid Sterba <dsterba@suse.com>
Mon, 2 Nov 2015 14:10:14 +0000 (15:10 +0100)
Comparing unsigned type for <= 0 does not make much sense, we should
really check the signed value returned by sysconf.

Resolves-coverity-id: 1324536
Signed-off-by: David Sterba <dsterba@suse.com>
btrfs-image.c

index 20396ef..d1d3d07 100644 (file)
@@ -2787,9 +2787,11 @@ int main(int argc, char *argv[])
 
        if (compress_level > 0 || create == 0) {
                if (num_threads == 0) {
-                       num_threads = sysconf(_SC_NPROCESSORS_ONLN);
-                       if (num_threads <= 0)
-                               num_threads = 1;
+                       long tmp = sysconf(_SC_NPROCESSORS_ONLN);
+
+                       if (tmp <= 0)
+                               tmp = 1;
+                       num_threads = tmp;
                }
        } else {
                num_threads = 0;