[warnings] fix compare integers of different signs

This commit is contained in:
akallabeth 2024-09-03 14:38:45 +02:00
parent cbeded839d
commit baa70d1ab6
No known key found for this signature in database
GPG Key ID: A49454A3FC909FD5
21 changed files with 83 additions and 59 deletions

View File

@ -366,7 +366,7 @@ static rdpPrinter** printer_cups_enum_printers(rdpPrinterDriver* driver)
if (!printers)
return NULL;
for (size_t i = 0; i < num_dests; i++)
for (size_t i = 0; i < (size_t)num_dests; i++)
{
const cups_dest_t* dest = &dests[i];
if (dest->instance == NULL)

View File

@ -864,7 +864,7 @@ static UINT32 libusb_udev_control_query_device_text(IUDEVICE* idev, UINT32 TextT
msg, ret, devDescriptor->iProduct);
len = MIN(sizeof(strDesc), inSize);
for (ssize_t i = 0; i < len; i++)
for (size_t i = 0; i < len; i++)
text[i] = (WCHAR)strDesc[i];
*BufferSize = (BYTE)(len * 2);
@ -899,7 +899,7 @@ static UINT32 libusb_udev_control_query_device_text(IUDEVICE* idev, UINT32 TextT
len = strnlen(deviceLocation,
MIN(sizeof(deviceLocation), (inSize > 0) ? inSize - 1U : 0));
for (ssize_t i = 0; i < len; i++)
for (size_t i = 0; i < len; i++)
text[i] = (WCHAR)deviceLocation[i];
text[len++] = '\0';
*BufferSize = (UINT8)(len * sizeof(WCHAR));

View File

@ -458,7 +458,7 @@ std::string SDLConnectionDialog::print(const char* fmt, va_list ap)
size = vsnprintf(res.data(), res.size(), fmt, copy);
va_end(copy);
} while ((size > 0) && (size > res.size()));
} while ((size > 0) && (static_cast<size_t>(size) > res.size()));
return res;
}

View File

