idmap: use UL for bitshift literals
PATCH 1/1 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.
--- src/idmap.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
src/idmap.c +4 -4
@@ -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; }
Signature · 1 line
1.9.0
Hi Tony,
Quoted 8 lines · Tony Espy
The current bitshift logic in idmap incorrectly uses the literal 1 for the value to shift in
idmap_alloc(),idmap_take(), andidmap_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.
Quoted 4 lines
--- src/idmap.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
Good catch. Patch has been applied, thanks.
Regards,
-Denis
Quoted 16 lines · Denis Kenzior
Hi Tony,
Quoted 8 lines · Tony Espy
The current bitshift logic in idmap incorrectly uses the literal 1 for the value to shift in
idmap_alloc(),idmap_take(), andidmap_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.Quoted 4 lines
--- src/idmap.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
Quoted 1 line
Good catch. Patch has been applied, thanks.
Denis -
One of my co-workers recently sent a couple of patches that add Python3 support to the ofono test scripts, however he's not currently subscribed to the mailing list so they emails appear to be in limbo...
Can someone clear these as a list moderator, or should I go ahead and re-send them myself?
Regards,
/tony
Hi Tony,
Quoted 10 lines
Denis -
One of my co-workers recently sent a couple of patches that add Python3 support to the ofono test scripts, however he's not currently subscribed to the mailing list so they emails appear to be in limbo...
Can someone clear these as a list moderator, or should I go ahead and re-send them myself?
I'm too lazy to moderate the list as there's too much spam. Easiest would be for someone subscribed to re-send the patches.
Thanks,
-Denis