From bd637c6cd1d1785fb75bff621612e23776ac6992 Mon Sep 17 00:00:00 2001 From: akallabeth Date: Thu, 29 Aug 2024 16:13:43 +0200 Subject: [PATCH] [warnings] fix various clang-tidy warnings --- channels/parallel/client/parallel_main.c | 3 ++- channels/rdpdr/client/rdpdr_main.c | 3 ++- channels/rdpei/client/rdpei_main.c | 6 +++--- channels/rdpei/rdpei_common.c | 2 +- channels/rdpgfx/client/rdpgfx_main.c | 9 +++++++-- channels/rdpsnd/client/alsa/rdpsnd_alsa.c | 6 +----- channels/serial/client/serial_main.c | 1 - channels/urbdrc/client/data_transfer.c | 3 --- channels/urbdrc/client/libusb/libusb_udevice.h | 2 +- channels/urbdrc/client/urbdrc_main.h | 2 +- channels/video/client/video_main.c | 2 +- client/SDL/SDL2/sdl_pointer.cpp | 2 +- client/SDL/SDL3/sdl_pointer.cpp | 2 +- libfreerdp/codec/dsp_ffmpeg.c | 2 +- libfreerdp/core/activation.c | 2 +- libfreerdp/core/smartcardlogon.c | 12 ++++++++---- libfreerdp/core/tcp.c | 8 ++++---- winpr/libwinpr/synch/timer.c | 4 ---- 18 files changed, 35 insertions(+), 36 deletions(-) diff --git a/channels/parallel/client/parallel_main.c b/channels/parallel/client/parallel_main.c index c15c0119f..740fecf51 100644 --- a/channels/parallel/client/parallel_main.c +++ b/channels/parallel/client/parallel_main.c @@ -406,7 +406,8 @@ static UINT parallel_free_int(PARALLEL_DEVICE* parallel) static UINT parallel_free(DEVICE* device) { if (device) - parallel_free_int(device); + return parallel_free_int((PARALLEL_DEVICE*)device); + return CHANNEL_RC_OK; } static void parallel_message_free(void* obj) diff --git a/channels/rdpdr/client/rdpdr_main.c b/channels/rdpdr/client/rdpdr_main.c index 07eebd3a0..9f1dd9578 100644 --- a/channels/rdpdr/client/rdpdr_main.c +++ b/channels/rdpdr/client/rdpdr_main.c @@ -838,7 +838,8 @@ static struct mntent* getmntent_x(FILE* f, struct mntent* buffer, char* pathbuff size_t pathbuffersize) { #if defined(FREERDP_HAVE_GETMNTENT_R) - return getmntent_r(f, buffer, pathbuffer, pathbuffersize); + WINPR_ASSERT(pathbuffersize <= INT32_MAX); + return getmntent_r(f, buffer, pathbuffer, (int)pathbuffersize); #else (void)buffer; (void)pathbuffer; diff --git a/channels/rdpei/client/rdpei_main.c b/channels/rdpei/client/rdpei_main.c index eee72432d..cdb7759c1 100644 --- a/channels/rdpei/client/rdpei_main.c +++ b/channels/rdpei/client/rdpei_main.c @@ -1010,7 +1010,7 @@ static UINT rdpei_touch_process(RdpeiClientContext* context, INT32 externalId, U if (p >= 360) { WLog_WARN(TAG, - "TouchContact %" PRIu32 ": Invalid orientation value %" PRIu32 + "TouchContact %" PRId64 ": Invalid orientation value %" PRIu32 "degree, clamping to 359 degree", contactIdlocal, p); p = 359; @@ -1023,7 +1023,7 @@ static UINT rdpei_touch_process(RdpeiClientContext* context, INT32 externalId, U if (p > 1024) { WLog_WARN(TAG, - "TouchContact %" PRIu32 ": Invalid pressure value %" PRIu32 + "TouchContact %" PRId64 ": Invalid pressure value %" PRIu32 ", clamping to 1024", contactIdlocal, p); p = 1024; @@ -1035,7 +1035,7 @@ static UINT rdpei_touch_process(RdpeiClientContext* context, INT32 externalId, U } if (contactId) - *contactId = contactIdlocal; + *contactId = (INT32)contactIdlocal; return error; } diff --git a/channels/rdpei/rdpei_common.c b/channels/rdpei/rdpei_common.c index 75946723f..4fc826543 100644 --- a/channels/rdpei/rdpei_common.c +++ b/channels/rdpei/rdpei_common.c @@ -101,7 +101,7 @@ BOOL rdpei_read_2byte_signed(wStream* s, INT16* value) return FALSE; Stream_Read_UINT8(s, byte); - *value = (*value << 8) | byte; + *value = ((*value & 0xFF) << 8) | byte; } if (negative) diff --git a/channels/rdpgfx/client/rdpgfx_main.c b/channels/rdpgfx/client/rdpgfx_main.c index de40f2d50..b60739942 100644 --- a/channels/rdpgfx/client/rdpgfx_main.c +++ b/channels/rdpgfx/client/rdpgfx_main.c @@ -502,7 +502,6 @@ fail: */ static UINT rdpgfx_recv_reset_graphics_pdu(GENERIC_CHANNEL_CALLBACK* callback, wStream* s) { - int pad = 0; MONITOR_DEF* monitor = NULL; RDPGFX_RESET_GRAPHICS_PDU pdu = { 0 }; WINPR_ASSERT(callback); @@ -543,7 +542,13 @@ static UINT rdpgfx_recv_reset_graphics_pdu(GENERIC_CHANNEL_CALLBACK* callback, w Stream_Read_UINT32(s, monitor->flags); /* flags (4 bytes) */ } - pad = 340 - (RDPGFX_HEADER_SIZE + 12 + (pdu.monitorCount * 20)); + const size_t size = (RDPGFX_HEADER_SIZE + 12ULL + (pdu.monitorCount * 20ULL)); + if (size > 340) + { + free(pdu.monitorDefArray); + return CHANNEL_RC_NULL_DATA; + } + const size_t pad = 340ULL - size; if (!Stream_CheckAndLogRequiredLength(TAG, s, (size_t)pad)) { diff --git a/channels/rdpsnd/client/alsa/rdpsnd_alsa.c b/channels/rdpsnd/client/alsa/rdpsnd_alsa.c index 5908d7bbf..43e812bee 100644 --- a/channels/rdpsnd/client/alsa/rdpsnd_alsa.c +++ b/channels/rdpsnd/client/alsa/rdpsnd_alsa.c @@ -454,12 +454,8 @@ static UINT rdpsnd_alsa_play(rdpsndDevicePlugin* device, const BYTE* data, size_ snd_pcm_sframes_t delay = 0; int rc = snd_pcm_avail_delay(alsa->pcm_handle, &available, &delay); - if (rc != 0) - latency = 0; - else if (available == 0) /* Get [ms] from number of samples */ + if ((rc == 0) && (available == 0)) /* Get [ms] from number of samples */ latency = delay * 1000 / alsa->actual_rate; - else - latency = 0; } return latency + alsa->latency; diff --git a/channels/serial/client/serial_main.c b/channels/serial/client/serial_main.c index 556787703..8ceb5f51b 100644 --- a/channels/serial/client/serial_main.c +++ b/channels/serial/client/serial_main.c @@ -21,7 +21,6 @@ #include -#include #include #include #include diff --git a/channels/urbdrc/client/data_transfer.c b/channels/urbdrc/client/data_transfer.c index c516acaaa..008778987 100644 --- a/channels/urbdrc/client/data_transfer.c +++ b/channels/urbdrc/client/data_transfer.c @@ -44,9 +44,6 @@ static void usb_process_get_port_status(IUDEVICE* pdev, wStream* out) break; case USB_v2_0: - Stream_Write_UINT32(out, 0x503); - break; - default: Stream_Write_UINT32(out, 0x503); break; diff --git a/channels/urbdrc/client/libusb/libusb_udevice.h b/channels/urbdrc/client/libusb/libusb_udevice.h index 33705e3a5..79203c829 100644 --- a/channels/urbdrc/client/libusb/libusb_udevice.h +++ b/channels/urbdrc/client/libusb/libusb_udevice.h @@ -69,7 +69,7 @@ typedef UDEVICE* PUDEVICE; size_t udev_new_by_id(URBDRC_PLUGIN* urbdrc, libusb_context* ctx, UINT16 idVendor, UINT16 idProduct, IUDEVICE*** devArray); -IUDEVICE* udev_new_by_addr(URBDRC_PLUGIN* urbdrc, libusb_context* ctx, BYTE bus_number, +IUDEVICE* udev_new_by_addr(URBDRC_PLUGIN* urbdrc, libusb_context* context, BYTE bus_number, BYTE dev_number); const char* usb_interface_class_to_string(uint8_t class); diff --git a/channels/urbdrc/client/urbdrc_main.h b/channels/urbdrc/client/urbdrc_main.h index d13ed956b..210e29c21 100644 --- a/channels/urbdrc/client/urbdrc_main.h +++ b/channels/urbdrc/client/urbdrc_main.h @@ -217,6 +217,6 @@ FREERDP_API BOOL add_device(IUDEVMAN* idevman, UINT32 flags, BYTE busnum, BYTE d FREERDP_API BOOL del_device(IUDEVMAN* idevman, UINT32 flags, BYTE busnum, BYTE devnum, UINT16 idVendor, UINT16 idProduct); -UINT stream_write_and_free(IWTSPlugin* plugin, IWTSVirtualChannel* channel, wStream* s); +UINT stream_write_and_free(IWTSPlugin* plugin, IWTSVirtualChannel* channel, wStream* out); #endif /* FREERDP_CHANNEL_URBDRC_CLIENT_MAIN_H */ diff --git a/channels/video/client/video_main.c b/channels/video/client/video_main.c index cad308184..93c117e7d 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, 1ull * frame->scanline * frame->h); + frame->surfaceData = BufferPool_Take(priv->surfacePool, 1ll * frame->scanline * frame->h); if (!frame->surfaceData) goto fail; diff --git a/client/SDL/SDL2/sdl_pointer.cpp b/client/SDL/SDL2/sdl_pointer.cpp index b21779e1f..c1037e0f2 100644 --- a/client/SDL/SDL2/sdl_pointer.cpp +++ b/client/SDL/SDL2/sdl_pointer.cpp @@ -191,7 +191,7 @@ BOOL sdl_register_pointer(rdpGraphics* graphics) const rdpPointer pointer = { sizeof(sdlPointer), sdl_Pointer_New, sdl_Pointer_Free, sdl_Pointer_Set, sdl_Pointer_SetNull, sdl_Pointer_SetDefault, - sdl_Pointer_SetPosition, 0 }; + sdl_Pointer_SetPosition, { 0 } }; graphics_register_pointer(graphics, &pointer); return TRUE; } diff --git a/client/SDL/SDL3/sdl_pointer.cpp b/client/SDL/SDL3/sdl_pointer.cpp index c0c8314f3..fabdf6de9 100644 --- a/client/SDL/SDL3/sdl_pointer.cpp +++ b/client/SDL/SDL3/sdl_pointer.cpp @@ -189,7 +189,7 @@ BOOL sdl_register_pointer(rdpGraphics* graphics) const rdpPointer pointer = { sizeof(sdlPointer), sdl_Pointer_New, sdl_Pointer_Free, sdl_Pointer_Set, sdl_Pointer_SetNull, sdl_Pointer_SetDefault, - sdl_Pointer_SetPosition, 0 }; + sdl_Pointer_SetPosition, { 0 } }; graphics_register_pointer(graphics, &pointer); return TRUE; } diff --git a/libfreerdp/codec/dsp_ffmpeg.c b/libfreerdp/codec/dsp_ffmpeg.c index 284a465bb..46bf374d1 100644 --- a/libfreerdp/codec/dsp_ffmpeg.c +++ b/libfreerdp/codec/dsp_ffmpeg.c @@ -277,7 +277,7 @@ static BOOL ffmpeg_open_context(FREERDP_DSP_CONTEXT* WINPR_RESTRICT context) #endif context->context->sample_rate = (int)format->nSamplesPerSec; context->context->block_align = format->nBlockAlign; - context->context->bit_rate = format->nAvgBytesPerSec * 8; + context->context->bit_rate = format->nAvgBytesPerSec * 8LL; context->context->sample_fmt = ffmpeg_sample_format(format); context->context->time_base = av_make_q(1, context->context->sample_rate); diff --git a/libfreerdp/core/activation.c b/libfreerdp/core/activation.c index fae161f2a..70e5320f9 100644 --- a/libfreerdp/core/activation.c +++ b/libfreerdp/core/activation.c @@ -266,7 +266,7 @@ static BOOL rdp_write_client_persistent_key_list_pdu(wStream* s, for (UINT32 index = 0; index < info->keyCount; index++) { - const UINT32 key1 = (UINT32)info->keyList[index]; + const UINT32 key1 = (UINT32)(info->keyList[index] & UINT32_MAX); const UINT32 key2 = (UINT32)(info->keyList[index] >> 32); Stream_Write_UINT32(s, key1); Stream_Write_UINT32(s, key2); diff --git a/libfreerdp/core/smartcardlogon.c b/libfreerdp/core/smartcardlogon.c index 87c0e5f65..cbd36bc7e 100644 --- a/libfreerdp/core/smartcardlogon.c +++ b/libfreerdp/core/smartcardlogon.c @@ -138,11 +138,15 @@ static BOOL add_cert_to_list(SmartcardCertInfo*** certInfoList, size_t* count, } } - curInfoList = realloc(curInfoList, sizeof(SmartcardCertInfo*) * (curCount + 1)); - if (!curInfoList) { - WLog_ERR(TAG, "unable to reallocate certs"); - return FALSE; + SmartcardCertInfo** tmpInfoList = + realloc(curInfoList, sizeof(SmartcardCertInfo*) * (curCount + 1)); + if (!tmpInfoList) + { + WLog_ERR(TAG, "unable to reallocate certs"); + return FALSE; + } + curInfoList = tmpInfoList; } curInfoList[curCount++] = certInfo; diff --git a/libfreerdp/core/tcp.c b/libfreerdp/core/tcp.c index d2be0db1f..470856520 100644 --- a/libfreerdp/core/tcp.c +++ b/libfreerdp/core/tcp.c @@ -1239,10 +1239,10 @@ int freerdp_tcp_default_connect(rdpContext* context, rdpSettings* settings, cons sockfd = socket(addr->ai_family, addr->ai_socktype, addr->ai_protocol); if (sockfd < 0) { - const int rc = get_next_addrinfo(context, addr->ai_next, &addr, - FREERDP_ERROR_CONNECT_FAILED); - if (rc < 0) - return rc; + const int lrc = get_next_addrinfo(context, addr->ai_next, &addr, + FREERDP_ERROR_CONNECT_FAILED); + if (lrc < 0) + return lrc; } } while (sockfd < 0); diff --git a/winpr/libwinpr/synch/timer.c b/winpr/libwinpr/synch/timer.c index 7f3f81704..2e6753d60 100644 --- a/winpr/libwinpr/synch/timer.c +++ b/winpr/libwinpr/synch/timer.c @@ -670,7 +670,6 @@ BOOL CancelWaitableTimer(HANDLE hTimer) int GetTimerFileDescriptor(HANDLE hTimer) { -#ifndef _WIN32 WINPR_HANDLE* hdl = NULL; ULONG type = 0; @@ -682,9 +681,6 @@ int GetTimerFileDescriptor(HANDLE hTimer) } return winpr_Handle_getFd(hTimer); -#else - return -1; -#endif } /**