From b0c7231f53d33ed5559ef886b520a509a6893289 Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Sat, 16 Jul 2011 02:51:48 +0200 Subject: [PATCH] ffsl, ffsll: Avoid unportable behaviour. * lib/ffsl.h (FUNC): Use 'unsigned int' instead of 'int'. --- ChangeLog | 5 +++++ lib/ffsl.h | 8 ++++---- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/ChangeLog b/ChangeLog index 9ee9bea80..e97313b66 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,10 @@ 2011-07-15 Bruno Haible + ffsl, ffsll: Avoid unportable behaviour. + * lib/ffsl.h (FUNC): Use 'unsigned int' instead of 'int'. + +2011-07-15 Bruno Haible + ffs: More tests. * tests/test-ffs.c (NBITS): New macro. (main): Add more tests. diff --git a/lib/ffsl.h b/lib/ffsl.h index 673b0aa2b..eb7fead56 100644 --- a/lib/ffsl.h +++ b/lib/ffsl.h @@ -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); } } -- 2.11.0