[warnings] fix integer casting

* use WINPR_ASSERTING_INT_CAST where possible
 * fix a few inconsistencies
This commit is contained in:
akallabeth
2024-12-19 12:32:40 +01:00
parent 411c3b4e06
commit 26eac974fe
9 changed files with 91 additions and 62 deletions

View File

@@ -26,6 +26,7 @@
#include <winpr/winpr.h>
#include <winpr/crt.h>
#include <winpr/cast.h>
#include <winpr/assert.h>
#include <winpr/ssl.h>
#include <winpr/synch.h>
@@ -404,8 +405,9 @@ static void test_peer_draw_icon(freerdp_peer* client, UINT32 x, UINT32 y)
rect.x = 0;
rect.y = 0;
rect.width = context->image->width;
rect.height = context->image->height;
rect.width = WINPR_ASSERTING_INT_CAST(UINT16, context->image->width);
rect.height = WINPR_ASSERTING_INT_CAST(UINT16, context->image->height);
const UINT32 w = freerdp_settings_get_uint32(settings, FreeRDP_DesktopWidth);
const UINT32 h = freerdp_settings_get_uint32(settings, FreeRDP_DesktopHeight);
@@ -1347,7 +1349,7 @@ static void print_entry(FILE* fp, WINPR_FORMAT_ARG const char* fmt, const char*
}
WINPR_PRAGMA_DIAG_POP
static WINPR_NORETURN(void usage(const char* app, const char* invalid))
static int usage(const char* app, const char* invalid)
{
FILE* fp = stdout;
@@ -1360,7 +1362,7 @@ static WINPR_NORETURN(void usage(const char* app, const char* invalid))
print_entry(fp, "\t%s\n", options.sfast, sizeof(options.sfast));
print_entry(fp, "\t%s<port>\n", options.sport, sizeof(options.sport));
print_entry(fp, "\t%s\n", options.slocal_only, sizeof(options.slocal_only));
exit(-1);
return -1;
}
int main(int argc, char* argv[])
@@ -1392,7 +1394,7 @@ int main(int argc, char* argv[])
port = strtol(sport, NULL, 10);
if ((port < 1) || (port > UINT16_MAX) || (errno != 0))
usage(app, arg);
return usage(app, arg);
}
else if (strncmp(arg, options.slocal_only, sizeof(options.slocal_only)) == 0)
localOnly = TRUE;
@@ -1400,22 +1402,22 @@ int main(int argc, char* argv[])
{
info.test_pcap_file = &arg[sizeof(options.spcap)];
if (!winpr_PathFileExists(info.test_pcap_file))
usage(app, arg);
return usage(app, arg);
}
else if (strncmp(arg, options.scert, sizeof(options.scert)) == 0)
{
info.cert = &arg[sizeof(options.scert)];
if (!winpr_PathFileExists(info.cert))
usage(app, arg);
return usage(app, arg);
}
else if (strncmp(arg, options.skey, sizeof(options.skey)) == 0)
{
info.key = &arg[sizeof(options.skey)];
if (!winpr_PathFileExists(info.key))
usage(app, arg);
return usage(app, arg);
}
else
usage(app, arg);
return usage(app, arg);
}
WTSRegisterWtsApiFunctionTable(FreeRDP_InitWtsApi());

View File

