[uwac] fix integer cast warnings

This commit is contained in:
akallabeth
2024-12-19 11:22:08 +01:00
parent 411c3b4e06
commit e061c02747
2 changed files with 24 additions and 21 deletions

View File

@@ -42,18 +42,16 @@
static struct wl_buffer* create_pointer_buffer(UwacSeat* seat, const void* src, size_t size) static struct wl_buffer* create_pointer_buffer(UwacSeat* seat, const void* src, size_t size)
{ {
struct wl_buffer* buffer = NULL; struct wl_buffer* buffer = NULL;
int fd = 0;
void* data = NULL;
struct wl_shm_pool* pool = NULL; struct wl_shm_pool* pool = NULL;
assert(seat); 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) if (fd < 0)
return buffer; 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) if (data == MAP_FAILED)
{ {
@@ -69,9 +67,10 @@ static struct wl_buffer* create_pointer_buffer(UwacSeat* seat, const void* src,
goto error_mmap; goto error_mmap;
} }
buffer = buffer = wl_shm_pool_create_buffer(
wl_shm_pool_create_buffer(pool, 0, seat->pointer_image->width, seat->pointer_image->height, pool, 0, WINPR_ASSERTING_INT_CAST(int32_t, seat->pointer_image->width),
seat->pointer_image->width * 4, WL_SHM_FORMAT_ARGB8888); 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); wl_shm_pool_destroy(pool);
if (munmap(data, size) < 0) if (munmap(data, size) < 0)
@@ -121,8 +120,8 @@ static UwacReturnCode set_cursor_image(UwacSeat* seat, uint32_t serial)
return UWAC_ERROR_INTERNAL; return UWAC_ERROR_INTERNAL;
surface = seat->pointer_surface; surface = seat->pointer_surface;
x = image->hotspot_x / scale; x = WINPR_ASSERTING_INT_CAST(int32_t, image->hotspot_x / scale);
y = image->hotspot_y / scale; y = WINPR_ASSERTING_INT_CAST(int32_t, image->hotspot_y / scale);
break; break;
case 1: /* NULL pointer */ case 1: /* NULL pointer */
break; break;
@@ -133,8 +132,8 @@ static UwacReturnCode set_cursor_image(UwacSeat* seat, uint32_t serial)
image = cursor->images[0]; image = cursor->images[0];
if (!image) if (!image)
return UWAC_ERROR_INTERNAL; return UWAC_ERROR_INTERNAL;
x = image->hotspot_x; x = WINPR_ASSERTING_INT_CAST(int32_t, image->hotspot_x);
y = image->hotspot_y; y = WINPR_ASSERTING_INT_CAST(int32_t, image->hotspot_y);
buffer = wl_cursor_image_get_buffer(image); buffer = wl_cursor_image_get_buffer(image);
if (!buffer) if (!buffer)
return UWAC_ERROR_INTERNAL; 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_set_buffer_scale(surface, scale);
wl_surface_attach(surface, buffer, 0, 0); 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); wl_surface_commit(surface);
} }

View File

@@ -34,6 +34,8 @@
#include <uwac/config.h> #include <uwac/config.h>
#include <winpr/cast.h>
#define UWAC_INITIAL_BUFFERS 3ull #define UWAC_INITIAL_BUFFERS 3ull
static int bppFromShmFormat(enum wl_shm_format format) 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) if (allocbuffersize > INT32_MAX)
return UWAC_ERROR_NOMEMORY; 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) if (fd < 0)
{ {
@@ -424,7 +426,7 @@ static UwacBuffer* UwacWindowFindFreeBuffer(UwacWindow* w, ssize_t* index)
{ {
w->buffers[i].used = true; w->buffers[i].used = true;
if (index) if (index)
*index = i; *index = WINPR_ASSERTING_INT_CAST(ssize_t, i);
return &w->buffers[i]; return &w->buffers[i];
} }
} }
@@ -440,7 +442,7 @@ static UwacBuffer* UwacWindowFindFreeBuffer(UwacWindow* w, ssize_t* index)
w->buffers[i].used = true; w->buffers[i].used = true;
if (index) if (index)
*index = i; *index = WINPR_ASSERTING_INT_CAST(ssize_t, i);
return &w->buffers[i]; return &w->buffers[i];
} }
@@ -482,7 +484,6 @@ UwacWindow* UwacCreateWindowShm(UwacDisplay* display, uint32_t width, uint32_t h
enum wl_shm_format format) enum wl_shm_format format)
{ {
UwacWindow* w = NULL; UwacWindow* w = NULL;
int allocSize = 0;
int ret = 0; int ret = 0;
if (!display) if (!display)
@@ -500,10 +501,10 @@ UwacWindow* UwacCreateWindowShm(UwacDisplay* display, uint32_t width, uint32_t h
w->display = display; w->display = display;
w->format = format; w->format = format;
w->width = width; w->width = WINPR_ASSERTING_INT_CAST(int32_t, width);
w->height = height; w->height = WINPR_ASSERTING_INT_CAST(int32_t, height);
w->stride = width * bppFromShmFormat(format); w->stride = WINPR_ASSERTING_INT_CAST(int32_t, width* bppFromShmFormat(format));
allocSize = w->stride * height; const size_t allocSize = 1ULL * w->stride * height;
ret = UwacWindowShmAllocBuffers(w, UWAC_INITIAL_BUFFERS, allocSize, width, height, format); ret = UwacWindowShmAllocBuffers(w, UWAC_INITIAL_BUFFERS, allocSize, width, height, format);
if (ret != UWAC_SUCCESS) if (ret != UWAC_SUCCESS)
@@ -662,7 +663,9 @@ UwacReturnCode UwacWindowSetOpaqueRegion(UwacWindow* window, uint32_t x, uint32_
if (!window->opaque_region) if (!window->opaque_region)
return UWAC_ERROR_NOMEMORY; 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); wl_surface_set_opaque_region(window->surface, window->opaque_region);
return UWAC_SUCCESS; return UWAC_SUCCESS;
} }