From 7ab917dca8944e85ced349b93c1c47ba44f94106 Mon Sep 17 00:00:00 2001 From: akallabeth Date: Mon, 5 Dec 2022 08:58:38 +0100 Subject: [PATCH] Fixed Wsign-compare warnings --- channels/rdpsnd/server/rdpsnd_main.c | 4 ++-- channels/tsmf/client/ffmpeg/tsmf_ffmpeg.c | 16 ++++++++++----- libfreerdp/codec/clear.c | 10 +++------- .../codec/test/TestFreeRDPCodecProgressive.c | 5 ++--- libfreerdp/core/activation.c | 10 +++------- libfreerdp/core/license.c | 2 +- libfreerdp/core/smartcardlogon.c | 6 +++--- libfreerdp/locale/locale.c | 6 +++--- winpr/libwinpr/clipboard/synthetic_file.c | 2 +- .../libwinpr/crt/test/TestUnicodeConversion.c | 20 +++++++++---------- winpr/libwinpr/crt/unicode.c | 8 ++++---- winpr/libwinpr/ncrypt/ncrypt_pkcs11.c | 2 +- winpr/libwinpr/pool/pool.c | 2 +- winpr/libwinpr/sspi/NTLM/ntlm.c | 4 ++-- winpr/libwinpr/sspi/NTLM/ntlm_compute.c | 5 ++--- 15 files changed, 49 insertions(+), 53 deletions(-) diff --git a/channels/rdpsnd/server/rdpsnd_main.c b/channels/rdpsnd/server/rdpsnd_main.c index 5368846eb..6b8aa553e 100644 --- a/channels/rdpsnd/server/rdpsnd_main.c +++ b/channels/rdpsnd/server/rdpsnd_main.c @@ -337,8 +337,8 @@ static UINT rdpsnd_server_initialize(RdpsndServerContext* context, BOOL ownThrea */ static UINT rdpsnd_server_select_format(RdpsndServerContext* context, UINT16 client_format_index) { - int bs; - int out_buffer_size; + size_t bs; + size_t out_buffer_size; AUDIO_FORMAT* format; UINT error = CHANNEL_RC_OK; diff --git a/channels/tsmf/client/ffmpeg/tsmf_ffmpeg.c b/channels/tsmf/client/ffmpeg/tsmf_ffmpeg.c index c0e0ad1cb..339462d86 100644 --- a/channels/tsmf/client/ffmpeg/tsmf_ffmpeg.c +++ b/channels/tsmf/client/ffmpeg/tsmf_ffmpeg.c @@ -197,7 +197,8 @@ static BOOL tsmf_ffmpeg_init_stream(ITSMFDecoder* decoder, const TS_AM_MEDIA_TYP /* The extradata format that FFmpeg uses is following CodecPrivate in Matroska. See http://haali.su/mkv/codecs.pdf */ p = mdecoder->codec_context->extradata; - if (mdecoder->codec_context->extradata_size < required) + if ((mdecoder->codec_context->extradata_size < 0) || + ((size_t)mdecoder->codec_context->extradata_size < required)) return FALSE; *p++ = 1; /* Reserved? */ *p++ = media_type->ExtraData[8]; /* Profile */ @@ -208,18 +209,21 @@ static BOOL tsmf_ffmpeg_init_stream(ITSMFDecoder* decoder, const TS_AM_MEDIA_TYP s = media_type->ExtraData + 20; size = ((UINT32)(*s)) * 256 + ((UINT32)(*(s + 1))); required += size + 2; - if (mdecoder->codec_context->extradata_size < required) + if ((mdecoder->codec_context->extradata_size < 0) || + ((size_t)mdecoder->codec_context->extradata_size < required)) return FALSE; memcpy(p, s, size + 2); s += size + 2; p += size + 2; required++; - if (mdecoder->codec_context->extradata_size < required) + if ((mdecoder->codec_context->extradata_size < 0) || + ((size_t)mdecoder->codec_context->extradata_size < required)) return FALSE; *p++ = 1; /* #pps */ size = ((UINT32)(*s)) * 256 + ((UINT32)(*(s + 1))); required += size + 2; - if (mdecoder->codec_context->extradata_size < required) + if ((mdecoder->codec_context->extradata_size < 0) || + ((size_t)mdecoder->codec_context->extradata_size < required)) return FALSE; memcpy(p, s, size + 2); } @@ -227,7 +231,9 @@ static BOOL tsmf_ffmpeg_init_stream(ITSMFDecoder* decoder, const TS_AM_MEDIA_TYP { memcpy(mdecoder->codec_context->extradata, media_type->ExtraData, media_type->ExtraDataSize); - if (mdecoder->codec_context->extradata_size < media_type->ExtraDataSize + 8) + if ((mdecoder->codec_context->extradata_size < 0) || + ((size_t)mdecoder->codec_context->extradata_size < + media_type->ExtraDataSize + 8ull)) return FALSE; memset(mdecoder->codec_context->extradata + media_type->ExtraDataSize, 0, 8); } diff --git a/libfreerdp/codec/clear.c b/libfreerdp/codec/clear.c index 3b1a0b76a..f02ad6c81 100644 --- a/libfreerdp/codec/clear.c +++ b/libfreerdp/codec/clear.c @@ -84,11 +84,9 @@ static const BYTE CLEAR_8BIT_MASKS[9] = { 0x00, 0x01, 0x03, 0x07, 0x0F, 0x1F, 0x static void clear_reset_vbar_storage(CLEAR_CONTEXT* clear, BOOL zero) { - int i; - if (zero) { - for (i = 0; i < ARRAYSIZE(clear->VBarStorage); i++) + for (size_t i = 0; i < ARRAYSIZE(clear->VBarStorage); i++) free(clear->VBarStorage[i].pixels); ZeroMemory(clear->VBarStorage, sizeof(clear->VBarStorage)); @@ -98,7 +96,7 @@ static void clear_reset_vbar_storage(CLEAR_CONTEXT* clear, BOOL zero) if (zero) { - for (i = 0; i < ARRAYSIZE(clear->ShortVBarStorage); i++) + for (size_t i = 0; i < ARRAYSIZE(clear->ShortVBarStorage); i++) free(clear->ShortVBarStorage[i].pixels); ZeroMemory(clear->ShortVBarStorage, sizeof(clear->ShortVBarStorage)); @@ -109,9 +107,7 @@ static void clear_reset_vbar_storage(CLEAR_CONTEXT* clear, BOOL zero) static void clear_reset_glyph_cache(CLEAR_CONTEXT* clear) { - int i; - - for (i = 0; i < ARRAYSIZE(clear->GlyphCache); i++) + for (size_t i = 0; i < ARRAYSIZE(clear->GlyphCache); i++) free(clear->GlyphCache[i].pixels); ZeroMemory(clear->GlyphCache, sizeof(clear->GlyphCache)); diff --git a/libfreerdp/codec/test/TestFreeRDPCodecProgressive.c b/libfreerdp/codec/test/TestFreeRDPCodecProgressive.c index d81c8f495..6b3237c49 100644 --- a/libfreerdp/codec/test/TestFreeRDPCodecProgressive.c +++ b/libfreerdp/codec/test/TestFreeRDPCodecProgressive.c @@ -1039,7 +1039,6 @@ static BOOL colordiff(UINT32 format, UINT32 a, UINT32 b) static BOOL test_encode_decode(const char* path) { - int x, y; BOOL res = FALSE; int rc; BYTE* resultData = NULL; @@ -1087,11 +1086,11 @@ static BOOL test_encode_decode(const char* path) dstImage->data = resultData; winpr_image_write(dstImage, "/tmp/test.bmp"); } - for (y = 0; y < image->height; y++) + for (UINT32 y = 0; y < image->height; y++) { const BYTE* orig = &image->data[y * image->scanline]; const BYTE* dec = &resultData[y * image->scanline]; - for (x = 0; x < image->width; x++) + for (UINT32 x = 0; x < image->width; x++) { const BYTE* po = &orig[x * 4]; const BYTE* pd = &dec[x * 4]; diff --git a/libfreerdp/core/activation.c b/libfreerdp/core/activation.c index 2b9962ecf..008e7a7a5 100644 --- a/libfreerdp/core/activation.c +++ b/libfreerdp/core/activation.c @@ -235,10 +235,6 @@ BOOL rdp_send_client_control_pdu(rdpRdp* rdp, UINT16 action) static BOOL rdp_write_client_persistent_key_list_pdu(wStream* s, RDP_BITMAP_PERSISTENT_INFO* info) { - int index; - UINT32 key1; - UINT32 key2; - WINPR_ASSERT(s); WINPR_ASSERT(info); @@ -263,10 +259,10 @@ static BOOL rdp_write_client_persistent_key_list_pdu(wStream* s, RDP_BITMAP_PERS if (!Stream_EnsureRemainingCapacity(s, info->keyCount * 8ull)) return FALSE; - for (index = 0; index < info->keyCount; index++) + for (UINT32 index = 0; index < info->keyCount; index++) { - key1 = (UINT32)info->keyList[index]; - key2 = (UINT32)(info->keyList[index] >> 32); + const UINT32 key1 = (UINT32)info->keyList[index]; + const UINT32 key2 = (UINT32)(info->keyList[index] >> 32); Stream_Write_UINT32(s, key1); Stream_Write_UINT32(s, key2); } diff --git a/libfreerdp/core/license.c b/libfreerdp/core/license.c index aa521e805..28102f266 100644 --- a/libfreerdp/core/license.c +++ b/libfreerdp/core/license.c @@ -447,7 +447,7 @@ static BOOL license_check_stream_length(wStream* s, SSIZE_T expect, const char* WLog_WARN(TAG, "invalid %s, expected value %" PRIdz " invalid", where, expect); return FALSE; } - if (remain < expect) + if (remain < (size_t)expect) { WLog_WARN(TAG, "short %s, expected %" PRIdz " bytes, got %" PRIuz, where, expect, remain); return FALSE; diff --git a/libfreerdp/core/smartcardlogon.c b/libfreerdp/core/smartcardlogon.c index 03a9976b7..265dbd38f 100644 --- a/libfreerdp/core/smartcardlogon.c +++ b/libfreerdp/core/smartcardlogon.c @@ -53,15 +53,15 @@ static void delete_file(char* path) if (fp) { const char buffer[8192] = { 0 }; - INT64 x, size = 0; + INT64 size = 0; int rs = _fseeki64(fp, 0, SEEK_END); if (rs == 0) size = _ftelli64(fp); _fseeki64(fp, 0, SEEK_SET); - for (x = 0; x < size; x += sizeof(buffer)) + for (INT64 x = 0; x < size; x += sizeof(buffer)) { - fwrite(buffer, MIN(sizeof(buffer), size - x), 1, fp); + fwrite(buffer, MIN(sizeof(buffer), (size_t)size - x), 1, fp); } fclose(fp); diff --git a/libfreerdp/locale/locale.c b/libfreerdp/locale/locale.c index 1d58b3573..80a1bcf8c 100644 --- a/libfreerdp/locale/locale.c +++ b/libfreerdp/locale/locale.c @@ -685,9 +685,9 @@ static BOOL freerdp_get_system_language_and_country_codes(char* language, size_t } #else { - int dot; + size_t dot; DWORD nSize; - int underscore; + size_t underscore; char* env_lang = NULL; LPCSTR lang = "LANG"; /* LANG = _. */ @@ -718,7 +718,7 @@ static BOOL freerdp_get_system_language_and_country_codes(char* language, size_t else { /* Get language code */ - size_t len = MIN(languageLen - 1, underscore); + size_t len = MIN(languageLen - 1u, underscore); strncpy(language, env_lang, len); language[len] = '\0'; } diff --git a/winpr/libwinpr/clipboard/synthetic_file.c b/winpr/libwinpr/clipboard/synthetic_file.c index 758f5bb05..070e5bbb2 100644 --- a/winpr/libwinpr/clipboard/synthetic_file.c +++ b/winpr/libwinpr/clipboard/synthetic_file.c @@ -1145,7 +1145,7 @@ UINT synthetic_file_read_close(struct synthetic_file* file, BOOL force) * so avoid caching to prevent running out of available file descriptors */ UINT64 size = 0; file_get_size(file, &size); - if ((file->offset >= size) || force) + if ((file->offset < 0) || ((UINT64)file->offset >= size) || force) { WLog_VRB(TAG, "close file %d", file->fd); if (CloseHandle(file->fd) < 0) diff --git a/winpr/libwinpr/crt/test/TestUnicodeConversion.c b/winpr/libwinpr/crt/test/TestUnicodeConversion.c index f73a72e8c..ae5448b09 100644 --- a/winpr/libwinpr/crt/test/TestUnicodeConversion.c +++ b/winpr/libwinpr/crt/test/TestUnicodeConversion.c @@ -84,7 +84,7 @@ static BOOL compare_utf16_int(const WCHAR* what, size_t buffersize, SSIZE_T rc, const size_t welen = _wcsnlen(test->utf16, test->utf16len); if (buffersize > welen) { - if (rc != welen) + if ((rc < 0) || ((size_t)rc != welen)) { fprintf(stderr, "%s length does not match expectation: %" PRIdz " != %" PRIuz "\n", prefix, rc, welen); @@ -97,10 +97,10 @@ static BOOL compare_utf16_int(const WCHAR* what, size_t buffersize, SSIZE_T rc, return FALSE; } - if ((rc > 0) && (buffersize > rc)) + if ((rc > 0) && (buffersize > (size_t)rc)) { const size_t wlen = _wcsnlen(what, buffersize); - if (wlen > rc) + if ((rc < 0) || (wlen > (size_t)rc)) { fprintf(stderr, "%s length does not match wcslen: %" PRIdz " < %" PRIuz "\n", prefix, rc, wlen); @@ -134,7 +134,7 @@ static BOOL compare_utf8_int(const char* what, size_t buffersize, SSIZE_T rc, SS const size_t slen = strnlen(test->utf8, test->utf8len); if (buffersize > slen) { - if (rc != slen) + if ((rc < 0) || ((size_t)rc != slen)) { fprintf(stderr, "%s length does not match expectation: %" PRIdz " != %" PRIuz "\n", prefix, rc, slen); @@ -147,10 +147,10 @@ static BOOL compare_utf8_int(const char* what, size_t buffersize, SSIZE_T rc, SS return FALSE; } - if ((rc > 0) && (buffersize > rc)) + if ((rc > 0) && (buffersize > (size_t)rc)) { const size_t wlen = strnlen(what, buffersize); - if (wlen != rc) + if (wlen != (size_t)rc) { fprintf(stderr, "%s length does not match strnlen: %" PRIdz " != %" PRIuz "\n", prefix, rc, wlen); @@ -177,7 +177,7 @@ static BOOL test_convert_to_utf16(const testcase_t* test) const SSIZE_T rc2 = ConvertUtf8ToWChar(test->utf8, NULL, 0); const size_t wlen = _wcsnlen(test->utf16, test->utf16len); - if (rc2 != wlen) + if ((rc2 < 0) || ((size_t)rc2 != wlen)) { char prefix[8192] = { 0 }; create_prefix(prefix, ARRAYSIZE(prefix), 0, rc2, -1, test, __FUNCTION__, __LINE__); @@ -204,7 +204,7 @@ static BOOL test_convert_to_utf16_n(const testcase_t* test) const SSIZE_T rc2 = ConvertUtf8NToWChar(test->utf8, test->utf8len, NULL, 0); const size_t wlen = _wcsnlen(test->utf16, test->utf16len); - if (rc2 != wlen) + if ((rc2 < 0) || ((size_t)rc2 != wlen)) { char prefix[8192] = { 0 }; create_prefix(prefix, ARRAYSIZE(prefix), 0, rc2, test->utf8len, test, __FUNCTION__, @@ -241,7 +241,7 @@ static BOOL test_convert_to_utf8(const testcase_t* test) const SSIZE_T rc2 = ConvertWCharToUtf8(test->utf16, NULL, 0); const size_t wlen = strnlen(test->utf8, test->utf8len); - if (rc2 != wlen) + if ((rc2 < 0) || ((size_t)rc2 != wlen)) { char prefix[8192] = { 0 }; create_prefix(prefix, ARRAYSIZE(prefix), 0, rc2, -1, test, __FUNCTION__, __LINE__); @@ -269,7 +269,7 @@ static BOOL test_convert_to_utf8_n(const testcase_t* test) const SSIZE_T rc2 = ConvertWCharNToUtf8(test->utf16, test->utf16len, NULL, 0); const size_t wlen = strnlen(test->utf8, test->utf8len); - if (rc2 != wlen) + if ((rc2 < 0) || ((size_t)rc2 != wlen)) { char prefix[8192] = { 0 }; create_prefix(prefix, ARRAYSIZE(prefix), 0, rc2, test->utf16len, test, __FUNCTION__, diff --git a/winpr/libwinpr/crt/unicode.c b/winpr/libwinpr/crt/unicode.c index ef9ff5e59..31abbcc99 100644 --- a/winpr/libwinpr/crt/unicode.c +++ b/winpr/libwinpr/crt/unicode.c @@ -380,7 +380,7 @@ SSIZE_T ConvertWCharToUtf8(const WCHAR* wstr, char* str, size_t len) WideCharToMultiByte(CP_UTF8, 0, wstr, -1, str, (int)MIN(INT32_MAX, len), NULL, NULL); if (rc <= 0) return rc; - else if (rc == len) + else if ((size_t)rc == len) { if (str && (str[rc - 1] != '\0')) return rc; @@ -407,15 +407,15 @@ SSIZE_T ConvertWCharNToUtf8(const WCHAR* wstr, size_t wlen, char* str, size_t le } const int rc = WideCharToMultiByte(CP_UTF8, 0, wstr, (int)iwlen, str, (int)MIN(INT32_MAX, len), NULL, NULL); - if ((rc <= 0) || ((len > 0) && (rc > len))) + if ((rc <= 0) || ((len > 0) && ((size_t)rc > len))) return -1; else if (!isNullTerminated) { - if (str && (rc < len)) + if (str && ((size_t)rc < len)) str[rc] = '\0'; return rc; } - else if (rc == len) + else if ((size_t)rc == len) { if (str && (str[rc - 1] != '\0')) return rc; diff --git a/winpr/libwinpr/ncrypt/ncrypt_pkcs11.c b/winpr/libwinpr/ncrypt/ncrypt_pkcs11.c index 468f47fdd..2c2d2ffcb 100644 --- a/winpr/libwinpr/ncrypt/ncrypt_pkcs11.c +++ b/winpr/libwinpr/ncrypt/ncrypt_pkcs11.c @@ -623,7 +623,7 @@ static SECURITY_STATUS parseKeyName(LPCWSTR pszKeyName, CK_SLOT_ID* slotId, CK_B if (!pos) return NTE_BAD_KEY; - if (pos - &asciiKeyName[1] > sizeof(CK_SLOT_ID) * 2) + if (pos - &asciiKeyName[1] > sizeof(CK_SLOT_ID) * 2ull) return NTE_BAD_KEY; *slotId = (CK_SLOT_ID)0; diff --git a/winpr/libwinpr/pool/pool.c b/winpr/libwinpr/pool/pool.c index 398ce08f9..a41a6d810 100644 --- a/winpr/libwinpr/pool/pool.c +++ b/winpr/libwinpr/pool/pool.c @@ -219,7 +219,7 @@ BOOL winpr_SetThreadpoolThreadMinimum(PTP_POOL ptpp, DWORD cthrdMic) #endif ptpp->Minimum = cthrdMic; - while (ArrayList_Count(ptpp->Threads) < (INT64)ptpp->Minimum) + while (ArrayList_Count(ptpp->Threads) < ptpp->Minimum) { if (!(thread = CreateThread(NULL, 0, thread_pool_work_func, (void*)ptpp, 0, NULL))) { diff --git a/winpr/libwinpr/sspi/NTLM/ntlm.c b/winpr/libwinpr/sspi/NTLM/ntlm.c index dd150b978..36a617715 100644 --- a/winpr/libwinpr/sspi/NTLM/ntlm.c +++ b/winpr/libwinpr/sspi/NTLM/ntlm.c @@ -1203,7 +1203,7 @@ static SECURITY_STATUS SEC_ENTRY ntlm_MakeSignature(PCtxtHandle phContext, ULONG context = sspi_SecureHandleGetLowerPointer(phContext); - for (int i = 0; i < pMessage->cBuffers; i++) + for (ULONG i = 0; i < pMessage->cBuffers; i++) { if (pMessage->pBuffers[i].BufferType == SECBUFFER_DATA) data_buffer = &pMessage->pBuffers[i]; @@ -1254,7 +1254,7 @@ static SECURITY_STATUS SEC_ENTRY ntlm_VerifySignature(PCtxtHandle phContext, if (!context) return SEC_E_INVALID_HANDLE; - for (int i = 0; i < pMessage->cBuffers; i++) + for (ULONG i = 0; i < pMessage->cBuffers; i++) { if (pMessage->pBuffers[i].BufferType == SECBUFFER_DATA) data_buffer = &pMessage->pBuffers[i]; diff --git a/winpr/libwinpr/sspi/NTLM/ntlm_compute.c b/winpr/libwinpr/sspi/NTLM/ntlm_compute.c index 98b4a574e..eb06f51cb 100644 --- a/winpr/libwinpr/sspi/NTLM/ntlm_compute.c +++ b/winpr/libwinpr/sspi/NTLM/ntlm_compute.c @@ -319,7 +319,6 @@ fail: static int ntlm_convert_password_hash(NTLM_CONTEXT* context, BYTE* hash) { - int i; char PasswordHash[32] = { 0 }; INT64 PasswordHashLength = 0; SSPI_CREDENTIALS* credentials = NULL; @@ -333,14 +332,14 @@ static int ntlm_convert_password_hash(NTLM_CONTEXT* context, BYTE* hash) PasswordHashLength = credentials->identity.PasswordLength - SSPI_CREDENTIALS_HASH_LENGTH_OFFSET; WINPR_ASSERT(PasswordHashLength >= 0); - WINPR_ASSERT(PasswordHashLength < ARRAYSIZE(PasswordHash)); + WINPR_ASSERT((size_t)PasswordHashLength < ARRAYSIZE(PasswordHash)); if (ConvertWCharNToUtf8(credentials->identity.Password, PasswordHashLength, PasswordHash, ARRAYSIZE(PasswordHash)) <= 0) return -1; CharUpperBuffA(PasswordHash, (DWORD)PasswordHashLength); - for (i = 0; i < ARRAYSIZE(PasswordHash); i += 2) + for (size_t i = 0; i < ARRAYSIZE(PasswordHash); i += 2) { BYTE hn = (BYTE)(PasswordHash[i] > '9' ? PasswordHash[i] - 'A' + 10 : PasswordHash[i] - '0');