diff options
author | Michael Brown | 2007-09-16 18:39:29 +0200 |
---|---|---|
committer | Michael Brown | 2007-09-21 02:14:44 +0200 |
commit | 7e3527a65831b9dc6d6f370f393a437b7caa2524 (patch) | |
tree | 7cbd35af1a684b4f7e5f918576beab95949ed35f /src/core/bitops.c | |
parent | Add fls() for non-constant values. (diff) | |
download | ipxe-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.c | 9 |
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; } |