[ccan] [PATCH] bitmap: use unsigned int for iterating over bitmap words

Emilio G. Cota cota at braap.org
Tue Mar 11 02:04:50 EST 2014


From: "Emilio G. Cota" <cota at braap.org>

Bitmap words (e.g. resulting from BITMAP_{N,HEAD}WORDS) are of
unsigned type.

Use "unsigned int" to iterate over bitmap words to avoid comparisons
between signed and unsigned expressions. GCC otherwise warns about
these when -Wsign-compare is enabled.

Signed-off-by: Emilio G. Cota <cota at braap.org>
---
 ccan/bitmap/bitmap.h | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/ccan/bitmap/bitmap.h b/ccan/bitmap/bitmap.h
index 50086c0..2be18f3 100644
--- a/ccan/bitmap/bitmap.h
+++ b/ccan/bitmap/bitmap.h
@@ -100,7 +100,7 @@ static inline void bitmap_copy(bitmap *dst, bitmap *src, int nbits)
 	static inline void bitmap_##_name(bitmap *dst, bitmap *src1, bitmap *src2, \
 					 int nbits) \
 	{ \
-		int i = 0; \
+		unsigned int i = 0; \
 		for (i = 0; i < BITMAP_NWORDS(nbits); i++) { \
 			dst[i].w = src1[i].w _op src2[i].w; \
 		} \
@@ -115,7 +115,7 @@ BITMAP_DEF_BINOP(andnot, & ~)
 
 static inline void bitmap_complement(bitmap *dst, bitmap *src, int nbits)
 {
-	int i;
+	unsigned int i;
 
 	for (i = 0; i < BITMAP_NWORDS(nbits); i++)
 		dst[i].w = ~src[i].w;
@@ -130,7 +130,7 @@ static inline bool bitmap_equal(bitmap *src1, bitmap *src2, int nbits)
 
 static inline bool bitmap_intersects(bitmap *src1, bitmap *src2, int nbits)
 {
-	int i;
+	unsigned int i;
 
 	for (i = 0; i < BITMAP_HEADWORDS(nbits); i++) {
 		if (src1[i].w & src2[i].w)
@@ -144,7 +144,7 @@ static inline bool bitmap_intersects(bitmap *src1, bitmap *src2, int nbits)
 
 static inline bool bitmap_subset(bitmap *src1, bitmap *src2, int nbits)
 {
-	int i;
+	unsigned int i;
 
 	for (i = 0; i < BITMAP_HEADWORDS(nbits); i++) {
 		if (src1[i].w  & ~src2[i].w)
@@ -158,7 +158,7 @@ static inline bool bitmap_subset(bitmap *src1, bitmap *src2, int nbits)
 
 static inline bool bitmap_full(bitmap *bitmap, int nbits)
 {
-	int i;
+	unsigned int i;
 
 	for (i = 0; i < BITMAP_HEADWORDS(nbits); i++) {
 		if (bitmap[i].w != -1UL)
@@ -173,7 +173,7 @@ static inline bool bitmap_full(bitmap *bitmap, int nbits)
 
 static inline bool bitmap_empty(bitmap *bitmap, int nbits)
 {
-	int i;
+	unsigned int i;
 
 	for (i = 0; i < BITMAP_HEADWORDS(nbits); i++) {
 		if (bitmap[i].w != 0)
-- 
1.8.3



More information about the ccan mailing list