From f529345d84150846708ff8c2d417e35a0363f86a Mon Sep 17 00:00:00 2001 From: akallabeth Date: Thu, 19 Sep 2024 11:50:26 +0200 Subject: [PATCH] [warnings] fix Wcast-qual --- channels/rdpecam/client/camera_device_main.c | 2 +- channels/rdpecam/client/encoding.c | 5 +++-- channels/tsmf/client/ffmpeg/tsmf_ffmpeg.c | 12 +++++++----- channels/tsmf/client/tsmf_codec.c | 12 ++++++------ libfreerdp/codec/h264_openh264.c | 7 ++++--- libfreerdp/common/settings.c | 3 ++- libfreerdp/utils/ringbuffer.c | 2 +- winpr/include/winpr/smartcard.h | 2 +- winpr/libwinpr/crt/unicode_builtin.c | 4 ++-- winpr/libwinpr/utils/image.c | 4 ++-- 10 files changed, 29 insertions(+), 24 deletions(-) diff --git a/channels/rdpecam/client/camera_device_main.c b/channels/rdpecam/client/camera_device_main.c index f7d4c0d91..e46a220be 100644 --- a/channels/rdpecam/client/camera_device_main.c +++ b/channels/rdpecam/client/camera_device_main.c @@ -149,7 +149,7 @@ static UINT ecam_dev_sample_captured_callback(CameraDevice* dev, int streamIndex } else /* passthrough */ { - encodedSample = (BYTE*)sample; + encodedSample = WINPR_CAST_CONST_PTR_AWAY(sample, BYTE*); encodedSize = size; } diff --git a/channels/rdpecam/client/encoding.c b/channels/rdpecam/client/encoding.c index 3099d5bd5..6712be2e9 100644 --- a/channels/rdpecam/client/encoding.c +++ b/channels/rdpecam/client/encoding.c @@ -110,8 +110,9 @@ static BOOL ecam_encoder_compress_h264(CameraDeviceStream* stream, const BYTE* s return FALSE; /* convert from source format to YUV420P */ - if (av_image_fill_pointers(srcSlice, pixFormat, (int)size.height, (BYTE*)srcData, - stream->srcLineSizes) < 0) + BYTE* ptr = WINPR_CAST_CONST_PTR_AWAY(srcData, BYTE*); + if (av_image_fill_pointers(srcSlice, pixFormat, (int)size.height, ptr, stream->srcLineSizes) < + 0) return FALSE; const BYTE* cSrcSlice[4] = { srcSlice[0], srcSlice[1], srcSlice[2], srcSlice[3] }; diff --git a/channels/tsmf/client/ffmpeg/tsmf_ffmpeg.c b/channels/tsmf/client/ffmpeg/tsmf_ffmpeg.c index ce5bcd7c2..d70321943 100644 --- a/channels/tsmf/client/ffmpeg/tsmf_ffmpeg.c +++ b/channels/tsmf/client/ffmpeg/tsmf_ffmpeg.c @@ -386,7 +386,7 @@ static BOOL tsmf_ffmpeg_decode_video(ITSMFDecoder* decoder, const BYTE* data, UI #if LIBAVCODEC_VERSION_INT < AV_VERSION_INT(58, 133, 100) av_init_packet(&pkt); #endif - pkt.data = (BYTE*)data; + pkt.data = WINPR_CAST_CONST_PTR_AWAY(data, BYTE*); pkt.size = data_size; if (extensions & TSMM_SAMPLE_EXT_CLEANPOINT) @@ -441,9 +441,11 @@ static BOOL tsmf_ffmpeg_decode_video(ITSMFDecoder* decoder, const BYTE* data, UI av_image_fill_arrays(frame->data, frame->linesize, mdecoder->decoded_data, mdecoder->codec_context->pix_fmt, mdecoder->codec_context->width, mdecoder->codec_context->height, 1); - av_image_copy(frame->data, frame->linesize, (const uint8_t**)mdecoder->frame->data, - mdecoder->frame->linesize, mdecoder->codec_context->pix_fmt, - mdecoder->codec_context->width, mdecoder->codec_context->height); + + const uint8_t* const* ptr = (const uint8_t* const*)mdecoder->frame->data; + av_image_copy(frame->data, frame->linesize, ptr, mdecoder->frame->linesize, + mdecoder->codec_context->pix_fmt, mdecoder->codec_context->width, + mdecoder->codec_context->height); av_free(frame); } @@ -530,7 +532,7 @@ static BOOL tsmf_ffmpeg_decode_audio(ITSMFDecoder* decoder, const BYTE* data, UI av_init_packet(&pkt); #endif - pkt.data = (BYTE*)src; + pkt.data = WINPR_CAST_CONST_PTR_AWAY(src, BYTE*); pkt.size = src_size; #if LIBAVCODEC_VERSION_INT < AV_VERSION_INT(57, 48, 101) len = avcodec_decode_audio4(mdecoder->codec_context, decoded_frame, &got_frame, &pkt); diff --git a/channels/tsmf/client/tsmf_codec.c b/channels/tsmf/client/tsmf_codec.c index d3f67078d..d7b877f81 100644 --- a/channels/tsmf/client/tsmf_codec.c +++ b/channels/tsmf/client/tsmf_codec.c @@ -254,12 +254,12 @@ static void tsmf_print_guid(const BYTE* guid) #ifdef WITH_DEBUG_TSMF char guidString[37]; - snprintf(guidString, sizeof(guidString), - "%02" PRIX8 "%02" PRIX8 "%02" PRIX8 "%02" PRIX8 "-%02" PRIX8 "%02" PRIX8 "-%02" PRIX8 - "%02" PRIX8 "-%02" PRIX8 "%02" PRIX8 "-%02" PRIX8 "%02" PRIX8 "%02" PRIX8 "%02" PRIX8 - "%02" PRIX8 "%02" PRIX8 "", - guid[3], guid[2], guid[1], guid[0], guid[5], guid[4], guid[7], guid[6], guid[8], - guid[9], guid[10], guid[11], guid[12], guid[13], guid[14], guid[15]); + (void)snprintf(guidString, sizeof(guidString), + "%02" PRIX8 "%02" PRIX8 "%02" PRIX8 "%02" PRIX8 "-%02" PRIX8 "%02" PRIX8 + "-%02" PRIX8 "%02" PRIX8 "-%02" PRIX8 "%02" PRIX8 "-%02" PRIX8 "%02" PRIX8 + "%02" PRIX8 "%02" PRIX8 "%02" PRIX8 "%02" PRIX8 "", + guid[3], guid[2], guid[1], guid[0], guid[5], guid[4], guid[7], guid[6], guid[8], + guid[9], guid[10], guid[11], guid[12], guid[13], guid[14], guid[15]); WLog_INFO(TAG, "%s", guidString); #endif diff --git a/libfreerdp/codec/h264_openh264.c b/libfreerdp/codec/h264_openh264.c index 41deb06bb..d6baac779 100644 --- a/libfreerdp/codec/h264_openh264.c +++ b/libfreerdp/codec/h264_openh264.c @@ -20,6 +20,7 @@ */ #include +#include #include #include @@ -380,9 +381,9 @@ static int openh264_compress(H264_CONTEXT* WINPR_RESTRICT h264, pic.iStride[0] = (int)iStride[0]; pic.iStride[1] = (int)iStride[1]; pic.iStride[2] = (int)iStride[2]; - pic.pData[0] = (unsigned char*)pYUVData[0]; - pic.pData[1] = (unsigned char*)pYUVData[1]; - pic.pData[2] = (unsigned char*)pYUVData[2]; + pic.pData[0] = WINPR_CAST_CONST_PTR_AWAY(pYUVData[0], BYTE*); + pic.pData[1] = WINPR_CAST_CONST_PTR_AWAY(pYUVData[1], BYTE*); + pic.pData[2] = WINPR_CAST_CONST_PTR_AWAY(pYUVData[2], BYTE*); WINPR_ASSERT((*sys->pEncoder)->EncodeFrame); status = (*sys->pEncoder)->EncodeFrame(sys->pEncoder, &pic, &info); diff --git a/libfreerdp/common/settings.c b/libfreerdp/common/settings.c index 0079db8d1..6e483942e 100644 --- a/libfreerdp/common/settings.c +++ b/libfreerdp/common/settings.c @@ -1114,7 +1114,8 @@ int freerdp_set_param_uint64(rdpSettings* settings, int id, UINT64 param) char* freerdp_get_param_string(const rdpSettings* settings, int id) { - return (char*)freerdp_settings_get_string(settings, (FreeRDP_Settings_Keys_String)id); + const char* str = freerdp_settings_get_string(settings, (FreeRDP_Settings_Keys_String)id); + return WINPR_CAST_CONST_PTR_AWAY(str, char*); } int freerdp_set_param_string(rdpSettings* settings, int id, const char* param) diff --git a/libfreerdp/utils/ringbuffer.c b/libfreerdp/utils/ringbuffer.c index b74deed8f..a6473b52f 100644 --- a/libfreerdp/utils/ringbuffer.c +++ b/libfreerdp/utils/ringbuffer.c @@ -246,7 +246,7 @@ int ringbuffer_peek(const RingBuffer* rb, DataChunk chunks[2], size_t sz) size_t toRead = 0; int chunkIndex = 0; int status = 0; - DEBUG_RINGBUFFER("ringbuffer_peek(%p): sz: %" PRIdz "", (void*)rb, sz); + DEBUG_RINGBUFFER("ringbuffer_peek(%p): sz: %" PRIdz "", (const void*)rb, sz); if (sz < 1) return 0; diff --git a/winpr/include/winpr/smartcard.h b/winpr/include/winpr/smartcard.h index 278786cf2..23eac318b 100644 --- a/winpr/include/winpr/smartcard.h +++ b/winpr/include/winpr/smartcard.h @@ -315,7 +315,7 @@ typedef SCARDCONTEXT *PSCARDCONTEXT, *LPSCARDCONTEXT; typedef ULONG_PTR SCARDHANDLE; typedef SCARDHANDLE *PSCARDHANDLE, *LPSCARDHANDLE; -#define SCARD_AUTOALLOCATE (DWORD)(-1) +#define SCARD_AUTOALLOCATE UINT32_MAX #define SCARD_SCOPE_USER 0 #define SCARD_SCOPE_TERMINAL 1 diff --git a/winpr/libwinpr/crt/unicode_builtin.c b/winpr/libwinpr/crt/unicode_builtin.c index e56ddd781..501327be0 100644 --- a/winpr/libwinpr/crt/unicode_builtin.c +++ b/winpr/libwinpr/crt/unicode_builtin.c @@ -543,7 +543,7 @@ static int winpr_ConvertUTF8toUTF16(const uint8_t* src, int cchSrc, uint16_t* ds ConversionResult result = sourceIllegal; if (cchSrc == -1) - cchSrc = strlen((char*)src) + 1; + cchSrc = (int)strnlen((const char*)src, INT32_MAX - 1) + 1; srcBeg = src; srcEnd = &src[cchSrc]; @@ -585,7 +585,7 @@ static int winpr_ConvertUTF16toUTF8(const uint16_t* src, int cchSrc, uint8_t* ds ConversionResult result = sourceIllegal; if (cchSrc == -1) - cchSrc = _wcslen((uint16_t*)src) + 1; + cchSrc = (int)_wcsnlen((const WCHAR*)src, INT32_MAX - 1) + 1; srcBeg = src; srcEnd = &src[cchSrc]; diff --git a/winpr/libwinpr/utils/image.c b/winpr/libwinpr/utils/image.c index badf432bc..602437c25 100644 --- a/winpr/libwinpr/utils/image.c +++ b/winpr/libwinpr/utils/image.c @@ -644,7 +644,7 @@ static void* winpr_convert_to_jpeg(const void* data, size_t size, UINT32 width, /* libjpeg is not const correct, we must cast here to avoid issues * with newer C compilers type check errors */ - JSAMPLE* coffset = (JSAMPLE*)&cdata[offset]; + JSAMPLE* coffset = WINPR_CAST_CONST_PTR_AWAY(&cdata[offset], JSAMPLE*); if (jpeg_write_scanlines(&cinfo, &coffset, 1) != 1) goto fail; } @@ -946,7 +946,7 @@ static void* winpr_read_png_from_buffer(const void* data, size_t SrcSize, size_t if (!info_ptr) goto fail; - memory_reader_state.buffer = (png_bytep)data; + memory_reader_state.buffer = WINPR_CAST_CONST_PTR_AWAY(data, png_bytep); memory_reader_state.bufsize = SrcSize; memory_reader_state.current_pos = 0;