Skip to content

Commit

Permalink
[warnings] fix integer multiplications
Browse files Browse the repository at this point in the history
Ensure the integer width for size arguments is 64bit in a
multiplication. Leading 64bit constant 1ull expands width, a trailing
one is ignored.

(cherry picked from commit b3f0ab2814e39e0f779343c53699e7dc6c1b1c22)
  • Loading branch information
akallabeth authored and mfleisz committed Aug 22, 2023
1 parent ed264b9 commit d8a1ac3
Show file tree
Hide file tree
Showing 19 changed files with 38 additions and 38 deletions.
2 changes: 1 addition & 1 deletion channels/rdpsnd/server/rdpsnd_main.c
Expand Up @@ -523,7 +523,7 @@ static UINT rdpsnd_server_send_wave_pdu(RdpsndServerContext* context, UINT16 wTi
Stream_Seek(s, 3); /* bPad */
start = Stream_GetPosition(s);
src = context->priv->out_buffer;
length = context->priv->out_pending_frames * context->priv->src_bytes_per_frame * 1ULL;
length = 1ull * context->priv->out_pending_frames * context->priv->src_bytes_per_frame;

if (!freerdp_dsp_encode(context->priv->dsp_context, context->src_format, src, length, s))
return ERROR_INTERNAL_ERROR;
Expand Down
2 changes: 1 addition & 1 deletion client/X11/xf_gdi.c
Expand Up @@ -1066,7 +1066,7 @@ static BOOL xf_gdi_surface_bits(rdpContext* context, const SURFACE_BITS_COMMAND*
case RDP_CODEC_ID_NONE:
pSrcData = cmd->bmp.bitmapData;
format = gdi_get_pixel_format(cmd->bmp.bpp);
size = cmd->bmp.width * cmd->bmp.height * GetBytesPerPixel(format) * 1ULL;
size = 1ull * cmd->bmp.width * cmd->bmp.height * GetBytesPerPixel(format);
if (size > cmd->bmp.bitmapDataLength)
{
WLog_ERR(TAG, "Short nocodec message: got %" PRIu32 " bytes, require %" PRIuz,
Expand Down
4 changes: 2 additions & 2 deletions client/X11/xf_gfx.c
Expand Up @@ -288,7 +288,7 @@ static UINT xf_CreateSurface(RdpgfxClientContext* context,

surface->gdi.scanline = surface->gdi.width * GetBytesPerPixel(surface->gdi.format);
surface->gdi.scanline = x11_pad_scanline(surface->gdi.scanline, xfc->scanline_pad);
size = surface->gdi.scanline * surface->gdi.height * 1ULL;
size = 1ull * surface->gdi.scanline * surface->gdi.height;
surface->gdi.data = (BYTE*)_aligned_malloc(size, 16);

if (!surface->gdi.data)
Expand All @@ -312,7 +312,7 @@ static UINT xf_CreateSurface(RdpgfxClientContext* context,
UINT32 bytes = GetBytesPerPixel(gdi->dstFormat);
surface->stageScanline = width * bytes;
surface->stageScanline = x11_pad_scanline(surface->stageScanline, xfc->scanline_pad);
size = surface->stageScanline * surface->gdi.height * 1ULL;
size = 1ull * surface->stageScanline * surface->gdi.height;
surface->stage = (BYTE*)_aligned_malloc(size, 16);

if (!surface->stage)
Expand Down
4 changes: 2 additions & 2 deletions client/X11/xf_graphics.c
Expand Up @@ -311,7 +311,7 @@ static BOOL xf_Pointer_GetCursorForCurrentScale(rdpContext* context, const rdpPo
ci.height = yTargetSize;
ci.xhot = pointer->xPos * xscale;
ci.yhot = pointer->yPos * yscale;
size = ci.height * ci.width * GetBytesPerPixel(CursorFormat) * 1ULL;
size = 1ull * ci.height * ci.width * GetBytesPerPixel(CursorFormat);

if (!(ci.pixels = (XcursorPixel*)_aligned_malloc(size, 16)))
{
Expand Down Expand Up @@ -421,7 +421,7 @@ static BOOL xf_Pointer_New(rdpContext* context, rdpPointer* pointer)
xpointer->nCursors = 0;
xpointer->mCursors = 0;

size = pointer->height * pointer->width * GetBytesPerPixel(CursorFormat) * 1ULL;
size = 1ull * pointer->height * pointer->width * GetBytesPerPixel(CursorFormat);

if (!(xpointer->cursorPixels = (XcursorPixel*)_aligned_malloc(size, 16)))
goto fail;
Expand Down
4 changes: 2 additions & 2 deletions client/X11/xf_rail.c
Expand Up @@ -544,7 +544,7 @@ static xfRailIconCache* RailIconCache_New(rdpSettings* settings)

cache->numCaches = settings->RemoteAppNumIconCaches;
cache->numCacheEntries = settings->RemoteAppNumIconCacheEntries;
cache->entries = calloc(cache->numCaches * cache->numCacheEntries * 1ULL, sizeof(xfRailIcon));
cache->entries = calloc(1ull * cache->numCaches * cache->numCacheEntries, sizeof(xfRailIcon));

if (!cache->entries)
{
Expand Down Expand Up @@ -614,7 +614,7 @@ static BOOL convert_rail_icon(const ICON_INFO* iconInfo, xfRailIcon* railIcon)
long* pixels;
int i;
int nelements;
argbPixels = calloc(iconInfo->width * iconInfo->height * 1ULL, 4);
argbPixels = calloc(1ull * iconInfo->width * iconInfo->height, 4);

if (!argbPixels)
goto error;
Expand Down
4 changes: 2 additions & 2 deletions libfreerdp/codec/clear.c
Expand Up @@ -566,7 +566,7 @@ static BOOL resize_vbar_entry(CLEAR_CONTEXT* clear, CLEAR_VBAR_ENTRY* vBarEntry)
const UINT32 diffSize = (vBarEntry->count - vBarEntry->size) * bpp;
BYTE* tmp;
vBarEntry->size = vBarEntry->count;
tmp = (BYTE*)realloc(vBarEntry->pixels, vBarEntry->count * bpp * 1ULL);
tmp = (BYTE*)realloc(vBarEntry->pixels, 1ull * vBarEntry->count * bpp);

if (!tmp)
{
Expand Down Expand Up @@ -980,7 +980,7 @@ static BOOL clear_decompress_glyph_data(CLEAR_CONTEXT* clear, wStream* s, UINT32
if (glyphEntry->count > glyphEntry->size)
{
BYTE* tmp;
tmp = realloc(glyphEntry->pixels, glyphEntry->count * bpp * 1ULL);
tmp = realloc(glyphEntry->pixels, 1ull * glyphEntry->count * bpp);

if (!tmp)
{
Expand Down
6 changes: 3 additions & 3 deletions libfreerdp/codec/color.c
Expand Up @@ -56,7 +56,7 @@ BYTE* freerdp_glyph_convert(UINT32 width, UINT32 height, const BYTE* data)
* means of accessing individual pixels in blitting operations
*/
scanline = (width + 7) / 8;
dstData = (BYTE*)_aligned_malloc(width * height * 1ULL, 16);
dstData = (BYTE*)_aligned_malloc(1ull * width * height, 16);

if (!dstData)
return NULL;
Expand Down Expand Up @@ -545,7 +545,7 @@ BOOL freerdp_image_copy_from_pointer_data(BYTE* pDstData, UINT32 DstFormat, UINT
for (y = nYDst; y < nHeight; y++)
{
BYTE* pDstLine = &pDstData[y * nDstStep + nXDst * dstBytesPerPixel];
memset(pDstLine, 0, dstBytesPerPixel * (nWidth - nXDst) * 1ULL);
memset(pDstLine, 0, 1ull * dstBytesPerPixel * (nWidth - nXDst));
}

switch (xorBpp)
Expand Down Expand Up @@ -743,7 +743,7 @@ BOOL freerdp_image_fill(BYTE* pDstData, DWORD DstFormat, UINT32 nDstStep, UINT32
for (UINT32 y = 1; y < nHeight; y++)
{
BYTE* pDstLine = &pDstData[(y + nYDst) * nDstStep + nXDst * bpp];
memcpy(pDstLine, pFirstDstLineXOffset, nWidth * bpp * 1ULL);
memcpy(pDstLine, pFirstDstLineXOffset, 1ull * nWidth * bpp);
}

return TRUE;
Expand Down
6 changes: 3 additions & 3 deletions libfreerdp/codec/h264.c
Expand Up @@ -63,9 +63,9 @@ BOOL avc420_ensure_buffer(H264_CONTEXT* h264, UINT32 stride, UINT32 width, UINT3
_aligned_free(h264->pYUVData[0]);
_aligned_free(h264->pYUVData[1]);
_aligned_free(h264->pYUVData[2]);
h264->pYUVData[0] = _aligned_malloc(h264->iStride[0] * height * 1ULL, 16);
h264->pYUVData[1] = _aligned_malloc(h264->iStride[1] * height * 1ULL, 16);
h264->pYUVData[2] = _aligned_malloc(h264->iStride[2] * height * 1ULL, 16);
h264->pYUVData[0] = _aligned_malloc(1ull * h264->iStride[0] * height, 16);
h264->pYUVData[1] = _aligned_malloc(1ull * h264->iStride[1] * height, 16);
h264->pYUVData[2] = _aligned_malloc(1ull * h264->iStride[2] * height, 16);

if (!h264->pYUVData[0] || !h264->pYUVData[1] || !h264->pYUVData[2])
return FALSE;
Expand Down
2 changes: 1 addition & 1 deletion libfreerdp/codec/progressive.c
Expand Up @@ -415,7 +415,7 @@ static INLINE BOOL progressive_tile_allocate(RFX_PROGRESSIVE_TILE* tile)
tile->stride = 4 * tile->width;

{
size_t dataLen = tile->stride * tile->height * 1ULL;
size_t dataLen = 1ull * tile->stride * tile->height;
tile->data = (BYTE*)_aligned_malloc(dataLen, 16);
}

Expand Down
2 changes: 1 addition & 1 deletion libfreerdp/gdi/bitmap.c
Expand Up @@ -148,7 +148,7 @@ HGDI_BITMAP gdi_CreateCompatibleBitmap(HGDI_DC hdc, UINT32 nWidth, UINT32 nHeigh
hBitmap->width = nWidth;
hBitmap->height = nHeight;
hBitmap->data =
_aligned_malloc(nWidth * nHeight * GetBytesPerPixel(hBitmap->format) * 1ULL, 16);
_aligned_malloc(1ull * nWidth * nHeight * GetBytesPerPixel(hBitmap->format), 16);
hBitmap->free = _aligned_free;

if (!hBitmap->data)
Expand Down
2 changes: 1 addition & 1 deletion libfreerdp/gdi/gdi.c
Expand Up @@ -1086,7 +1086,7 @@ static BOOL gdi_surface_bits(rdpContext* context, const SURFACE_BITS_COMMAND* cm

case RDP_CODEC_ID_NONE:
format = gdi_get_pixel_format(cmd->bmp.bpp);
size = cmd->bmp.width * cmd->bmp.height * GetBytesPerPixel(format) * 1ULL;
size = 1ull * cmd->bmp.width * cmd->bmp.height * GetBytesPerPixel(format);
if (size > cmd->bmp.bitmapDataLength)
{
WLog_ERR(TAG, "Short nocodec message: got %" PRIu32 " bytes, require %" PRIuz,
Expand Down
4 changes: 2 additions & 2 deletions libfreerdp/gdi/gfx.c
Expand Up @@ -726,7 +726,7 @@ static UINT gdi_SurfaceCommand_Alpha(rdpGdi* gdi, RdpgfxClientContext* context,
{
UINT32 x, y;

if (Stream_GetRemainingLength(&s) < cmd->height * cmd->width * 1ULL)
if (Stream_GetRemainingLength(&s) < 1ull * cmd->height * cmd->width)
return ERROR_INVALID_DATA;

for (y = cmd->top; y < cmd->top + cmd->height; y++)
Expand Down Expand Up @@ -1025,7 +1025,7 @@ static UINT gdi_CreateSurface(RdpgfxClientContext* context,
}

surface->scanline = gfx_align_scanline(surface->width * 4UL, 16);
surface->data = (BYTE*)_aligned_malloc(surface->scanline * surface->height * 1ULL, 16);
surface->data = (BYTE*)_aligned_malloc(1ull * surface->scanline * surface->height, 16);

if (!surface->data)
{
Expand Down
2 changes: 1 addition & 1 deletion libfreerdp/gdi/graphics.c
Expand Up @@ -52,7 +52,7 @@ HGDI_BITMAP gdi_create_bitmap(rdpGdi* gdi, UINT32 nWidth, UINT32 nHeight, UINT32
return NULL;

nDstStep = nWidth * GetBytesPerPixel(gdi->dstFormat);
pDstData = _aligned_malloc(nHeight * nDstStep * 1ULL, 16);
pDstData = _aligned_malloc(1ull * nHeight * nDstStep, 16);

if (!pDstData)
return NULL;
Expand Down
2 changes: 1 addition & 1 deletion libfreerdp/gdi/shape.c
Expand Up @@ -158,7 +158,7 @@ BOOL gdi_FillRect(HGDI_DC hdc, const HGDI_RECT rect, HGDI_BRUSH hbr)
for (y = 1; y < nHeight; y++)
{
BYTE* dstp = gdi_get_bitmap_pointer(hdc, nXDest, nYDest + y);
memcpy(dstp, srcp, nWidth * formatSize * 1ULL);
memcpy(dstp, srcp, 1ull * nWidth * formatSize);
}

break;
Expand Down
2 changes: 1 addition & 1 deletion libfreerdp/gdi/video.c
Expand Up @@ -66,7 +66,7 @@ static VideoSurface* gdiVideoCreateSurface(VideoClientContext* video, BYTE* data
ret->base.w = width;
ret->base.h = height;
ret->scanline = width * bpp;
ret->image = _aligned_malloc(ret->scanline * height * 1ULL, 16);
ret->image = _aligned_malloc(1ull * ret->scanline * height, 16);

if (!ret->image)
{
Expand Down
4 changes: 2 additions & 2 deletions libfreerdp/primitives/prim_copy.c
Expand Up @@ -60,14 +60,14 @@ static BOOL memory_regions_overlap_2d(const BYTE* p1, int p1Step, int p1Size, co

if (p1m <= p2m)
{
ULONG_PTR p1mEnd = p1m + (height - 1) * p1Step * 1ULL + width * p1Size * 1ULL;
ULONG_PTR p1mEnd = p1m + 1ull * (height - 1) * p1Step + 1ull * width * p1Size;

if (p1mEnd > p2m)
return TRUE;
}
else
{
ULONG_PTR p2mEnd = p2m + (height - 1) * p2Step * 1ULL + width * p2Size * 1ULL;
ULONG_PTR p2mEnd = p2m + 1ull * (height - 1) * p2Step + 1ull * width * p2Size;

if (p2mEnd > p1m)
return TRUE;
Expand Down
2 changes: 1 addition & 1 deletion libfreerdp/primitives/primitives.c
Expand Up @@ -157,7 +157,7 @@ static primitives_YUV_benchmark* primitives_YUV_benchmark_init(primitives_YUV_be
if (!buf)
goto fail;

winpr_RAND(buf, roi->width * roi->height * 1ULL);
winpr_RAND(buf, 1ull * roi->width * roi->height);
ret->steps[i] = roi->width;
}

Expand Down
8 changes: 4 additions & 4 deletions uwac/libuwac/uwac-window.c
Expand Up @@ -320,14 +320,14 @@ int UwacWindowShmAllocBuffers(UwacWindow* w, int nbuffers, int allocSize, uint32

w->buffers = newBuffers;
memset(w->buffers + w->nbuffers, 0, sizeof(UwacBuffer) * nbuffers);
fd = uwac_create_anonymous_file(allocSize * nbuffers * 1ULL);
fd = uwac_create_anonymous_file(1ull * allocSize * nbuffers);

if (fd < 0)
{
return UWAC_ERROR_INTERNAL;
}

data = mmap(NULL, allocSize * nbuffers * 1ULL, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
data = mmap(NULL, 1ull * allocSize * nbuffers, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);

if (data == MAP_FAILED)
{
Expand All @@ -339,7 +339,7 @@ int UwacWindowShmAllocBuffers(UwacWindow* w, int nbuffers, int allocSize, uint32

if (!pool)
{
munmap(data, allocSize * nbuffers * 1ULL);
munmap(data, 1ull * allocSize * nbuffers);
ret = UWAC_ERROR_NOMEMORY;
goto error_mmap;
}
Expand Down Expand Up @@ -764,7 +764,7 @@ UwacReturnCode UwacWindowSubmitBuffer(UwacWindow* window, bool copyContentForNex

if (copyContentForNextFrame)
memcpy(nextDrawingBuffer->data, pendingBuffer->data,
window->stride * window->height * 1ULL);
1ull * window->stride * window->height);

UwacSubmitBufferPtr(window, pendingBuffer);
return UWAC_SUCCESS;
Expand Down
14 changes: 7 additions & 7 deletions winpr/libwinpr/utils/lodepng/lodepng.c
Expand Up @@ -3815,7 +3815,7 @@ unsigned lodepng_convert(unsigned char* out, const unsigned char* in, LodePNGCol
{
size_t i;
ColorTree tree;
size_t numpixels = w * h * 1ULL;
size_t numpixels = 1ull * w * h;

if (lodepng_color_mode_equal(mode_out, mode_in))
{
Expand Down Expand Up @@ -3918,7 +3918,7 @@ unsigned get_color_profile(LodePNGColorProfile* profile, const unsigned char* in
unsigned error = 0;
size_t i;
ColorTree tree;
size_t numpixels = w * h * 1ULL;
size_t numpixels = 1ull * w * h;

unsigned colored_done = lodepng_is_greyscale_type(mode) ? 1 : 0;
unsigned alpha_done = lodepng_can_have_alpha(mode) ? 0 : 1;
Expand Down Expand Up @@ -4539,7 +4539,7 @@ static unsigned postProcessScanlines(unsigned char* out, unsigned char* in, unsi
if (bpp < 8 && w * bpp != ((w * bpp + 7) / 8) * 8)
{
CERROR_TRY_RETURN(unfilter(in, in, w, h, bpp));
removePaddingBits(out, in, w * bpp * 1ULL, ((w * bpp + 7ULL) / 8ULL) * 8ULL, h);
removePaddingBits(out, in, 1ull * w * bpp, ((w * bpp + 7ULL) / 8ULL) * 8ULL, h);
}
/*we can immediatly filter into the out buffer, no other steps needed*/
else
Expand All @@ -4565,7 +4565,7 @@ static unsigned postProcessScanlines(unsigned char* out, unsigned char* in, unsi
bits between the different reduced images: each reduced image still starts nicely at
a byte*/
removePaddingBits(&in[passstart[i]], &in[padded_passstart[i]],
passw[i] * bpp * 1ULL, ((passw[i] * bpp + 7ULL) / 8ULL) * 8ULL,
1ull * passw[i] * bpp, ((passw[i] * bpp + 7ULL) / 8ULL) * 8ULL,
passh[i]);
}
}
Expand Down Expand Up @@ -6056,7 +6056,7 @@ static unsigned preProcessScanlines(unsigned char** out, size_t* outsize, const
error = 83; /*alloc fail*/
if (!error)
{
addPaddingBits(padded, in, ((w * bpp + 7ULL) / 8ULL) * 8ULL, w * bpp * 1ULL, h);
addPaddingBits(padded, in, ((w * bpp + 7ULL) / 8ULL) * 8ULL, 1ull * w * bpp, h);
error = filter(*out, padded, w, h, &info_png->color, settings);
}
free(padded);
Expand Down Expand Up @@ -6100,8 +6100,8 @@ static unsigned preProcessScanlines(unsigned char** out, size_t* outsize, const
if (!padded)
ERROR_BREAK(83); /*alloc fail*/
addPaddingBits(padded, &adam7[passstart[i]],
((passw[i] * bpp + 7ULL) / 8ULL) * 8ULL, passw[i] * bpp * 1ULL,
passh[i] * 1ULL);
((passw[i] * bpp + 7ULL) / 8ULL) * 8ULL, 1ull * passw[i] * bpp,
1ull * passh[i]);
error = filter(&(*out)[filter_passstart[i]], padded, passw[i], passh[i],
&info_png->color, settings);
free(padded);
Expand Down

0 comments on commit d8a1ac3

Please sign in to comment.