[Drbd-dev] left shift of negative value in dcbp_set_pad_bits()
David Butterfield
dab21774 at gmail.com
Mon Jul 8 20:09:50 CEST 2019
This fixes a C undefined-behavior runtime error encountered by libubsan after gcc -fsanitize=undefined:
left shift of negative value in dcbp_set_pad_bits()
I mentioned this one before, but in the context of a boring compiler warning.
The runtime undefined-behavior may make it more interesting.
diff --git a/drbd/drbd_main.c b/drbd/drbd_main.c
index 062c5ca1..16b4f02d 100644
--- a/drbd/drbd_main.c
+++ b/drbd/drbd_main.c
@@ -1832,7 +1840,7 @@ static void dcbp_set_start(struct p_compressed_bm *p, int set)
static void dcbp_set_pad_bits(struct p_compressed_bm *p, int n)
{
BUG_ON(n & ~0x7);
- p->encoding = (p->encoding & (~0x7 << 4)) | (n << 4);
+ p->encoding = (p->encoding & (~0x7u << 4)) | (n << 4);
}
static int fill_bitmap_rle_bits(struct drbd_peer_device *peer_device,
More information about the drbd-dev
mailing list