[libdispatch-dev] [PATCH] bug fix for invalid comparison with unsigned value < 0
Joakim Johansson
jocke at tbricks.com
Sat May 28 05:23:23 PDT 2011
The comparison "_dispatch_hw_config.cc_max_active < 0” is of an unsigned value and thus never true, the attached patch uses and checks failure of sysconf() properly instead.
Cheers,
Joakim
Index: src/queue.c
===================================================================
--- src/queue.c (revision 197)
+++ src/queue.c (working copy)
@@ -474,12 +474,13 @@
_dispatch_hw_config.cc_max_physical =
_dispatch_hw_config.cc_max_active;
#elif HAVE_SYSCONF && defined(_SC_NPROCESSORS_ONLN)
- _dispatch_hw_config.cc_max_active = (int)sysconf(_SC_NPROCESSORS_ONLN);
- if (_dispatch_hw_config.cc_max_active < 0)
- _dispatch_hw_config.cc_max_active = 1;
+ int ret;
+
+ ret = (int)sysconf(_SC_NPROCESSORS_ONLN);
+
_dispatch_hw_config.cc_max_logical =
_dispatch_hw_config.cc_max_physical =
- _dispatch_hw_config.cc_max_active;
+ _dispatch_hw_config.cc_max_active = (ret < 0) ? 1 : ret;
#else
#warning "_dispatch_queue_set_width_init: no supported way to query CPU count"
_dispatch_hw_config.cc_max_logical =
More information about the libdispatch-dev
mailing list