Fixed compilation warnings and typos

This commit is contained in:
Armin Novak 2021-06-16 14:43:07 +02:00 committed by akallabeth
parent 3cf90a4572
commit 1af7ef2f1b
27 changed files with 171 additions and 107 deletions

View File

@ -85,14 +85,14 @@ extern "C"
{
#endif
WINPR_API int winpr_bitmap_write(const char* filename, const BYTE* data, int width, int height,
int bpp);
WINPR_API BYTE* winpr_bitmap_construct_header(int width, int height, int bpp);
WINPR_API int winpr_bitmap_write(const char* filename, const BYTE* data, size_t width,
size_t height, size_t bpp);
WINPR_API BYTE* winpr_bitmap_construct_header(size_t width, size_t height, size_t bpp);
WINPR_API int winpr_image_write(wImage* image, const char* filename);
WINPR_API int winpr_image_read(wImage* image, const char* filename);
WINPR_API int winpr_image_read_buffer(wImage* image, const BYTE* buffer, int size);
WINPR_API int winpr_image_read_buffer(wImage* image, const BYTE* buffer, size_t size);
WINPR_API wImage* winpr_image_new(void);
WINPR_API void winpr_image_free(wImage* image, BOOL bFreeBuffer);

View File

@ -176,7 +176,12 @@ static void* clipboard_synthesize_utf8_string(wClipboard* clipboard, UINT32 form
return NULL;
size = ConvertLineEndingToLF(pDstData, size);
*pSize = size;
if (size < 0)
{
free(pDstData);
return NULL;
}
*pSize = (UINT32)size;
return pDstData;
}
else if ((formatId == CF_TEXT) || (formatId == CF_OEMTEXT) ||
@ -184,6 +189,7 @@ static void* clipboard_synthesize_utf8_string(wClipboard* clipboard, UINT32 form
(formatId == ClipboardGetFormatId(clipboard, "TEXT")) ||
(formatId == ClipboardGetFormatId(clipboard, "STRING")))
{
int rc;
size = (INT64)*pSize;
pDstData = (char*)malloc(size);
@ -191,8 +197,13 @@ static void* clipboard_synthesize_utf8_string(wClipboard* clipboard, UINT32 form
return NULL;
CopyMemory(pDstData, data, size);
size = ConvertLineEndingToLF((char*)pDstData, size);
*pSize = size;
rc = ConvertLineEndingToLF((char*)pDstData, (int)size);
if (rc < 0)
{
free(pDstData);
return NULL;
}
*pSize = (UINT32)rc;
return pDstData;
}
@ -336,17 +347,20 @@ static void* clipboard_synthesize_html_format(wClipboard* clipboard, UINT32 form
if (SrcSize > 2)
{
if (SrcSize > INT_MAX)
return NULL;
CopyMemory(bom, data, 2);
if ((bom[0] == 0xFE) && (bom[1] == 0xFF))
{
ByteSwapUnicode((WCHAR*)data, SrcSize / 2);
ByteSwapUnicode((WCHAR*)data, (int)(SrcSize / 2));
}
if ((bom[0] == 0xFF) && (bom[1] == 0xFE))
{
wstr = (WCHAR*)&((BYTE*)data)[2];
ConvertFromUnicode(CP_UTF8, 0, wstr, (SrcSize - 2) / 2, &pSrcData, 0, NULL, NULL);
ConvertFromUnicode(CP_UTF8, 0, wstr, (int)(SrcSize - 2) / 2, &pSrcData, 0, NULL,
NULL);
}
}
@ -423,12 +437,12 @@ static void* clipboard_synthesize_text_html(wClipboard* clipboard, UINT32 format
char* str;
char* begStr;
char* endStr;
INT64 SrcSize;
long DstSize = -1;
BYTE* pDstData = NULL;
if (formatId == ClipboardGetFormatId(clipboard, "HTML Format"))
{
INT64 SrcSize;
str = (char*)data;
SrcSize = (INT64)*pSize;
begStr = strstr(str, "StartHTML:");
@ -450,7 +464,7 @@ static void* clipboard_synthesize_text_html(wClipboard* clipboard, UINT32 format
return NULL;
DstSize = end - beg;
pDstData = (BYTE*)malloc(SrcSize - beg + 1);
pDstData = (BYTE*)malloc((size_t)(SrcSize - beg + 1));
if (!pDstData)
return NULL;

View File

@ -1425,7 +1425,7 @@ BOOL CommCloseHandle(HANDLE handle)
return FALSE;
}
if (pComm->PendingEvents & SERIAL_EV_FREERDP_WAITING)
if (pComm->PendingEvents & SERIAL_EV_WINPR_WAITING)
{
ULONG WaitMask = 0;
DWORD BytesReturned = 0;

View File

@ -88,11 +88,11 @@ typedef struct winpr_comm WINPR_COMM;
#define SERIAL_EV_RX80FULL 0x0400
#define SERIAL_EV_EVENT1 0x0800
#define SERIAL_EV_EVENT2 0x1000
#define SERIAL_EV_FREERDP_WAITING 0x4000 /* bit today unused by other SERIAL_EV_* */
#define SERIAL_EV_FREERDP_STOP 0x8000 /* bit today unused by other SERIAL_EV_* */
#define SERIAL_EV_WINPR_WAITING 0x4000 /* bit today unused by other SERIAL_EV_* */
#define SERIAL_EV_WINPR_STOP 0x8000 /* bit today unused by other SERIAL_EV_* */
#define FREERDP_PURGE_TXABORT 0x00000001 /* abort pending transmission */
#define FREERDP_PURGE_RXABORT 0x00000002 /* abort pending reception */
#define WINPR_PURGE_TXABORT 0x00000001 /* abort pending transmission */
#define WINPR_PURGE_RXABORT 0x00000002 /* abort pending reception */
void CommLog_Print(DWORD wlog_level, ...);

View File

@ -297,13 +297,13 @@ BOOL CommReadFile(HANDLE hDevice, LPVOID lpBuffer, DWORD nNumberOfBytesToRead,
WINPR_ASSERT(errno == EAGAIN);
}
if (event == FREERDP_PURGE_RXABORT)
if (event == WINPR_PURGE_RXABORT)
{
SetLastError(ERROR_CANCELLED);
goto return_false;
}
WINPR_ASSERT(event == FREERDP_PURGE_RXABORT); /* no other expected event so far */
WINPR_ASSERT(event == WINPR_PURGE_RXABORT); /* no other expected event so far */
}
if (FD_ISSET(pComm->fd_read, &read_set))
@ -352,7 +352,7 @@ BOOL CommReadFile(HANDLE hDevice, LPVOID lpBuffer, DWORD nNumberOfBytesToRead,
*lpNumberOfBytesRead = nbRead;
EnterCriticalSection(&pComm->EventsLock);
if (pComm->PendingEvents & SERIAL_EV_FREERDP_WAITING)
if (pComm->PendingEvents & SERIAL_EV_WINPR_WAITING)
{
if (pComm->eventChar != '\0' && memchr(lpBuffer, pComm->eventChar, nbRead))
pComm->PendingEvents |= SERIAL_EV_RXCHAR;
@ -498,13 +498,13 @@ BOOL CommWriteFile(HANDLE hDevice, LPCVOID lpBuffer, DWORD nNumberOfBytesToWrite
WINPR_ASSERT(errno == EAGAIN);
}
if (event == FREERDP_PURGE_TXABORT)
if (event == WINPR_PURGE_TXABORT)
{
SetLastError(ERROR_CANCELLED);
goto return_false;
}
WINPR_ASSERT(event == FREERDP_PURGE_TXABORT); /* no other expected event so far */
WINPR_ASSERT(event == WINPR_PURGE_TXABORT); /* no other expected event so far */
}
/* write_set */

View File

@ -1035,16 +1035,16 @@ static BOOL _set_wait_mask(WINPR_COMM* pComm, const ULONG* pWaitMask)
* http://msdn.microsoft.com/en-us/library/ff546805%28v=vs.85%29.aspx
*/
if (pComm->PendingEvents & SERIAL_EV_FREERDP_WAITING)
if (pComm->PendingEvents & SERIAL_EV_WINPR_WAITING)
{
/* FIXME: any doubt on reading PendingEvents out of a critical section? */
EnterCriticalSection(&pComm->EventsLock);
pComm->PendingEvents |= SERIAL_EV_FREERDP_STOP;
pComm->PendingEvents |= SERIAL_EV_WINPR_STOP;
LeaveCriticalSection(&pComm->EventsLock);
/* waiting the end of the pending _wait_on_mask() */
while (pComm->PendingEvents & SERIAL_EV_FREERDP_WAITING)
while (pComm->PendingEvents & SERIAL_EV_WINPR_WAITING)
Sleep(10); /* 10ms */
}
@ -1146,7 +1146,7 @@ static BOOL _purge(WINPR_COMM* pComm, const ULONG* pPurgeMask)
{
/* Purges all write (IRP_MJ_WRITE) requests. */
if (eventfd_write(pComm->fd_write_event, FREERDP_PURGE_TXABORT) < 0)
if (eventfd_write(pComm->fd_write_event, WINPR_PURGE_TXABORT) < 0)
{
if (errno != EAGAIN)
{
@ -1162,7 +1162,7 @@ static BOOL _purge(WINPR_COMM* pComm, const ULONG* pPurgeMask)
{
/* Purges all read (IRP_MJ_READ) requests. */
if (eventfd_write(pComm->fd_read_event, FREERDP_PURGE_RXABORT) < 0)
if (eventfd_write(pComm->fd_read_event, WINPR_PURGE_RXABORT) < 0)
{
if (errno != EAGAIN)
{
@ -1401,7 +1401,7 @@ static BOOL _wait_on_mask(WINPR_COMM* pComm, ULONG* pOutputMask)
WINPR_ASSERT(*pOutputMask == 0);
EnterCriticalSection(&pComm->EventsLock);
pComm->PendingEvents |= SERIAL_EV_FREERDP_WAITING;
pComm->PendingEvents |= SERIAL_EV_WINPR_WAITING;
LeaveCriticalSection(&pComm->EventsLock);
while (TRUE)
@ -1410,7 +1410,7 @@ static BOOL _wait_on_mask(WINPR_COMM* pComm, ULONG* pOutputMask)
if (!_refresh_PendingEvents(pComm))
{
EnterCriticalSection(&pComm->EventsLock);
pComm->PendingEvents &= ~SERIAL_EV_FREERDP_WAITING;
pComm->PendingEvents &= ~SERIAL_EV_WINPR_WAITING;
LeaveCriticalSection(&pComm->EventsLock);
return FALSE;
}
@ -1418,9 +1418,9 @@ static BOOL _wait_on_mask(WINPR_COMM* pComm, ULONG* pOutputMask)
/* NB: ensure to leave the critical section before to return */
EnterCriticalSection(&pComm->EventsLock);
if (pComm->PendingEvents & SERIAL_EV_FREERDP_STOP)
if (pComm->PendingEvents & SERIAL_EV_WINPR_STOP)
{
pComm->PendingEvents &= ~SERIAL_EV_FREERDP_STOP;
pComm->PendingEvents &= ~SERIAL_EV_WINPR_STOP;
/* pOutputMask must remain empty but should
* not have been modified.
@ -1429,7 +1429,7 @@ static BOOL _wait_on_mask(WINPR_COMM* pComm, ULONG* pOutputMask)
*/
WINPR_ASSERT(*pOutputMask == 0);
pComm->PendingEvents &= ~SERIAL_EV_FREERDP_WAITING;
pComm->PendingEvents &= ~SERIAL_EV_WINPR_WAITING;
LeaveCriticalSection(&pComm->EventsLock);
return TRUE;
}
@ -1455,7 +1455,7 @@ static BOOL _wait_on_mask(WINPR_COMM* pComm, ULONG* pOutputMask)
/* at least an event occurred */
EnterCriticalSection(&pComm->EventsLock);
pComm->PendingEvents &= ~SERIAL_EV_FREERDP_WAITING;
pComm->PendingEvents &= ~SERIAL_EV_WINPR_WAITING;
LeaveCriticalSection(&pComm->EventsLock);
return TRUE;
}

View File

@ -41,8 +41,10 @@
#include "utf.h"
#include <winpr/endian.h>
#if __GNUC__
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wimplicit-fallthrough"
#endif
static const int halfShift = 10; /* used for shifting by 10 bits */
static const DWORD halfBase = 0x0010000UL;
@ -645,9 +647,9 @@ ConversionResult ConvertUTF8toUTF16(const BYTE** sourceStart, const BYTE* source
if (!computeLength)
{
WCHAR wchar;
wchar = (ch >> halfShift) + UNI_SUR_HIGH_START;
wchar = (WCHAR)((ch >> halfShift) + UNI_SUR_HIGH_START);
Data_Write_UINT16(&(*targetStart)[target++], wchar);
wchar = (ch & halfMask) + UNI_SUR_LOW_START;
wchar = (WCHAR)((ch & halfMask) + UNI_SUR_LOW_START);
Data_Write_UINT16(&(*targetStart)[target++], wchar);
}
else
@ -876,4 +878,6 @@ ConversionResult ConvertUTF8toUTF32(const BYTE** sourceStart, const BYTE* source
similarly unrolled loops.
--------------------------------------------------------------------- */
#if __GNUC__
#pragma GCC diagnostic pop
#endif

View File

@ -79,8 +79,8 @@
------------------------------------------------------------------------ */
#ifndef FREERDP_UNICODE_CONVERT_UTF_H
#define FREERDP_UNICODE_CONVERT_UTF_H
#ifndef WINPR_UNICODE_CONVERT_UTF_H
#define WINPR_UNICODE_CONVERT_UTF_H
#include <winpr/wtypes.h>
@ -147,4 +147,4 @@ extern "C"
}
#endif
#endif /* FREERDP_UNICODE_CONVERT_UTF_H */
#endif /* WINPR_UNICODE_CONVERT_UTF_H */

View File

@ -55,6 +55,8 @@ static WINPR_RC4_CTX* winpr_RC4_New_Internal(const BYTE* key, size_t keylen, BOO
#if defined(WITH_OPENSSL)
if (keylen > INT_MAX)
return NULL;
if (!(ctx = (WINPR_RC4_CTX*)EVP_CIPHER_CTX_new()))
return NULL;
@ -72,7 +74,7 @@ static WINPR_RC4_CTX* winpr_RC4_New_Internal(const BYTE* key, size_t keylen, BOO
EVP_CIPHER_CTX_set_flags((EVP_CIPHER_CTX*)ctx, EVP_CIPH_FLAG_NON_FIPS_ALLOW);
#endif
EVP_CIPHER_CTX_set_key_length((EVP_CIPHER_CTX*)ctx, keylen);
EVP_CIPHER_CTX_set_key_length((EVP_CIPHER_CTX*)ctx, (int)keylen);
EVP_EncryptInit_ex((EVP_CIPHER_CTX*)ctx, NULL, NULL, key, NULL);
#elif defined(WITH_MBEDTLS) && defined(MBEDTLS_ARC4_C)
@ -99,7 +101,10 @@ BOOL winpr_RC4_Update(WINPR_RC4_CTX* ctx, size_t length, const BYTE* input, BYTE
{
#if defined(WITH_OPENSSL)
int outputLength;
EVP_CipherUpdate((EVP_CIPHER_CTX*)ctx, output, &outputLength, input, length);
if (length > INT_MAX)
return FALSE;
EVP_CipherUpdate((EVP_CIPHER_CTX*)ctx, output, &outputLength, input, (int)length);
return TRUE;
#elif defined(WITH_MBEDTLS) && defined(MBEDTLS_ARC4_C)
@ -619,7 +624,10 @@ BOOL winpr_Cipher_Update(WINPR_CIPHER_CTX* ctx, const BYTE* input, size_t ilen,
#if defined(WITH_OPENSSL)
int outl = (int)*olen;
if (EVP_CipherUpdate((EVP_CIPHER_CTX*)ctx, output, &outl, input, ilen) == 1)
if (ilen > INT_MAX)
return FALSE;
if (EVP_CipherUpdate((EVP_CIPHER_CTX*)ctx, output, &outl, input, (int)ilen) == 1)
{
*olen = (size_t)outl;
return TRUE;

View File

@ -185,12 +185,14 @@ BOOL winpr_HMAC_Init(WINPR_HMAC_CTX* ctx, WINPR_MD_TYPE md, const BYTE* key, siz
if (!evp || !hmac)
return FALSE;
if (keylen > INT_MAX)
return FALSE;
#if (OPENSSL_VERSION_NUMBER < 0x10000000L) || defined(LIBRESSL_VERSION_NUMBER)
HMAC_Init_ex(hmac, key, keylen, evp, NULL); /* no return value on OpenSSL 0.9.x */
HMAC_Init_ex(hmac, key, (int)keylen, evp, NULL); /* no return value on OpenSSL 0.9.x */
return TRUE;
#else
if (HMAC_Init_ex(hmac, key, keylen, evp, NULL) == 1)
if (HMAC_Init_ex(hmac, key, (int)keylen, evp, NULL) == 1)
return TRUE;
#endif

View File

@ -39,7 +39,9 @@
int winpr_RAND(BYTE* output, size_t len)
{
#if defined(WITH_OPENSSL)
if (RAND_bytes(output, len) != 1)
if (len > INT_MAX)
return -1;
if (RAND_bytes(output, (int)len) != 1)
return -1;
#elif defined(WITH_MBEDTLS) && defined(MBEDTLS_HAVEGE_C)
mbedtls_havege_state hs;

View File

@ -546,13 +546,15 @@ DWORD GetEnvironmentVariableEBA(LPCSTR envBlock, LPCSTR lpName, LPSTR lpBuffer,
return 0;
vLength = strlen(env);
if (vLength >= UINT32_MAX)
return 0;
if ((vLength + 1 > nSize) || (!lpBuffer))
return vLength + 1;
return (DWORD)vLength + 1;
CopyMemory(lpBuffer, env, vLength + 1);
return vLength;
return (DWORD)vLength;
}
BOOL SetEnvironmentVariableEBA(LPSTR* envBlock, LPCSTR lpName, LPCSTR lpValue)

View File

@ -24,4 +24,4 @@
#define WINPR_TAG(tag) "com.winpr." tag
#endif /* FREERDP_UTILS_DEBUG_H */
#endif /* WINPR_UTILS_DEBUG_H */

View File

@ -81,12 +81,12 @@ static void reg_load_start(Reg* reg)
if (file_size < 1)
return;
reg->buffer = (char*)malloc(file_size + 2);
reg->buffer = (char*)malloc((size_t)file_size + 2);
if (!reg->buffer)
return;
if (fread(reg->buffer, file_size, 1, reg->fp) != 1)
if (fread(reg->buffer, (size_t)file_size, 1, reg->fp) != 1)
{
free(reg->buffer);
reg->buffer = NULL;

View File

@ -18,8 +18,8 @@
* limitations under the License.
*/
#ifndef FREERDP_SSPI_KERBEROS_PRIVATE_H
#define FREERDP_SSPI_KERBEROS_PRIVATE_H
#ifndef WINPR_SSPI_KERBEROS_PRIVATE_H
#define WINPR_SSPI_KERBEROS_PRIVATE_H
#include <winpr/sspi.h>
#include <winpr/windows.h>
@ -34,4 +34,4 @@
typedef struct _KRB_CONTEXT KRB_CONTEXT;
#endif /* FREERDP_SSPI_KERBEROS_PRIVATE_H */
#endif /* WINPR_SSPI_KERBEROS_PRIVATE_H */

View File

@ -287,4 +287,4 @@ SECURITY_STATUS ntlm_computeMicValue(NTLM_CONTEXT* ntlm, SecBuffer* micvalue);
#define WITH_DEBUG_NTLM
#endif
#endif /* FREERDP_SSPI_NTLM_PRIVATE_H */
#endif /* WINPR_SSPI_NTLM_PRIVATE_H */

View File

@ -19,8 +19,8 @@
* limitations under the License.
*/
#ifndef FREERDP_SSPI_GSS_PRIVATE_H
#define FREERDP_SSPI_GSS_PRIVATE_H
#ifndef WINPR_SSPI_GSS_PRIVATE_H
#define WINPR_SSPI_GSS_PRIVATE_H
#include <winpr/crt.h>
#include <winpr/sspi.h>
@ -677,4 +677,4 @@ extern "C"
}
#endif
#endif /* FREERDP_SSPI_GSS_PRIVATE_H */
#endif /* WINPR_SSPI_GSS_PRIVATE_H */

View File

@ -5,7 +5,7 @@
#include <winpr/synch.h>
#include <winpr/thread.h>
#define THREADS 24
#define THREADS 8
static DWORD WINAPI test_thread(LPVOID arg)
{
@ -22,7 +22,7 @@ static int start_threads(DWORD count, HANDLE* threads)
for (i = 0; i < count; i++)
{
threads[i] = CreateThread(NULL, 0, test_thread, NULL, 0, NULL);
threads[i] = CreateThread(NULL, 0, test_thread, NULL, CREATE_SUSPENDED, NULL);
if (!threads[i])
{
@ -31,6 +31,8 @@ static int start_threads(DWORD count, HANDLE* threads)
}
}
for (i = 0; i < count; i++)
ResumeThread(threads[i]);
return 0;
}
@ -135,7 +137,7 @@ static BOOL TestWaitOneTimeout(void)
return FALSE;
}
ret = WaitForMultipleObjects(THREADS, threads, FALSE, 10);
ret = WaitForMultipleObjects(THREADS, threads, FALSE, 1);
if (ret != WAIT_TIMEOUT)
{
fprintf(stderr, "%s: WaitForMultipleObjects timeout 50 failed, ret=%d\n", __FUNCTION__,

View File

@ -283,12 +283,20 @@ static BOOL _CreateProcessExA(HANDLE hToken, DWORD dwLogonFlags, LPCSTR lpApplic
}
if (token->UserId)
setuid((uid_t)token->UserId);
{
int rc = setuid((uid_t)token->UserId);
if (rc != 0)
goto finish;
}
}
/* TODO: add better cwd handling and error checking */
if (lpCurrentDirectory && strlen(lpCurrentDirectory) > 0)
chdir(lpCurrentDirectory);
{
int rc = chdir(lpCurrentDirectory);
if (rc != 0)
goto finish;
}
if (execve(filename, pArgs, envp) < 0)
{

View File

@ -92,7 +92,7 @@ void PubSub_AddEventTypes(wPubSub* pubSub, wEventType* events, size_t count)
while (pubSub->count + count >= pubSub->size)
{
int new_size;
size_t new_size;
wEventType* new_event;
new_size = pubSub->size * 2;

View File

@ -107,21 +107,23 @@ static void StreamPool_ShiftUsed(wStreamPool* pool, size_t index, INT64 count)
WINPR_ASSERT(pool);
if (count > 0)
{
StreamPool_EnsureCapacity(pool, (size_t)count, TRUE);
const size_t pcount = (size_t)count;
StreamPool_EnsureCapacity(pool, pcount, TRUE);
MoveMemory(&pool->uArray[index + count], &pool->uArray[index],
MoveMemory(&pool->uArray[index + pcount], &pool->uArray[index],
(pool->uSize - index) * sizeof(wStream*));
pool->uSize += count;
pool->uSize += pcount;
}
else if (count < 0)
{
if (pool->uSize - index + count > 0)
const size_t pcount = (size_t)-count;
if ((pool->uSize - index - pcount) > 0)
{
MoveMemory(&pool->uArray[index], &pool->uArray[index - count],
(pool->uSize - index + count) * sizeof(wStream*));
MoveMemory(&pool->uArray[index], &pool->uArray[index + pcount],
(pool->uSize - index - pcount) * sizeof(wStream*));
}
pool->uSize += count;
pool->uSize -= pcount;
}
}
@ -163,20 +165,24 @@ static void StreamPool_ShiftAvailable(wStreamPool* pool, size_t index, INT64 cou
WINPR_ASSERT(pool);
if (count > 0)
{
StreamPool_EnsureCapacity(pool, (size_t)count, FALSE);
MoveMemory(&pool->aArray[index + count], &pool->aArray[index],
const size_t pcount = (size_t)count;
StreamPool_EnsureCapacity(pool, pcount, FALSE);
MoveMemory(&pool->aArray[index + pcount], &pool->aArray[index],
(pool->aSize - index) * sizeof(wStream*));
pool->aSize += count;
pool->aSize += pcount;
}
else if (count < 0)
{
if (pool->aSize - index + count > 0)
const size_t pcount = (size_t)-count;
if ((pool->aSize - index - pcount) > 0)
{
MoveMemory(&pool->aArray[index], &pool->aArray[index - count],
(pool->aSize - index + count) * sizeof(wStream*));
MoveMemory(&pool->aArray[index], &pool->aArray[index + pcount],
(pool->aSize - index - pcount) * sizeof(wStream*));
}
pool->aSize += count;
pool->aSize -= pcount;
}
}

View File

@ -45,6 +45,7 @@
#include <winpr/wlog.h>
#include <winpr/debug.h>
#define MIN(a, b) (a) < (b) ? (a) : (b)
#define TAG "com.winpr.utils.debug"
#define LOGT(...) \
do \
@ -434,7 +435,7 @@ char** winpr_backtrace_symbols(void* buffer, size_t* used)
}
line->SizeOfStruct = sizeof(IMAGEHLP_LINE64);
symbol->MaxNameLen = line_len;
symbol->MaxNameLen = (ULONG)line_len;
symbol->SizeOfStruct = sizeof(SYMBOL_INFO);
/* Set the pointers in the allocated buffer's initial array section */
@ -494,7 +495,7 @@ void winpr_backtrace_symbols_fd(void* buffer, int fd)
if (lines)
{
for (i = 0; i < used; i++)
write(fd, lines[i], strlen(lines[i]));
write(fd, lines[i], (unsigned)strnlen(lines[i], UINT32_MAX));
}
}
#else
@ -553,11 +554,11 @@ char* winpr_strerror(DWORD dw, char* dmsg, size_t size)
if (rc)
{
#if defined(UNICODE)
WideCharToMultiByte(CP_ACP, 0, msg, rc, dmsg, size - 1, NULL, NULL);
WideCharToMultiByte(CP_ACP, 0, msg, rc, dmsg, (int)MIN(size - 1, INT_MAX), NULL, NULL);
#else /* defined(UNICODE) */
memcpy(dmsg, msg, min(rc, size - 1));
memcpy(dmsg, msg, MIN(rc, size - 1));
#endif /* defined(UNICODE) */
dmsg[min(rc, size - 1)] = 0;
dmsg[MIN(rc, size - 1)] = 0;
#ifdef FORMAT_MESSAGE_ALLOCATE_BUFFER
LocalFree(msg);
#else

View File

@ -101,12 +101,14 @@ static BOOL readBitmapInfoHeader(wStream* s, WINPR_BITMAP_INFO_HEADER* bi)
return TRUE;
}
BYTE* winpr_bitmap_construct_header(int width, int height, int bpp)
BYTE* winpr_bitmap_construct_header(size_t width, size_t height, size_t bpp)
{
WINPR_BITMAP_FILE_HEADER bf;
WINPR_BITMAP_INFO_HEADER bi;
wStream s;
BYTE* buffer = NULL;
if ((width > INT32_MAX) || (height > INT32_MAX) || (bpp > UINT16_MAX))
return NULL;
buffer = malloc(WINPR_IMAGE_BMP_HEADER_LEN);
if (!buffer)
@ -118,19 +120,19 @@ BYTE* winpr_bitmap_construct_header(int width, int height, int bpp)
bf.bfType[1] = 'M';
bf.bfReserved1 = 0;
bf.bfReserved2 = 0;
bf.bfOffBits = sizeof(WINPR_BITMAP_FILE_HEADER) + sizeof(WINPR_BITMAP_INFO_HEADER);
bi.biSizeImage = width * height * (bpp / 8);
bf.bfOffBits = (UINT32)sizeof(WINPR_BITMAP_FILE_HEADER) + sizeof(WINPR_BITMAP_INFO_HEADER);
bi.biSizeImage = (UINT32)width * height * (bpp / 8);
bf.bfSize = bf.bfOffBits + bi.biSizeImage;
bi.biWidth = width;
bi.biHeight = -1 * height;
bi.biWidth = (INT32)width;
bi.biHeight = -1 * (INT32)height;
bi.biPlanes = 1;
bi.biBitCount = bpp;
bi.biBitCount = (UINT16)bpp;
bi.biCompression = 0;
bi.biXPelsPerMeter = width;
bi.biYPelsPerMeter = height;
bi.biXPelsPerMeter = (INT32)width;
bi.biYPelsPerMeter = (INT32)height;
bi.biClrUsed = 0;
bi.biClrImportant = 0;
bi.biSize = sizeof(WINPR_BITMAP_INFO_HEADER);
bi.biSize = (UINT32)sizeof(WINPR_BITMAP_INFO_HEADER);
if (!writeBitmapFileHeader(&s, &bf))
goto fail;
@ -147,11 +149,12 @@ fail:
* Refer to "Compressed Image File Formats: JPEG, PNG, GIF, XBM, BMP" book
*/
int winpr_bitmap_write(const char* filename, const BYTE* data, int width, int height, int bpp)
int winpr_bitmap_write(const char* filename, const BYTE* data, size_t width, size_t height,
size_t bpp)
{
FILE* fp;
BYTE* bmp_header = NULL;
UINT32 img_size = width * height * (bpp / 8);
size_t img_size = width * height * (bpp / 8);
int ret = -1;
fp = winpr_fopen(filename, "w+b");
@ -188,7 +191,7 @@ int winpr_image_write(wImage* image, const char* filename)
}
else
{
int lodepng_status;
unsigned lodepng_status;
lodepng_status = lodepng_encode32_file(filename, image->data, image->width, image->height);
status = (lodepng_status) ? -1 : 1;
}
@ -206,18 +209,21 @@ static int winpr_image_png_read_fp(wImage* image, FILE* fp)
_fseeki64(fp, 0, SEEK_END);
size = _ftelli64(fp);
_fseeki64(fp, 0, SEEK_SET);
data = (BYTE*)malloc(size);
if (size < 0)
return -1;
data = (BYTE*)malloc((size_t)size);
if (!data)
return -1;
if (fread((void*)data, size, 1, fp) != 1)
if (fread((void*)data, (size_t)size, 1, fp) != 1)
{
free(data);
return -1;
}
lodepng_status = lodepng_decode32(&(image->data), &width, &height, data, size);
lodepng_status = lodepng_decode32(&(image->data), &width, &height, data, (size_t)size);
free(data);
if (lodepng_status)
@ -446,7 +452,7 @@ int winpr_image_read(wImage* image, const char* filename)
return status;
}
int winpr_image_read_buffer(wImage* image, const BYTE* buffer, int size)
int winpr_image_read_buffer(wImage* image, const BYTE* buffer, size_t size)
{
BYTE sig[8];
int status = -1;

View File

@ -137,17 +137,17 @@ static BOOL SamLookupStart(WINPR_SAM* sam)
return FALSE;
sam->context = NULL;
sam->buffer = (char*)calloc(fileSize + 2, 1);
sam->buffer = (char*)calloc((size_t)fileSize + 2, 1);
if (!sam->buffer)
return FALSE;
readSize = fread(sam->buffer, fileSize, 1, sam->fp);
readSize = fread(sam->buffer, (size_t)fileSize, 1, sam->fp);
if (!readSize)
{
if (!ferror(sam->fp))
readSize = fileSize;
readSize = (size_t)fileSize;
}
if (readSize < 1)
@ -337,13 +337,14 @@ WINPR_SAM_ENTRY* SamLookupUserW(WINPR_SAM* sam, LPCWSTR User, UINT32 UserLength,
WINPR_SAM_ENTRY* entry = NULL;
char* utfUser = NULL;
char* utfDomain = NULL;
const size_t UserCharLength = UserLength / sizeof(WCHAR);
const size_t DomainCharLength = DomainLength / sizeof(WCHAR);
rc = ConvertFromUnicode(CP_UTF8, 0, User, UserCharLength, &utfUser, 0, NULL, NULL);
const UINT32 UserCharLength = UserLength / sizeof(WCHAR);
const UINT32 DomainCharLength = DomainLength / sizeof(WCHAR);
if ((UserCharLength > INT_MAX) || (DomainCharLength > INT_MAX))
goto fail;
rc = ConvertFromUnicode(CP_UTF8, 0, User, (int)UserCharLength, &utfUser, 0, NULL, NULL);
if ((rc < 0) || ((size_t)rc != UserCharLength))
goto fail;
rc = ConvertFromUnicode(CP_UTF8, 0, Domain, DomainCharLength, &utfDomain, 0, NULL, NULL);
rc = ConvertFromUnicode(CP_UTF8, 0, Domain, (int)DomainCharLength, &utfDomain, 0, NULL, NULL);
if ((rc < 0) || ((size_t)rc != DomainCharLength))
goto fail;
entry = SamLookupUserA(sam, utfUser, UserCharLength, utfDomain, DomainCharLength);

View File

@ -1368,8 +1368,10 @@ TRIO_PRIVATE double TrioLogarithmBase TRIO_ARGS1((base), int base)
* Description:
* Parse the qualifiers of a potential conversion specifier
*/
#if __GNUC__
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wimplicit-fallthrough"
#endif
TRIO_PRIVATE int TrioParseQualifiers TRIO_ARGS4((type, format, offset, parameter), int type,
TRIO_CONST char* format, int offset,
trio_parameter_t* parameter)
@ -1659,7 +1661,9 @@ TRIO_PRIVATE int TrioParseQualifiers TRIO_ARGS4((type, format, offset, parameter
return 0;
}
#if __GNUC__
#pragma GCC diagnostic pop
#endif
/*************************************************************************
* TrioParseSpecifier
@ -1667,8 +1671,10 @@ TRIO_PRIVATE int TrioParseQualifiers TRIO_ARGS4((type, format, offset, parameter
* Description:
* Parse the specifier part of a potential conversion specifier
*/
#if __GNUC__
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wimplicit-fallthrough"
#endif
TRIO_PRIVATE int TrioParseSpecifier TRIO_ARGS4((type, format, offset, parameter), int type,
TRIO_CONST char* format, int offset,
trio_parameter_t* parameter)
@ -1906,7 +1912,9 @@ TRIO_PRIVATE int TrioParseSpecifier TRIO_ARGS4((type, format, offset, parameter)
return 0;
}
#if __GNUC__
#pragma GCC diagnostic pop
#endif
/*************************************************************************
* TrioParse

View File

@ -222,7 +222,7 @@ wPcap* Pcap_Open(char* name, BOOL write)
{
if (_fseeki64(pcap->fp, 0, SEEK_END) < 0)
goto out_fail;
pcap->file_size = _ftelli64(pcap->fp);
pcap->file_size = (SSIZE_T)_ftelli64(pcap->fp);
if (pcap->file_size < 0)
goto out_fail;
if (_fseeki64(pcap->fp, 0, SEEK_SET) < 0)

View File

@ -60,8 +60,8 @@ struct _wPcap
FILE* fp;
char* name;
BOOL write;
int file_size;
int record_count;
SSIZE_T file_size;
size_t record_count;
wPcapHeader header;
wPcapRecord* head;
wPcapRecord* tail;