summaryrefslogtreecommitdiffstats
path: root/src/core/bitops.c
diff options
context:
space:
mode:
authorMichael Brown2007-09-16 18:39:29 +0200
committerMichael Brown2007-09-21 02:14:44 +0200
commit7e3527a65831b9dc6d6f370f393a437b7caa2524 (patch)
tree7cbd35af1a684b4f7e5f918576beab95949ed35f /src/core/bitops.c
parentAdd fls() for non-constant values. (diff)
downloadipxe-7e3527a65831b9dc6d6f370f393a437b7caa2524.tar.gz
ipxe-7e3527a65831b9dc6d6f370f393a437b7caa2524.tar.xz
ipxe-7e3527a65831b9dc6d6f370f393a437b7caa2524.zip
Don't get stuck in an infinite loop on negative integers!
Diffstat (limited to 'src/core/bitops.c')
-rw-r--r--src/core/bitops.c9
1 files changed, 5 insertions, 4 deletions
diff --git a/src/core/bitops.c b/src/core/bitops.c
index 75d57bf9..53abaaea 100644
--- a/src/core/bitops.c
+++ b/src/core/bitops.c
@@ -1,10 +1,11 @@
#include <strings.h>
int __flsl ( long x ) {
- int r = 0;
+ unsigned long value = x;
+ int ls = 0;
- for ( r = 0 ; x ; r++ ) {
- x >>= 1;
+ for ( ls = 0 ; value ; ls++ ) {
+ value >>= 1;
}
- return r;
+ return ls;
}