From ba40c971d2ea8595e6f2ebe0959801dcba0acb73 Mon Sep 17 00:00:00 2001 From: Armin Novak Date: Thu, 7 Feb 2019 14:18:53 +0100 Subject: [PATCH] Fixed sign-compare warnings --- libfreerdp/gdi/gdi.c | 11 +++++++---- libfreerdp/gdi/region.c | 2 +- libfreerdp/gdi/test/TestGdiCreate.c | 24 ++++++++++++------------ libfreerdp/gdi/test/TestGdiRop3.c | 2 +- libfreerdp/gdi/video.c | 14 ++++++++++---- 5 files changed, 31 insertions(+), 22 deletions(-) diff --git a/libfreerdp/gdi/gdi.c b/libfreerdp/gdi/gdi.c index 83c635eed..22cae564d 100644 --- a/libfreerdp/gdi/gdi.c +++ b/libfreerdp/gdi/gdi.c @@ -1245,15 +1245,18 @@ BOOL gdi_resize_ex(rdpGdi* gdi, UINT32 width, UINT32 height, if (!gdi || !gdi->primary) return FALSE; - if (gdi->width == width && gdi->height == height && - (!buffer || gdi->primary_buffer == buffer)) + if ((width > INT32_MAX) || (height > INT32_MAX)) + return FALSE; + + if ((gdi->width == (INT32)width) && (gdi->height == (INT32)height) && + (!buffer || (gdi->primary_buffer == buffer))) return TRUE; if (gdi->drawing == gdi->primary) gdi->drawing = NULL; - gdi->width = width; - gdi->height = height; + gdi->width = (INT32)width; + gdi->height = (INT32)height; gdi_bitmap_free_ex(gdi->primary); gdi->primary = NULL; gdi->primary_buffer = NULL; diff --git a/libfreerdp/gdi/region.c b/libfreerdp/gdi/region.c index d3b28b562..bd10978be 100644 --- a/libfreerdp/gdi/region.c +++ b/libfreerdp/gdi/region.c @@ -439,7 +439,7 @@ INLINE BOOL gdi_InvalidateRegion(HGDI_DC hdc, INT32 x, INT32 y, INT32 w, cinvalid = hdc->hwnd->cinvalid; - if ((hdc->hwnd->ninvalid + 1) > hdc->hwnd->count) + if ((hdc->hwnd->ninvalid + 1) > (INT64)hdc->hwnd->count) { int new_cnt; HGDI_RGN new_rgn; diff --git a/libfreerdp/gdi/test/TestGdiCreate.c b/libfreerdp/gdi/test/TestGdiCreate.c index e7390adc9..4c145ded2 100644 --- a/libfreerdp/gdi/test/TestGdiCreate.c +++ b/libfreerdp/gdi/test/TestGdiCreate.c @@ -96,8 +96,8 @@ static int test_gdi_CreateBitmap(void) { int rc = -1; UINT32 format = PIXEL_FORMAT_ARGB32; - UINT32 width; - UINT32 height; + INT32 width; + INT32 height; BYTE* data; HGDI_BITMAP hBitmap = NULL; width = 32; @@ -145,8 +145,8 @@ static int test_gdi_CreateCompatibleBitmap(void) { int rc = -1; HGDI_DC hdc; - UINT32 width; - UINT32 height; + INT32 width; + INT32 height; HGDI_BITMAP hBitmap = NULL; if (!(hdc = gdi_GetDC())) @@ -268,10 +268,10 @@ fail: static int test_gdi_CreateRectRgn(void) { int rc = -1; - UINT32 x1 = 32; - UINT32 y1 = 64; - UINT32 x2 = 128; - UINT32 y2 = 256; + INT32 x1 = 32; + INT32 y1 = 64; + INT32 x2 = 128; + INT32 y2 = 256; HGDI_RGN hRegion = gdi_CreateRectRgn(x1, y1, x2, y2); if (!hRegion) @@ -305,10 +305,10 @@ static int test_gdi_CreateRect(void) { int rc = -1; HGDI_RECT hRect; - UINT32 x1 = 32; - UINT32 y1 = 64; - UINT32 x2 = 128; - UINT32 y2 = 256; + INT32 x1 = 32; + INT32 y1 = 64; + INT32 x2 = 128; + INT32 y2 = 256; if (!(hRect = gdi_CreateRect(x1, y1, x2, y2))) { diff --git a/libfreerdp/gdi/test/TestGdiRop3.c b/libfreerdp/gdi/test/TestGdiRop3.c index 9e9c4144c..d955695ca 100644 --- a/libfreerdp/gdi/test/TestGdiRop3.c +++ b/libfreerdp/gdi/test/TestGdiRop3.c @@ -206,7 +206,7 @@ static const char* test_ROP3[] = int TestGdiRop3(int argc, char* argv[]) { - int index; + size_t index; for (index = 0; index < sizeof(test_ROP3) / sizeof(test_ROP3[0]); index++) { diff --git a/libfreerdp/gdi/video.c b/libfreerdp/gdi/video.c index 0813df492..40f95f458 100644 --- a/libfreerdp/gdi/video.c +++ b/libfreerdp/gdi/video.c @@ -91,13 +91,17 @@ static BOOL gdiVideoShowSurface(VideoClientContext* video, VideoSurface* surface surfaceRect.right = surface->x + surface->w; surfaceRect.bottom = surface->y + surface->h; update->BeginPaint(gdi->context); + + if ((gdi->width < 0) || (gdi->height < 0)) + return FALSE; + else { const UINT32 nXSrc = surface->x; const UINT32 nYSrc = surface->y; const UINT32 nXDst = nXSrc; const UINT32 nYDst = nYSrc; - const UINT32 width = (surface->w + surface->x < gdi->width) ? surface->w : gdi->width - surface->x; - const UINT32 height = (surface->h + surface->y < gdi->height) ? surface->h : gdi->height - + const UINT32 width = (surface->w + surface->x < (UINT32)gdi->width) ? surface->w : (UINT32)gdi->width - surface->x; + const UINT32 height = (surface->h + surface->y < (UINT32)gdi->height) ? surface->h : (UINT32)gdi->height - surface->y; if (!freerdp_image_copy(gdi->primary_buffer, gdi->primary->hdc->format, @@ -105,9 +109,11 @@ static BOOL gdiVideoShowSurface(VideoClientContext* video, VideoSurface* surface nXDst, nYDst, width, height, surface->data, gdi->primary->hdc->format, gdiSurface->scanline, 0, 0, NULL, FREERDP_FLIP_NONE)) - return CHANNEL_RC_NULL_DATA; + return FALSE; - gdi_InvalidateRegion(gdi->primary->hdc, nXDst, nYDst, width, height); + if ((nXDst > INT32_MAX) || (nYDst > INT32_MAX) || (width > INT32_MAX) || (height > INT32_MAX)) + return FALSE; + gdi_InvalidateRegion(gdi->primary->hdc, (INT32)nXDst, (INT32)nYDst, (INT32)width, (INT32)height); } update->EndPaint(gdi->context); return TRUE;