diff options
| author | Michael Brown | 2007-09-16 18:39:29 +0200 |
|---|---|---|
| committer | Michael Brown | 2007-09-16 18:39:29 +0200 |
| commit | 83a6cc8c9bf8972b937a5e57d514da023936466e (patch) | |
| tree | c9076ad971c4a5c7dfd9ac73005ea6bbb15536eb /src/core/bitops.c | |
| parent | Add fls() for non-constant values. (diff) | |
| download | ipxe-83a6cc8c9bf8972b937a5e57d514da023936466e.tar.gz ipxe-83a6cc8c9bf8972b937a5e57d514da023936466e.tar.xz ipxe-83a6cc8c9bf8972b937a5e57d514da023936466e.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 75d57bf99..53abaaeac 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; } |
