[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)
{
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);
}

View File

@@ -34,6 +34,8 @@
#include <uwac/config.h>
#include <winpr/cast.h>
#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;
}