Merge pull request #5230 from akallabeth/sign_compare_fixes

Sign compare fixes
This commit is contained in:
Martin Fleisz 2019-02-08 09:35:50 +01:00 committed by GitHub
commit 3169b77d70
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 49 additions and 42 deletions

View File

@ -1786,7 +1786,7 @@ BOOL gcc_read_client_monitor_data(wStream* s, rdpMcs* mcs, UINT16 blockLength)
void gcc_write_client_monitor_data(wStream* s, rdpMcs* mcs)
{
int i;
UINT32 i;
UINT16 length;
UINT32 left, top, right, bottom, flags;
INT32 baseX = 0, baseY = 0;

View File

@ -579,7 +579,7 @@ typedef struct _wEventType wEventType;
DEFINE_EVENT_UNSUBSCRIBE(_name)
#define DEFINE_EVENT_ENTRY(_name) \
{ #_name, { sizeof( _name ## EventArgs), NULL }, 0, { NULL } },
{ #_name, { sizeof( _name ## EventArgs), NULL }, 0, { NULL } },
struct _wPubSub
{
@ -643,8 +643,8 @@ typedef struct _wEventType wEventType;
WINPR_API BYTE* BipBuffer_ReadTryReserve(wBipBuffer* bb, size_t size, size_t* reserved);
WINPR_API void BipBuffer_ReadCommit(wBipBuffer* bb, size_t size);
WINPR_API int BipBuffer_Read(wBipBuffer* bb, BYTE* data, size_t size);
WINPR_API int BipBuffer_Write(wBipBuffer* bb, BYTE* data, size_t size);
WINPR_API SSIZE_T BipBuffer_Read(wBipBuffer* bb, BYTE* data, size_t size);
WINPR_API SSIZE_T BipBuffer_Write(wBipBuffer* bb, const BYTE* data, size_t size);
WINPR_API wBipBuffer* BipBuffer_New(size_t size);
WINPR_API void BipBuffer_Free(wBipBuffer* bb);

View File

@ -517,6 +517,17 @@ typedef const BYTE* LPCBYTE;
#endif /* _MSC_VER */
#endif /* WINPR_HAVE_INTTYPES_H not defined*/
#ifndef SSIZE_MAX
#if defined(_POSIX_SSIZE_MAX)
#define SSIZE_MAX _POSIX_SSIZE_MAX
#elif defined(_WIN64)
#define SSIZE_MAX _I64_MAX
#elif defined(_WIN32)
#define SSIZE_MAX LONG_MAX
#else
#define SSIZE_MAX LONG_MAX
#endif
#endif
#if defined(_MSC_VER) && _MSC_VER < 1900
/* %z not supported before MSVC 2015 */

View File

@ -51,7 +51,7 @@
DWORD GetCurrentDirectoryA(DWORD nBufferLength, LPSTR lpBuffer)
{
char* cwd;
int length;
size_t length;
cwd = getcwd(NULL, 0);
@ -139,7 +139,7 @@ BOOL NeedCurrentDirectoryForExePathW(LPCWSTR ExeName)
DWORD GetEnvironmentVariableA(LPCSTR lpName, LPSTR lpBuffer, DWORD nSize)
{
#if !defined(_UWP)
int length;
size_t length;
char* env = NULL;
env = getenv(lpName);

View File

@ -726,7 +726,7 @@ HRESULT PathCchStripPrefixW(PWSTR pszPath, size_t cchPath)
if (cchPath < (lstrlenW(&pszPath[4]) + 1))
return HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER);
if (IsCharAlpha(pszPath[4]) && (pszPath[5] == ':')) /* like C: */
if (IsCharAlphaW(pszPath[4]) && (pszPath[5] == L':')) /* like C: */
{
wmemmove_s(pszPath, cchPath, &pszPath[4], cchPath - 4);
/* since the passed pszPath must not necessarily be null terminated

View File

@ -189,7 +189,7 @@ BOOL WINAPI winpr_EnterSynchronizationBarrier(LPSYNCHRONIZATION_BARRIER lpBarrie
* of processors.
*/
if (spinOnly || (remainingThreads < dwProcessors && !blockOnly))
if (spinOnly || (((ULONG)remainingThreads < dwProcessors) && !blockOnly))
{
DWORD dwSpinCount = lpBarrier->Reserved5;
DWORD sp = 0;

View File

@ -67,7 +67,7 @@ int CommandLineParseArgumentsA(int argc, LPSTR* argv, COMMAND_LINE_ARGUMENT_A* o
const char* sigil;
size_t sigil_length;
char* keyword;
SSIZE_T keyword_length;
size_t keyword_length;
SSIZE_T keyword_index;
char* separator;
char* value;

View File

@ -21,6 +21,7 @@
#include "config.h"
#endif
#include <limits.h>
#include <winpr/crt.h>
#include <winpr/sysinfo.h>
@ -52,14 +53,12 @@ BOOL BipBuffer_AllocBuffer(wBipBuffer* bb, size_t size)
return FALSE;
size += size % bb->pageSize;
bb->buffer = (BYTE*) malloc(size);
if (!bb->buffer)
return FALSE;
bb->size = size;
return TRUE;
}
@ -69,7 +68,6 @@ BOOL BipBuffer_Grow(wBipBuffer* bb, size_t size)
BYTE* buffer;
size_t blockSize = 0;
size_t commitSize = 0;
size += size % bb->pageSize;
if (size <= bb->size)
@ -99,14 +97,11 @@ BOOL BipBuffer_Grow(wBipBuffer* bb, size_t size)
}
BipBuffer_Clear(bb);
free(bb->buffer);
bb->buffer = buffer;
bb->size = size;
bb->blockA.index = 0;
bb->blockA.size = commitSize;
return TRUE;
}
@ -141,7 +136,6 @@ BYTE* BipBuffer_WriteTryReserve(wBipBuffer* bb, size_t size, size_t* reserved)
if (!bb->blockB.size)
{
/* block B does not exist */
reservable = bb->size - bb->blockA.index - bb->blockA.size; /* space after block A */
if (reservable >= bb->blockA.index)
@ -154,7 +148,6 @@ BYTE* BipBuffer_WriteTryReserve(wBipBuffer* bb, size_t size, size_t* reserved)
bb->writeR.size = reservable;
*reserved = reservable;
bb->writeR.index = bb->blockA.index + bb->blockA.size;
return &bb->buffer[bb->writeR.index];
}
@ -167,13 +160,11 @@ BYTE* BipBuffer_WriteTryReserve(wBipBuffer* bb, size_t size, size_t* reserved)
bb->writeR.size = size;
*reserved = size;
bb->writeR.index = 0;
return bb->buffer;
}
/* block B exists */
reservable = bb->blockA.index - bb->blockB.index - bb->blockB.size; /* space after block B */
if (size < reservable)
@ -184,7 +175,6 @@ BYTE* BipBuffer_WriteTryReserve(wBipBuffer* bb, size_t size, size_t* reserved)
bb->writeR.size = reservable;
*reserved = reservable;
bb->writeR.index = bb->blockB.index + bb->blockB.size;
return &bb->buffer[bb->writeR.index];
}
@ -193,7 +183,6 @@ BYTE* BipBuffer_WriteReserve(wBipBuffer* bb, size_t size)
{
BYTE* block = NULL;
size_t reserved = 0;
block = BipBuffer_WriteTryReserve(bb, size, &reserved);
if (reserved == size)
@ -203,7 +192,6 @@ BYTE* BipBuffer_WriteReserve(wBipBuffer* bb, size_t size)
return NULL;
block = BipBuffer_WriteTryReserve(bb, size, &reserved);
return block;
}
@ -234,16 +222,22 @@ void BipBuffer_WriteCommit(wBipBuffer* bb, size_t size)
BipBlock_Clear(bb->writeR);
}
int BipBuffer_Write(wBipBuffer* bb, BYTE* data, size_t size)
SSIZE_T BipBuffer_Write(wBipBuffer* bb, const BYTE* data, size_t size)
{
int status = 0;
size_t status = 0;
BYTE* block = NULL;
size_t writeSize = 0;
size_t blockSize = 0;
if (!bb)
if (size == 0)
return 0;
if (!bb || !data)
return -1;
if (size > SSIZE_MAX)
size = SSIZE_MAX;
block = BipBuffer_WriteReserve(bb, size);
if (!block)
@ -260,10 +254,10 @@ int BipBuffer_Write(wBipBuffer* bb, BYTE* data, size_t size)
CopyMemory(block, &data[status], writeSize);
BipBuffer_WriteCommit(bb, writeSize);
status += (int) writeSize;
status += writeSize;
if ((status == size) || (writeSize < blockSize))
return status;
return (SSIZE_T)status;
}
block = BipBuffer_WriteTryReserve(bb, size - status, &blockSize);
@ -277,13 +271,13 @@ int BipBuffer_Write(wBipBuffer* bb, BYTE* data, size_t size)
CopyMemory(block, &data[status], writeSize);
BipBuffer_WriteCommit(bb, writeSize);
status += (int) writeSize;
status += writeSize;
if ((status == size) || (writeSize < blockSize))
return status;
return (SSIZE_T)status;
}
return status;
return (SSIZE_T)status;
}
BYTE* BipBuffer_ReadTryReserve(wBipBuffer* bb, size_t size, size_t* reserved)
@ -349,16 +343,22 @@ void BipBuffer_ReadCommit(wBipBuffer* bb, size_t size)
}
}
int BipBuffer_Read(wBipBuffer* bb, BYTE* data, size_t size)
SSIZE_T BipBuffer_Read(wBipBuffer* bb, BYTE* data, size_t size)
{
int status = 0;
size_t status = 0;
BYTE* block = NULL;
size_t readSize = 0;
size_t blockSize = 0;
if (!bb)
if (size == 0)
return 0;
if (!bb || !data)
return -1;
if (size > SSIZE_MAX)
size = SSIZE_MAX;
block = BipBuffer_ReadTryReserve(bb, 0, &blockSize);
if (block)
@ -370,10 +370,10 @@ int BipBuffer_Read(wBipBuffer* bb, BYTE* data, size_t size)
CopyMemory(&data[status], block, readSize);
BipBuffer_ReadCommit(bb, readSize);
status += (int) readSize;
status += readSize;
if ((status == size) || (readSize < blockSize))
return status;
return (SSIZE_T)status;
}
block = BipBuffer_ReadTryReserve(bb, 0, &blockSize);
@ -387,13 +387,13 @@ int BipBuffer_Read(wBipBuffer* bb, BYTE* data, size_t size)
CopyMemory(&data[status], block, readSize);
BipBuffer_ReadCommit(bb, readSize);
status += (int) readSize;
status += readSize;
if ((status == size) || (readSize < blockSize))
return status;
return (SSIZE_T)status;
}
return status;
return (SSIZE_T)status;
}
/**
@ -403,15 +403,12 @@ int BipBuffer_Read(wBipBuffer* bb, BYTE* data, size_t size)
wBipBuffer* BipBuffer_New(size_t size)
{
wBipBuffer* bb;
bb = (wBipBuffer*) calloc(1, sizeof(wBipBuffer));
if (bb)
{
SYSTEM_INFO si;
GetSystemInfo(&si);
bb->pageSize = (size_t) si.dwPageSize;
if (bb->pageSize < 4096)
@ -433,6 +430,5 @@ void BipBuffer_Free(wBipBuffer* bb)
return;
BipBuffer_FreeBuffer(bb);
free(bb);
}