From 7a7144147618547df9b60ade73a7464b8e3f02df Mon Sep 17 00:00:00 2001 From: akallabeth Date: Tue, 22 Aug 2023 09:41:28 +0200 Subject: [PATCH] [warnings] fix integer multiplications Ensure the integer width for size arguments is 64bit in a multiplication. Leading 64bit constant 1ull expands width, a trailing one is ignored. --- channels/rdpsnd/server/rdpsnd_main.c | 2 +- channels/video/client/video_main.c | 4 ++-- client/X11/xf_gdi.c | 2 +- client/X11/xf_gfx.c | 4 ++-- client/X11/xf_graphics.c | 4 ++-- client/X11/xf_rail.c | 4 ++-- libfreerdp/codec/clear.c | 4 ++-- libfreerdp/codec/color.c | 6 +++--- libfreerdp/codec/dsp.c | 2 +- libfreerdp/codec/progressive.c | 2 +- libfreerdp/gdi/bitmap.c | 2 +- libfreerdp/gdi/gdi.c | 2 +- libfreerdp/gdi/gfx.c | 4 ++-- libfreerdp/gdi/graphics.c | 2 +- libfreerdp/gdi/shape.c | 2 +- libfreerdp/gdi/video.c | 2 +- libfreerdp/primitives/prim_copy.c | 4 ++-- libfreerdp/primitives/primitives.c | 2 +- rdtk/librdtk/rdtk_nine_patch.c | 2 +- server/proxy/modules/capture/cap_main.c | 2 +- server/shadow/X11/x11_shadow.c | 2 +- server/shadow/shadow_surface.c | 2 +- uwac/libuwac/uwac-window.c | 8 ++++---- 23 files changed, 35 insertions(+), 35 deletions(-) diff --git a/channels/rdpsnd/server/rdpsnd_main.c b/channels/rdpsnd/server/rdpsnd_main.c index 3ad7070a7..fe3f878af 100644 --- a/channels/rdpsnd/server/rdpsnd_main.c +++ b/channels/rdpsnd/server/rdpsnd_main.c @@ -520,7 +520,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; diff --git a/channels/video/client/video_main.c b/channels/video/client/video_main.c index 6d0c1b7d4..724fc8150 100644 --- a/channels/video/client/video_main.c +++ b/channels/video/client/video_main.c @@ -310,7 +310,7 @@ static VideoFrame* VideoFrame_new(VideoClientContextPriv* priv, PresentationCont frame->h = surface->alignedHeight; frame->scanline = surface->scanline; - frame->surfaceData = BufferPool_Take(priv->surfacePool, frame->scanline * frame->h * 1ull); + frame->surfaceData = BufferPool_Take(priv->surfacePool, 1ull * frame->scanline * frame->h); if (!frame->surfaceData) goto fail; @@ -710,7 +710,7 @@ static void video_timer(VideoClientContext* video, UINT64 now) presentation = frame->presentation; priv->publishedFrames++; - memcpy(presentation->surface->data, frame->surfaceData, frame->scanline * frame->h * 1ull); + memcpy(presentation->surface->data, frame->surfaceData, 1ull * frame->scanline * frame->h); WINPR_ASSERT(video->showSurface); video->showSurface(video, presentation->surface, presentation->ScaledWidth, diff --git a/client/X11/xf_gdi.c b/client/X11/xf_gdi.c index 6f394d314..07de82da1 100644 --- a/client/X11/xf_gdi.c +++ b/client/X11/xf_gdi.c @@ -1056,7 +1056,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 * FreeRDPGetBytesPerPixel(format) * 1ULL; + size = 1ull * cmd->bmp.width * cmd->bmp.height * FreeRDPGetBytesPerPixel(format); if (size > cmd->bmp.bitmapDataLength) { WLog_ERR(TAG, "Short nocodec message: got %" PRIu32 " bytes, require %" PRIuz, diff --git a/client/X11/xf_gfx.c b/client/X11/xf_gfx.c index 6650de958..7860a3718 100644 --- a/client/X11/xf_gfx.c +++ b/client/X11/xf_gfx.c @@ -310,7 +310,7 @@ static UINT xf_CreateSurface(RdpgfxClientContext* context, surface->gdi.scanline = surface->gdi.width * FreeRDPGetBytesPerPixel(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*)winpr_aligned_malloc(size, 16); if (!surface->gdi.data) @@ -335,7 +335,7 @@ static UINT xf_CreateSurface(RdpgfxClientContext* context, UINT32 bytes = FreeRDPGetBytesPerPixel(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*)winpr_aligned_malloc(size, 16); if (!surface->stage) diff --git a/client/X11/xf_graphics.c b/client/X11/xf_graphics.c index 5ab403471..267228840 100644 --- a/client/X11/xf_graphics.c +++ b/client/X11/xf_graphics.c @@ -313,7 +313,7 @@ static BOOL xf_Pointer_GetCursorForCurrentScale(rdpContext* context, rdpPointer* ci.height = yTargetSize; ci.xhot = pointer->xPos * xscale; ci.yhot = pointer->yPos * yscale; - const size_t size = ci.height * ci.width * FreeRDPGetBytesPerPixel(CursorFormat) * 1ULL; + const size_t size = 1ull * ci.height * ci.width * FreeRDPGetBytesPerPixel(CursorFormat); void* tmp = winpr_aligned_malloc(size, 16); if (!tmp) @@ -427,7 +427,7 @@ static BOOL xf_Pointer_New(rdpContext* context, rdpPointer* pointer) xpointer->nCursors = 0; xpointer->mCursors = 0; - size = pointer->height * pointer->width * FreeRDPGetBytesPerPixel(CursorFormat) * 1ULL; + size = 1ull * pointer->height * pointer->width * FreeRDPGetBytesPerPixel(CursorFormat); if (!(xpointer->cursorPixels = (XcursorPixel*)winpr_aligned_malloc(size, 16))) goto fail; diff --git a/client/X11/xf_rail.c b/client/X11/xf_rail.c index 6ee899846..9844a9cd6 100644 --- a/client/X11/xf_rail.c +++ b/client/X11/xf_rail.c @@ -575,7 +575,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) { @@ -645,7 +645,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; diff --git a/libfreerdp/codec/clear.c b/libfreerdp/codec/clear.c index ca627f197..c17849b32 100644 --- a/libfreerdp/codec/clear.c +++ b/libfreerdp/codec/clear.c @@ -552,7 +552,7 @@ static BOOL resize_vbar_entry(CLEAR_CONTEXT* clear, CLEAR_VBAR_ENTRY* vBarEntry) vBarEntry->size = vBarEntry->count; BYTE* tmp = - (BYTE*)winpr_aligned_recalloc(vBarEntry->pixels, vBarEntry->count, bpp * 1ULL, 32); + (BYTE*)winpr_aligned_recalloc(vBarEntry->pixels, vBarEntry->count, 1ull * bpp, 32); if (!tmp) { @@ -950,7 +950,7 @@ static BOOL clear_decompress_glyph_data(CLEAR_CONTEXT* clear, wStream* s, UINT32 if (glyphEntry->count > glyphEntry->size) { BYTE* tmp = - winpr_aligned_recalloc(glyphEntry->pixels, glyphEntry->count, bpp * 1ULL, 32); + winpr_aligned_recalloc(glyphEntry->pixels, glyphEntry->count, 1ull * bpp, 32); if (!tmp) { diff --git a/libfreerdp/codec/color.c b/libfreerdp/codec/color.c index 6d963e0ca..56d8e8275 100644 --- a/libfreerdp/codec/color.c +++ b/libfreerdp/codec/color.c @@ -54,7 +54,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*)winpr_aligned_malloc(width * height * 1ULL, 16); + dstData = (BYTE*)winpr_aligned_malloc(1ull * width * height, 16); if (!dstData) return NULL; @@ -540,7 +540,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) @@ -775,7 +775,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; diff --git a/libfreerdp/codec/dsp.c b/libfreerdp/codec/dsp.c index 87e6b3c3d..8b7d8dea3 100644 --- a/libfreerdp/codec/dsp.c +++ b/libfreerdp/codec/dsp.c @@ -1327,7 +1327,7 @@ BOOL freerdp_dsp_context_reset(FREERDP_DSP_CONTEXT* context, const AUDIO_FORMAT* if (context->format.wFormatTag == WAVE_FORMAT_DVI_ADPCM) { size_t min_frame_data = - context->format.wBitsPerSample * context->format.nChannels * FramesPerPacket * 1ULL; + 1ull * context->format.wBitsPerSample * context->format.nChannels * FramesPerPacket; size_t data_per_block = (context->format.nBlockAlign - 4 * context->format.nChannels) * 8; size_t nb_block_per_packet = min_frame_data / data_per_block; diff --git a/libfreerdp/codec/progressive.c b/libfreerdp/codec/progressive.c index c70a09225..e0d77eeb2 100644 --- a/libfreerdp/codec/progressive.c +++ b/libfreerdp/codec/progressive.c @@ -418,7 +418,7 @@ static INLINE RFX_PROGRESSIVE_TILE* progressive_tile_new(void) tile->height = 64; tile->stride = 4 * tile->width; - size_t dataLen = tile->stride * tile->height * 1ULL; + size_t dataLen = 1ull * tile->stride * tile->height; tile->data = (BYTE*)winpr_aligned_malloc(dataLen, 16); if (!tile->data) goto fail; diff --git a/libfreerdp/gdi/bitmap.c b/libfreerdp/gdi/bitmap.c index 8e7297f2e..178f5fd41 100644 --- a/libfreerdp/gdi/bitmap.c +++ b/libfreerdp/gdi/bitmap.c @@ -158,7 +158,7 @@ HGDI_BITMAP gdi_CreateCompatibleBitmap(HGDI_DC hdc, UINT32 nWidth, UINT32 nHeigh hBitmap->width = nWidth; hBitmap->height = nHeight; hBitmap->data = winpr_aligned_malloc( - nWidth * nHeight * FreeRDPGetBytesPerPixel(hBitmap->format) * 1ULL, 16); + 1ull * nWidth * nHeight * FreeRDPGetBytesPerPixel(hBitmap->format), 16); hBitmap->free = winpr_aligned_free; if (!hBitmap->data) diff --git a/libfreerdp/gdi/gdi.c b/libfreerdp/gdi/gdi.c index 1bafa96f6..cd9ebdca1 100644 --- a/libfreerdp/gdi/gdi.c +++ b/libfreerdp/gdi/gdi.c @@ -1103,7 +1103,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 * FreeRDPGetBytesPerPixel(format) * 1ULL; + size = 1ull * cmd->bmp.width * cmd->bmp.height * FreeRDPGetBytesPerPixel(format); if (size > cmd->bmp.bitmapDataLength) { WLog_ERR(TAG, "Short nocodec message: got %" PRIu32 " bytes, require %" PRIuz, diff --git a/libfreerdp/gdi/gfx.c b/libfreerdp/gdi/gfx.c index 5bd1c11a1..4d3480539 100644 --- a/libfreerdp/gdi/gfx.c +++ b/libfreerdp/gdi/gfx.c @@ -355,7 +355,7 @@ static UINT gdi_SurfaceCommand_Uncompressed(rdpGdi* gdi, RdpgfxClientContext* co return ERROR_INVALID_DATA; bpp = FreeRDPGetBytesPerPixel(cmd->format); - size = bpp * cmd->width * cmd->height * 1ULL; + size = 1ull * bpp * cmd->width * cmd->height; if (cmd->length < size) { WLog_ERR(TAG, "Not enough data, got %" PRIu32 ", expected %" PRIuz, cmd->length, size); @@ -1154,7 +1154,7 @@ static UINT gdi_CreateSurface(RdpgfxClientContext* context, } surface->scanline = gfx_align_scanline(surface->width * 4UL, 16); - surface->data = (BYTE*)winpr_aligned_malloc(surface->scanline * surface->height * 1ULL, 16); + surface->data = (BYTE*)winpr_aligned_malloc(1ull * surface->scanline * surface->height, 16); if (!surface->data) { diff --git a/libfreerdp/gdi/graphics.c b/libfreerdp/gdi/graphics.c index aa89ef25c..d6c09c0cd 100644 --- a/libfreerdp/gdi/graphics.c +++ b/libfreerdp/gdi/graphics.c @@ -51,7 +51,7 @@ HGDI_BITMAP gdi_create_bitmap(rdpGdi* gdi, UINT32 nWidth, UINT32 nHeight, UINT32 return NULL; nDstStep = nWidth * FreeRDPGetBytesPerPixel(gdi->dstFormat); - pDstData = winpr_aligned_malloc(nHeight * nDstStep * 1ULL, 16); + pDstData = winpr_aligned_malloc(1ull * nHeight * nDstStep, 16); if (!pDstData) return NULL; diff --git a/libfreerdp/gdi/shape.c b/libfreerdp/gdi/shape.c index a32c997dc..a9c9b795f 100644 --- a/libfreerdp/gdi/shape.c +++ b/libfreerdp/gdi/shape.c @@ -160,7 +160,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; diff --git a/libfreerdp/gdi/video.c b/libfreerdp/gdi/video.c index c67fef30a..fc605eba0 100644 --- a/libfreerdp/gdi/video.c +++ b/libfreerdp/gdi/video.c @@ -194,7 +194,7 @@ VideoSurface* VideoClient_CreateCommonContext(size_t size, UINT32 x, UINT32 y, U ret->alignedHeight = ret->h + 32 - ret->h % 16; ret->scanline = ret->alignedWidth * FreeRDPGetBytesPerPixel(ret->format); - ret->data = winpr_aligned_malloc(ret->scanline * ret->alignedHeight * 1ULL, 64); + ret->data = winpr_aligned_malloc(1ull * ret->scanline * ret->alignedHeight, 64); if (!ret->data) goto fail; return ret; diff --git a/libfreerdp/primitives/prim_copy.c b/libfreerdp/primitives/prim_copy.c index 78530ac30..f140c20aa 100644 --- a/libfreerdp/primitives/prim_copy.c +++ b/libfreerdp/primitives/prim_copy.c @@ -58,14 +58,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; diff --git a/libfreerdp/primitives/primitives.c b/libfreerdp/primitives/primitives.c index b843c1ace..6276b7b70 100644 --- a/libfreerdp/primitives/primitives.c +++ b/libfreerdp/primitives/primitives.c @@ -156,7 +156,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; } diff --git a/rdtk/librdtk/rdtk_nine_patch.c b/rdtk/librdtk/rdtk_nine_patch.c index 2d5025c1a..4ae376190 100644 --- a/rdtk/librdtk/rdtk_nine_patch.c +++ b/rdtk/librdtk/rdtk_nine_patch.c @@ -358,7 +358,7 @@ static BOOL rdtk_nine_patch_get_fill_ht(rdtkNinePatch* ninePatch, wImage* image) { const uint32_t* pixel = (uint32_t*)&image->data[((image->width - 1) * sizeof(uint32_t)) + - image->scanline * y * 1ull]; /* (width - 1, 1) */ + 1ull * image->scanline * y]; /* (width - 1, 1) */ if (beg < 0) { if (*pixel) diff --git a/server/proxy/modules/capture/cap_main.c b/server/proxy/modules/capture/cap_main.c index a8a108879..38f9626a8 100644 --- a/server/proxy/modules/capture/cap_main.c +++ b/server/proxy/modules/capture/cap_main.c @@ -162,7 +162,7 @@ static BOOL capture_plugin_send_frame(pClientContext* pc, SOCKET socket, const B settings = pc->context.settings; WINPR_ASSERT(settings); - frame_size = settings->DesktopWidth * settings->DesktopHeight * 1ull * + frame_size = 1ull * settings->DesktopWidth * settings->DesktopHeight * (freerdp_settings_get_uint32(settings, FreeRDP_ColorDepth) / 8ull); bmp_header = winpr_bitmap_construct_header(settings->DesktopWidth, settings->DesktopHeight, diff --git a/server/shadow/X11/x11_shadow.c b/server/shadow/X11/x11_shadow.c index a4762bafe..8dc9b4e7f 100644 --- a/server/shadow/X11/x11_shadow.c +++ b/server/shadow/X11/x11_shadow.c @@ -1117,7 +1117,7 @@ static int x11_shadow_xshm_init(x11ShadowSubsystem* subsystem) } subsystem->fb_shm_info.shmid = shmget( - IPC_PRIVATE, subsystem->fb_image->bytes_per_line * subsystem->fb_image->height * 1ull, + IPC_PRIVATE, 1ull * subsystem->fb_image->bytes_per_line * subsystem->fb_image->height, IPC_CREAT | 0600); if (subsystem->fb_shm_info.shmid == -1) diff --git a/server/shadow/shadow_surface.c b/server/shadow/shadow_surface.c index 21a7e379d..599e290c0 100644 --- a/server/shadow/shadow_surface.c +++ b/server/shadow/shadow_surface.c @@ -87,7 +87,7 @@ BOOL shadow_surface_resize(rdpShadowSurface* surface, UINT16 x, UINT16 y, UINT32 return TRUE; } - buffer = (BYTE*)realloc(surface->data, scanline * ALIGN_SCREEN_SIZE(height, 4) * 1ull); + buffer = (BYTE*)realloc(surface->data, 1ull * scanline * ALIGN_SCREEN_SIZE(height, 4ull)); if (buffer) { diff --git a/uwac/libuwac/uwac-window.c b/uwac/libuwac/uwac-window.c index 7ef856da5..072d53052 100644 --- a/uwac/libuwac/uwac-window.c +++ b/uwac/libuwac/uwac-window.c @@ -323,14 +323,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) { @@ -342,7 +342,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; } @@ -789,7 +789,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;