From 2de7399e5286e37964e5285c0601ea2ebdbc49da Mon Sep 17 00:00:00 2001 From: Armin Novak Date: Wed, 7 Jun 2023 15:23:03 +0200 Subject: [PATCH] [winpr,stream] change Stream_Pointer return to void* Eliminates possible type warnings as we return a void* If a specific type is desired, use the Stream_PointerAs macro. --- winpr/include/winpr/stream.h | 4 ++-- winpr/libwinpr/utils/stream.c | 20 +++++--------------- 2 files changed, 7 insertions(+), 17 deletions(-) diff --git a/winpr/include/winpr/stream.h b/winpr/include/winpr/stream.h index 0630c9d15..8274a063a 100644 --- a/winpr/include/winpr/stream.h +++ b/winpr/include/winpr/stream.h @@ -441,13 +441,13 @@ extern "C" #define Stream_GetBuffer(_s, _b) _b = Stream_Buffer(_s) #define Stream_PointerAs(s, type) (type*)Stream_Pointer(s) - static INLINE BYTE* Stream_Pointer(wStream* _s) + static INLINE void* Stream_Pointer(wStream* _s) { WINPR_ASSERT(_s); return _s->pointer; } - static INLINE const BYTE* Stream_ConstPointer(const wStream* _s) + static INLINE const void* Stream_ConstPointer(const wStream* _s) { WINPR_ASSERT(_s); return _s->pointer; diff --git a/winpr/libwinpr/utils/stream.c b/winpr/libwinpr/utils/stream.c index 65bdaa725..3cf393bfa 100644 --- a/winpr/libwinpr/utils/stream.c +++ b/winpr/libwinpr/utils/stream.c @@ -464,12 +464,7 @@ BOOL Stream_CheckAndLogRequiredLengthWLogExVa(wLog* log, DWORD level, wStream* s SSIZE_T Stream_Write_UTF16_String_From_UTF8(wStream* s, size_t dlen, const char* src, size_t length, BOOL fill) { - union - { - WCHAR* wc; - BYTE* b; - } cnv; - cnv.b = Stream_Pointer(s); + WCHAR* str = Stream_PointerAs(s, WCHAR); if (length == 0) return 0; @@ -477,7 +472,7 @@ SSIZE_T Stream_Write_UTF16_String_From_UTF8(wStream* s, size_t dlen, const char* if (!Stream_CheckAndLogRequiredCapacityOfSize(STREAM_TAG, s, dlen, sizeof(WCHAR))) return -1; - SSIZE_T rc = ConvertUtf8NToWChar(src, length, cnv.wc, dlen); + SSIZE_T rc = ConvertUtf8NToWChar(src, length, str, dlen); if (rc < 0) return -1; @@ -490,12 +485,7 @@ SSIZE_T Stream_Write_UTF16_String_From_UTF8(wStream* s, size_t dlen, const char* char* Stream_Read_UTF16_String_As_UTF8(wStream* s, size_t dlen, size_t* psize) { - union - { - const WCHAR* wc; - const BYTE* b; - } cnv; - cnv.b = Stream_Pointer(s); + const WCHAR* str = Stream_ConstPointer(s); if (dlen > SIZE_MAX / sizeof(WCHAR)) return NULL; @@ -503,13 +493,13 @@ char* Stream_Read_UTF16_String_As_UTF8(wStream* s, size_t dlen, size_t* psize) return NULL; Stream_Seek(s, dlen * sizeof(WCHAR)); - return ConvertWCharNToUtf8Alloc(cnv.wc, dlen, psize); + return ConvertWCharNToUtf8Alloc(str, dlen, psize); } SSIZE_T Stream_Read_UTF16_String_As_UTF8_Buffer(wStream* s, size_t wcharLength, char* utfBuffer, size_t utfBufferCharLength) { - const WCHAR* ptr = (const WCHAR*)Stream_Pointer(s); + const WCHAR* ptr = Stream_ConstPointer(s); if (wcharLength > SIZE_MAX / sizeof(WCHAR)) return -1;