[warnings] fix integer casting

* use asserting casts to detect overflows or sign conversions
* code cleanup for issues uncovered by casts
This commit is contained in:
akallabeth
2024-12-19 14:45:06 +01:00
parent 7e44c7ca41
commit cc934795e4
127 changed files with 2356 additions and 1951 deletions

View File

@@ -60,7 +60,7 @@ UINT32 gdi_GetPixel(HGDI_DC hdc, UINT32 nXPos, UINT32 nYPos)
BYTE* gdi_GetPointer(HGDI_BITMAP hBmp, UINT32 X, UINT32 Y)
{
UINT32 bpp = FreeRDPGetBytesPerPixel(hBmp->format);
return &hBmp->data[(Y * hBmp->width * bpp) + X * bpp];
return &hBmp->data[(Y * WINPR_ASSERTING_INT_CAST(uint32_t, hBmp->width) * bpp) + X * bpp];
}
/**
@@ -128,8 +128,8 @@ HGDI_BITMAP gdi_CreateBitmapEx(UINT32 nWidth, UINT32 nHeight, UINT32 format, UIN
else
hBitmap->scanline = nWidth * FreeRDPGetBytesPerPixel(hBitmap->format);
hBitmap->width = nWidth;
hBitmap->height = nHeight;
hBitmap->width = WINPR_ASSERTING_INT_CAST(int, nWidth);
hBitmap->height = WINPR_ASSERTING_INT_CAST(int, nHeight);
hBitmap->data = data;
hBitmap->free = fkt_free;
return hBitmap;
@@ -329,7 +329,9 @@ static INLINE BOOL BitBlt_write(HGDI_DC hdcDest, HGDI_DC hdcSrc, INT32 nXDest, I
case GDI_BS_HATCHED:
case GDI_BS_PATTERN:
{
const BYTE* patp = gdi_get_brush_pointer(hdcDest, nXDest + x, nYDest + y);
const BYTE* patp =
gdi_get_brush_pointer(hdcDest, WINPR_ASSERTING_INT_CAST(uint32_t, nXDest + x),
WINPR_ASSERTING_INT_CAST(uint32_t, nYDest + y));
if (!patp)
{
@@ -623,9 +625,14 @@ BOOL gdi_BitBlt(HGDI_DC hdcDest, INT32 nXDest, INT32 nYDest, INT32 nWidth, INT32
if (!hSrcBmp || !hDstBmp)
return FALSE;
if (!freerdp_image_copy(hDstBmp->data, hDstBmp->format, hDstBmp->scanline, nXDest,
nYDest, nWidth, nHeight, hSrcBmp->data, hSrcBmp->format,
hSrcBmp->scanline, nXSrc, nYSrc, palette, FREERDP_FLIP_NONE))
if (!freerdp_image_copy(
hDstBmp->data, hDstBmp->format, hDstBmp->scanline,
WINPR_ASSERTING_INT_CAST(UINT32, nXDest),
WINPR_ASSERTING_INT_CAST(UINT32, nYDest),
WINPR_ASSERTING_INT_CAST(UINT32, nWidth),
WINPR_ASSERTING_INT_CAST(UINT32, nHeight), hSrcBmp->data, hSrcBmp->format,
hSrcBmp->scanline, WINPR_ASSERTING_INT_CAST(UINT32, nXSrc),
WINPR_ASSERTING_INT_CAST(UINT32, nYSrc), palette, FREERDP_FLIP_NONE))
return FALSE;
break;
@@ -644,9 +651,14 @@ BOOL gdi_BitBlt(HGDI_DC hdcDest, INT32 nXDest, INT32 nYDest, INT32 nWidth, INT32
if (!hSrcBmp || !hDstBmp)
return FALSE;
if (!freerdp_image_copy(hDstBmp->data, hDstBmp->format, hDstBmp->scanline, nXDest,
nYDest, nWidth, nHeight, hSrcBmp->data, hSrcBmp->format,
hSrcBmp->scanline, nXSrc, nYSrc, palette, FREERDP_FLIP_NONE))
if (!freerdp_image_copy(
hDstBmp->data, hDstBmp->format, hDstBmp->scanline,
WINPR_ASSERTING_INT_CAST(UINT32, nXDest),
WINPR_ASSERTING_INT_CAST(UINT32, nYDest),
WINPR_ASSERTING_INT_CAST(UINT32, nWidth),
WINPR_ASSERTING_INT_CAST(UINT32, nHeight), hSrcBmp->data, hSrcBmp->format,
hSrcBmp->scanline, WINPR_ASSERTING_INT_CAST(UINT32, nXSrc),
WINPR_ASSERTING_INT_CAST(UINT32, nYSrc), palette, FREERDP_FLIP_NONE))
return FALSE;
break;

View File

@@ -22,6 +22,8 @@
#ifndef FREERDP_LIB_GDI_BRUSH_H
#define FREERDP_LIB_GDI_BRUSH_H
#include <winpr/cast.h>
#include <freerdp/api.h>
#include <freerdp/gdi/gdi.h>
@@ -41,7 +43,7 @@ extern "C"
if (!hdc || !hdc->brush)
return GDI_BS_NULL;
return hdc->brush->style;
return WINPR_ASSERTING_INT_CAST(UINT32, hdc->brush->style);
}
#ifdef __cplusplus

View File

@@ -107,7 +107,7 @@ UINT32 gdi_SetBkColor(HGDI_DC hdc, UINT32 crColor)
* @return background mode
*/
UINT32 gdi_GetBkMode(HGDI_DC hdc)
INT32 gdi_GetBkMode(HGDI_DC hdc)
{
return hdc->bkMode;
}

