[Nagios-checkins] SF.net SVN: nagios:[2097] nagioscore/trunk/lib/lnag-utils.h

ageric at users.sourceforge.net ageric at users.sourceforge.net
Sun Aug 26 20:03:03 UTC 2012


Revision: 2097
          http://nagios.svn.sourceforge.net/nagios/?rev=2097&view=rev
Author:   ageric
Date:     2012-08-26 20:03:03 +0000 (Sun, 26 Aug 2012)
Log Message:
-----------
lib/lnag-utils: Fix ispof2() and rup2pof2()

They weren't cryptic enough before, but with an additional tertiary
statement we get them to be completely illegible for anyone without
an advanced degree in computer science. It also makes them correct,
since we previously claimed that 0 and 1 were prime, and tried to
round up 1 to 1 when rounding to the nearest power of two.

Signed-off-by: Andreas Ericsson <ae at op5.se>

Modified Paths:
--------------
    nagioscore/trunk/lib/lnag-utils.h

Modified: nagioscore/trunk/lib/lnag-utils.h
===================================================================
--- nagioscore/trunk/lib/lnag-utils.h	2012-08-26 20:02:42 UTC (rev 2096)
+++ nagioscore/trunk/lib/lnag-utils.h	2012-08-26 20:03:03 UTC (rev 2097)
@@ -65,7 +65,7 @@
  */
 static inline int lnag_ispof2(unsigned int x)
 {
-	return !(x & (x - 1));
+	return x > 1 ? !(x & (x - 1)) : 0;
 }
 
 #ifdef __GNUC__
@@ -94,7 +94,7 @@
  */
 static inline unsigned int rup2pof2(unsigned int r)
 {
-	return lnag_ispof2(r) ? r : 1 << ((sizeof(r) * 8) - (lnag_clz(r)));
+	return r < 2 ? 4 : lnag_ispof2(r) ? r : 1 << ((sizeof(r) * 8) - (lnag_clz(r)));
 }
 
 NAGIOS_END_DECL

This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.





More information about the Nagios-commits mailing list