ffsl, ffsll: Avoid unportable behaviour.
authorBruno Haible <bruno@clisp.org>
Sat, 16 Jul 2011 00:51:48 +0000 (02:51 +0200)
committerBruno Haible <bruno@clisp.org>
Sat, 16 Jul 2011 00:51:48 +0000 (02:51 +0200)
* lib/ffsl.h (FUNC): Use 'unsigned int' instead of 'int'.

ChangeLog
lib/ffsl.h

index 9ee9bea..e97313b 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,10 @@
 2011-07-15  Bruno Haible  <bruno@clisp.org>
 
+       ffsl, ffsll: Avoid unportable behaviour.
+       * lib/ffsl.h (FUNC): Use 'unsigned int' instead of 'int'.
+
+2011-07-15  Bruno Haible  <bruno@clisp.org>
+
        ffs: More tests.
        * tests/test-ffs.c (NBITS): New macro.
        (main): Add more tests.
index 673b0aa..eb7fead 100644 (file)
@@ -39,9 +39,9 @@ FUNC (TYPE i)
     return 0;
   while (1)
     {
-      if ((int) j)
-        return result + ffs (j);
-      j >>= CHAR_BIT * sizeof (int);
-      result += CHAR_BIT * sizeof (int);
+      if ((unsigned int) j)
+        return result + ffs ((unsigned int) j);
+      j >>= CHAR_BIT * sizeof (unsigned int);
+      result += CHAR_BIT * sizeof (unsigned int);
     }
 }