View File

@@ -34,7 +34,7 @@ extern "C"
FREERDP_LOCAL INT32 gdi_SetROP2(HGDI_DC hdc, INT32 fnDrawMode);
FREERDP_LOCAL UINT32 gdi_GetBkColor(HGDI_DC hdc);
FREERDP_LOCAL UINT32 gdi_SetBkColor(HGDI_DC hdc, UINT32 crColor);
FREERDP_LOCAL UINT32 gdi_GetBkMode(HGDI_DC hdc);
FREERDP_LOCAL INT32 gdi_GetBkMode(HGDI_DC hdc);
FREERDP_LOCAL INT32 gdi_SetBkMode(HGDI_DC hdc, INT32 iBkMode);
FREERDP_LOCAL UINT32 gdi_SetTextColor(HGDI_DC hdc, UINT32 crColor);

View File

@@ -26,6 +26,7 @@
#include <winpr/crt.h>
#include <winpr/assert.h>
#include <winpr/cast.h>
#include <freerdp/api.h>
#include <freerdp/log.h>
@@ -445,9 +446,13 @@ gdiBitmap* gdi_bitmap_new_ex(rdpGdi* gdi, int width, int height, int bpp, BYTE*
bpp);
if (!data)
bitmap->bitmap = gdi_CreateCompatibleBitmap(gdi->hdc, width, height);
bitmap->bitmap =
gdi_CreateCompatibleBitmap(gdi->hdc, WINPR_ASSERTING_INT_CAST(uint32_t, width),
WINPR_ASSERTING_INT_CAST(uint32_t, height));
else
bitmap->bitmap = gdi_create_bitmap(gdi, width, height, bpp, data);
bitmap->bitmap = gdi_create_bitmap(gdi, WINPR_ASSERTING_INT_CAST(uint32_t, width),
WINPR_ASSERTING_INT_CAST(uint32_t, height),
WINPR_ASSERTING_INT_CAST(uint32_t, bpp), data);
if (!bitmap->bitmap)
goto fail_bitmap_bitmap;
@@ -488,43 +493,39 @@ BOOL gdi_bitmap_update(rdpContext* context, const BITMAP_UPDATE* bitmapUpdate)
for (UINT32 index = 0; index < bitmapUpdate->number; index++)
{
BOOL rc = FALSE;
const BITMAP_DATA* bitmap = &(bitmapUpdate->rectangles[index]);
rdpBitmap* bmp = Bitmap_Alloc(context);
if (!bmp)
{
WLog_ERR(TAG, "Bitmap_Alloc failed");
return FALSE;
}
goto fail;
Bitmap_SetDimensions(bmp, bitmap->width, bitmap->height);
Bitmap_SetRectangle(bmp, bitmap->destLeft, bitmap->destTop, bitmap->destRight,
bitmap->destBottom);
if (!Bitmap_SetDimensions(bmp, WINPR_ASSERTING_INT_CAST(UINT16, bitmap->width),
WINPR_ASSERTING_INT_CAST(UINT16, bitmap->height)))
goto fail;
if (!Bitmap_SetRectangle(bmp, WINPR_ASSERTING_INT_CAST(UINT16, bitmap->destLeft),
WINPR_ASSERTING_INT_CAST(UINT16, bitmap->destTop),
WINPR_ASSERTING_INT_CAST(UINT16, bitmap->destRight),
WINPR_ASSERTING_INT_CAST(UINT16, bitmap->destBottom)))
goto fail;
if (!bmp->Decompress(context, bmp, bitmap->bitmapDataStream, bitmap->width, bitmap->height,
bitmap->bitsPerPixel, bitmap->bitmapLength, bitmap->compressed,
RDP_CODEC_ID_NONE))
{
WLog_ERR(TAG, "bmp->Decompress failed");
Bitmap_Free(context, bmp);
return FALSE;
}
goto fail;
if (!bmp->New(context, bmp))
{
WLog_ERR(TAG, "bmp->New failed");
Bitmap_Free(context, bmp);
return FALSE;
}
goto fail;
if (!bmp->Paint(context, bmp))
{
WLog_ERR(TAG, "bmp->Paint failed");
Bitmap_Free(context, bmp);
return FALSE;
}
goto fail;
rc = TRUE;
fail:
Bitmap_Free(context, bmp);
if (!rc)
return FALSE;
}
return TRUE;
@@ -675,8 +676,8 @@ static BOOL gdi_patblt(rdpContext* context, PATBLT_ORDER* patblt)
if (hbrush)
{
hbrush->nXOrg = brush->x;
hbrush->nYOrg = brush->y;
hbrush->nXOrg = WINPR_ASSERTING_INT_CAST(int32_t, brush->x);
hbrush->nYOrg = WINPR_ASSERTING_INT_CAST(int32_t, brush->y);
gdi->drawing->hdc->brush = hbrush;
ret = gdi_BitBlt(gdi->drawing->hdc, patblt->nLeftRect, patblt->nTopRect, patblt->nWidth,
patblt->nHeight, gdi->primary->hdc, nXSrc, nYSrc, rop, &gdi->palette);
@@ -786,7 +787,7 @@ static BOOL gdi_line_to(rdpContext* context, const LINE_TO_ORDER* lineTo)
return FALSE;
gdi_SelectObject(gdi->drawing->hdc, (HGDIOBJECT)hPen);
gdi_SetROP2(gdi->drawing->hdc, lineTo->bRop2);
gdi_SetROP2(gdi->drawing->hdc, WINPR_ASSERTING_INT_CAST(int32_t, lineTo->bRop2));
gdi_MoveToEx(gdi->drawing->hdc, lineTo->nXStart, lineTo->nYStart, NULL);
gdi_LineTo(gdi->drawing->hdc, lineTo->nXEnd, lineTo->nYEnd);
gdi_DeleteObject((HGDIOBJECT)hPen);
@@ -811,7 +812,7 @@ static BOOL gdi_polyline(rdpContext* context, const POLYLINE_ORDER* polyline)
return FALSE;
gdi_SelectObject(gdi->drawing->hdc, (HGDIOBJECT)hPen);
gdi_SetROP2(gdi->drawing->hdc, polyline->bRop2);
gdi_SetROP2(gdi->drawing->hdc, WINPR_ASSERTING_INT_CAST(int32_t, polyline->bRop2));
x = polyline->xStart;
y = polyline->yStart;
gdi_ClipCoords(gdi->drawing->hdc, &x, &y, &w, &h, NULL, NULL);
@@ -947,8 +948,8 @@ static BOOL gdi_mem3blt(rdpContext* context, MEM3BLT_ORDER* mem3blt)
goto out_fail;
}
gdi->drawing->hdc->brush->nXOrg = brush->x;
gdi->drawing->hdc->brush->nYOrg = brush->y;
gdi->drawing->hdc->brush->nXOrg = WINPR_ASSERTING_INT_CAST(int32_t, brush->x);
gdi->drawing->hdc->brush->nYOrg = WINPR_ASSERTING_INT_CAST(int32_t, brush->y);
ret = gdi_BitBlt(gdi->drawing->hdc, mem3blt->nLeftRect, mem3blt->nTopRect,
mem3blt->nWidth, mem3blt->nHeight, bitmap->hdc, mem3blt->nXSrc,
mem3blt->nYSrc, gdi_rop3_code_checked(mem3blt->bRop), &gdi->palette);
@@ -1086,8 +1087,8 @@ static BOOL gdi_surface_bits(rdpContext* context, const SURFACE_BITS_COMMAND* cm
case RDP_CODEC_ID_IMAGE_REMOTEFX:
if (!rfx_process_message(context->codecs->rfx, cmd->bmp.bitmapData,
cmd->bmp.bitmapDataLength, cmdRect.left, cmdRect.top,
gdi->primary_buffer, gdi->dstFormat, gdi->stride, gdi->height,
&region))
gdi->primary_buffer, gdi->dstFormat, gdi->stride,
WINPR_ASSERTING_INT_CAST(uint32_t, gdi->height), &region))
{
WLog_ERR(TAG, "Failed to process RemoteFX message");
goto out;
@@ -1148,7 +1149,10 @@ static BOOL gdi_surface_bits(rdpContext* context, const SURFACE_BITS_COMMAND* cm
UINT32 width = rects[i].right - rects[i].left;
UINT32 height = rects[i].bottom - rects[i].top;
if (!gdi_InvalidateRegion(gdi->primary->hdc, left, top, width, height))
if (!gdi_InvalidateRegion(gdi->primary->hdc, WINPR_ASSERTING_INT_CAST(int32_t, left),
WINPR_ASSERTING_INT_CAST(int32_t, top),
WINPR_ASSERTING_INT_CAST(int32_t, width),
WINPR_ASSERTING_INT_CAST(int32_t, height)))
{
WLog_ERR(TAG, "Failed to update invalid region");
goto out;
@@ -1228,7 +1232,8 @@ static BOOL gdi_init_primary(rdpGdi* gdi, UINT32 stride, UINT32 format, BYTE* bu
if (stride > 0)
gdi->stride = stride;
else
gdi->stride = gdi->width * FreeRDPGetBytesPerPixel(gdi->dstFormat);
gdi->stride = WINPR_ASSERTING_INT_CAST(uint32_t, gdi->width) *
FreeRDPGetBytesPerPixel(gdi->dstFormat);
if (!gdi->primary)
goto fail_primary;
@@ -1238,12 +1243,15 @@ static BOOL gdi_init_primary(rdpGdi* gdi, UINT32 stride, UINT32 format, BYTE* bu
if (!buffer)
{
gdi->primary->bitmap = gdi_CreateCompatibleBitmap(gdi->hdc, gdi->width, gdi->height);
gdi->primary->bitmap =
gdi_CreateCompatibleBitmap(gdi->hdc, WINPR_ASSERTING_INT_CAST(uint32_t, gdi->width),
WINPR_ASSERTING_INT_CAST(uint32_t, gdi->height));
}
else
{
gdi->primary->bitmap =
gdi_CreateBitmapEx(gdi->width, gdi->height, gdi->dstFormat, gdi->stride, buffer, pfree);
gdi->primary->bitmap = gdi_CreateBitmapEx(WINPR_ASSERTING_INT_CAST(uint32_t, gdi->width),
WINPR_ASSERTING_INT_CAST(uint32_t, gdi->height),
gdi->dstFormat, gdi->stride, buffer, pfree);
}
if (!gdi->primary->bitmap)
@@ -1372,8 +1380,10 @@ BOOL gdi_init_ex(freerdp* instance, UINT32 format, UINT32 stride, BYTE* buffer,
goto fail;
gdi->context = context;
gdi->width = freerdp_settings_get_uint32(context->settings, FreeRDP_DesktopWidth);
gdi->height = freerdp_settings_get_uint32(context->settings, FreeRDP_DesktopHeight);
gdi->width = WINPR_ASSERTING_INT_CAST(
int32_t, freerdp_settings_get_uint32(context->settings, FreeRDP_DesktopWidth));
gdi->height = WINPR_ASSERTING_INT_CAST(
int32_t, freerdp_settings_get_uint32(context->settings, FreeRDP_DesktopHeight));
gdi->dstFormat = format;
/* default internal buffer format */
WLog_Print(gdi->log, WLOG_INFO, "Local framebuffer format %s",
@@ -1449,7 +1459,10 @@ BOOL gdi_send_suppress_output(rdpGdi* gdi, BOOL suppress)
update = gdi->context->update;
rect.left = 0;
rect.top = 0;
rect.right = freerdp_settings_get_uint32(settings, FreeRDP_DesktopWidth);
rect.bottom = freerdp_settings_get_uint32(settings, FreeRDP_DesktopHeight);
const UINT32 w = freerdp_settings_get_uint32(settings, FreeRDP_DesktopWidth);
const UINT32 h = freerdp_settings_get_uint32(settings, FreeRDP_DesktopHeight);
rect.right = WINPR_ASSERTING_INT_CAST(UINT16, w);
rect.bottom = WINPR_ASSERTING_INT_CAST(UINT16, h);
return update->SuppressOutput(gdi->context, !suppress, &rect);
}

View File

@@ -20,6 +20,8 @@
#ifndef FREERDP_LIB_GDI_CORE_H
#define FREERDP_LIB_GDI_CORE_H
#include <winpr/cast.h>
#include "graphics.h"
#include "brush.h"
@@ -32,12 +34,12 @@ FREERDP_LOCAL void gdi_bitmap_free_ex(gdiBitmap* gdi_bmp);
static INLINE BYTE* gdi_get_bitmap_pointer(HGDI_DC hdcBmp, INT32 x, INT32 y)
{
BYTE* p = NULL;
HGDI_BITMAP hBmp = (HGDI_BITMAP)hdcBmp->selectedObject;
if ((x >= 0) && (y >= 0) && (x < hBmp->width) && (y < hBmp->height))
{
p = hBmp->data + (y * hBmp->scanline) + (x * FreeRDPGetBytesPerPixel(hdcBmp->format));
BYTE* p = hBmp->data + (WINPR_ASSERTING_INT_CAST(size_t, y) * hBmp->scanline) +
(WINPR_ASSERTING_INT_CAST(size_t, x) * FreeRDPGetBytesPerPixel(hdcBmp->format));
return p;
}
else
@@ -72,15 +74,14 @@ static INLINE BYTE* gdi_get_brush_pointer(HGDI_DC hdcBrush, UINT32 x, UINT32 y)
* at the brush origin and copy across the client area.
* Calculate the offset of the mapped pixel in the brush bitmap according to
* brush origin and dest coordinates */
x = (x + hBmpBrush->width - (hdcBrush->brush->nXOrg % hBmpBrush->width)) %
hBmpBrush->width;
y = (y + hBmpBrush->height - (hdcBrush->brush->nYOrg % hBmpBrush->height)) %
hBmpBrush->height;
const UINT32 w = WINPR_ASSERTING_INT_CAST(UINT32, hBmpBrush->width);
const UINT32 h = WINPR_ASSERTING_INT_CAST(UINT32, hBmpBrush->height);
x = (x + w - (WINPR_ASSERTING_INT_CAST(UINT32, hdcBrush->brush->nXOrg) % w)) % w;
y = (y + h - (WINPR_ASSERTING_INT_CAST(UINT32, hdcBrush->brush->nYOrg) % h)) % h;
p = hBmpBrush->data + (y * hBmpBrush->scanline) +
(x * FreeRDPGetBytesPerPixel(hBmpBrush->format));
return p;
}
break;
default:
break;

View File

@@ -23,6 +23,9 @@
#include "../core/update.h"
#include <winpr/assert.h>
#include <winpr/cast.h>
#include <freerdp/api.h>
#include <freerdp/log.h>
#include <freerdp/gdi/gfx.h>
@@ -1035,20 +1038,20 @@ static UINT gdi_SurfaceCommand(RdpgfxClientContext* context, const RDPGFX_SURFAC
gdi = (rdpGdi*)context->custom;
EnterCriticalSection(&context->mux);
const UINT16 codecId = WINPR_ASSERTING_INT_CAST(UINT16, cmd->codecId);
WLog_Print(gdi->log, WLOG_TRACE,
"surfaceId=%" PRIu32 ", codec=%s [%" PRIu32 "], contextId=%" PRIu32 ", format=%s, "
"left=%" PRIu32 ", top=%" PRIu32 ", right=%" PRIu32 ", bottom=%" PRIu32
", width=%" PRIu32 ", height=%" PRIu32 " "
"length=%" PRIu32 ", data=%p, extra=%p",
cmd->surfaceId, rdpgfx_get_codec_id_string(cmd->codecId), cmd->codecId,
cmd->contextId, FreeRDPGetColorFormatName(cmd->format), cmd->left, cmd->top,
cmd->right, cmd->bottom, cmd->width, cmd->height, cmd->length, (void*)cmd->data,
(void*)cmd->extra);
cmd->surfaceId, rdpgfx_get_codec_id_string(codecId), cmd->codecId, cmd->contextId,
FreeRDPGetColorFormatName(cmd->format), cmd->left, cmd->top, cmd->right, cmd->bottom,
cmd->width, cmd->height, cmd->length, (void*)cmd->data, (void*)cmd->extra);
#if defined(WITH_GFX_FRAME_DUMP)
dump_cmd(cmd, gdi->frameId);
#endif
switch (cmd->codecId)
switch (codecId)
{
case RDPGFX_CODECID_UNCOMPRESSED:
status = gdi_SurfaceCommand_Uncompressed(gdi, context, cmd);
@@ -1084,13 +1087,13 @@ static UINT gdi_SurfaceCommand(RdpgfxClientContext* context, const RDPGFX_SURFAC
break;
case RDPGFX_CODECID_CAPROGRESSIVE_V2:
WLog_WARN(TAG, "SurfaceCommand %s [0x%08" PRIX32 "] not implemented",
rdpgfx_get_codec_id_string(cmd->codecId), cmd->codecId);
WLog_WARN(TAG, "SurfaceCommand %s [0x%08" PRIX16 "] not implemented",
rdpgfx_get_codec_id_string(codecId), codecId);
break;
default:
WLog_WARN(TAG, "Invalid SurfaceCommand %s [0x%08" PRIX32 "]",
rdpgfx_get_codec_id_string(cmd->codecId), cmd->codecId);
WLog_WARN(TAG, "Invalid SurfaceCommand %s [0x%08" PRIX16 "]",
rdpgfx_get_codec_id_string(codecId), codecId);
break;
}
@@ -1251,8 +1254,9 @@ static BOOL intersect_rect(const RECTANGLE_16* rect, const gdiGfxSurface* surfac
return FALSE;
prect->left = rect->left;
prect->top = rect->top;
prect->right = MIN(rect->right, surface->width);
prect->bottom = MIN(rect->bottom, surface->height);
prect->right = MIN(rect->right, WINPR_ASSERTING_INT_CAST(UINT16, surface->width));
prect->bottom = MIN(rect->bottom, WINPR_ASSERTING_INT_CAST(UINT16, surface->height));
return TRUE;
}

View File

@@ -125,7 +125,9 @@ static BOOL gdi_Bitmap_Paint(rdpContext* context, rdpBitmap* bitmap)
gdiBitmap* gdi_bitmap = (gdiBitmap*)bitmap;
UINT32 width = bitmap->right - bitmap->left + 1;
UINT32 height = bitmap->bottom - bitmap->top + 1;
return gdi_BitBlt(context->gdi->primary->hdc, bitmap->left, bitmap->top, width, height,
return gdi_BitBlt(context->gdi->primary->hdc, WINPR_ASSERTING_INT_CAST(int, bitmap->left),
WINPR_ASSERTING_INT_CAST(int, bitmap->top),
WINPR_ASSERTING_INT_CAST(int, width), WINPR_ASSERTING_INT_CAST(int, height),
gdi_bitmap->hdc, 0, 0, GDI_SRCCOPY, &context->gdi->palette);
}
@@ -163,7 +165,7 @@ static BOOL gdi_Bitmap_Decompress(rdpContext* context, rdpBitmap* bitmap, const
if (!rfx_process_message(context->codecs->rfx, pSrcData, SrcSize, bitmap->left,
bitmap->top, bitmap->data, bitmap->format, gdi->stride,
gdi->height, &invalidRegion))
WINPR_ASSERTING_INT_CAST(UINT32, gdi->height), &invalidRegion))
{
WLog_ERR(TAG, "rfx_process_message failed");
return FALSE;

View File

@@ -37,7 +37,7 @@
#include "clipping.h"
#include "line.h"
static BOOL gdi_rop_color(UINT32 rop, BYTE* pixelPtr, UINT32 pen, UINT32 format)
static BOOL gdi_rop_color(INT32 rop, BYTE* pixelPtr, UINT32 pen, UINT32 format)
{
WINPR_ASSERT(pixelPtr);
const UINT32 srcPixel = FreeRDPReadColor(pixelPtr, format);
@@ -116,7 +116,7 @@ static BOOL gdi_rop_color(UINT32 rop, BYTE* pixelPtr, UINT32 pen, UINT32 format)
return FreeRDPWriteColor(pixelPtr, format, dstPixel);
}
BOOL gdi_LineTo(HGDI_DC hdc, UINT32 nXEnd, UINT32 nYEnd)
BOOL gdi_LineTo(HGDI_DC hdc, INT32 nXEnd, INT32 nYEnd)
{
INT32 e2 = 0;
UINT32 pen = 0;
@@ -126,8 +126,8 @@ BOOL gdi_LineTo(HGDI_DC hdc, UINT32 nXEnd, UINT32 nYEnd)
const INT32 x1 = hdc->pen->posX;
const INT32 y1 = hdc->pen->posY;
const INT32 x2 = nXEnd;
const INT32 y2 = nYEnd;
const INT32 x2 = WINPR_ASSERTING_INT_CAST(int32_t, nXEnd);
const INT32 y2 = WINPR_ASSERTING_INT_CAST(int32_t, nYEnd);
const INT32 dx = (x1 > x2) ? x1 - x2 : x2 - x1;
const INT32 dy = (y1 > y2) ? y1 - y2 : y2 - y1;
const INT32 sx = (x1 < x2) ? 1 : -1;
@@ -299,7 +299,7 @@ BOOL gdi_PolyPolyline(HGDI_DC hdc, GDI_POINT* lppt, const UINT32* lpdwPolyPoints
* @return nonzero on success, 0 otherwise
*/
BOOL gdi_MoveToEx(HGDI_DC hdc, UINT32 X, UINT32 Y, HGDI_POINT lpPoint)
BOOL gdi_MoveToEx(HGDI_DC hdc, INT32 X, INT32 Y, HGDI_POINT lpPoint)
{
WINPR_ASSERT(hdc);

View File

@@ -30,12 +30,12 @@ extern "C"
{
#endif
FREERDP_LOCAL BOOL gdi_LineTo(HGDI_DC hdc, UINT32 nXEnd, UINT32 nYEnd);
FREERDP_LOCAL BOOL gdi_LineTo(HGDI_DC hdc, INT32 nXEnd, INT32 nYEnd);
FREERDP_LOCAL BOOL gdi_PolylineTo(HGDI_DC hdc, GDI_POINT* lppt, DWORD cCount);
FREERDP_LOCAL BOOL gdi_Polyline(HGDI_DC hdc, GDI_POINT* lppt, UINT32 cPoints);
FREERDP_LOCAL BOOL gdi_PolyPolyline(HGDI_DC hdc, GDI_POINT* lppt, const UINT32* lpdwPolyPoints,
DWORD cCount);
FREERDP_LOCAL BOOL gdi_MoveToEx(HGDI_DC hdc, UINT32 X, UINT32 Y, HGDI_POINT lpPoint);
FREERDP_LOCAL BOOL gdi_MoveToEx(HGDI_DC hdc, INT32 X, INT32 Y, HGDI_POINT lpPoint);
#ifdef __cplusplus
}

View File

@@ -71,10 +71,14 @@ static void Ellipse_Bresenham(HGDI_DC hdc, int x1, int y1, int x2, int y2)
do
{
gdi_SetPixel(hdc, x2, y1, 0);
gdi_SetPixel(hdc, x1, y1, 0);
gdi_SetPixel(hdc, x1, y2, 0);
gdi_SetPixel(hdc, x2, y2, 0);
gdi_SetPixel(hdc, WINPR_ASSERTING_INT_CAST(UINT32, x2),
WINPR_ASSERTING_INT_CAST(UINT32, y1), 0);
gdi_SetPixel(hdc, WINPR_ASSERTING_INT_CAST(UINT32, x1),
WINPR_ASSERTING_INT_CAST(UINT32, y1), 0);
gdi_SetPixel(hdc, WINPR_ASSERTING_INT_CAST(UINT32, x1),
WINPR_ASSERTING_INT_CAST(UINT32, y2), 0);
gdi_SetPixel(hdc, WINPR_ASSERTING_INT_CAST(UINT32, x2),
WINPR_ASSERTING_INT_CAST(UINT32, y2), 0);
e2 = 2 * e;
if (e2 >= dx)
@@ -94,8 +98,13 @@ static void Ellipse_Bresenham(HGDI_DC hdc, int x1, int y1, int x2, int y2)
while (y1 - y2 < b)
{
gdi_SetPixel(hdc, x1 - 1, ++y1, 0);
gdi_SetPixel(hdc, x1 - 1, --y2, 0);
y1++;
y2--;
gdi_SetPixel(hdc, WINPR_ASSERTING_INT_CAST(uint32_t, x1 - 1),
WINPR_ASSERTING_INT_CAST(uint32_t, y1), 0);
gdi_SetPixel(hdc, WINPR_ASSERTING_INT_CAST(uint32_t, x1 - 1),
WINPR_ASSERTING_INT_CAST(uint32_t, y2), 0);
}
}
@@ -166,7 +175,7 @@ BOOL gdi_FillRect(HGDI_DC hdc, const HGDI_RECT rect, HGDI_BRUSH hbr)
for (INT32 y = 1; y < nHeight; y++)
{
BYTE* dstp = gdi_get_bitmap_pointer(hdc, nXDest, nYDest + y);
memcpy(dstp, srcp, 1ull * nWidth * formatSize);
memcpy(dstp, srcp, 1ull * WINPR_ASSERTING_INT_CAST(size_t, nWidth) * formatSize);
}
break;
@@ -181,9 +190,15 @@ BOOL gdi_FillRect(HGDI_DC hdc, const HGDI_RECT rect, HGDI_BRUSH hbr)
for (INT32 x = 0; x < nWidth; x++)
{
const size_t yOffset =
((1ULL * nYDest + y) * hbr->pattern->width % hbr->pattern->height) *
((1ULL * WINPR_ASSERTING_INT_CAST(size_t, nYDest) +
WINPR_ASSERTING_INT_CAST(size_t, y)) *
WINPR_ASSERTING_INT_CAST(size_t, hbr->pattern->width) %
WINPR_ASSERTING_INT_CAST(size_t, hbr->pattern->height)) *
formatSize;
const size_t xOffset = ((1ULL * nXDest + x) % hbr->pattern->width) * formatSize;
const size_t xOffset = ((1ULL * WINPR_ASSERTING_INT_CAST(size_t, nXDest) +
WINPR_ASSERTING_INT_CAST(size_t, x)) %
WINPR_ASSERTING_INT_CAST(size_t, hbr->pattern->width)) *
formatSize;
const BYTE* patp = &hbr->pattern->data[yOffset + xOffset];
if (monochrome)

View File

@@ -23,7 +23,9 @@ static int test_gdi_PtInRect(void)
UINT32 right = 60;
UINT32 bottom = 80;
if (!(hRect = gdi_CreateRect(left, top, right, bottom)))
if (!(hRect = gdi_CreateRect(
WINPR_ASSERTING_INT_CAST(int, left), WINPR_ASSERTING_INT_CAST(int, top),
WINPR_ASSERTING_INT_CAST(int, right), WINPR_ASSERTING_INT_CAST(int, bottom))))
{
printf("gdi_CreateRect failed\n");
return rc;
@@ -44,16 +46,18 @@ static int test_gdi_PtInRect(void)
if (!gdi_PtInRect(hRect, 30, 50))
goto fail;
if (!gdi_PtInRect(hRect, left, top))
if (!gdi_PtInRect(hRect, WINPR_ASSERTING_INT_CAST(int, left),
WINPR_ASSERTING_INT_CAST(int, top)))
goto fail;
if (!gdi_PtInRect(hRect, right, bottom))
if (!gdi_PtInRect(hRect, WINPR_ASSERTING_INT_CAST(int, right),
WINPR_ASSERTING_INT_CAST(int, bottom)))
goto fail;
if (!gdi_PtInRect(hRect, right, 60))
if (!gdi_PtInRect(hRect, WINPR_ASSERTING_INT_CAST(int, right), 60))
goto fail;
if (!gdi_PtInRect(hRect, 40, bottom))
if (!gdi_PtInRect(hRect, 40, WINPR_ASSERTING_INT_CAST(int, bottom)))
goto fail;
rc = 0;
@@ -89,7 +93,9 @@ static int test_gdi_FillRect(void)
hdc->format = PIXEL_FORMAT_XRGB32;
if (!(hRect = gdi_CreateRect(left, top, right, bottom)))
if (!(hRect = gdi_CreateRect(
WINPR_ASSERTING_INT_CAST(int, left), WINPR_ASSERTING_INT_CAST(int, top),
WINPR_ASSERTING_INT_CAST(int, right), WINPR_ASSERTING_INT_CAST(int, bottom))))
{
printf("gdi_CreateRect failed\n");
goto fail;
@@ -111,7 +117,8 @@ static int test_gdi_FillRect(void)
rawPixel = gdi_GetPixel(hdc, x, y);
pixel = FreeRDPConvertColor(rawPixel, hdc->format, PIXEL_FORMAT_ARGB32, NULL);
if (gdi_PtInRect(hRect, x, y))
if (gdi_PtInRect(hRect, WINPR_ASSERTING_INT_CAST(int, x),
WINPR_ASSERTING_INT_CAST(int, y)))
{
if (pixel == color)
{

View File

@@ -53,18 +53,18 @@ HGDI_BITMAP test_convert_to_bitmap(const BYTE* src, UINT32 SrcFormat, UINT32 Src
return bmp;
}
static void test_dump_data(unsigned char* p, int len, int width, const char* name)
static void test_dump_data(unsigned char* p, size_t len, size_t width, const char* name)
{
unsigned char* line = p;
int thisline = 0;
int offset = 0;
printf("\n%s[%d][%d]:\n", name, len / width, width);
const size_t stride = (width > 0) ? len / width : 1;
size_t offset = 0;
printf("\n%s[%" PRIuz "][%" PRIuz "]:\n", name, stride, width);
while (offset < len)
{
int i = 0;
printf("%04x ", offset);
thisline = len - offset;
size_t i = 0;
printf("%04" PRIxz " ", offset);
size_t thisline = len - offset;
if (thisline > width)
thisline = width;
@@ -86,16 +86,20 @@ static void test_dump_data(unsigned char* p, int len, int width, const char* nam
void test_dump_bitmap(HGDI_BITMAP hBmp, const char* name)
{
UINT32 stride = hBmp->width * FreeRDPGetBytesPerPixel(hBmp->format);
test_dump_data(hBmp->data, hBmp->height * stride, stride, name);
const size_t stride =
WINPR_ASSERTING_INT_CAST(size_t, hBmp->width) * FreeRDPGetBytesPerPixel(hBmp->format);
test_dump_data(hBmp->data, stride * WINPR_ASSERTING_INT_CAST(uint32_t, hBmp->height), stride,
name);
}
static BOOL CompareBitmaps(HGDI_BITMAP hBmp1, HGDI_BITMAP hBmp2, const gdiPalette* palette)
{
const BYTE* p1 = hBmp1->data;
const BYTE* p2 = hBmp2->data;
const UINT32 minw = (hBmp1->width < hBmp2->width) ? hBmp1->width : hBmp2->width;
const UINT32 minh = (hBmp1->height < hBmp2->height) ? hBmp1->height : hBmp2->height;
const UINT32 minw = WINPR_ASSERTING_INT_CAST(
uint32_t, (hBmp1->width < hBmp2->width) ? hBmp1->width : hBmp2->width);
const UINT32 minh = WINPR_ASSERTING_INT_CAST(
uint32_t, (hBmp1->height < hBmp2->height) ? hBmp1->height : hBmp2->height);
for (UINT32 y = 0; y < minh; y++)
{