Skip to content

Commit d2361ae

Browse files
committed
Avoid an undefined shift
(1 << 32), an operation on a signed 32-bit int, is undefined in C. The operation on the unsigned int (1u<<32) is defined as zero, which is the desired outcome (subtracting 1 yields the value with all bits set) This problem was detected by clang scan-build static analysis
1 parent dc363e5 commit d2361ae

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

shared-module/displayio/Bitmap.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,8 @@ void common_hal_displayio_bitmap_construct_from_buffer(displayio_bitmap_t *self,
7070
self->x_shift++;
7171
power_of_two <<= 1;
7272
}
73-
self->x_mask = (1 << self->x_shift) - 1; // Used as a modulus on the x value
74-
self->bitmask = (1 << bits_per_value) - 1;
73+
self->x_mask = (1u << self->x_shift) - 1u; // Used as a modulus on the x value
74+
self->bitmask = (1u << bits_per_value) - 1u;
7575

7676
self->dirty_area.x1 = 0;
7777
self->dirty_area.x2 = width;

0 commit comments

Comments
 (0)