From b9149df1e64d63a05e51fe68bc4af59618947ba0 Mon Sep 17 00:00:00 2001 From: akallabeth Date: Fri, 15 May 2020 15:04:05 +0200 Subject: [PATCH] Fixed BehaviourSanitizer warnings in streams. --- winpr/include/winpr/stream.h | 92 +++++++++++++++++++----------------- 1 file changed, 48 insertions(+), 44 deletions(-) diff --git a/winpr/include/winpr/stream.h b/winpr/include/winpr/stream.h index 49b66a550..42e6913d7 100644 --- a/winpr/include/winpr/stream.h +++ b/winpr/include/winpr/stream.h @@ -74,60 +74,64 @@ extern "C" Stream_Seek(_s, sizeof(_t)); \ } while (0) -#define _stream_read_n16_le(_t, _s, _v, _p) \ - do \ - { \ - (_v) = (_t)(*(_s)->pointer) + (_t)(((_t)(*((_s)->pointer + 1))) << 8); \ - if (_p) \ - Stream_Seek(_s, sizeof(_t)); \ +#define _stream_read_n16_le(_t, _s, _v, _p) \ + do \ + { \ + (_v) = (_t)((*(_s)->pointer) + (((UINT16)(*((_s)->pointer + 1))) << 8)); \ + if (_p) \ + Stream_Seek(_s, sizeof(_t)); \ } while (0) -#define _stream_read_n16_be(_t, _s, _v, _p) \ - do \ - { \ - (_v) = (_t)(((_t)(*(_s)->pointer)) << 8) + (_t)(*((_s)->pointer + 1)); \ - if (_p) \ - Stream_Seek(_s, sizeof(_t)); \ - } while (0) - -#define _stream_read_n32_le(_t, _s, _v, _p) \ - do \ - { \ - (_v) = (_t)(*(_s)->pointer) + (((_t)(*((_s)->pointer + 1))) << 8) + \ - (((_t)(*((_s)->pointer + 2))) << 16) + (((_t)(*((_s)->pointer + 3))) << 24); \ - if (_p) \ - Stream_Seek(_s, sizeof(_t)); \ - } while (0) - -#define _stream_read_n32_be(_t, _s, _v, _p) \ +#define _stream_read_n16_be(_t, _s, _v, _p) \ do \ { \ - (_v) = (((_t)(*((_s)->pointer))) << 24) + (((_t)(*((_s)->pointer + 1))) << 16) + \ - (((_t)(*((_s)->pointer + 2))) << 8) + (((_t)(*((_s)->pointer + 3)))); \ + (_v) = (_t)((((UINT16)(*(_s)->pointer)) << 8) + (UINT16)(*((_s)->pointer + 1))); \ if (_p) \ Stream_Seek(_s, sizeof(_t)); \ } while (0) -#define _stream_read_n64_le(_t, _s, _v, _p) \ - do \ - { \ - (_v) = (_t)(*(_s)->pointer) + (((_t)(*((_s)->pointer + 1))) << 8) + \ - (((_t)(*((_s)->pointer + 2))) << 16) + (((_t)(*((_s)->pointer + 3))) << 24) + \ - (((_t)(*((_s)->pointer + 4))) << 32) + (((_t)(*((_s)->pointer + 5))) << 40) + \ - (((_t)(*((_s)->pointer + 6))) << 48) + (((_t)(*((_s)->pointer + 7))) << 56); \ - if (_p) \ - Stream_Seek(_s, sizeof(_t)); \ +#define _stream_read_n32_le(_t, _s, _v, _p) \ + do \ + { \ + (_v) = (_t)((UINT32)(*(_s)->pointer) + (((UINT32)(*((_s)->pointer + 1))) << 8) + \ + (((UINT32)(*((_s)->pointer + 2))) << 16) + \ + ((((UINT32) * ((_s)->pointer + 3))) << 24)); \ + if (_p) \ + Stream_Seek(_s, sizeof(_t)); \ } while (0) -#define _stream_read_n64_be(_t, _s, _v, _p) \ - do \ - { \ - (_v) = (((_t)(*((_s)->pointer))) << 56) + (((_t)(*((_s)->pointer + 1))) << 48) + \ - (((_t)(*((_s)->pointer + 2))) << 40) + (((_t)(*((_s)->pointer + 3))) << 32) + \ - (((_t)(*((_s)->pointer + 4))) << 24) + (((_t)(*((_s)->pointer + 5))) << 16) + \ - (((_t)(*((_s)->pointer + 6))) << 8) + (((_t)(*((_s)->pointer + 7)))); \ - if (_p) \ - Stream_Seek(_s, sizeof(_t)); \ +#define _stream_read_n32_be(_t, _s, _v, _p) \ + do \ + { \ + (_v) = (_t)(((((UINT32) * ((_s)->pointer))) << 24) + \ + (((UINT32)(*((_s)->pointer + 1))) << 16) + \ + (((UINT32)(*((_s)->pointer + 2))) << 8) + (((UINT32)(*((_s)->pointer + 3))))); \ + if (_p) \ + Stream_Seek(_s, sizeof(_t)); \ + } while (0) + +#define _stream_read_n64_le(_t, _s, _v, _p) \ + do \ + { \ + (_v) = (_t)( \ + (UINT64)(*(_s)->pointer) + (((UINT64)(*((_s)->pointer + 1))) << 8) + \ + (((UINT64)(*((_s)->pointer + 2))) << 16) + (((UINT64)(*((_s)->pointer + 3))) << 24) + \ + (((UINT64)(*((_s)->pointer + 4))) << 32) + (((UINT64)(*((_s)->pointer + 5))) << 40) + \ + (((UINT64)(*((_s)->pointer + 6))) << 48) + (((UINT64)(*((_s)->pointer + 7))) << 56)); \ + if (_p) \ + Stream_Seek(_s, sizeof(_t)); \ + } while (0) + +#define _stream_read_n64_be(_t, _s, _v, _p) \ + do \ + { \ + (_v) = (_t)( \ + (((UINT64)(*((_s)->pointer))) << 56) + (((UINT64)(*((_s)->pointer + 1))) << 48) + \ + (((UINT64)(*((_s)->pointer + 2))) << 40) + (((UINT64)(*((_s)->pointer + 3))) << 32) + \ + (((UINT64)(*((_s)->pointer + 4))) << 24) + (((UINT64)(*((_s)->pointer + 5))) << 16) + \ + (((UINT64)(*((_s)->pointer + 6))) << 8) + (((UINT64)(*((_s)->pointer + 7))))); \ + if (_p) \ + Stream_Seek(_s, sizeof(_t)); \ } while (0) #define Stream_Read_UINT8(_s, _v) _stream_read_n8(UINT8, _s, _v, TRUE)