[warnings] fix integer casting

* use WINPR_ASSERTING_INT_CAST where possible
* clean up client code
This commit is contained in:
akallabeth
2024-12-19 12:44:51 +01:00
parent 411c3b4e06
commit 6701359cc1
50 changed files with 793 additions and 562 deletions

View File

@@ -19,6 +19,7 @@
*/
#include <winpr/sysinfo.h>
#include <winpr/cast.h>
#include "wlf_disp.h"
@@ -141,14 +142,14 @@ static BOOL wlf_disp_sendResize(wlfDispContext* wlfDisp)
wlfDisp->waitingResize = TRUE;
layout.Flags = DISPLAY_CONTROL_MONITOR_PRIMARY;
layout.Top = layout.Left = 0;
layout.Width = wlfDisp->targetWidth;
layout.Height = wlfDisp->targetHeight;
layout.Width = WINPR_ASSERTING_INT_CAST(uint32_t, wlfDisp->targetWidth);
layout.Height = WINPR_ASSERTING_INT_CAST(uint32_t, wlfDisp->targetHeight);
layout.Orientation = freerdp_settings_get_uint16(settings, FreeRDP_DesktopOrientation);
layout.DesktopScaleFactor =
freerdp_settings_get_uint32(settings, FreeRDP_DesktopScaleFactor);
layout.DeviceScaleFactor = freerdp_settings_get_uint32(settings, FreeRDP_DeviceScaleFactor);
layout.PhysicalWidth = wlfDisp->targetWidth;
layout.PhysicalHeight = wlfDisp->targetHeight;
layout.PhysicalWidth = WINPR_ASSERTING_INT_CAST(uint32_t, wlfDisp->targetWidth);
layout.PhysicalHeight = WINPR_ASSERTING_INT_CAST(uint32_t, wlfDisp->targetHeight);
if (IFCALLRESULT(CHANNEL_RC_OK, wlfDisp->disp->SendMonitorLayout, wlfDisp->disp, 1,
&layout) != CHANNEL_RC_OK)
@@ -261,9 +262,9 @@ wlfDispContext* wlf_disp_new(wlfContext* wlc)
ret->wlc = wlc;
ret->lastSentWidth = ret->targetWidth =
freerdp_settings_get_uint32(settings, FreeRDP_DesktopWidth);
WINPR_ASSERTING_INT_CAST(int, freerdp_settings_get_uint32(settings, FreeRDP_DesktopWidth));
ret->lastSentHeight = ret->targetHeight =
freerdp_settings_get_uint32(settings, FreeRDP_DesktopHeight);
WINPR_ASSERTING_INT_CAST(int, freerdp_settings_get_uint32(settings, FreeRDP_DesktopHeight));
PubSub_SubscribeActivated(pubSub, wlf_disp_OnActivated);
PubSub_SubscribeGraphicsReset(pubSub, wlf_disp_OnGraphicsReset);
PubSub_SubscribeTimer(pubSub, wlf_disp_OnTimer);
@@ -318,8 +319,8 @@ UINT wlf_disp_sendLayout(DispClientContext* disp, const rdpMonitor* monitors, si
layout->Flags = (monitor->is_primary ? DISPLAY_CONTROL_MONITOR_PRIMARY : 0);
layout->Left = monitor->x;
layout->Top = monitor->y;
layout->Width = monitor->width;
layout->Height = monitor->height;
layout->Width = WINPR_ASSERTING_INT_CAST(UINT32, monitor->width);
layout->Height = WINPR_ASSERTING_INT_CAST(UINT32, monitor->height);
layout->Orientation = ORIENTATION_LANDSCAPE;
layout->PhysicalWidth = monitor->attributes.physicalWidth;
layout->PhysicalHeight = monitor->attributes.physicalHeight;
@@ -439,7 +440,8 @@ int wlf_list_monitors(wlfContext* wlc)
for (uint32_t i = 0; i < nmonitors; i++)
{
const UwacOutput* monitor = UwacDisplayGetOutput(wlc->display, i);
const UwacOutput* monitor =
UwacDisplayGetOutput(wlc->display, WINPR_ASSERTING_INT_CAST(int, i));
UwacSize resolution;
UwacPosition pos;

View File

@@ -24,6 +24,7 @@
#include <linux/input.h>
#include <winpr/assert.h>
#include <winpr/cast.h>
#include <freerdp/config.h>
#include <freerdp/locale/keyboard.h>
@@ -72,16 +73,14 @@ BOOL wlf_handle_pointer_enter(freerdp* instance, const UwacPointerEnterLeaveEven
if (!wlf_scale_coordinates(instance->context, &x, &y, TRUE))
return FALSE;
WINPR_ASSERT(x <= UINT16_MAX);
WINPR_ASSERT(y <= UINT16_MAX);
cctx = (rdpClientContext*)instance->context;
return freerdp_client_send_button_event(cctx, FALSE, PTR_FLAGS_MOVE, x, y);
return freerdp_client_send_button_event(cctx, FALSE, PTR_FLAGS_MOVE,
WINPR_ASSERTING_INT_CAST(int, x),
WINPR_ASSERTING_INT_CAST(int, y));
}
BOOL wlf_handle_pointer_motion(freerdp* instance, const UwacPointerMotionEvent* ev)
{
uint32_t x = 0;
uint32_t y = 0;
rdpClientContext* cctx = NULL;
if (!instance || !ev)
@@ -90,15 +89,15 @@ BOOL wlf_handle_pointer_motion(freerdp* instance, const UwacPointerMotionEvent*
cctx = (rdpClientContext*)instance->context;
WINPR_ASSERT(cctx);
x = ev->x;
y = ev->y;
uint32_t x = ev->x;
uint32_t y = ev->y;
if (!wlf_scale_coordinates(instance->context, &x, &y, TRUE))
return FALSE;
WINPR_ASSERT(x <= UINT16_MAX);
WINPR_ASSERT(y <= UINT16_MAX);
return freerdp_client_send_button_event(cctx, FALSE, PTR_FLAGS_MOVE, x, y);
return freerdp_client_send_button_event(cctx, FALSE, PTR_FLAGS_MOVE,
WINPR_ASSERTING_INT_CAST(int32_t, x),
WINPR_ASSERTING_INT_CAST(int32_t, y));
}
BOOL wlf_handle_pointer_buttons(freerdp* instance, const UwacPointerButtonEvent* ev)
@@ -106,8 +105,6 @@ BOOL wlf_handle_pointer_buttons(freerdp* instance, const UwacPointerButtonEvent*
rdpClientContext* cctx = NULL;
UINT16 flags = 0;
UINT16 xflags = 0;
uint32_t x = 0;
uint32_t y = 0;
if (!instance || !ev)
return FALSE;
@@ -115,8 +112,8 @@ BOOL wlf_handle_pointer_buttons(freerdp* instance, const UwacPointerButtonEvent*
cctx = (rdpClientContext*)instance->context;
WINPR_ASSERT(cctx);
x = ev->x;
y = ev->y;
uint32_t x = ev->x;
uint32_t y = ev->y;
if (!wlf_scale_coordinates(instance->context, &x, &y, TRUE))
return FALSE;
@@ -153,14 +150,14 @@ BOOL wlf_handle_pointer_buttons(freerdp* instance, const UwacPointerButtonEvent*
return TRUE;
}
WINPR_ASSERT(x <= UINT16_MAX);
WINPR_ASSERT(y <= UINT16_MAX);
const INT32 cx = WINPR_ASSERTING_INT_CAST(int32_t, x);
const INT32 cy = WINPR_ASSERTING_INT_CAST(int32_t, y);
if ((flags & ~PTR_FLAGS_DOWN) != 0)
return freerdp_client_send_button_event(cctx, FALSE, flags, x, y);
return freerdp_client_send_button_event(cctx, FALSE, flags, cx, cy);
if ((xflags & ~PTR_XFLAGS_DOWN) != 0)
return freerdp_client_send_extended_button_event(cctx, FALSE, xflags, x, y);
return freerdp_client_send_extended_button_event(cctx, FALSE, xflags, cx, cy);
return FALSE;
}
@@ -453,5 +450,6 @@ BOOL wlf_handle_touch_motion(freerdp* instance, const UwacTouchMotion* ev)
if (!scale_signed_coordinates(instance->context, &x, &y, TRUE))
return FALSE;
return freerdp_client_handle_touch(&wlf->common, FREERDP_TOUCH_MOTION, 0, ev->id, x, y);
return freerdp_client_handle_touch(&wlf->common, FREERDP_TOUCH_MOTION, 0,
WINPR_ASSERTING_INT_CAST(uint32_t, ev->id), x, y);
}

View File

@@ -26,6 +26,7 @@
#include <float.h>
#include <winpr/sysinfo.h>
#include <winpr/cast.h>
#include <freerdp/client/cmdline.h>
#include <freerdp/channels/channels.h>
@@ -52,14 +53,10 @@ static BOOL wl_update_buffer(wlfContext* context_w, INT32 ix, INT32 iy, INT32 iw
BOOL res = FALSE;
rdpGdi* gdi = NULL;
char* data = NULL;
UINT32 x = 0;
UINT32 y = 0;
UINT32 w = 0;
UINT32 h = 0;
UwacSize geometry;
UwacSize geometry = { 0 };
size_t stride = 0;
UwacReturnCode rc = UWAC_ERROR_INTERNAL;
RECTANGLE_16 area;
RECTANGLE_16 area = { 0 };
if (!context_w)
return FALSE;
@@ -68,10 +65,10 @@ static BOOL wl_update_buffer(wlfContext* context_w, INT32 ix, INT32 iy, INT32 iw
return FALSE;
EnterCriticalSection(&context_w->critical);
x = (UINT32)ix;
y = (UINT32)iy;
w = (UINT32)iw;
h = (UINT32)ih;
UINT32 x = WINPR_ASSERTING_INT_CAST(UINT16, ix);
UINT32 y = WINPR_ASSERTING_INT_CAST(UINT16, iy);
UINT32 w = WINPR_ASSERTING_INT_CAST(UINT16, iw);
UINT32 h = WINPR_ASSERTING_INT_CAST(UINT16, ih);
rc = UwacWindowGetDrawingBufferGeometry(context_w->window, &geometry, &stride);
data = UwacWindowGetDrawingBuffer(context_w->window);
@@ -90,14 +87,16 @@ static BOOL wl_update_buffer(wlfContext* context_w, INT32 ix, INT32 iy, INT32 iw
goto fail;
}
area.left = x;
area.top = y;
area.right = x + w;
area.bottom = y + h;
area.left = WINPR_ASSERTING_INT_CAST(UINT16, x);
area.top = WINPR_ASSERTING_INT_CAST(UINT16, y);
area.right = WINPR_ASSERTING_INT_CAST(UINT16, x + w);
area.bottom = WINPR_ASSERTING_INT_CAST(UINT16, y + h);
if (!wlf_copy_image(
gdi->primary_buffer, gdi->stride, gdi->width, gdi->height, data, stride, geometry.width,
geometry.height, &area,
gdi->primary_buffer, gdi->stride, WINPR_ASSERTING_INT_CAST(size_t, gdi->width),
WINPR_ASSERTING_INT_CAST(size_t, gdi->height), data, stride,
WINPR_ASSERTING_INT_CAST(size_t, geometry.width),
WINPR_ASSERTING_INT_CAST(size_t, geometry.height), &area,
freerdp_settings_get_bool(context_w->common.context.settings, FreeRDP_SmartSizing)))
goto fail;
@@ -577,7 +576,7 @@ disconnect:
if (timer)
(void)CloseHandle(timer);
freerdp_disconnect(instance);
return status;
return WINPR_ASSERTING_INT_CAST(int, status);
}
static BOOL wlf_client_global_init(void)