8000 Fix several mistakes discovered by clang scan-build by jepler · Pull Request #7407 · adafruit/circuitpython · GitHub
[go: up one dir, main page]

Skip to content

Fix several mistakes discovered by clang scan-build #7407

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jan 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion py/objtype.c
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,9 @@ STATIC mp_obj_t native_base_init_wrapper(size_t n_args, const mp_obj_t *pos_args
// copy in args
memcpy(args2, pos_args, n_args * sizeof(mp_obj_t));
// copy in kwargs
memcpy(args2 + n_args, kw_args->table, 2 * n_kw * sizeof(mp_obj_t));
if (n_kw) {
memcpy(args2 + n_args, kw_args->table, 2 * n_kw * sizeof(mp_obj_t));
}
self->subobj[0] = native_base->make_new(native_base, n_args, n_kw, args2);
m_del(mp_obj_t, args2, n_args + 2 * n_kw);

Expand Down
2 changes: 1 addition & 1 deletion shared-module/bitmaptools/__init__.c
Original file line number Diff line number Diff line change
Expand Up @@ -689,7 +689,7 @@ STATIC void fill_row(displayio_bitmap_t *bitmap, int swap, int16_t *luminance_da
static void write_pixels(displayio_bitmap_t *bitmap, int y, bool *data) {
if (bitmap->bits_per_value == 1) {
uint32_t *pixel_data = (uint32_t *)(bitmap->data + bitmap->stride * y);
for (int i = 0; i < bitmap->stride; i++) {
for (int i = 0; i < bitmap->width; i++) {
uint32_t p = 0;
for (int j = 0; j < 32; j++) {
p = (p << 1);
Expand Down
10 changes: 5 additions & 5 deletions shared-module/displayio/Bitmap.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@

#include "py/runtime.h"

enum { align_bits = 8 * sizeof(uint32_t) };
enum { ALIGN_BITS = 8 * sizeof(uint32_t) };

static int stride(uint32_t width, uint32_t bits_per_value) {
uint32_t row_width = width * bits_per_value;
// align to uint32_t
return (row_width + align_bits - 1) / align_bits;
return (row_width + ALIGN_BITS - 1) / ALIGN_BITS;
}

void common_hal_displayio_bitmap_construct(displayio_bitmap_t *self, uint32_t width,
Expand Down Expand Up @@ -66,12 +66,12 @@ void common_hal_displayio_bitmap_construct_from_buffer(displayio_bitmap_t *self,
self->x_shift = 0; // Used to divide the index by the number of pixels per word. Its used in a
// shift which effectively divides by 2 ** x_shift.
uint32_t power_of_two = 1;
while (power_of_two < align_bits / bits_per_value) {
while (power_of_two < ALIGN_BITS / bits_per_value) {
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;
Expand Down
0