@@ -21,6 +21,7 @@
#include <freerdp/config.h>
#include <winpr/assert.h>
#include <winpr/cast.h>
#include <winpr/string.h>
#include <winpr/print.h>
@@ -1973,8 +1974,9 @@ static PfChannelResult pf_rdpdr_back_data(proxyData* pdata,
WINPR_ASSERT(pdata);
WINPR_ASSERT(channel);
if (!pf_channel_rdpdr_client_handle(pdata->pc, channel->back_channel_id, channel->channel_name,
xdata, xsize, flags, totalSize))
if (!pf_channel_rdpdr_client_handle(pdata->pc,
WINPR_ASSERTING_INT_CAST(UINT16, channel->back_channel_id),
channel->channel_name, xdata, xsize, flags, totalSize))
return PF_CHANNEL_RESULT_ERROR;
#if defined(WITH_PROXY_EMULATE_SMARTCARD)
@@ -1992,8 +1994,9 @@ static PfChannelResult pf_rdpdr_front_data(proxyData* pdata,
WINPR_ASSERT(pdata);
WINPR_ASSERT(channel);
if (!pf_channel_rdpdr_server_handle(pdata->ps, channel->front_channel_id, channel->channel_name,
xdata, xsize, flags, totalSize))
if (!pf_channel_rdpdr_server_handle(pdata->ps,
WINPR_ASSERTING_INT_CAST(UINT16, channel->front_channel_id),
channel->channel_name, xdata, xsize, flags, totalSize))
return PF_CHANNEL_RESULT_ERROR;
#if defined(WITH_PROXY_EMULATE_SMARTCARD)

View File

@@ -16,6 +16,7 @@
* limitations under the License.
*/
#include <winpr/assert.h>
#include <winpr/cast.h>
#include <freerdp/freerdp.h>
#include <freerdp/server/proxy/proxy_log.h>
@@ -199,9 +200,9 @@ PfChannelResult channelTracker_flushCurrent(ChannelStateTracker* t, BOOL first,
if (toBack)
{
proxyChannelDataEventInfo ev;
proxyChannelDataEventInfo ev = { 0 };
ev.channel_id = channel->front_channel_id;
ev.channel_id = WINPR_ASSERTING_INT_CAST(UINT16, channel->front_channel_id);
ev.channel_name = channel->channel_name;
ev.data = Stream_Buffer(currentPacket);
ev.data_len = Stream_GetPosition(currentPacket);
@@ -216,9 +217,9 @@ PfChannelResult channelTracker_flushCurrent(ChannelStateTracker* t, BOOL first,
}
ps = pdata->ps;
r = ps->context.peer->SendChannelPacket(ps->context.peer, channel->front_channel_id,
currentPacketSize, flags, Stream_Buffer(currentPacket),
Stream_GetPosition(currentPacket));
r = ps->context.peer->SendChannelPacket(
ps->context.peer, WINPR_ASSERTING_INT_CAST(UINT16, channel->front_channel_id),
currentPacketSize, flags, Stream_Buffer(currentPacket), Stream_GetPosition(currentPacket));
return r ? PF_CHANNEL_RESULT_DROP : PF_CHANNEL_RESULT_ERROR;
}
@@ -236,7 +237,7 @@ static PfChannelResult pf_channel_generic_back_data(proxyData* pdata,
switch (channel->channelMode)
{
case PF_UTILS_CHANNEL_PASSTHROUGH:
ev.channel_id = channel->back_channel_id;
ev.channel_id = WINPR_ASSERTING_INT_CAST(UINT16, channel->back_channel_id);
ev.channel_name = channel->channel_name;
ev.data = xdata;
ev.data_len = xsize;
@@ -270,7 +271,7 @@ static PfChannelResult pf_channel_generic_front_data(proxyData* pdata,
switch (channel->channelMode)
{
case PF_UTILS_CHANNEL_PASSTHROUGH:
ev.channel_id = channel->front_channel_id;
ev.channel_id = WINPR_ASSERTING_INT_CAST(UINT16, channel->front_channel_id);
ev.channel_name = channel->channel_name;
ev.data = xdata;
ev.data_len = xsize;

View File

@@ -21,6 +21,9 @@
* limitations under the License.
*/
#include <winpr/assert.h>
#include <winpr/cast.h>
#include <freerdp/config.h>
#include <freerdp/freerdp.h>
@@ -486,8 +489,9 @@ static BOOL pf_client_receive_channel_data_hook(freerdp* instance, UINT16 channe
if (channel->front_channel_id == 0)
return TRUE;
return ps->context.peer->SendChannelPacket(ps->context.peer, channel->front_channel_id,
totalSize, flags, xdata, xsize);
return ps->context.peer->SendChannelPacket(
ps->context.peer, WINPR_ASSERTING_INT_CAST(UINT16, channel->front_channel_id),
totalSize, flags, xdata, xsize);
case PF_CHANNEL_RESULT_DROP:
return TRUE;
case PF_CHANNEL_RESULT_ERROR:

View File

@@ -34,6 +34,7 @@
#include <winpr/crt.h>
#include <winpr/assert.h>
#include <winpr/cast.h>
#include <winpr/path.h>
#include <winpr/synch.h>
#include <winpr/image.h>
@@ -558,8 +559,8 @@ static int x11_shadow_query_cursor(x11ShadowSubsystem* subsystem, BOOL getImage)
if ((x != (INT64)subsystem->common.pointerX) || (y != (INT64)subsystem->common.pointerY))
{
subsystem->common.pointerX = x;
subsystem->common.pointerY = y;
subsystem->common.pointerX = WINPR_ASSERTING_INT_CAST(UINT32, x);
subsystem->common.pointerY = WINPR_ASSERTING_INT_CAST(UINT32, y);
x11_shadow_pointer_position_update(subsystem);
}
@@ -594,10 +595,10 @@ static void x11_shadow_validate_region(x11ShadowSubsystem* subsystem, int x, int
if (!subsystem->use_xfixes || !subsystem->use_xdamage)
return;
region.x = x;
region.y = y;
region.width = width;
region.height = height;
region.x = WINPR_ASSERTING_INT_CAST(INT16, x);
region.y = WINPR_ASSERTING_INT_CAST(INT16, y);
region.width = WINPR_ASSERTING_INT_CAST(UINT16, width);
region.height = WINPR_ASSERTING_INT_CAST(UINT16, height);
#if defined(WITH_XFIXES) && defined(WITH_XDAMAGE)
XLockDisplay(subsystem->display);
XFixesSetRegion(subsystem->display, subsystem->xdamage_region, &region, 1);
@@ -679,7 +680,8 @@ static int x11_shadow_blend_cursor(x11ShadowSubsystem* subsystem)
for (size_t y = 0; y < nHeight; y++)
{
const BYTE* pSrcPixel = &pSrcData[((nYSrc + y) * nSrcStep) + (4ULL * nXSrc)];
BYTE* pDstPixel = &pDstData[((nYDst + y) * nDstStep) + (4ULL * nXDst)];
BYTE* pDstPixel = &pDstData[((WINPR_ASSERTING_INT_CAST(uint32_t, nYDst) + y) * nDstStep) +
(4ULL * WINPR_ASSERTING_INT_CAST(uint32_t, nXDst))];
for (size_t x = 0; x < nWidth; x++)
{
@@ -783,8 +785,9 @@ static int x11_shadow_screen_grab(x11ShadowSubsystem* subsystem)
EnterCriticalSection(&surface->lock);
surfaceRect.left = 0;
surfaceRect.top = 0;
surfaceRect.right = surface->width;
surfaceRect.bottom = surface->height;
surfaceRect.right = WINPR_ASSERTING_INT_CAST(UINT16, surface->width);
surfaceRect.bottom = WINPR_ASSERTING_INT_CAST(UINT16, surface->height);
LeaveCriticalSection(&surface->lock);
XLockDisplay(subsystem->display);
@@ -803,8 +806,8 @@ static int x11_shadow_screen_grab(x11ShadowSubsystem* subsystem)
EnterCriticalSection(&surface->lock);
status = shadow_capture_compare_with_format(
surface->data, surface->format, surface->scanline, surface->width, surface->height,
(BYTE*)&(image->data[surface->width * 4ull]), subsystem->format, image->bytes_per_line,
&invalidRect);
(BYTE*)&(image->data[surface->width * 4ull]), subsystem->format,
WINPR_ASSERTING_INT_CAST(UINT32, image->bytes_per_line), &invalidRect);
LeaveCriticalSection(&surface->lock);
}
else
@@ -818,7 +821,8 @@ static int x11_shadow_screen_grab(x11ShadowSubsystem* subsystem)
{
status = shadow_capture_compare_with_format(
surface->data, surface->format, surface->scanline, surface->width, surface->height,
(BYTE*)image->data, subsystem->format, image->bytes_per_line, &invalidRect);
(BYTE*)image->data, subsystem->format,
WINPR_ASSERTING_INT_CAST(UINT32, image->bytes_per_line), &invalidRect);
}
LeaveCriticalSection(&surface->lock);
if (!image)
@@ -859,9 +863,13 @@ static int x11_shadow_screen_grab(x11ShadowSubsystem* subsystem)
WINPR_ASSERT(width >= 0);
WINPR_ASSERT(height >= 0);
success = freerdp_image_copy_no_overlap(
surface->data, surface->format, surface->scanline, x, y, (UINT32)width,
(UINT32)height, (BYTE*)image->data, subsystem->format,
(UINT32)image->bytes_per_line, x, y, NULL, FREERDP_FLIP_NONE);
surface->data, surface->format, surface->scanline,
WINPR_ASSERTING_INT_CAST(uint32_t, x), WINPR_ASSERTING_INT_CAST(uint32_t, y),
WINPR_ASSERTING_INT_CAST(uint32_t, width),
WINPR_ASSERTING_INT_CAST(uint32_t, height), (BYTE*)image->data, subsystem->format,
WINPR_ASSERTING_INT_CAST(uint32_t, image->bytes_per_line),
WINPR_ASSERTING_INT_CAST(UINT32, x), WINPR_ASSERTING_INT_CAST(UINT32, y), NULL,
FREERDP_FLIP_NONE);
LeaveCriticalSection(&surface->lock);
if (!success)
goto fail_capture;
@@ -1006,9 +1014,9 @@ static int x11_shadow_subsystem_base_init(x11ShadowSubsystem* subsystem)
subsystem->xfds = ConnectionNumber(subsystem->display);
subsystem->number = DefaultScreen(subsystem->display);
subsystem->screen = ScreenOfDisplay(subsystem->display, subsystem->number);
subsystem->depth = DefaultDepthOfScreen(subsystem->screen);
subsystem->width = WidthOfScreen(subsystem->screen);
subsystem->height = HeightOfScreen(subsystem->screen);
subsystem->depth = WINPR_ASSERTING_INT_CAST(UINT32, DefaultDepthOfScreen(subsystem->screen));
subsystem->width = WINPR_ASSERTING_INT_CAST(UINT32, WidthOfScreen(subsystem->screen));
subsystem->height = WINPR_ASSERTING_INT_CAST(UINT32, HeightOfScreen(subsystem->screen));
subsystem->root_window = RootWindow(subsystem->display, subsystem->number);
return 1;
}
@@ -1134,9 +1142,11 @@ static int x11_shadow_xshm_init(x11ShadowSubsystem* subsystem)
return -1;
}
subsystem->fb_shm_info.shmid = shmget(
IPC_PRIVATE, 1ull * subsystem->fb_image->bytes_per_line * subsystem->fb_image->height,
IPC_CREAT | 0600);
subsystem->fb_shm_info.shmid =
shmget(IPC_PRIVATE,
1ull * WINPR_ASSERTING_INT_CAST(uint32_t, subsystem->fb_image->bytes_per_line) *
WINPR_ASSERTING_INT_CAST(uint32_t, subsystem->fb_image->height),
IPC_CREAT | 0600);
if (subsystem->fb_shm_info.shmid == -1)
{
@@ -1158,10 +1168,11 @@ static int x11_shadow_xshm_init(x11ShadowSubsystem* subsystem)
XSync(subsystem->display, False);
shmctl(subsystem->fb_shm_info.shmid, IPC_RMID, 0);
subsystem->fb_pixmap =
XShmCreatePixmap(subsystem->display, subsystem->root_window, subsystem->fb_image->data,
&(subsystem->fb_shm_info), subsystem->fb_image->width,
subsystem->fb_image->height, subsystem->fb_image->depth);
subsystem->fb_pixmap = XShmCreatePixmap(
subsystem->display, subsystem->root_window, subsystem->fb_image->data,
&(subsystem->fb_shm_info), WINPR_ASSERTING_INT_CAST(uint32_t, subsystem->fb_image->width),
WINPR_ASSERTING_INT_CAST(uint32_t, subsystem->fb_image->height),
WINPR_ASSERTING_INT_CAST(uint32_t, subsystem->fb_image->depth));
XSync(subsystem->display, False);
if (!subsystem->fb_pixmap)
@@ -1193,7 +1204,7 @@ UINT32 x11_shadow_enum_monitors(MONITOR_DEF* monitors, UINT32 maxMonitors)
if (!display)
{
WLog_ERR(TAG, "failed to open display: %s", XDisplayName(NULL));
return -1;
return 0;
}
displayWidth = WidthOfScreen(DefaultScreenOfDisplay(display));
@@ -1257,7 +1268,7 @@ UINT32 x11_shadow_enum_monitors(MONITOR_DEF* monitors, UINT32 maxMonitors)
}
errno = 0;
return numMonitors;
return WINPR_ASSERTING_INT_CAST(uint32_t, numMonitors);
}
static int x11_shadow_subsystem_init(rdpShadowSubsystem* sub)
@@ -1321,8 +1332,8 @@ static int x11_shadow_subsystem_init(rdpShadowSubsystem* sub)
if (pf->depth == (INT64)subsystem->depth)
{
subsystem->bpp = pf->bits_per_pixel;
subsystem->scanline_pad = pf->scanline_pad;
subsystem->bpp = WINPR_ASSERTING_INT_CAST(uint32_t, pf->bits_per_pixel);
subsystem->scanline_pad = WINPR_ASSERTING_INT_CAST(uint32_t, pf->scanline_pad);
break;
}
}

View File

@@ -22,6 +22,7 @@
#include <winpr/crt.h>
#include <winpr/assert.h>
#include <winpr/cast.h>
#include <winpr/file.h>
#include <winpr/path.h>
#include <winpr/synch.h>
@@ -1291,8 +1292,8 @@ static BOOL shadow_client_send_surface_gfx(rdpShadowClient* client, const BYTE*
WINPR_ASSERT(cmd.bottom <= UINT16_MAX);
rect.x = (UINT16)cmd.left;
rect.y = (UINT16)cmd.top;
rect.width = (UINT16)cmd.right - cmd.left;
rect.height = (UINT16)cmd.bottom - cmd.top;
rect.width = WINPR_ASSERTING_INT_CAST(UINT16, cmd.right - cmd.left);
rect.height = WINPR_ASSERTING_INT_CAST(UINT16, cmd.bottom - cmd.top);
rc = rfx_compose_message(encoder->rfx, s, &rect, 1, pSrcData, nWidth, nHeight, nSrcStep);
@@ -2141,12 +2142,12 @@ static int shadow_client_subsystem_process_message(rdpShadowClient* client, wMes
pointerNew.xorBpp = 24;
pointerColor = &(pointerNew.colorPtrAttr);
pointerColor->cacheIndex = 0;
pointerColor->hotSpotX = msg->xHot;
pointerColor->hotSpotY = msg->yHot;
pointerColor->width = msg->width;
pointerColor->height = msg->height;
pointerColor->lengthAndMask = msg->lengthAndMask;
pointerColor->lengthXorMask = msg->lengthXorMask;
pointerColor->hotSpotX = WINPR_ASSERTING_INT_CAST(UINT16, msg->xHot);
pointerColor->hotSpotY = WINPR_ASSERTING_INT_CAST(UINT16, msg->yHot);
pointerColor->width = WINPR_ASSERTING_INT_CAST(UINT16, msg->width);
pointerColor->height = WINPR_ASSERTING_INT_CAST(UINT16, msg->height);
pointerColor->lengthAndMask = WINPR_ASSERTING_INT_CAST(UINT16, msg->lengthAndMask);
pointerColor->lengthXorMask = WINPR_ASSERTING_INT_CAST(UINT16, msg->lengthXorMask);
pointerColor->xorMaskData = msg->xorMaskData;
pointerColor->andMaskData = msg->andMaskData;
pointerCached.cacheIndex = pointerColor->cacheIndex;

View File

@@ -170,7 +170,7 @@ static int shadow_encoder_init_nsc(rdpShadowEncoder* encoder)
goto fail;
if (!nsc_context_set_parameters(
encoder->nsc, NSC_ALLOW_SUBSAMPLING,
freerdp_settings_get_bool(settings, FreeRDP_NSCodecAllowSubsampling)))
freerdp_settings_get_bool(settings, FreeRDP_NSCodecAllowSubsampling) ? 1 : 0))
goto fail;
if (!nsc_context_set_parameters(
encoder->nsc, NSC_DYNAMIC_COLOR_FIDELITY,

View File

@@ -19,6 +19,8 @@
#include <freerdp/config.h>
#include <winpr/assert.h>
#include <winpr/cast.h>
#include <rdtk/rdtk.h>
#include "shadow.h"
@@ -42,7 +44,9 @@ BOOL shadow_client_init_lobby(rdpShadowServer* server)
return FALSE;
EnterCriticalSection(&lobby->lock);
surface = rdtk_surface_new(engine, lobby->data, lobby->width, lobby->height, lobby->scanline);
surface =
rdtk_surface_new(engine, lobby->data, WINPR_ASSERTING_INT_CAST(uint16_t, lobby->width),
WINPR_ASSERTING_INT_CAST(uint16_t, lobby->height), lobby->scanline);
if (!surface)
goto fail;

View File

@@ -19,6 +19,9 @@
#include <freerdp/config.h>
#include <winpr/crt.h>
#include <winpr/assert.h>
#include <winpr/cast.h>
#include <freerdp/log.h>
#include <freerdp/codec/dsp.h>
#include <freerdp/server/server-common.h>
@@ -37,7 +40,7 @@ static void rdpsnd_activated(RdpsndServerContext* context)
{
if (audio_format_compatible(&context->server_formats[j], &context->client_formats[i]))
{
context->SelectFormat(context, i);
context->SelectFormat(context, WINPR_ASSERTING_INT_CAST(UINT16, i));
return;
}
}