[warnings] fix casts

* Add macro WINPR_REINTERPRET_CAST to cast (checked) from type A to B
* Fix cast warnings
This commit is contained in:
akallabeth 2024-09-13 13:09:51 +02:00
parent 01c6447963
commit d5b41bb8a0
No known key found for this signature in database
GPG Key ID: A49454A3FC909FD5
4 changed files with 30 additions and 8 deletions

View File

@ -730,7 +730,7 @@ BOOL ndr_struct_write_fromDescr(NdrContext* context, wStream* s, const NdrStruct
{
ndr_refid ptrId = NDR_PTR_NULL;
BOOL isNew = 0;
ptr = *(const void**)ptr;
ptr = *(WINPR_CAST_CONST_PTR_AWAY(ptr, const void**));
if (!ptr && field->pointerType == NDR_POINTER_NON_NULL)
{
@ -797,7 +797,7 @@ void ndr_struct_dump_fromDescr(wLog* logger, UINT32 lvl, size_t identLevel,
{
case NDR_POINTER:
case NDR_POINTER_NON_NULL:
ptr = *(const void**)ptr;
ptr = *(WINPR_CAST_CONST_PTR_AWAY(ptr, const void**));
break;
case NDR_NOT_POINTER:
break;

View File

@ -1050,8 +1050,9 @@ progressive_decompress_tile_first(PROGRESSIVE_CONTEXT* WINPR_RESTRICT progressiv
if (rc < 0)
goto fail;
rc = prims->yCbCrToRGB_16s8u_P3AC4R((const INT16**)pSrcDst, 64 * 2, tile->data, tile->stride,
progressive->format, &roi_64x64);
const INT16** ptr = WINPR_REINTERPRET_CAST(pSrcDst, INT16**, const INT16**);
rc = prims->yCbCrToRGB_16s8u_P3AC4R(ptr, 64 * 2, tile->data, tile->stride, progressive->format,
&roi_64x64);
fail:
BufferPool_Return(progressive->bufferPool, pBuffer);
return rc;
@ -1494,8 +1495,9 @@ progressive_decompress_tile_upgrade(PROGRESSIVE_CONTEXT* WINPR_RESTRICT progress
if (status < 0)
goto fail;
status = prims->yCbCrToRGB_16s8u_P3AC4R((const INT16**)pSrcDst, 64 * 2, tile->data,
tile->stride, progressive->format, &roi_64x64);
const INT16** ptr = WINPR_REINTERPRET_CAST(pSrcDst, INT16**, const INT16**);
status = prims->yCbCrToRGB_16s8u_P3AC4R(ptr, 64 * 2, tile->data, tile->stride,
progressive->format, &roi_64x64);
fail:
BufferPool_Return(progressive->bufferPool, pBuffer);
return status;

View File

@ -2850,8 +2850,9 @@ BOOL license_server_configure(rdpLicense* license)
freerdp_settings_get_uint32(settings, FreeRDP_ServerLicenseProductVersion);
const UINT32 issuerCount =
freerdp_settings_get_uint32(settings, FreeRDP_ServerLicenseProductIssuersCount);
const char** issuers =
(const char**)freerdp_settings_get_pointer(settings, FreeRDP_ServerLicenseProductIssuers);
const void* ptr = freerdp_settings_get_pointer(settings, FreeRDP_ServerLicenseProductIssuers);
const char** issuers = WINPR_REINTERPRET_CAST(ptr, const void*, const char**);
WINPR_ASSERT(CompanyName);
WINPR_ASSERT(ProductName);

View File

@ -138,6 +138,24 @@ WINPR_API const char* winpr_get_build_config(void);
#define WINPR_UNUSED(x) (void)(x)
#if defined(__GNUC__) || defined(__clang__)
/**
* @brief A macro to do dirty casts. Do not use without a good justification!
* @param ptr The pointer to cast
* @param dstType The data type to cast to
* @return The casted pointer
* @since version 3.9.0
*/
#define WINPR_REINTERPRET_CAST(ptr, srcType, dstType) \
({ \
union \
{ \
srcType src; \
dstType dst; \
} cnv; \
cnv.src = ptr; \
cnv.dst; \
})
/**
* @brief A macro to do dirty casts. Do not use without a good justification!
* @param ptr The pointer to cast
@ -174,6 +192,7 @@ WINPR_API const char* winpr_get_build_config(void);
cnv.dst; \
})
#else
#define WINPR_REINTERPRET_CAST(ptr, srcType, dstType) (dstType) ptr
#define WINPR_CAST_CONST_PTR_AWAY(ptr, dstType) (dstType) ptr
#define WINPR_FUNC_PTR_CAST(ptr, dstType) (dstType)(uintptr_t) ptr
#endif