@ -326,9 +326,13 @@ BOOL sdl_detect_monitors(SdlContext* sdl, UINT32* pMaxWidth, UINT32* pMaxHeight)
const int numDisplays = SDL_GetNumVideoDisplays();
auto nr = freerdp_settings_get_uint32(settings, FreeRDP_NumMonitorIds);
if (numDisplays < 0)
return FALSE;
if (nr == 0)
{
if (!freerdp_settings_set_pointer_len(settings, FreeRDP_MonitorIds, nullptr, numDisplays))
if (!freerdp_settings_set_pointer_len(settings, FreeRDP_MonitorIds, nullptr,
static_cast<size_t>(numDisplays)))
return FALSE;
for (size_t x = 0; x < numDisplays; x++)
{
@ -340,7 +344,7 @@ BOOL sdl_detect_monitors(SdlContext* sdl, UINT32* pMaxWidth, UINT32* pMaxHeight)
{
/* There were more IDs supplied than there are monitors */
if (nr > numDisplays)
if (nr > static_cast<UINT32>(numDisplays))
{
WLog_ERR(TAG,
"Found %" PRIu32 " monitor IDs, but only have %" PRIu32 " monitors connected",

View File

@ -456,7 +456,7 @@ std::string SDLConnectionDialog::print(const char* fmt, va_list ap)
size = vsnprintf(res.data(), res.size(), fmt, copy);
va_end(copy);
} while ((size > 0) && (size > res.size()));
} while ((size > 0) && (static_cast<size_t>(size) > res.size()));
return res;
}

View File

@ -323,8 +323,11 @@ BOOL sdl_detect_monitors(SdlContext* sdl, UINT32* pMaxWidth, UINT32* pMaxHeight)
{
int numDisplays = 0;
auto sids = SDL_GetDisplays(&numDisplays);
ids = std::vector<SDL_DisplayID>(sids, sids + numDisplays);
if (sids && (numDisplays > 0))
ids = std::vector<SDL_DisplayID>(sids, sids + numDisplays);
SDL_free(sids);
if (numDisplays < 0)
return FALSE;
}
auto nr = freerdp_settings_get_uint32(settings, FreeRDP_NumMonitorIds);

View File

@ -94,7 +94,7 @@ std::vector<std::string> SdlPref::get_array(const std::string& key,
return fallback;
std::vector<std::string> values;
for (int x = 0; x < WINPR_JSON_GetArraySize(item); x++)
for (size_t x = 0; x < WINPR_JSON_GetArraySize(item); x++)
{
auto cur = WINPR_JSON_GetArrayItem(item, x);
values.push_back(item_to_str(cur));

View File

@ -186,15 +186,17 @@ BOOL xf_detect_monitors(xfContext* xfc, UINT32* pMaxWidth, UINT32* pMaxHeight)
if (XRRQueryExtension(xfc->display, &major, &minor) &&
(XRRQueryVersion(xfc->display, &major, &minor) == True) && (major * 100 + minor >= 105))
{
rrmonitors =
XRRGetMonitors(xfc->display, DefaultRootWindow(xfc->display), 1, &vscreen->nmonitors);
int nmonitors = 0;
rrmonitors = XRRGetMonitors(xfc->display, DefaultRootWindow(xfc->display), 1, &nmonitors);
if (vscreen->nmonitors > 16)
if ((nmonitors < 0) || (nmonitors > 16))
vscreen->nmonitors = 0;
else
vscreen->nmonitors = (UINT32)nmonitors;
if (vscreen->nmonitors)
{
for (int i = 0; i < vscreen->nmonitors; i++)
for (UINT32 i = 0; i < vscreen->nmonitors; i++)
{
MONITOR_INFO* cur_vscreen = &vscreen->monitors[i];
const XRRMonitorInfo* cur_monitor = &rrmonitors[i];
@ -213,14 +215,17 @@ BOOL xf_detect_monitors(xfContext* xfc, UINT32* pMaxWidth, UINT32* pMaxHeight)
#ifdef WITH_XINERAMA
if (XineramaQueryExtension(xfc->display, &major, &minor) && XineramaIsActive(xfc->display))
{
XineramaScreenInfo* screenInfo = XineramaQueryScreens(xfc->display, &vscreen->nmonitors);
int nmonitors = 0;
XineramaScreenInfo* screenInfo = XineramaQueryScreens(xfc->display, &nmonitors);
if (vscreen->nmonitors > 16)
if ((nmonitors < 0) || (nmonitors > 16))
vscreen->nmonitors = 0;
else
vscreen->nmonitors = (UINT32)nmonitors;
if (vscreen->nmonitors)
{
for (int i = 0; i < vscreen->nmonitors; i++)
for (UINT32 i = 0; i < vscreen->nmonitors; i++)
{
MONITOR_INFO* monitor = &vscreen->monitors[i];
monitor->area.left = screenInfo[i].x_org;
@ -240,7 +245,7 @@ BOOL xf_detect_monitors(xfContext* xfc, UINT32* pMaxWidth, UINT32* pMaxHeight)
/* Determine which monitor that the mouse cursor is on */
if (vscreen->monitors)
{
for (int i = 0; i < vscreen->nmonitors; i++)
for (UINT32 i = 0; i < vscreen->nmonitors; i++)
{
const MONITOR_INFO* monitor = &vscreen->monitors[i];

View File

@ -32,7 +32,7 @@ typedef struct
typedef struct
{
int nmonitors;
UINT32 nmonitors;
RECTANGLE_16 area;
RECTANGLE_16 workarea;
MONITOR_INFO* monitors;

View File

@ -320,7 +320,7 @@ static CliprdrFuseClipDataEntry* clip_data_entry_new(CliprdrFileContext* file_co
}
static BOOL should_remove_fuse_file(CliprdrFuseFile* fuse_file, BOOL all_files,
BOOL has_clip_data_id, BOOL clip_data_id)
BOOL has_clip_data_id, UINT32 clip_data_id)
{
if (all_files)
return TRUE;
@ -329,7 +329,8 @@ static BOOL should_remove_fuse_file(CliprdrFuseFile* fuse_file, BOOL all_files,
return FALSE;
if (!fuse_file->has_clip_data_id && !has_clip_data_id)
return TRUE;
if (fuse_file->has_clip_data_id && has_clip_data_id && fuse_file->clip_data_id == clip_data_id)
if (fuse_file->has_clip_data_id && has_clip_data_id &&
(fuse_file->clip_data_id == clip_data_id))
return TRUE;
return FALSE;
@ -972,7 +973,7 @@ static void cliprdr_file_fuse_read(fuse_req_t fuse_req, fuse_ino_t fuse_ino, siz
fuse_reply_err(fuse_req, EISDIR);
return;
}
if (!fuse_file->has_size || offset > fuse_file->size)
if (!fuse_file->has_size || (offset < 0) || (offset > fuse_file->size))
{
HashTable_Unlock(file_context->inode_table);
fuse_reply_err(fuse_req, EINVAL);
@ -1051,7 +1052,7 @@ static void cliprdr_file_fuse_readdir(fuse_req_t fuse_req, fuse_ino_t fuse_ino,
DEBUG_CLIPRDR(file_context->log, "Reading directory \"%s\" at offset %lu",
fuse_file->filename_with_root, offset);
if (offset >= ArrayList_Count(fuse_file->children))
if ((offset < 0) || ((size_t)offset >= ArrayList_Count(fuse_file->children)))
{
HashTable_Unlock(file_context->inode_table);
fuse_reply_buf(fuse_req, NULL, 0);
@ -1100,7 +1101,7 @@ static void cliprdr_file_fuse_readdir(fuse_req_t fuse_req, fuse_ino_t fuse_ino,
for (size_t j = 0, i = 2; j < ArrayList_Count(fuse_file->children); ++j, ++i)
{
if (i < offset)
if (i < (size_t)offset)
continue;
child = ArrayList_GetItem(fuse_file->children, j);

View File

@ -38,7 +38,7 @@ static INLINE void rfx_differential_decode(INT16* WINPR_RESTRICT buffer, size_t
static INLINE void rfx_differential_encode(INT16* WINPR_RESTRICT buffer, size_t size)
{
INT16 n1 = buffer[0];
for (int x = 0; x < size - 1; x++)
for (size_t x = 0; x < size - 1; x++)
{
INT16* dst = &buffer[x + 1];
const INT16 n2 = *dst;

View File

@ -561,7 +561,7 @@ int rfx_rlgr_decode(RLGR_MODE mode, const BYTE* WINPR_RESTRICT pSrcData, UINT32
offset = (pOutput - pDstData);
if (offset != DstSize)
if ((DstSize < 0) || (offset != (size_t)DstSize))
return -1;
return 1;

View File

@ -423,7 +423,7 @@ static BOOL freerdp_assistance_parse_attr(const char** opt, size_t* plength, con
char bkey[128] = { 0 };
const int rc = _snprintf(bkey, sizeof(bkey), "%s=\"", key);
WINPR_ASSERT(rc > 0);
WINPR_ASSERT(rc < sizeof(bkey));
WINPR_ASSERT((size_t)rc < sizeof(bkey));
char* p = strstr(tag, bkey);
if (!p)
@ -523,7 +523,7 @@ static char* freerdp_assistance_contains_element(char* input, size_t ilen, const
char bkey[128] = { 0 };
const int rc = _snprintf(bkey, sizeof(bkey), "<%s", key);
WINPR_ASSERT(rc > 0);
WINPR_ASSERT(rc < sizeof(bkey));
WINPR_ASSERT((size_t)rc < sizeof(bkey));
char* tag = strstr(input, bkey);
if (!tag || (tag > input + ilen))
@ -562,7 +562,7 @@ static char* freerdp_assistance_contains_element(char* input, size_t ilen, const
char ekey[128] = { 0 };
const int erc = _snprintf(ekey, sizeof(ekey), "</%s>", key);
WINPR_ASSERT(erc > 0);
WINPR_ASSERT(erc < sizeof(ekey));
WINPR_ASSERT((size_t)erc < sizeof(ekey));
const size_t offset = start - tag;
dend = end = strrstr(start, ilen - offset, ekey);
if (end)

View File

@ -211,10 +211,16 @@ static int transport_bio_named_read(BIO* bio, char* buf, int size)
}
}
int ret = MIN(size, ringbuffer_used(&ptr->readBuffer));
if (ret)
SSIZE_T ret = -1;
if (size >= 0)
{
DataChunk chunks[2];
size_t rsize = ringbuffer_used(&ptr->readBuffer);
if (rsize <= SSIZE_MAX)
ret = MIN(size, (SSIZE_T)rsize);
}
if ((size >= 0) && ret)
{
DataChunk chunks[2] = { 0 };
int nchunks = ringbuffer_peek(&ptr->readBuffer, chunks, ret);
for (int i = 0; i < nchunks; i++)
{
@ -226,10 +232,6 @@ static int transport_bio_named_read(BIO* bio, char* buf, int size)
WLog_VRB(TAG, "(%d)=%d nchunks=%d", size, ret, nchunks);
}
else
{
ret = -1;
}
if (!ringbuffer_used(&ptr->readBuffer))
{

View File

@ -511,7 +511,7 @@ BOOL freerdp_channels_data(freerdp* instance, UINT16 channelId, const BYTE* cdat
return FALSE;
}
for (int index = 0; index < mcs->channelCount; index++)
for (UINT32 index = 0; index < mcs->channelCount; index++)
{
rdpMcsChannel* cur = &mcs->channels[index];

View File

@ -758,8 +758,11 @@ static BOOL rdp_client_establish_keys(rdpRdp* rdp)
crypto_rsa_public_encrypt(settings->ClientRandom, settings->ClientRandomLength, info,
crypt_client_random, info->ModulusLength);
/* send crypt client random to server */
const size_t length =
RDP_PACKET_HEADER_MAX_LENGTH + RDP_SECURITY_HEADER_LENGTH + 4 + info->ModulusLength + 8;
const size_t length = RDP_PACKET_HEADER_MAX_LENGTH + RDP_SECURITY_HEADER_LENGTH + 4ULL +
info->ModulusLength + 8ULL;
if (length > UINT16_MAX)
return FALSE;
s = Stream_New(NULL, length);
if (!s)

View File

@ -161,9 +161,9 @@ const char* data_pdu_type_to_string(UINT8 type)
}
static BOOL rdp_read_flow_control_pdu(rdpRdp* rdp, wStream* s, UINT16* type, UINT16* channel_id);
static BOOL rdp_write_share_control_header(rdpRdp* rdp, wStream* s, UINT16 length, UINT16 type,
static BOOL rdp_write_share_control_header(rdpRdp* rdp, wStream* s, size_t length, UINT16 type,
UINT16 channel_id);
static BOOL rdp_write_share_data_header(rdpRdp* rdp, wStream* s, UINT16 length, BYTE type,
static BOOL rdp_write_share_data_header(rdpRdp* rdp, wStream* s, size_t length, BYTE type,
UINT32 share_id);
/**
@ -301,11 +301,13 @@ BOOL rdp_read_share_control_header(rdpRdp* rdp, wStream* s, UINT16* tpktLength,
return Stream_CheckAndLogRequiredLengthWLog(rdp->log, s, remLen);
}
BOOL rdp_write_share_control_header(rdpRdp* rdp, wStream* s, UINT16 length, UINT16 type,
BOOL rdp_write_share_control_header(rdpRdp* rdp, wStream* s, size_t length, UINT16 type,
UINT16 channel_id)
{
WINPR_ASSERT(s);
WINPR_ASSERT(rdp);
if (length > UINT16_MAX)
return FALSE;
if (length < RDP_PACKET_HEADER_MAX_LENGTH)
return FALSE;
@ -339,13 +341,15 @@ BOOL rdp_read_share_data_header(rdpRdp* rdp, wStream* s, UINT16* length, BYTE* t
return TRUE;
}
BOOL rdp_write_share_data_header(rdpRdp* rdp, wStream* s, UINT16 length, BYTE type, UINT32 share_id)
BOOL rdp_write_share_data_header(rdpRdp* rdp, wStream* s, size_t length, BYTE type, UINT32 share_id)
{
const size_t headerLen = RDP_PACKET_HEADER_MAX_LENGTH + RDP_SHARE_CONTROL_HEADER_LENGTH +
RDP_SHARE_DATA_HEADER_LENGTH;
WINPR_ASSERT(s);
WINPR_ASSERT(rdp);
if (length > UINT16_MAX)
return FALSE;
if (length < headerLen)
return FALSE;
@ -647,12 +651,14 @@ BOOL rdp_read_header(rdpRdp* rdp, wStream* s, UINT16* length, UINT16* channelId)
* @return \b TRUE for success, \b FALSE otherwise
*/
BOOL rdp_write_header(rdpRdp* rdp, wStream* s, UINT16 length, UINT16 channelId)
BOOL rdp_write_header(rdpRdp* rdp, wStream* s, size_t length, UINT16 channelId)
{
WINPR_ASSERT(rdp);
WINPR_ASSERT(rdp->settings);
WINPR_ASSERT(s);
WINPR_ASSERT(length >= RDP_PACKET_HEADER_MAX_LENGTH);
if (length > UINT16_MAX)
return FALSE;
DomainMCSPDU MCSPDU = (rdp->settings->ServerMode) ? DomainMCSPDU_SendDataIndication
: DomainMCSPDU_SendDataRequest;
@ -687,12 +693,13 @@ BOOL rdp_write_header(rdpRdp* rdp, wStream* s, UINT16 length, UINT16 channelId)
return TRUE;
}
static BOOL rdp_security_stream_out(rdpRdp* rdp, wStream* s, int length, UINT32 sec_flags,
static BOOL rdp_security_stream_out(rdpRdp* rdp, wStream* s, size_t length, UINT32 sec_flags,
UINT32* pad)
{
BOOL status = 0;
WINPR_ASSERT(rdp);
WINPR_ASSERT(length >= 0);
if (length > UINT16_MAX)
return FALSE;
sec_flags |= rdp->sec_flags;
*pad = 0;
@ -715,7 +722,7 @@ static BOOL rdp_security_stream_out(rdpRdp* rdp, wStream* s, int length, UINT32
if (size > length)
goto unlock;
length -= (int)size;
length -= size;
Stream_Write_UINT16(s, 0x10); /* length */
Stream_Write_UINT8(s, 0x1); /* TSFIPS_VERSION 1*/
@ -742,7 +749,10 @@ static BOOL rdp_security_stream_out(rdpRdp* rdp, wStream* s, int length, UINT32
else
{
const BYTE* data = Stream_PointerAs(s, const BYTE) + 8;
length = length - (data - Stream_Buffer(s));
const size_t diff = Stream_GetPosition(s) + 8ULL;
if (diff > length)
goto unlock;
length -= diff;
if (!Stream_CheckAndLogRequiredCapacityWLog(rdp->log, s, 8))
goto unlock;
@ -811,7 +821,6 @@ BOOL rdp_send(rdpRdp* rdp, wStream* s, UINT16 channel_id)
{
BOOL rc = FALSE;
UINT32 pad = 0;
UINT16 length = 0;
if (!s)
return FALSE;
@ -819,7 +828,7 @@ BOOL rdp_send(rdpRdp* rdp, wStream* s, UINT16 channel_id)
if (!rdp)
goto fail;
length = Stream_GetPosition(s);
size_t length = Stream_GetPosition(s);
Stream_SetPosition(s, 0);
if (!rdp_write_header(rdp, s, length, channel_id))
goto fail;
@ -842,7 +851,6 @@ fail:
BOOL rdp_send_pdu(rdpRdp* rdp, wStream* s, UINT16 type, UINT16 channel_id)
{
UINT16 length = 0;
UINT32 sec_bytes = 0;
size_t sec_hold = 0;
UINT32 pad = 0;
@ -850,7 +858,7 @@ BOOL rdp_send_pdu(rdpRdp* rdp, wStream* s, UINT16 type, UINT16 channel_id)
if (!rdp || !s)
return FALSE;
length = Stream_GetPosition(s);
size_t length = Stream_GetPosition(s);
Stream_SetPosition(s, 0);
if (!rdp_write_header(rdp, s, length, MCS_GLOBAL_CHANNEL_ID))
return FALSE;
@ -877,7 +885,6 @@ BOOL rdp_send_pdu(rdpRdp* rdp, wStream* s, UINT16 type, UINT16 channel_id)
BOOL rdp_send_data_pdu(rdpRdp* rdp, wStream* s, BYTE type, UINT16 channel_id)
{
BOOL rc = FALSE;
size_t length = 0;
UINT32 sec_bytes = 0;
size_t sec_hold = 0;
UINT32 pad = 0;
@ -888,7 +895,7 @@ BOOL rdp_send_data_pdu(rdpRdp* rdp, wStream* s, BYTE type, UINT16 channel_id)
if (!rdp)
goto fail;
length = Stream_GetPosition(s);
size_t length = Stream_GetPosition(s);
Stream_SetPosition(s, 0);
if (!rdp_write_header(rdp, s, length, MCS_GLOBAL_CHANNEL_ID))
goto fail;
@ -924,13 +931,12 @@ fail:
BOOL rdp_send_message_channel_pdu(rdpRdp* rdp, wStream* s, UINT16 sec_flags)
{
BOOL rc = FALSE;
UINT16 length = 0;
UINT32 pad = 0;
WINPR_ASSERT(rdp);
WINPR_ASSERT(s);
length = Stream_GetPosition(s);
size_t length = Stream_GetPosition(s);
Stream_SetPosition(s, 0);
if (!rdp_write_header(rdp, s, length, rdp->mcs->messageChannelId))
goto fail;

View File

@ -223,7 +223,7 @@ FREERDP_LOCAL wStream* rdp_send_stream_init(rdpRdp* rdp);
FREERDP_LOCAL wStream* rdp_send_stream_pdu_init(rdpRdp* rdp);
FREERDP_LOCAL BOOL rdp_read_header(rdpRdp* rdp, wStream* s, UINT16* length, UINT16* channel_id);
FREERDP_LOCAL BOOL rdp_write_header(rdpRdp* rdp, wStream* s, UINT16 length, UINT16 channel_id);
FREERDP_LOCAL BOOL rdp_write_header(rdpRdp* rdp, wStream* s, size_t length, UINT16 channel_id);
FREERDP_LOCAL BOOL rdp_send_pdu(rdpRdp* rdp, wStream* s, UINT16 type, UINT16 channel_id);

View File

@ -160,7 +160,7 @@ BOOL tpkt_ensure_stream_consumed_(wStream* s, size_t length, const char* fkt)
* @return \b TRUE for success, \b FALSE otherwise
*/
BOOL tpkt_write_header(wStream* s, UINT16 length)
BOOL tpkt_write_header(wStream* s, size_t length)
{
if (!Stream_CheckAndLogRequiredCapacity(TAG, (s), 4))
return FALSE;

View File

@ -30,7 +30,7 @@
FREERDP_LOCAL int tpkt_verify_header(wStream* s);
FREERDP_LOCAL BOOL tpkt_read_header(wStream* s, UINT16* length);
FREERDP_LOCAL BOOL tpkt_write_header(wStream* s, UINT16 length);
FREERDP_LOCAL BOOL tpkt_write_header(wStream* s, size_t length);
#define tpkt_ensure_stream_consumed(s, length) tpkt_ensure_stream_consumed_((s), (length), __func__)
FREERDP_LOCAL BOOL tpkt_ensure_stream_consumed_(wStream* s, size_t length, const char* fkt);

View File

@ -929,7 +929,7 @@ static BOOL update_read_desktop_actively_monitored_order(wStream* s, WINDOW_ORDE
monitored_desktop->windowIds = newid;
/* windowIds */
for (UINT32 i = 0; i < (int)monitored_desktop->numWindowIds; i++)
for (UINT32 i = 0; i < monitored_desktop->numWindowIds; i++)
{
Stream_Read_UINT32(s, monitored_desktop->windowIds[i]);
}