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
This commit is contained in:
Jeff Epler 2023-01-01 16:39:52 -06:00
parent dc363e5a87
commit d2361ae4f9
No known key found for this signature in database
GPG Key ID: D5BF15AB975AB4DE
1 changed files with 2 additions and 2 deletions

View File

@ -70,8 +70,8 @@ void common_hal_displayio_bitmap_construct_from_buffer(displayio_bitmap_t *self,
self->x_shift++;
power_of_two <<= 1;
}
self->x_mask = (1 << self->x_shift) - 1; // Used as a modulus on the x value
self->bitmask = (1 << bits_per_value) - 1;
self->x_mask = (1u << self->x_shift) - 1u; // Used as a modulus on the x value
self->bitmask = (1u << bits_per_value) - 1u;
self->dirty_area.x1 = 0;
self->dirty_area.x2 = width;