Merge pull request #10623 from akallabeth/warn-fixes-stream
Warn fixes stream
This commit is contained in:
commit
183be60bac
@ -147,7 +147,7 @@ extern "C"
|
|||||||
WINPR_ASSERT(_s);
|
WINPR_ASSERT(_s);
|
||||||
WINPR_ASSERT(Stream_GetRemainingLength(_s) >= sizeof(UINT8));
|
WINPR_ASSERT(Stream_GetRemainingLength(_s) >= sizeof(UINT8));
|
||||||
|
|
||||||
const UINT8 v = WINPR_STREAM_CAST(UINT8, *(_s)->pointer);
|
const UINT8 v = *(_s)->pointer;
|
||||||
if (seek)
|
if (seek)
|
||||||
Stream_Seek(_s, sizeof(UINT8));
|
Stream_Seek(_s, sizeof(UINT8));
|
||||||
return v;
|
return v;
|
||||||
@ -155,197 +155,146 @@ extern "C"
|
|||||||
|
|
||||||
static INLINE INT8 stream_read_i8(wStream* _s, BOOL seek)
|
static INLINE INT8 stream_read_i8(wStream* _s, BOOL seek)
|
||||||
{
|
{
|
||||||
WINPR_ASSERT(_s);
|
const UINT8 v = stream_read_u8(_s, seek);
|
||||||
WINPR_ASSERT(Stream_GetRemainingLength(_s) >= sizeof(INT8));
|
return WINPR_STREAM_CAST(INT8, v);
|
||||||
|
|
||||||
const INT8 v = WINPR_STREAM_CAST(INT8, *(_s)->pointer);
|
|
||||||
if (seek)
|
|
||||||
Stream_Seek(_s, sizeof(INT8));
|
|
||||||
return v;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static INLINE UINT16 stream_read_u16_le(wStream* _s, BOOL seek)
|
static INLINE UINT16 stream_read_u16_le(wStream* _s, BOOL seek)
|
||||||
{
|
{
|
||||||
|
const size_t typesize = sizeof(UINT16);
|
||||||
WINPR_ASSERT(_s);
|
WINPR_ASSERT(_s);
|
||||||
WINPR_ASSERT(Stream_GetRemainingLength(_s) >= sizeof(UINT16));
|
WINPR_ASSERT(Stream_GetRemainingLength(_s) >= typesize);
|
||||||
|
|
||||||
const UINT16 v = WINPR_STREAM_CAST(
|
UINT16 v = 0;
|
||||||
UINT16, (*(_s)->pointer) + ((WINPR_STREAM_CAST(UINT16, *((_s)->pointer + 1))) << 8));
|
for (size_t x = 0; x < typesize; x++)
|
||||||
|
{
|
||||||
|
v <<= 8;
|
||||||
|
v |= (_s)->pointer[typesize - x - 1];
|
||||||
|
}
|
||||||
if (seek)
|
if (seek)
|
||||||
Stream_Seek(_s, sizeof(UINT16));
|
Stream_Seek(_s, typesize);
|
||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
|
|
||||||
static INLINE UINT16 stream_read_u16_be(wStream* _s, BOOL seek)
|
static INLINE UINT16 stream_read_u16_be(wStream* _s, BOOL seek)
|
||||||
{
|
{
|
||||||
|
const size_t typesize = sizeof(UINT16);
|
||||||
WINPR_ASSERT(_s);
|
WINPR_ASSERT(_s);
|
||||||
WINPR_ASSERT(Stream_GetRemainingLength(_s) >= sizeof(UINT16));
|
WINPR_ASSERT(Stream_GetRemainingLength(_s) >= typesize);
|
||||||
|
|
||||||
const UINT16 v = ((WINPR_STREAM_CAST(UINT16, *(_s)->pointer) << 8) +
|
UINT16 v = 0;
|
||||||
(WINPR_STREAM_CAST(UINT16, *((_s)->pointer + 1))));
|
for (size_t x = 0; x < typesize; x++)
|
||||||
|
{
|
||||||
|
v <<= 8;
|
||||||
|
v |= (_s)->pointer[x];
|
||||||
|
}
|
||||||
if (seek)
|
if (seek)
|
||||||
Stream_Seek(_s, sizeof(UINT16));
|
Stream_Seek(_s, typesize);
|
||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
|
|
||||||
static INLINE INT16 stream_read_i16_le(wStream* _s, BOOL seek)
|
static INLINE INT16 stream_read_i16_le(wStream* _s, BOOL seek)
|
||||||
{
|
{
|
||||||
WINPR_ASSERT(_s);
|
const UINT16 v = stream_read_u16_le(_s, seek);
|
||||||
WINPR_ASSERT(Stream_GetRemainingLength(_s) >= sizeof(INT16));
|
return WINPR_STREAM_CAST(INT16, v);
|
||||||
|
|
||||||
const INT16 v = WINPR_STREAM_CAST(
|
|
||||||
INT16, (*(_s)->pointer) + ((WINPR_STREAM_CAST(INT16, *((_s)->pointer + 1))) << 8));
|
|
||||||
if (seek)
|
|
||||||
Stream_Seek(_s, sizeof(INT16));
|
|
||||||
return v;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static INLINE INT16 stream_read_i16_be(wStream* _s, BOOL seek)
|
static INLINE INT16 stream_read_i16_be(wStream* _s, BOOL seek)
|
||||||
{
|
{
|
||||||
WINPR_ASSERT(_s);
|
const UINT16 v = stream_read_u16_be(_s, seek);
|
||||||
WINPR_ASSERT(Stream_GetRemainingLength(_s) >= sizeof(INT16));
|
return WINPR_STREAM_CAST(INT16, v);
|
||||||
|
|
||||||
const INT16 v = ((WINPR_STREAM_CAST(INT16, *(_s)->pointer) << 8) +
|
|
||||||
(WINPR_STREAM_CAST(INT16, *((_s)->pointer + 1))));
|
|
||||||
if (seek)
|
|
||||||
Stream_Seek(_s, sizeof(INT16));
|
|
||||||
return v;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static INLINE UINT32 stream_read_u32_le(wStream* _s, BOOL seek)
|
static INLINE UINT32 stream_read_u32_le(wStream* _s, BOOL seek)
|
||||||
{
|
{
|
||||||
|
const size_t typesize = sizeof(UINT32);
|
||||||
WINPR_ASSERT(_s);
|
WINPR_ASSERT(_s);
|
||||||
WINPR_ASSERT(Stream_GetRemainingLength(_s) >= sizeof(UINT32));
|
WINPR_ASSERT(Stream_GetRemainingLength(_s) >= typesize);
|
||||||
|
|
||||||
const UINT32 v = (WINPR_STREAM_CAST(UINT32, *(_s)->pointer) << 0) +
|
UINT32 v = 0;
|
||||||
((WINPR_STREAM_CAST(UINT32, *((_s)->pointer + 1))) << 8) +
|
for (size_t x = 0; x < typesize; x++)
|
||||||
((WINPR_STREAM_CAST(UINT32, *((_s)->pointer + 2))) << 16) +
|
{
|
||||||
(((WINPR_STREAM_CAST(UINT32, *((_s)->pointer + 3))) << 24));
|
v <<= 8;
|
||||||
|
v |= (_s)->pointer[typesize - x - 1];
|
||||||
|
}
|
||||||
if (seek)
|
if (seek)
|
||||||
Stream_Seek(_s, sizeof(UINT32));
|
Stream_Seek(_s, typesize);
|
||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
|
|
||||||
static INLINE UINT32 stream_read_u32_be(wStream* _s, BOOL seek)
|
static INLINE UINT32 stream_read_u32_be(wStream* _s, BOOL seek)
|
||||||
{
|
{
|
||||||
|
const size_t typesize = sizeof(UINT32);
|
||||||
WINPR_ASSERT(_s);
|
WINPR_ASSERT(_s);
|
||||||
WINPR_ASSERT(Stream_GetRemainingLength(_s) >= sizeof(UINT32));
|
WINPR_ASSERT(Stream_GetRemainingLength(_s) >= typesize);
|
||||||
|
|
||||||
const UINT32 v = (WINPR_STREAM_CAST(UINT32, *(_s)->pointer) << 24) +
|
UINT32 v = 0;
|
||||||
((WINPR_STREAM_CAST(UINT32, *((_s)->pointer + 1))) << 16) +
|
for (size_t x = 0; x < typesize; x++)
|
||||||
((WINPR_STREAM_CAST(UINT32, *((_s)->pointer + 2))) << 8) +
|
{
|
||||||
(((WINPR_STREAM_CAST(UINT32, *((_s)->pointer + 3))) << 0));
|
v <<= 8;
|
||||||
|
v |= (_s)->pointer[x];
|
||||||
|
}
|
||||||
if (seek)
|
if (seek)
|
||||||
Stream_Seek(_s, sizeof(UINT32));
|
Stream_Seek(_s, typesize);
|
||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
|
|
||||||
static INLINE INT32 stream_read_i32_le(wStream* _s, BOOL seek)
|
static INLINE INT32 stream_read_i32_le(wStream* _s, BOOL seek)
|
||||||
{
|
{
|
||||||
WINPR_ASSERT(_s);
|
const UINT32 v = stream_read_u32_le(_s, seek);
|
||||||
WINPR_ASSERT(Stream_GetRemainingLength(_s) >= sizeof(UINT32));
|
return WINPR_STREAM_CAST(INT32, v);
|
||||||
|
|
||||||
const INT32 v =
|
|
||||||
WINPR_STREAM_CAST(INT32, (WINPR_STREAM_CAST(UINT32, *(_s)->pointer) << 0) +
|
|
||||||
((WINPR_STREAM_CAST(UINT32, *((_s)->pointer + 1))) << 8) +
|
|
||||||
((WINPR_STREAM_CAST(UINT32, *((_s)->pointer + 2))) << 16) +
|
|
||||||
((WINPR_STREAM_CAST(UINT32, *((_s)->pointer + 3))) << 24));
|
|
||||||
if (seek)
|
|
||||||
Stream_Seek(_s, sizeof(UINT32));
|
|
||||||
return v;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static INLINE INT32 stream_read_i32_be(wStream* _s, BOOL seek)
|
static INLINE INT32 stream_read_i32_be(wStream* _s, BOOL seek)
|
||||||
{
|
{
|
||||||
WINPR_ASSERT(_s);
|
const UINT32 v = stream_read_u32_be(_s, seek);
|
||||||
WINPR_ASSERT(Stream_GetRemainingLength(_s) >= sizeof(UINT32));
|
return WINPR_STREAM_CAST(INT32, v);
|
||||||
|
|
||||||
const INT32 v = WINPR_STREAM_CAST(
|
|
||||||
INT32, (WINPR_STREAM_CAST(UINT32, *(_s)->pointer) << 24) +
|
|
||||||
((WINPR_STREAM_CAST(UINT32, *((_s)->pointer + 1))) << 16) +
|
|
||||||
((WINPR_STREAM_CAST(UINT32, *((_s)->pointer + 2))) << 8) +
|
|
||||||
(((WINPR_STREAM_CAST(UINT32, *((_s)->pointer + 3))) << 0)));
|
|
||||||
if (seek)
|
|
||||||
Stream_Seek(_s, sizeof(UINT32));
|
|
||||||
return v;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static INLINE UINT64 stream_read_u64_le(wStream* _s, BOOL seek)
|
static INLINE UINT64 stream_read_u64_le(wStream* _s, BOOL seek)
|
||||||
{
|
{
|
||||||
|
const size_t typesize = sizeof(UINT64);
|
||||||
WINPR_ASSERT(_s);
|
WINPR_ASSERT(_s);
|
||||||
WINPR_ASSERT(Stream_GetRemainingLength(_s) >= sizeof(UINT64));
|
WINPR_ASSERT(Stream_GetRemainingLength(_s) >= typesize);
|
||||||
|
|
||||||
const UINT64 v = (WINPR_STREAM_CAST(UINT64, *(_s)->pointer) << 0) +
|
|
||||||
((WINPR_STREAM_CAST(UINT64, *((_s)->pointer + 1))) << 8) +
|
|
||||||
((WINPR_STREAM_CAST(UINT64, *((_s)->pointer + 2))) << 16) +
|
|
||||||
((WINPR_STREAM_CAST(UINT64, *((_s)->pointer + 3))) << 24) +
|
|
||||||
((WINPR_STREAM_CAST(UINT64, *((_s)->pointer + 4))) << 32) +
|
|
||||||
((WINPR_STREAM_CAST(UINT64, *((_s)->pointer + 5))) << 40) +
|
|
||||||
((WINPR_STREAM_CAST(UINT64, *((_s)->pointer + 6))) << 48) +
|
|
||||||
((WINPR_STREAM_CAST(UINT64, *((_s)->pointer + 7))) << 56);
|
|
||||||
|
|
||||||
|
UINT64 v = 0;
|
||||||
|
for (size_t x = 0; x < typesize; x++)
|
||||||
|
{
|
||||||
|
v <<= 8;
|
||||||
|
v |= (_s)->pointer[typesize - x - 1];
|
||||||
|
}
|
||||||
if (seek)
|
if (seek)
|
||||||
Stream_Seek(_s, sizeof(UINT64));
|
Stream_Seek(_s, typesize);
|
||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
|
|
||||||
static INLINE UINT64 stream_read_u64_be(wStream* _s, BOOL seek)
|
static INLINE UINT64 stream_read_u64_be(wStream* _s, BOOL seek)
|
||||||
{
|
{
|
||||||
|
const size_t typesize = sizeof(UINT64);
|
||||||
WINPR_ASSERT(_s);
|
WINPR_ASSERT(_s);
|
||||||
WINPR_ASSERT(Stream_GetRemainingLength(_s) >= sizeof(UINT64));
|
WINPR_ASSERT(Stream_GetRemainingLength(_s) >= typesize);
|
||||||
|
|
||||||
const UINT64 v = (WINPR_STREAM_CAST(UINT64, *(_s)->pointer) << 56) +
|
|
||||||
((WINPR_STREAM_CAST(UINT64, *((_s)->pointer + 1))) << 48) +
|
|
||||||
((WINPR_STREAM_CAST(UINT64, *((_s)->pointer + 2))) << 40) +
|
|
||||||
((WINPR_STREAM_CAST(UINT64, *((_s)->pointer + 3))) << 32) +
|
|
||||||
((WINPR_STREAM_CAST(UINT64, *((_s)->pointer + 4))) << 24) +
|
|
||||||
((WINPR_STREAM_CAST(UINT64, *((_s)->pointer + 5))) << 16) +
|
|
||||||
((WINPR_STREAM_CAST(UINT64, *((_s)->pointer + 6))) << 8) +
|
|
||||||
((WINPR_STREAM_CAST(UINT64, *((_s)->pointer + 7))) << 0);
|
|
||||||
|
|
||||||
|
UINT64 v = 0;
|
||||||
|
for (size_t x = 0; x < typesize; x++)
|
||||||
|
{
|
||||||
|
v <<= 8;
|
||||||
|
v |= (_s)->pointer[x];
|
||||||
|
}
|
||||||
if (seek)
|
if (seek)
|
||||||
Stream_Seek(_s, sizeof(UINT64));
|
Stream_Seek(_s, typesize);
|
||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
|
|
||||||
static INLINE INT64 stream_read_i64_le(wStream* _s, BOOL seek)
|
static INLINE INT64 stream_read_i64_le(wStream* _s, BOOL seek)
|
||||||
{
|
{
|
||||||
WINPR_ASSERT(_s);
|
const UINT64 v = stream_read_u64_le(_s, seek);
|
||||||
WINPR_ASSERT(Stream_GetRemainingLength(_s) >= sizeof(INT64));
|
return WINPR_STREAM_CAST(INT64, v);
|
||||||
|
|
||||||
const INT64 v =
|
|
||||||
WINPR_STREAM_CAST(INT64, ((WINPR_STREAM_CAST(UINT64, *(_s)->pointer) << 0) +
|
|
||||||
((WINPR_STREAM_CAST(UINT64, *((_s)->pointer + 1))) << 8) +
|
|
||||||
((WINPR_STREAM_CAST(UINT64, *((_s)->pointer + 2))) << 16) +
|
|
||||||
((WINPR_STREAM_CAST(UINT64, *((_s)->pointer + 3))) << 24) +
|
|
||||||
((WINPR_STREAM_CAST(UINT64, *((_s)->pointer + 4))) << 32) +
|
|
||||||
((WINPR_STREAM_CAST(UINT64, *((_s)->pointer + 5))) << 40) +
|
|
||||||
((WINPR_STREAM_CAST(UINT64, *((_s)->pointer + 6))) << 48) +
|
|
||||||
((WINPR_STREAM_CAST(UINT64, *((_s)->pointer + 7))) << 56)));
|
|
||||||
|
|
||||||
if (seek)
|
|
||||||
Stream_Seek(_s, sizeof(UINT64));
|
|
||||||
return v;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static INLINE INT64 stream_read_i64_be(wStream* _s, BOOL seek)
|
static INLINE INT64 stream_read_i64_be(wStream* _s, BOOL seek)
|
||||||
{
|
{
|
||||||
WINPR_ASSERT(_s);
|
const UINT64 v = stream_read_u64_be(_s, seek);
|
||||||
WINPR_ASSERT(Stream_GetRemainingLength(_s) >= sizeof(INT64));
|
return WINPR_STREAM_CAST(INT64, v);
|
||||||
|
|
||||||
const INT64 v =
|
|
||||||
WINPR_STREAM_CAST(INT64, ((WINPR_STREAM_CAST(UINT64, *(_s)->pointer) << 56) +
|
|
||||||
((WINPR_STREAM_CAST(UINT64, *((_s)->pointer + 1))) << 48) +
|
|
||||||
((WINPR_STREAM_CAST(UINT64, *((_s)->pointer + 2))) << 40) +
|
|
||||||
((WINPR_STREAM_CAST(UINT64, *((_s)->pointer + 3))) << 32) +
|
|
||||||
((WINPR_STREAM_CAST(UINT64, *((_s)->pointer + 4))) << 24) +
|
|
||||||
((WINPR_STREAM_CAST(UINT64, *((_s)->pointer + 5))) << 16) +
|
|
||||||
((WINPR_STREAM_CAST(UINT64, *((_s)->pointer + 6))) << 8) +
|
|
||||||
((WINPR_STREAM_CAST(UINT64, *((_s)->pointer + 7))) << 0)));
|
|
||||||
|
|
||||||
if (seek)
|
|
||||||
Stream_Seek(_s, sizeof(UINT64));
|
|
||||||
return v;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -1008,12 +957,23 @@ extern "C"
|
|||||||
Stream_Seek(_src, _n);
|
Stream_Seek(_src, _n);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** @brief Convenience macro to get a pointer to the stream buffer casted to a specific type
|
||||||
|
*
|
||||||
|
* @since version 3.9.0
|
||||||
|
*/
|
||||||
|
#define Stream_BufferAs(s, type) WINPR_STREAM_CAST(type*, Stream_Buffer(s))
|
||||||
|
|
||||||
static INLINE BYTE* Stream_Buffer(wStream* _s)
|
static INLINE BYTE* Stream_Buffer(wStream* _s)
|
||||||
{
|
{
|
||||||
WINPR_ASSERT(_s);
|
WINPR_ASSERT(_s);
|
||||||
return _s->buffer;
|
return _s->buffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** @brief Convenience macro to get a const pointer to the stream buffer casted to a specific type
|
||||||
|
*
|
||||||
|
* @since version 3.9.0
|
||||||
|
*/
|
||||||
|
#define Stream_ConstBufferAs(s, type) WINPR_STREAM_CAST(type*, Stream_ConstBuffer(s))
|
||||||
static INLINE const BYTE* Stream_ConstBuffer(const wStream* _s)
|
static INLINE const BYTE* Stream_ConstBuffer(const wStream* _s)
|
||||||
{
|
{
|
||||||
WINPR_ASSERT(_s);
|
WINPR_ASSERT(_s);
|
||||||
@ -1021,7 +981,14 @@ extern "C"
|
|||||||
}
|
}
|
||||||
|
|
||||||
#define Stream_GetBuffer(_s, _b) _b = Stream_Buffer(_s)
|
#define Stream_GetBuffer(_s, _b) _b = Stream_Buffer(_s)
|
||||||
#define Stream_PointerAs(s, type) (type*)Stream_Pointer(s)
|
|
||||||
|
/** @brief Convenience macro to get a pointer to the stream buffer casted to a specific type
|
||||||
|
*
|
||||||
|
* @since version 3.9.0
|
||||||
|
*/
|
||||||
|
#define Stream_GetBufferAs(_s, _b) _b = Stream_BufferAs(_s, typeof(_b))
|
||||||
|
|
||||||
|
#define Stream_PointerAs(s, type) WINPR_STREAM_CAST(type*, Stream_Pointer(s))
|
||||||
|
|
||||||
static INLINE void* Stream_Pointer(wStream* _s)
|
static INLINE void* Stream_Pointer(wStream* _s)
|
||||||
{
|
{
|
||||||
@ -1037,6 +1004,12 @@ extern "C"
|
|||||||
|
|
||||||
#define Stream_GetPointer(_s, _p) _p = Stream_Pointer(_s)
|
#define Stream_GetPointer(_s, _p) _p = Stream_Pointer(_s)
|
||||||
|
|
||||||
|
/** @brief Convenience macro to get a pointer to the stream pointer casted to a specific type
|
||||||
|
*
|
||||||
|
* @since version 3.9.0
|
||||||
|
*/
|
||||||
|
#define Stream_GetPointerAs(_s, _p) _p = Stream_PointerAs(_s, typeof(_p))
|
||||||
|
|
||||||
#if defined(WITH_WINPR_DEPRECATED)
|
#if defined(WITH_WINPR_DEPRECATED)
|
||||||
WINPR_API WINPR_DEPRECATED_VAR("Use Stream_SetPosition instead",
|
WINPR_API WINPR_DEPRECATED_VAR("Use Stream_SetPosition instead",
|
||||||
BOOL Stream_SetPointer(wStream* _s, BYTE* _p));
|
BOOL Stream_SetPointer(wStream* _s, BYTE* _p));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user