summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorTony Espy <espy@canonical.com>2014-03-04 19:01:34 -0500
committerDenis Kenzior <denkenz@gmail.com>2014-03-05 08:49:50 -0600
commit201d34b0a11b1c12034f5de3e4da3cfd667ceeae (patch)
treee73dd77805e6acb074a079df712d0d11e0f3a7bc /src
parent76a7f9014d4d59228a55d2d885e7002d8b36b76d (diff)
downloadofono-201d34b0a11b1c12034f5de3e4da3cfd667ceeae.tar.bz2
idmap: use UL for bitshift literals
The current bitshift logic in idmap incorrectly uses the literal 1 for the value to shift in idmap_alloc(), idmap_take(), and idmap_alloc_next(). This causes the resulting value to be an int instead of a long, which results in the wrong bit being set once the number of bits to shift operand exceeds sizeof(int). Also on some platforms, the behavior of the left bitshift operator is undefined when this overflow occurs.
Diffstat (limited to 'src')
-rw-r--r--src/idmap.c8
1 files changed, 4 insertions, 4 deletions
diff --git a/src/idmap.c b/src/idmap.c
index 63f5c7c4..c097eb4b 100644
--- a/src/idmap.c
+++ b/src/idmap.c
@@ -135,7 +135,7 @@ void idmap_put(struct idmap *idmap, unsigned int id)
id %= BITS_PER_LONG;
- idmap->bits[offset] &= ~(1 << id);
+ idmap->bits[offset] &= ~(1UL << id);
}
unsigned int idmap_alloc(struct idmap *idmap)
@@ -149,7 +149,7 @@ unsigned int idmap_alloc(struct idmap *idmap)
return idmap->max + 1;
offset = bit / BITS_PER_LONG;
- idmap->bits[offset] |= 1 << (bit % BITS_PER_LONG);
+ idmap->bits[offset] |= 1UL << (bit % BITS_PER_LONG);
return bit + idmap->min;
}
@@ -163,7 +163,7 @@ void idmap_take(struct idmap *idmap, unsigned int id)
return;
offset = bit / BITS_PER_LONG;
- idmap->bits[offset] |= 1 << (bit % BITS_PER_LONG);
+ idmap->bits[offset] |= 1UL << (bit % BITS_PER_LONG);
}
/*
@@ -186,7 +186,7 @@ unsigned int idmap_alloc_next(struct idmap *idmap, unsigned int last)
return idmap_alloc(idmap);
offset = bit / BITS_PER_LONG;
- idmap->bits[offset] |= 1 << (bit % BITS_PER_LONG);
+ idmap->bits[offset] |= 1UL << (bit % BITS_PER_LONG);
return bit + idmap->min;
}