From e061c02747f036ae4698fb68bb5f81971f8c62f4 Mon Sep 17 00:00:00 2001 From: akallabeth Date: Thu, 19 Dec 2024 11:22:08 +0100 Subject: [PATCH] [uwac] fix integer cast warnings --- uwac/libuwac/uwac-input.c | 24 ++++++++++++------------ uwac/libuwac/uwac-window.c | 21 ++++++++++++--------- 2 files changed, 24 insertions(+), 21 deletions(-) diff --git a/uwac/libuwac/uwac-input.c b/uwac/libuwac/uwac-input.c index d70a2b5a1..aabca14c5 100644 --- a/uwac/libuwac/uwac-input.c +++ b/uwac/libuwac/uwac-input.c @@ -42,18 +42,16 @@ static struct wl_buffer* create_pointer_buffer(UwacSeat* seat, const void* src, size_t size) { struct wl_buffer* buffer = NULL; - int fd = 0; - void* data = NULL; struct wl_shm_pool* pool = NULL; assert(seat); - fd = uwac_create_anonymous_file(size); + const int fd = uwac_create_anonymous_file(WINPR_ASSERTING_INT_CAST(off_t, size)); if (fd < 0) return buffer; - data = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); + void* data = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); if (data == MAP_FAILED) { @@ -69,9 +67,10 @@ static struct wl_buffer* create_pointer_buffer(UwacSeat* seat, const void* src, goto error_mmap; } - buffer = - wl_shm_pool_create_buffer(pool, 0, seat->pointer_image->width, seat->pointer_image->height, - seat->pointer_image->width * 4, WL_SHM_FORMAT_ARGB8888); + buffer = wl_shm_pool_create_buffer( + pool, 0, WINPR_ASSERTING_INT_CAST(int32_t, seat->pointer_image->width), + WINPR_ASSERTING_INT_CAST(int32_t, seat->pointer_image->height), + WINPR_ASSERTING_INT_CAST(int32_t, seat->pointer_image->width * 4), WL_SHM_FORMAT_ARGB8888); wl_shm_pool_destroy(pool); if (munmap(data, size) < 0) @@ -121,8 +120,8 @@ static UwacReturnCode set_cursor_image(UwacSeat* seat, uint32_t serial) return UWAC_ERROR_INTERNAL; surface = seat->pointer_surface; - x = image->hotspot_x / scale; - y = image->hotspot_y / scale; + x = WINPR_ASSERTING_INT_CAST(int32_t, image->hotspot_x / scale); + y = WINPR_ASSERTING_INT_CAST(int32_t, image->hotspot_y / scale); break; case 1: /* NULL pointer */ break; @@ -133,8 +132,8 @@ static UwacReturnCode set_cursor_image(UwacSeat* seat, uint32_t serial) image = cursor->images[0]; if (!image) return UWAC_ERROR_INTERNAL; - x = image->hotspot_x; - y = image->hotspot_y; + x = WINPR_ASSERTING_INT_CAST(int32_t, image->hotspot_x); + y = WINPR_ASSERTING_INT_CAST(int32_t, image->hotspot_y); buffer = wl_cursor_image_get_buffer(image); if (!buffer) return UWAC_ERROR_INTERNAL; @@ -146,7 +145,8 @@ static UwacReturnCode set_cursor_image(UwacSeat* seat, uint32_t serial) { wl_surface_set_buffer_scale(surface, scale); wl_surface_attach(surface, buffer, 0, 0); - wl_surface_damage(surface, 0, 0, image->width, image->height); + wl_surface_damage(surface, 0, 0, WINPR_ASSERTING_INT_CAST(int32_t, image->width), + WINPR_ASSERTING_INT_CAST(int32_t, image->height)); wl_surface_commit(surface); } diff --git a/uwac/libuwac/uwac-window.c b/uwac/libuwac/uwac-window.c index 352369d8b..b23d0e067 100644 --- a/uwac/libuwac/uwac-window.c +++ b/uwac/libuwac/uwac-window.c @@ -34,6 +34,8 @@ #include +#include + #define UWAC_INITIAL_BUFFERS 3ull static int bppFromShmFormat(enum wl_shm_format format) @@ -354,7 +356,7 @@ int UwacWindowShmAllocBuffers(UwacWindow* w, uint64_t nbuffers, uint64_t allocSi if (allocbuffersize > INT32_MAX) return UWAC_ERROR_NOMEMORY; - fd = uwac_create_anonymous_file((off_t)allocbuffersize); + fd = uwac_create_anonymous_file(WINPR_ASSERTING_INT_CAST(off_t, allocbuffersize)); if (fd < 0) { @@ -424,7 +426,7 @@ static UwacBuffer* UwacWindowFindFreeBuffer(UwacWindow* w, ssize_t* index) { w->buffers[i].used = true; if (index) - *index = i; + *index = WINPR_ASSERTING_INT_CAST(ssize_t, i); return &w->buffers[i]; } } @@ -440,7 +442,7 @@ static UwacBuffer* UwacWindowFindFreeBuffer(UwacWindow* w, ssize_t* index) w->buffers[i].used = true; if (index) - *index = i; + *index = WINPR_ASSERTING_INT_CAST(ssize_t, i); return &w->buffers[i]; } @@ -482,7 +484,6 @@ UwacWindow* UwacCreateWindowShm(UwacDisplay* display, uint32_t width, uint32_t h enum wl_shm_format format) { UwacWindow* w = NULL; - int allocSize = 0; int ret = 0; if (!display) @@ -500,10 +501,10 @@ UwacWindow* UwacCreateWindowShm(UwacDisplay* display, uint32_t width, uint32_t h w->display = display; w->format = format; - w->width = width; - w->height = height; - w->stride = width * bppFromShmFormat(format); - allocSize = w->stride * height; + w->width = WINPR_ASSERTING_INT_CAST(int32_t, width); + w->height = WINPR_ASSERTING_INT_CAST(int32_t, height); + w->stride = WINPR_ASSERTING_INT_CAST(int32_t, width* bppFromShmFormat(format)); + const size_t allocSize = 1ULL * w->stride * height; ret = UwacWindowShmAllocBuffers(w, UWAC_INITIAL_BUFFERS, allocSize, width, height, format); if (ret != UWAC_SUCCESS) @@ -662,7 +663,9 @@ UwacReturnCode UwacWindowSetOpaqueRegion(UwacWindow* window, uint32_t x, uint32_ if (!window->opaque_region) return UWAC_ERROR_NOMEMORY; - wl_region_add(window->opaque_region, x, y, width, height); + wl_region_add(window->opaque_region, WINPR_ASSERTING_INT_CAST(int32_t, x), + WINPR_ASSERTING_INT_CAST(int32_t, y), WINPR_ASSERTING_INT_CAST(int32_t, width), + WINPR_ASSERTING_INT_CAST(int32_t, height)); wl_surface_set_opaque_region(window->surface, window->opaque_region); return UWAC_SUCCESS; }