#ifndef _INTSAFE_H_INCLUDED_
#define _INTSAFE_H_INCLUDED_
#include <winapifamily.h>
#if (_MSC_VER > 1000)
#pragma once
#endif
#pragma region Application Family
#if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_APP | WINAPI_PARTITION_SYSTEM)
#include <specstrings.h> // for _In_, etc.
#if _MSC_VER >= 1200
#pragma warning(push)
#pragma warning(disable:4668) // #if not_defined treated as #if 0
#endif
#pragma warning(disable:
4668
)
#if !defined(_W64)
#if !defined(__midl) && (defined(_X86_) || defined(_M_IX86) || defined(_ARM_) || defined(_M_ARM)) && (_MSC_VER >= 1300)
#define _W64 __w64
#else
#define _W64
#endif
#endif
typedef
char
;
typedef
signed
char
;
typedef
unsigned
char
;
typedef
unsigned
char
;
typedef
unsigned
char
;
typedef
short
;
typedef
signed
short
;
typedef
unsigned
short
;
typedef
unsigned
short
;
typedef
unsigned
short
;
typedef
int
;
typedef
signed
int
;
typedef
unsigned
int
;
typedef
unsigned
int
;
typedef
long
;
typedef
unsigned
long
;
typedef
unsigned
long
;
typedef
__int64
;
typedef
__int64
;
typedef
signed
__int64
;
typedef
unsigned
__int64
;
typedef
unsigned
__int64
;
typedef
unsigned
__int64
;
typedef
unsigned
__int64
;
typedef
unsigned
__int64
;
#if (__midl > 501)
typedef [public] __int3264 INT_PTR;
typedef [public] unsigned __int3264 UINT_PTR;
typedef [public] __int3264 LONG_PTR;
typedef [public] unsigned __int3264 ULONG_PTR;
#else
#ifdef _WIN64
typedef __int64 INT_PTR;
typedef unsigned __int64 UINT_PTR;
typedef __int64 LONG_PTR;
typedef unsigned __int64 ULONG_PTR;
#else
typedef _W64 int INT_PTR;
typedef _W64 unsigned int UINT_PTR;
typedef _W64 long LONG_PTR;
typedef _W64 unsigned long ULONG_PTR;
#endif // WIN64
#endif // (__midl > 501)
#ifdef _WIN64
typedef __int64 ptrdiff_t;
typedef unsigned __int64 size_t;
#else
typedef _W64 int ptrdiff_t;
typedef _W64 unsigned int size_t;
#endif
typedef
;
typedef
;
typedef
;
#undef _USE_INTRINSIC_MULTIPLY128
#if !defined(_M_CEE) && (defined(_AMD64_) || (defined(_IA64_) && (_MSC_VER >= 1400)))
#define _USE_INTRINSIC_MULTIPLY128
#endif
#if defined(_USE_INTRINSIC_MULTIPLY128)
#ifdef __cplusplus
extern "C" {
#endif
#define UnsignedMultiply128 _umul128
ULONG64
UnsignedMultiply128(
_In_ ULONGLONG ullMultiplicand,
_In_ ULONGLONG ullMultiplier,
_Out_ _Deref_out_range_(==, ullMultiplicand * ullMultiplier) ULONGLONG* pullResultHigh);
#pragma intrinsic(_umul128)
#ifdef __cplusplus
}
#endif
#endif // _USE_INTRINSIC_MULTIPLY128
typedef _Return_type_success_(return >= 0) long HRESULT;
#define SUCCEEDED(hr) (((HRESULT)(hr)) >= 0)
#define FAILED(hr) (((HRESULT)(hr)) < 0)
#define S_OK ((HRESULT)0L)
#define INTSAFE_E_ARITHMETIC_OVERFLOW ((HRESULT)0x80070216L) // 0x216 = 534 = ERROR_ARITHMETIC_OVERFLOW
#ifndef SORTPP_PASS
#define C_ASSERT(e) typedef char __C_ASSERT__[(e)?1:-1]
#else
#define C_ASSERT(e)
#endif
#ifndef UInt32x32To64
#if defined(MIDL_PASS) || defined(RC_INVOKED) || defined(_M_CEE_PURE) \
|| defined(_68K_) || defined(_MPPC_) \
|| defined(_M_IA64) || defined(_M_AMD64) || defined(_M_ARM) || defined(_M_ARM64) \
|| defined(_M_HYBRID_X86_ARM64)
#define UInt32x32To64(a, b) (((unsigned __int64)((unsigned int)(a))) * ((unsigned __int64)((unsigned int)(b))))
#elif defined(_M_IX86)
#define UInt32x32To64(a, b) ((unsigned __int64)(((unsigned __int64)((unsigned int)(a))) * ((unsigned int)(b))))
#else
#error Must define a target architecture.
#endif
#endif
#define INT8_MIN (-127i8 - 1)
#define SHORT_MIN (-32768)
#define INT16_MIN (-32767i16 - 1)
#define INT_MIN (-2147483647 - 1)
#define INT32_MIN (-2147483647i32 - 1)
#define LONG_MIN (-2147483647L - 1)
#define LONGLONG_MIN (-9223372036854775807i64 - 1)
#define LONG64_MIN (-9223372036854775807i64 - 1)
#define INT64_MIN (-9223372036854775807i64 - 1)
#define INT128_MIN (-170141183460469231731687303715884105727i128 - 1)
#ifdef _WIN64
#define INT_PTR_MIN (-9223372036854775807i64 - 1)
#define LONG_PTR_MIN (-9223372036854775807i64 - 1)
#define PTRDIFF_T_MIN (-9223372036854775807i64 - 1)
#define SSIZE_T_MIN (-9223372036854775807i64 - 1)
#else
#define INT_PTR_MIN (-2147483647 - 1)
#define LONG_PTR_MIN (-2147483647L - 1)
#define PTRDIFF_T_MIN (-2147483647 - 1)
#define SSIZE_T_MIN (-2147483647L - 1)
#endif
#define INT8_MAX 127i8
#define UINT8_MAX 0xffui8
#define BYTE_MAX 0xff
#define SHORT_MAX 32767
#define INT16_MAX 32767i16
#define USHORT_MAX 0xffff
#define UINT16_MAX 0xffffui16
#define WORD_MAX 0xffff
#define INT_MAX 2147483647
#define INT32_MAX 2147483647i32
#define UINT_MAX 0xffffffff
#define UINT32_MAX 0xffffffffui32
#define LONG_MAX 2147483647L
#define ULONG_MAX 0xffffffffUL
#define DWORD_MAX 0xffffffffUL
#define LONGLONG_MAX 9223372036854775807i64
#define LONG64_MAX 9223372036854775807i64
#define INT64_MAX 9223372036854775807i64
#define ULONGLONG_MAX 0xffffffffffffffffui64
#define DWORDLONG_MAX 0xffffffffffffffffui64
#define ULONG64_MAX 0xffffffffffffffffui64
#define DWORD64_MAX 0xffffffffffffffffui64
#define UINT64_MAX 0xffffffffffffffffui64
#define INT128_MAX 170141183460469231731687303715884105727i128
#define UINT128_MAX 0xffffffffffffffffffffffffffffffffui128
#undef SIZE_T_MAX
#ifdef _WIN64
#define INT_PTR_MAX 9223372036854775807i64
#define UINT_PTR_MAX 0xffffffffffffffffui64
#define LONG_PTR_MAX 9223372036854775807i64
#define ULONG_PTR_MAX 0xffffffffffffffffui64
#define DWORD_PTR_MAX 0xffffffffffffffffui64
#define PTRDIFF_T_MAX 9223372036854775807i64
#define SIZE_T_MAX 0xffffffffffffffffui64
#define SSIZE_T_MAX 9223372036854775807i64
#define _SIZE_T_MAX 0xffffffffffffffffui64
#else
#define INT_PTR_MAX 2147483647
#define UINT_PTR_MAX 0xffffffff
#define LONG_PTR_MAX 2147483647L
#define ULONG_PTR_MAX 0xffffffffUL
#define DWORD_PTR_MAX 0xffffffffUL
#define PTRDIFF_T_MAX 2147483647
#define SIZE_T_MAX 0xffffffff
#define SSIZE_T_MAX 2147483647L
#define _SIZE_T_MAX 0xffffffffUL
#endif
#define INT8_ERROR (-1i8)
#define UINT8_ERROR 0xffui8
#define BYTE_ERROR 0xff
#define SHORT_ERROR (-1)
#define INT16_ERROR (-1i16)
#define USHORT_ERROR 0xffff
#define UINT16_ERROR 0xffffui16
#define WORD_ERROR 0xffff
#define INT_ERROR (-1)
#define INT32_ERROR (-1i32)
#define UINT_ERROR 0xffffffff
#define UINT32_ERROR 0xffffffffui32
#define LONG_ERROR (-1L)
#define ULONG_ERROR 0xffffffffUL
#define DWORD_ERROR 0xffffffffUL
#define LONGLONG_ERROR (-1i64)
#define LONG64_ERROR (-1i64)
#define INT64_ERROR (-1i64)
#define ULONGLONG_ERROR 0xffffffffffffffffui64
#define DWORDLONG_ERROR 0xffffffffffffffffui64
#define ULONG64_ERROR 0xffffffffffffffffui64
#define UINT64_ERROR 0xffffffffffffffffui64
#ifdef _WIN64
#define INT_PTR_ERROR (-1i64)
#define UINT_PTR_ERROR 0xffffffffffffffffui64
#define LONG_PTR_ERROR (-1i64)
#define ULONG_PTR_ERROR 0xffffffffffffffffui64
#define DWORD_PTR_ERROR 0xffffffffffffffffui64
#define PTRDIFF_T_ERROR (-1i64)
#define SIZE_T_ERROR 0xffffffffffffffffui64
#define SSIZE_T_ERROR (-1i64)
#define _SIZE_T_ERROR 0xffffffffffffffffui64
#else
#define INT_PTR_ERROR (-1)
#define UINT_PTR_ERROR 0xffffffff
#define LONG_PTR_ERROR (-1L)
#define ULONG_PTR_ERROR 0xffffffffUL
#define DWORD_PTR_ERROR 0xffffffffUL
#define PTRDIFF_T_ERROR (-1)
#define SIZE_T_ERROR 0xffffffff
#define SSIZE_T_ERROR (-1L)
#define _SIZE_T_ERROR 0xffffffffUL
#endif
C_ASSERT(sizeof(USHORT) == 2);
typedef
char
[(
sizeof
(
) ==
2
)?
1
:-
1
];
C_ASSERT(sizeof(INT) == 4);
typedef
char
[(
sizeof
(
) ==
4
)?
1
:-
1
];
C_ASSERT(sizeof(UINT) == 4);
typedef
char
[(
sizeof
(
) ==
4
)?
1
:-
1
];
C_ASSERT(sizeof(LONG) == 4);
typedef
char
[(
sizeof
(
) ==
4
)?
1
:-
1
];
C_ASSERT(sizeof(ULONG) == 4);
typedef
char
[(
sizeof
(
) ==
4
)?
1
:-
1
];
C_ASSERT(sizeof(UINT_PTR) == sizeof(ULONG_PTR));
typedef
char
[(
sizeof
(
) ==
sizeof
(
))?
1
:-
1
];
_Must_inspect_result_
__inline
(
_Out_ _Deref_out_range_(==, i8Operand) UCHAR* pch)
{
;
if
(
>=
0
)
{
*
= (
)
;
}
else
{
*
=
'\0'
;
hr = INTSAFE_E_ARITHMETIC_OVERFLOW;
}
return
hr
;
}
_Must_inspect_result_
__inline
(
_Out_ _Deref_out_range_(==, i8Operand) UINT8* pu8Result)
{
;
if
(
>=
0
)
{
*
= (
)
;
}
else
{
*pu8Result = UINT8_ERROR;
hr = INTSAFE_E_ARITHMETIC_OVERFLOW;
}
return
hr
;
}
#define Int8ToByte Int8ToUInt8
_Must_inspect_result_
__inline
(
_Out_ _Deref_out_range_(==, i8Operand) USHORT* pusResult)
{
;
if
(
>=
0
)
{
*
= (
)
;
}
else
{
*pusResult = USHORT_ERROR;
hr = INTSAFE_E_ARITHMETIC_OVERFLOW;
}
return
hr
;
}
#define Int8ToUInt16 Int8ToUShort
#define Int8ToWord Int8ToUShort
_Must_inspect_result_
__inline
(
_Out_ _Deref_out_range_(==, i8Operand) UINT* puResult)
{
;
if
(
>=
0
)
{
*
= (
)
;
}
else
{
hr = INTSAFE_E_ARITHMETIC_OVERFLOW;
}
return
hr
;
}
#define Int8ToUInt32 Int8ToUInt
_Must_inspect_result_
__inline
(
_Out_ _Deref_out_range_(==, i8Operand) UINT_PTR* puResult)
{
;
if
(
>=
0
)
{
*
= (
)
;
}
else
{
*puResult = UINT_PTR_ERROR;
hr = INTSAFE_E_ARITHMETIC_OVERFLOW;
}
return
hr
;
}
_Must_inspect_result_
__inline
(
_Out_ _Deref_out_range_(==, i8Operand) ULONG* pulResult)
{
;
if
(
>=
0
)
{
*
= (
)
;
}
else
{
*pulResult = ULONG_ERROR;
hr = INTSAFE_E_ARITHMETIC_OVERFLOW;
}
return
hr
;
}
_Must_inspect_result_
__inline
(
_Out_ _Deref_out_range_(==, i8Operand) ULONG_PTR* pulResult)
{
;
if
(
>=
0
)
{
*
= (
)
;
}
else
{
*pulResult = ULONG_PTR_ERROR;
hr = INTSAFE_E_ARITHMETIC_OVERFLOW;
}
return
hr
;
}
#define Int8ToDWord Int8ToULong
#define Int8ToDWordPtr Int8ToULongPtr
_Must_inspect_result_
__inline
(
_Out_ _Deref_out_range_(==, i8Operand) ULONGLONG* pullResult)
{
;
if
(
>=
0
)
{
*
= (
)
;
}
else
{
*pullResult = ULONGLONG_ERROR;
*
=
0xffffffffffffffffui64
;
hr = INTSAFE_E_ARITHMETIC_OVERFLOW;
}
return
hr
;
}
#define Int8ToDWordLong Int8ToULongLong
#define Int8ToULong64 Int8ToULongLong
#define Int8ToDWord64 Int8ToULongLong
#define Int8ToUInt64 Int8ToULongLong
#define Int8ToSizeT Int8ToUIntPtr
#define Int8ToSIZET Int8ToULongPtr
_Must_inspect_result_
__inline
(
_Out_ _Deref_out_range_(==, u8Operand) INT8* pi8Result)
{
;
if (u8Operand <= INT8_MAX)
{
*
= (
)
;
}
else
{
hr = INTSAFE_E_ARITHMETIC_OVERFLOW;
}
return
hr
;
}
__forceinline
(
_Out_ _Deref_out_range_(==, u8Operand) CHAR* pch)
{
#ifdef _CHAR_UNSIGNED
*pch = (CHAR)u8Operand;
return S_OK;
#else
return
(
, (
*)
);
#endif
}
_Must_inspect_result_
__inline
(
_Out_ _Deref_out_range_(==, bOperand) INT8* pi8Result)
{
;
if (bOperand <= INT8_MAX)
{
*
= (
)
;
}
else
{
hr = INTSAFE_E_ARITHMETIC_OVERFLOW;
}
return
hr
;
}
__forceinline
(
_Out_ _Deref_out_range_(==, bOperand) CHAR* pch)
{
#ifdef _CHAR_UNSIGNED
*pch = (CHAR)bOperand;
return S_OK;
#else
return
(
, (
*)
);
#endif
}
_Must_inspect_result_
__inline
(
_Out_ _Deref_out_range_(==, sOperand) INT8* pi8Result)
{
;
if ((sOperand >= INT8_MIN) && (sOperand <= INT8_MAX))
if
((
>= (-
127i8
-
1
)) && (
<=
127i8
))
{
*
= (
)
;
}
else
{
hr = INTSAFE_E_ARITHMETIC_OVERFLOW;
}
return
hr
;
}
_Must_inspect_result_
__inline
(
_Out_ _Deref_out_range_(==, sOperand) UCHAR* pch)
{
;
if
((
>=
0
) && (
<=
255
))
{
*
= (
)
;
}
else
{
*
=
'\0'
;
hr = INTSAFE_E_ARITHMETIC_OVERFLOW;
}
return
hr
;
}
__forceinline
(
_Out_ _Deref_out_range_(==, sOperand) CHAR* pch)
{
#ifdef _CHAR_UNSIGNED
return ShortToUChar(sOperand, (UCHAR*)pch);
#else
return
(
, (
*)
);
#endif // _CHAR_UNSIGNED
}
_Must_inspect_result_
__inline
(
_Out_ _Deref_out_range_(==, sOperand) UINT8* pui8Result)
{
;
if ((sOperand >= 0) && (sOperand <= UINT8_MAX))
if
((
>=
0
) && (
<=
0xffui8
))
{
*
= (
)
;
}
else
{
*pui8Result = UINT8_ERROR;
hr = INTSAFE_E_ARITHMETIC_OVERFLOW;
}
return
hr
;
}
#define ShortToByte ShortToUInt8
_Must_inspect_result_
__inline
(
_Out_ _Deref_out_range_(==, sOperand) USHORT* pusResult)
{
;
if
(
>=
0
)
{
*
= (
)
;
}
else
{
*pusResult = USHORT_ERROR;
hr = INTSAFE_E_ARITHMETIC_OVERFLOW;
}
return
hr
;
}
#define ShortToUInt16 ShortToUShort
#define ShortToWord ShortToUShort
_Must_inspect_result_
__inline
(
_Out_ _Deref_out_range_(==, sOperand) UINT* puResult)
{
;
if
(
>=
0
)
{
*
= (
)
;
}
else
{
hr = INTSAFE_E_ARITHMETIC_OVERFLOW;
}
return
hr
;
}
#define ShortToUInt32 ShortToUInt
_Must_inspect_result_
__inline
(
_Out_ _Deref_out_range_(==, sOperand) UINT_PTR* puResult)
{
;
if
(
>=
0
)
{
*
= (
)
;
}
else
{
*puResult = UINT_PTR_ERROR;
hr = INTSAFE_E_ARITHMETIC_OVERFLOW;
}
return
hr
;
}
_Must_inspect_result_
__inline
(
_Out_ _Deref_out_range_(==, sOperand) ULONG* pulResult)
{
;
if
(
>=
0
)
{
*
= (
)
;
}
else
{
*pulResult = ULONG_ERROR;
hr = INTSAFE_E_ARITHMETIC_OVERFLOW;
}
return
hr
;
}
_Must_inspect_result_
__inline
(
_Out_ _Deref_out_range_(==, sOperand) ULONG_PTR* pulResult)
{
;
if
(
>=
0
)
{
*
= (
)
;
}
else
{
*pulResult = ULONG_PTR_ERROR;
hr = INTSAFE_E_ARITHMETIC_OVERFLOW;
}
return
hr
;
}
#define ShortToDWord ShortToULong
_Must_inspect_result_
__inline
(
_Out_ _Deref_out_range_(==, sOperand) DWORD_PTR* pdwResult)
{
;
if
(
>=
0
)
{
*
= (
)
;
}
else
{
*pdwResult = DWORD_PTR_ERROR;
hr = INTSAFE_E_ARITHMETIC_OVERFLOW;
}
return
hr
;
}
_Must_inspect_result_
__inline
(
_Out_ _Deref_out_range_(==, sOperand) ULONGLONG* pullResult)
{
;
if
(
>=
0
)
{
*
= (
)
;
}
else
{
*pullResult = ULONGLONG_ERROR;
*
=
0xffffffffffffffffui64
;
hr = INTSAFE_E_ARITHMETIC_OVERFLOW;
}
return
hr
;
}
#define ShortToDWordLong ShortToULongLong
#define ShortToULong64 ShortToULongLong
#define ShortToDWord64 ShortToULongLong
#define ShortToUInt64 ShortToULongLong
#define ShortToSizeT ShortToUIntPtr
#define ShortToSIZET ShortToULongPtr
#define Int16ToChar ShortToChar
#define Int16ToInt8 ShortToInt8
#define Int16ToUChar ShortToUChar
#define Int16ToUInt8 ShortToUInt8
#define Int16ToByte ShortToUInt8
#define Int16ToUShort ShortToUShort
#define Int16ToUInt16 ShortToUShort
#define Int16ToWord ShortToUShort
#define Int16ToUInt ShortToUInt
#define Int16ToUInt32 ShortToUInt
#define Int16ToUIntPtr ShortToUIntPtr
#define Int16ToULong ShortToULong
#define Int16ToULongPtr ShortToULongPtr
#define Int16ToDWord ShortToULong
#define Int16ToDWordPtr ShortToULongPtr
#define Int16ToULongLong ShortToULongLong
#define Int16ToDWordLong ShortToULongLong
#define Int16ToULong64 ShortToULongLong
#define Int16ToDWord64 ShortToULongLong
#define Int16ToUInt64 ShortToULongLong
#define Int16ToSizeT ShortToUIntPtr
#define Int16ToSIZET ShortToULongPtr
_Must_inspect_result_
__inline
(
_Out_ _Deref_out_range_(==, usOperand) INT8* pi8Result)
{
;
if (usOperand <= INT8_MAX)
{
*
= (
)
;
}
else
{
hr = INTSAFE_E_ARITHMETIC_OVERFLOW;
}
return
hr
;
}
_Must_inspect_result_
__inline
(
_Out_ _Deref_out_range_(==, usOperand) UCHAR* pch)
{
;
if
(
<=
255
)
{
*
= (
)
;
}
else
{
*
=
'\0'
;
hr = INTSAFE_E_ARITHMETIC_OVERFLOW;
}
return
hr
;
}
__forceinline
(
_Out_ _Deref_out_range_(==, usOperand) CHAR* pch)
{
#ifdef _CHAR_UNSIGNED
return UShortToUChar(usOperand, (UCHAR*)pch);
#else
return
(
, (
*)
);
#endif // _CHAR_UNSIGNED
}
_Must_inspect_result_
__inline
(
_Out_ _Deref_out_range_(==, usOperand) UINT8* pui8Result)
{
;
if (usOperand <= UINT8_MAX)
{
*
= (
)
;
}
else
{
*pui8Result = UINT8_ERROR;
hr = INTSAFE_E_ARITHMETIC_OVERFLOW;
}
return
hr
;
}
#define UShortToByte UShortToUInt8
_Must_inspect_result_
__inline
(
_Out_ _Deref_out_range_(==, usOperand) SHORT* psResult)
{
;
if (usOperand <= SHORT_MAX)
{
*
= (
)
;
}
else
{
hr = INTSAFE_E_ARITHMETIC_OVERFLOW;
}
return
hr
;
}
#define UShortToInt16 UShortToShort
#define UInt16ToChar UShortToChar
#define UInt16ToInt8 UShortToInt8
#define UInt16ToUChar UShortToUChar
#define UInt16ToUInt8 UShortToUInt8
#define UInt16ToByte UShortToUInt8
#define UInt16ToShort UShortToShort
#define UInt16ToInt16 UShortToShort
#define WordToInt8 UShortToInt8
#define WordToChar UShortToChar
#define WordToUChar UShortToUChar
#define WordToUInt8 UShortToUInt8
#define WordToByte UShortToUInt8
#define WordToShort UShortToShort
#define WordToInt16 UShortToShort
_Must_inspect_result_
__inline
(
_Out_ _Deref_out_range_(==, iOperand) INT8* pi8Result)
{
;
if ((iOperand >= INT8_MIN) && (iOperand <= INT8_MAX))
if
((
>= (-
127i8
-
1
)) && (
<=
127i8
))
{
*
= (
)
;
}
else
{
hr = INTSAFE_E_ARITHMETIC_OVERFLOW;
}
return
hr
;
}
_Must_inspect_result_
__inline
(
_Out_ _Deref_out_range_(==, iOperand) UCHAR* pch)
{
;
if
((
>=
0
) && (
<=
255
))
{
*
= (
)
;
}
else
{
*
=
'\0'
;
hr = INTSAFE_E_ARITHMETIC_OVERFLOW;
}
return
hr
;
}
__forceinline
(
_Out_ _Deref_out_range_(==, iOperand) CHAR* pch)
{
#ifdef _CHAR_UNSIGNED
return IntToUChar(iOperand, (UCHAR*)pch);
#else
return
(
, (
*)
);
#endif // _CHAR_UNSIGNED
}
#define IntToByte IntToUInt8
_Must_inspect_result_
__inline
(
_Out_ _Deref_out_range_(==, iOperand) UINT8* pui8Result)
{
;
if ((iOperand >= 0) && (iOperand <= UINT8_MAX))
if
((
>=
0
) && (
<=
0xffui8
))
{
*
= (
)
;
}
else
{
*pui8Result = UINT8_ERROR;
hr = INTSAFE_E_ARITHMETIC_OVERFLOW;
}
return
hr
;
}
_Must_inspect_result_
__inline
(
_Out_ _Deref_out_range_(==, iOperand) SHORT* psResult)
{
;
if ((iOperand >= SHORT_MIN) && (iOperand <= SHORT_MAX))
if
((
>= (-
32768
)) && (
<=
32767
))
{
*
= (
)
;
}
else
{
hr = INTSAFE_E_ARITHMETIC_OVERFLOW;
}
return
hr
;
}
#define IntToInt16 IntToShort
_Must_inspect_result_
__inline
(
_Out_ _Deref_out_range_(==, iOperand) USHORT* pusResult)
{
;
if ((iOperand >= 0) && (iOperand <= USHORT_MAX))
if
((
>=
0
) && (
<=
0xffff
))
{
*
= (
)
;
}
else
{
*pusResult = USHORT_ERROR;
hr = INTSAFE_E_ARITHMETIC_OVERFLOW;
}
return
hr
;
}
#define IntToUInt16 IntToUShort
#define IntToWord IntToUShort
_Must_inspect_result_
__inline
(
_Out_ _Deref_out_range_(==, iOperand) UINT* puResult)
{
;
if
(
>=
0
)
{
*
= (
)
;
}
else
{
hr = INTSAFE_E_ARITHMETIC_OVERFLOW;
}
return
hr
;
}
#ifdef _WIN64
#define IntToUIntPtr IntToULongLong
#else
#define IntToUIntPtr IntToUInt
#endif
_Must_inspect_result_
__inline
(
_Out_ _Deref_out_range_(==, iOperand) ULONG* pulResult)
{
;
if
(
>=
0
)
{
*
= (
)
;
}
else
{
*pulResult = ULONG_ERROR;
hr = INTSAFE_E_ARITHMETIC_OVERFLOW;
}
return
hr
;
}
#ifdef _WIN64
#define IntToULongPtr IntToULongLong
#else
#define IntToULongPtr IntToULong
#endif
#define IntToDWord IntToULong
#define IntToDWordPtr IntToULongPtr
_Must_inspect_result_
__inline
(
_Out_ _Deref_out_range_(==, iOperand) ULONGLONG* pullResult)
{
;
if
(
>=
0
)
{
*
= (
)
;
}
else
{
*pullResult = ULONGLONG_ERROR;
*
=
0xffffffffffffffffui64
;
hr = INTSAFE_E_ARITHMETIC_OVERFLOW;
}
return
hr
;
}
#define IntToDWordLong IntToULongLong
#define IntToULong64 IntToULongLong
#define IntToDWord64 IntToULongLong
#define IntToUInt64 IntToULongLong
#define IntToSizeT IntToUIntPtr
#define IntToSIZET IntToULongPtr
#define Int32ToChar IntToChar
#define Int32ToInt8 IntToInt8
#define Int32ToUChar IntToUChar
#define Int32ToByte IntToUInt8
#define Int32ToUInt8 IntToUInt8
#define Int32ToShort IntToShort
#define Int32ToInt16 IntToShort
#define Int32ToUShort IntToUShort
#define Int32ToUInt16 IntToUShort
#define Int32ToWord IntToUShort
#define Int32ToUInt IntToUInt
#define Int32ToUInt32 IntToUInt
#define Int32ToUIntPtr IntToUIntPtr
#define Int32ToULong IntToULong
#define Int32ToULongPtr IntToULongPtr
#define Int32ToDWord IntToULong
#define Int32ToDWordPtr IntToULongPtr
#define Int32ToULongLong IntToULongLong
#define Int32ToDWordLong IntToULongLong
#define Int32ToULong64 IntToULongLong
#define Int32ToDWord64 IntToULongLong
#define Int32ToUInt64 IntToULongLong
#define Int32ToSizeT IntToUIntPtr
#define Int32ToSIZET IntToULongPtr
_Must_inspect_result_
__inline
(
_Out_ _Deref_out_range_(==, iOperand) INT8* pi8Result)
{
;
if ((iOperand >= INT8_MIN) && (iOperand <= INT8_MAX))
if
((
>= (-
127i8
-
1
)) && (
<=
127i8
))
{
*
= (
)
;
}
else
{
hr = INTSAFE_E_ARITHMETIC_OVERFLOW;
}
return
hr
;
}
_Must_inspect_result_
__inline
(
_Out_ _Deref_out_range_(==, iOperand) UCHAR* pch)
{
;
if
((
>=
0
) && (
<=
255
))
{
*
= (
)
;
}
else
{
*
=
'\0'
;
hr = INTSAFE_E_ARITHMETIC_OVERFLOW;
}
return
hr
;
}
__forceinline
(
_Out_ _Deref_out_range_(==, iOperand) CHAR* pch)
{
#ifdef _CHAR_UNSIGNED
return IntPtrToUChar(iOperand, (UCHAR*)pch);
#else
return
(
, (
*)
);
#endif // _CHAR_UNSIGNED
}
_Must_inspect_result_
__inline
(
_Out_ _Deref_out_range_(==, iOperand) UINT8* pui8Result)
{
;
if ((iOperand >= 0) && (iOperand <= UINT8_MAX))
if
((
>=
0
) && (
<=
0xffui8
))
{
*
= (
)
;
}
else
{
*pui8Result = UINT8_ERROR;
hr = INTSAFE_E_ARITHMETIC_OVERFLOW;
}
return
hr
;
}
#define IntPtrToByte IntPtrToUInt8
_Must_inspect_result_
__inline
(
_Out_ _Deref_out_range_(==, iOperand) SHORT* psResult)
{
;
if ((iOperand >= SHORT_MIN) && (iOperand <= SHORT_MAX))
if
((
>= (-
32768
)) && (
<=
32767
))
{
*
= (
)
;
}
else
{
hr = INTSAFE_E_ARITHMETIC_OVERFLOW;
}
return
hr
;
}
#define IntPtrToInt16 IntPtrToShort
_Must_inspect_result_
__inline
(
_Out_ _Deref_out_range_(==, iOperand) USHORT* pusResult)
{
;
if ((iOperand >= 0) && (iOperand <= USHORT_MAX))
if
((
>=
0
) && (
<=
0xffff
))
{
*
= (
)
;
}
else
{
*pusResult = USHORT_ERROR;
hr = INTSAFE_E_ARITHMETIC_OVERFLOW;
}
return
hr
;
}
#define IntPtrToUInt16 IntPtrToUShort
#define IntPtrToWord IntPtrToUShort
#ifdef _WIN64
#define IntPtrToInt LongLongToInt
#else
_Must_inspect_result_
__inline
(
_Out_ _Deref_out_range_(==, iOperand) INT* piResult)
{
*
= (
)
;
}
#endif
#define IntPtrToInt32 IntPtrToInt
#ifdef _WIN64
#define IntPtrToUInt LongLongToUInt
#else
_Must_inspect_result_
__inline
(
_Out_ _Deref_out_range_(==, iOperand) UINT* puResult)
{
;
if
(
>=
0
)
{
*
= (
)
;
}
else
{
hr = INTSAFE_E_ARITHMETIC_OVERFLOW;
}
return
hr
;
}
#endif
#define IntPtrToUInt32 IntPtrToUInt
#ifdef _WIN64
#define IntPtrToUIntPtr LongLongToULongLong
#else
_Must_inspect_result_
__inline
(
_Out_ _Deref_out_range_(==, iOperand) UINT_PTR* puResult)
{
;
if
(
>=
0
)
{
*
= (
)
;
}
else
{
*puResult = UINT_PTR_ERROR;
hr = INTSAFE_E_ARITHMETIC_OVERFLOW;
}
return
hr
;
}
#endif
#ifdef _WIN64
#define IntPtrToLong LongLongToLong
#else
_Must_inspect_result_
__inline
(
_Out_ _Deref_out_range_(==, iOperand) LONG* plResult)
{
*
= (
)
;
}
#endif
_Must_inspect_result_
__inline
(
_Out_ _Deref_out_range_(==, iOperand) LONG_PTR* plResult)
{
*
= (
)
;
}
#ifdef _WIN64
#define IntPtrToULong LongLongToULong
#else
_Must_inspect_result_
__inline
(
_Out_ _Deref_out_range_(==, iOperand) ULONG* pulResult)
{
;
if
(
>=
0
)
{
*
= (
)
;
}
else
{
*pulResult = ULONG_ERROR;
hr = INTSAFE_E_ARITHMETIC_OVERFLOW;
}
return
hr
;
}
#endif
#ifdef _WIN64
#define IntPtrToULongPtr LongLongToULongLong
#else
_Must_inspect_result_
__inline
(
_Out_ _Deref_out_range_(==, iOperand) ULONG_PTR* pulResult)
{
;
if
(
>=
0
)
{
*
= (
)
;
}
else
{
*pulResult = ULONG_PTR_ERROR;
hr = INTSAFE_E_ARITHMETIC_OVERFLOW;
}
return
hr
;
}
#endif
#define IntPtrToDWord IntPtrToULong
#define IntPtrToDWordPtr IntPtrToULongPtr
#ifdef _WIN64
#define IntPtrToULongLong LongLongToULongLong
#else
_Must_inspect_result_
__inline
(
_Out_ _Deref_out_range_(==, iOperand) ULONGLONG* pullResult)
{
;
if
(
>=
0
)
{
*
= (
)
;
}
else
{
*pullResult = ULONGLONG_ERROR;
*
=
0xffffffffffffffffui64
;
hr = INTSAFE_E_ARITHMETIC_OVERFLOW;
}
return
hr
;
}
#endif
#define IntPtrToDWordLong IntPtrToULongLong
#define IntPtrToULong64 IntPtrToULongLong
#define IntPtrToDWord64 IntPtrToULongLong
#define IntPtrToUInt64 IntPtrToULongLong
#define IntPtrToSizeT IntPtrToUIntPtr
#define IntPtrToSIZET IntPtrToULongPtr
_Must_inspect_result_
__inline
(
_Out_ _Deref_out_range_(==, uOperand) INT8* pi8Result)
{
;
if (uOperand <= INT8_MAX)
{
*
= (
)
;
}
else
{
hr = INTSAFE_E_ARITHMETIC_OVERFLOW;
}
return
hr
;
}
_Must_inspect_result_
__inline
(
_Out_ _Deref_out_range_(==, uOperand) UCHAR* pch)
{
;
if
(
<=
255
)
{
*
= (
)
;
}
else
{
*
=
'\0'
;
hr = INTSAFE_E_ARITHMETIC_OVERFLOW;
}
return
hr
;
}
__forceinline
(
_Out_ _Deref_out_range_(==, uOperand) CHAR* pch)
{
#ifdef _CHAR_UNSIGNED
return UIntToUChar(uOperand, (UCHAR*)pch);
#else
return
(
, (
*)
);
#endif
}
_Must_inspect_result_
__inline
(
_Out_ _Deref_out_range_(==, uOperand) UINT8* pui8Result)
{
;
if (uOperand <= UINT8_MAX)
{
*
= (
)
;
}
else
{
*pui8Result = UINT8_ERROR;
hr = INTSAFE_E_ARITHMETIC_OVERFLOW;
}
return
hr
;
}
#define UIntToByte UIntToUInt8
_Must_inspect_result_
__inline
(
_Out_ _Deref_out_range_(==, uOperand) SHORT* psResult)
{
;
if (uOperand <= SHORT_MAX)
{
*
= (
)
;
}
else
{
hr = INTSAFE_E_ARITHMETIC_OVERFLOW;
}
return
hr
;
}
#define UIntToInt16 UIntToShort
_Must_inspect_result_
__inline
(
_Out_ _Deref_out_range_(==, uOperand) USHORT* pusResult)
{
;
if (uOperand <= USHORT_MAX)
{
*
= (
)
;
}
else
{
*pusResult = USHORT_ERROR;
hr = INTSAFE_E_ARITHMETIC_OVERFLOW;
}
return
hr
;
}
#define UIntToUInt16 UIntToUShort
#define UIntToWord UIntToUShort
_Must_inspect_result_
__inline
(
_Out_ _Deref_out_range_(==, uOperand) INT* piResult)
{
;
{
*
= (
)
;
}
else
{
hr = INTSAFE_E_ARITHMETIC_OVERFLOW;
}
return
hr
;
}
#define UIntToInt32 UIntToInt
#ifdef _WIN64
_Must_inspect_result_
__inline
HRESULT
UIntToIntPtr(
_In_ UINT uOperand,
_Out_ _Deref_out_range_(==, uOperand) INT_PTR* piResult)
{
*piResult = uOperand;
return S_OK;
}
#else
#define UIntToIntPtr UIntToInt
#endif
_Must_inspect_result_
__inline
(
_Out_ _Deref_out_range_(==, uOperand) LONG* plResult)
{
;
if (uOperand <= LONG_MAX)
{
*
= (
)
;
}
else
{
hr = INTSAFE_E_ARITHMETIC_OVERFLOW;
}
return
hr
;
}
#ifdef _WIN64
_Must_inspect_result_
__inline
HRESULT
UIntToLongPtr(
_In_ UINT uOperand,
_Out_ _Deref_out_range_(==, uOperand) LONG_PTR* plResult)
{
*plResult = uOperand;
return S_OK;
}
#else
#define UIntToLongPtr UIntToLong
#endif
#define UIntToPtrdiffT UIntToIntPtr
#define UIntToSSIZET UIntToLongPtr
#define UInt32ToChar UIntToChar
#define UInt32ToInt8 UIntToInt8
#define UInt32ToUChar UIntToUChar
#define UInt32ToUInt8 UIntToUInt8
#define UInt32ToByte UInt32ToUInt8
#define UInt32ToShort UIntToShort
#define UInt32ToInt16 UIntToShort
#define UInt32ToUShort UIntToUShort
#define UInt32ToUInt16 UIntToUShort
#define UInt32ToWord UIntToUShort
#define UInt32ToInt UIntToInt
#define UInt32ToIntPtr UIntToIntPtr
#define UInt32ToInt32 UIntToInt
#define UInt32ToLong UIntToLong
#define UInt32ToLongPtr UIntToLongPtr
#define UInt32ToPtrdiffT UIntToPtrdiffT
#define UInt32ToSSIZET UIntToSSIZET
_Must_inspect_result_
__inline
(
_Out_ _Deref_out_range_(==, uOperand) INT8* pi8Result)
{
;
if (uOperand <= INT8_MAX)
{
*
= (
)
;
}
else
{
hr = INTSAFE_E_ARITHMETIC_OVERFLOW;
}
return
hr
;
}
_Must_inspect_result_
__inline
(
_Out_ _Deref_out_range_(==, uOperand) UCHAR* pch)
{
;
if
(
<=
255
)
{
*
= (
)
;
}
else
{
*
=
'\0'
;
hr = INTSAFE_E_ARITHMETIC_OVERFLOW;
}
return
hr
;
}
__forceinline
(
_Out_ _Deref_out_range_(==, uOperand) CHAR* pch)
{
#ifdef _CHAR_UNSIGNED
return UIntPtrToUChar(uOperand, (UCHAR*)pch);
#else
return
(
, (
*)
);
#endif
}
_Must_inspect_result_
__inline
(
_Out_ _Deref_out_range_(==,uOperand) UINT8* pu8Result)
{
;
if (uOperand <= UINT8_MAX)
{
*
= (
)
;
}
else
{
*pu8Result = UINT8_ERROR;
hr = INTSAFE_E_ARITHMETIC_OVERFLOW;
}
return
hr
;
}
#define UIntPtrToByte UIntPtrToUInt8
_Must_inspect_result_
__inline
(
_Out_ _Deref_out_range_(==, uOperand) SHORT* psResult)
{
;
if (uOperand <= SHORT_MAX)
{
*
= (
)
;
}
else
{
hr = INTSAFE_E_ARITHMETIC_OVERFLOW;
}
return
hr
;
}
_Must_inspect_result_
__inline
(
_Out_ _Deref_out_range_(==, uOperand) INT16* pi16Result)
{
;
if (uOperand <= INT16_MAX)
{
*
= (
)
;
}
else
{
*pi16Result = INT16_ERROR;
hr = INTSAFE_E_ARITHMETIC_OVERFLOW;
}
return
hr
;
}
_Must_inspect_result_
__inline
(
_Out_ _Deref_out_range_(==, uOperand) USHORT* pusResult)
{
;
if (uOperand <= USHORT_MAX)
{
*
= (
)
;
}
else
{
*pusResult = USHORT_ERROR;
hr = INTSAFE_E_ARITHMETIC_OVERFLOW;
}
return
hr
;
}
_Must_inspect_result_
__inline
(
_Out_ _Deref_out_range_(==, uOperand) UINT16* pu16Result)
{
;
if (uOperand <= UINT16_MAX)
{
*
= (
)
;
}
else
{
*pu16Result = UINT16_ERROR;
hr = INTSAFE_E_ARITHMETIC_OVERFLOW;
}
return
hr
;
}
#define UIntPtrToWord UIntPtrToUShort
_Must_inspect_result_
__inline
(
_Out_ _Deref_out_range_(==, uOperand) INT* piResult)
{
;
{
*
= (
)
;
}
else
{
hr = INTSAFE_E_ARITHMETIC_OVERFLOW;
}
return
hr
;
}
#define UIntPtrToInt32 UIntPtrToInt
_Must_inspect_result_
__inline
(
_Out_ _Deref_out_range_(==, uOperand) INT_PTR* piResult)
{
;
if (uOperand <= INT_PTR_MAX)
{
*
= (
)
;
}
else
{
*piResult = INT_PTR_ERROR;
hr = INTSAFE_E_ARITHMETIC_OVERFLOW;
}
return
hr
;
}
#ifdef _WIN64
#define UIntPtrToUInt ULongLongToUInt
#else
_Must_inspect_result_
__inline
(
_Out_ _Deref_out_range_(==, uOperand) UINT* puResult)
{
*
= (
)
;
}
#endif
#define UIntPtrToUInt32 UIntPtrToUInt
_Must_inspect_result_
__inline
(
_Out_ _Deref_out_range_(==, uOperand) LONG* plResult)
{
;
if (uOperand <= LONG_MAX)
{
*
= (
)
;
}
else
{
hr = INTSAFE_E_ARITHMETIC_OVERFLOW;
}
return
hr
;
}
_Must_inspect_result_
__inline
(
_Out_ _Deref_out_range_(==, uOperand) LONG_PTR* plResult)
{
;
if (uOperand <= LONG_PTR_MAX)
{
*
= (
)
;
}
else
{
*plResult = LONG_PTR_ERROR;
hr = INTSAFE_E_ARITHMETIC_OVERFLOW;
}
return
hr
;
}
#ifdef _WIN64
#define UIntPtrToULong ULongLongToULong
#else
_Must_inspect_result_
__inline
(
_Out_ _Deref_out_range_(==, uOperand) ULONG* pulResult)
{
*
= (
)
;
}
#endif
#define UIntPtrToDWord UIntPtrToULong
#ifdef _WIN64
#define UIntPtrToLongLong ULongLongToLongLong
#else
_Must_inspect_result_
__inline
(
_Out_ _Deref_out_range_(==, uOperand) LONGLONG* pllResult)
{
*
= (
)
;
}
#endif
#define UIntPtrToLong64 UIntPtrToLongLong
#define UIntPtrToInt64 UIntPtrToLongLong
#define UIntPtrToPtrdiffT UIntPtrToIntPtr
#define UIntPtrToSSIZET UIntPtrToLongPtr
_Must_inspect_result_
__inline
(
_Out_ _Deref_out_range_(==, lOperand) INT8* pi8Result)
{
;
if ((lOperand >= INT8_MIN) && (lOperand <= INT8_MAX))
if
((
>= (-
127i8
-
1
)) && (
<=
127i8
))
{
*
= (
)
;
}
else
{
hr = INTSAFE_E_ARITHMETIC_OVERFLOW;
}
return
hr
;
}
_Must_inspect_result_
__inline
(
_Out_ _Deref_out_range_(==, lOperand) UCHAR* pch)
{
;
if
((
>=
0
) && (
<=
255
))
{
*
= (
)
;
}
else
{
*
=
'\0'
;
hr = INTSAFE_E_ARITHMETIC_OVERFLOW;
}
return
hr
;
}
__forceinline
(
_Out_ _Deref_out_range_(==, lOperand) CHAR* pch)
{
#ifdef _CHAR_UNSIGNED
return LongToUChar(lOperand, (UCHAR*)pch);
#else
return
(
, (
*)
);
#endif
}
_Must_inspect_result_
__inline
(
_Out_ _Deref_out_range_(==, lOperand) UINT8* pui8Result)
{
;
if ((lOperand >= 0) && (lOperand <= UINT8_MAX))
if
((
>=
0
) && (
<=
0xffui8
))
{
*
= (
)
;
}
else
{
*pui8Result = UINT8_ERROR;
hr = INTSAFE_E_ARITHMETIC_OVERFLOW;
}
return
hr
;
}
#define LongToByte LongToUInt8
_Must_inspect_result_
__inline
(
_Out_ _Deref_out_range_(==, lOperand) SHORT* psResult)
{
;
if ((lOperand >= SHORT_MIN) && (lOperand <= SHORT_MAX))
if
((
>= (-
32768
)) && (
<=
32767
))
{
*
= (
)
;
}
else
{
hr = INTSAFE_E_ARITHMETIC_OVERFLOW;
}
return
hr
;
}
#define LongToInt16 LongToShort
_Must_inspect_result_
__inline
(
_Out_ _Deref_out_range_(==, lOperand) USHORT* pusResult)
{
;
if ((lOperand >= 0) && (lOperand <= USHORT_MAX))
if
((
>=
0
) && (
<=
0xffff
))
{
*
= (
)
;
}
else
{
*pusResult = USHORT_ERROR;
hr = INTSAFE_E_ARITHMETIC_OVERFLOW;
}
return
hr
;
}
#define LongToUInt16 LongToUShort
#define LongToWord LongToUShort
_Must_inspect_result_
__inline
(
_Out_ _Deref_out_range_(==, lOperand) INT* piResult)
{
C_ASSERT(sizeof(INT) == sizeof(LONG));
typedef
char
[(
sizeof
(
) ==
sizeof
(
))?
1
:-
1
];
*
= (
)
;
}
#define LongToInt32 LongToInt
#ifdef _WIN64
_Must_inspect_result_
__inline
HRESULT
LongToIntPtr(
_In_ LONG lOperand,
_Out_ _Deref_out_range_(==, lOperand) INT_PTR* piResult)
{
*piResult = lOperand;
return S_OK;
}
#else
#define LongToIntPtr LongToInt
#endif
_Must_inspect_result_
__inline
(
_Out_ _Deref_out_range_(==, lOperand) UINT* puResult)
{
;
if
(
>=
0
)
{
*
= (
)
;
}
else
{
hr = INTSAFE_E_ARITHMETIC_OVERFLOW;
}
return
hr
;
}
#define LongToUInt32 LongToUInt
#ifdef _WIN64
_Must_inspect_result_
__inline
HRESULT
LongToUIntPtr(
_In_ LONG lOperand,
_Out_ _Deref_out_range_(==, lOperand) UINT_PTR* puResult)
{
HRESULT hr;
if (lOperand >= 0)
{
*puResult = (UINT_PTR)lOperand;
hr = S_OK;
}
else
{
*puResult = UINT_PTR_ERROR;
hr = INTSAFE_E_ARITHMETIC_OVERFLOW;
}
return hr;
}
#else
#define LongToUIntPtr LongToUInt
#endif
_Must_inspect_result_
__inline
(
_Out_ _Deref_out_range_(==, lOperand) ULONG* pulResult)
{
;
if
(
>=
0
)
{
*
= (
)
;
}
else
{
*pulResult = ULONG_ERROR;
hr = INTSAFE_E_ARITHMETIC_OVERFLOW;
}
return
hr
;
}
#ifdef _WIN64
_Must_inspect_result_
__inline
HRESULT
LongToULongPtr(
_In_ LONG lOperand,
_Out_ _Deref_out_range_(==, lOperand) ULONG_PTR* pulResult)
{
HRESULT hr;
if (lOperand >= 0)
{
*pulResult = (ULONG_PTR)lOperand;
hr = S_OK;
}
else
{
*pulResult = ULONG_PTR_ERROR;
hr = INTSAFE_E_ARITHMETIC_OVERFLOW;
}
return hr;
}
#else
#define LongToULongPtr LongToULong
#endif
#define LongToDWord LongToULong
#define LongToDWordPtr LongToULongPtr
_Must_inspect_result_
__inline
(
_Out_ _Deref_out_range_(==, lOperand) ULONGLONG* pullResult)
{
;
if
(
>=
0
)
{
*
= (
)
;
}
else
{
*pullResult = ULONGLONG_ERROR;
*
=
0xffffffffffffffffui64
;
hr = INTSAFE_E_ARITHMETIC_OVERFLOW;
}
return
hr
;
}
#define LongToDWordLong LongToULongLong
#define LongToULong64 LongToULongLong
#define LongToDWord64 LongToULongLong
#define LongToUInt64 LongToULongLong
#define LongToPtrdiffT LongToIntPtr
#define LongToSizeT LongToUIntPtr
#define LongToSIZET LongToULongPtr
_Must_inspect_result_
__inline
(
_Out_ _Deref_out_range_(==, lOperand) INT8* pi8Result)
{
;
if ((lOperand >= INT8_MIN) && (lOperand <= INT8_MAX))
if
((
>= (-
127i8
-
1
)) && (
<=
127i8
))
{
*
= (
)
;
}
else
{
hr = INTSAFE_E_ARITHMETIC_OVERFLOW;
}
return
hr
;
}
_Must_inspect_result_
__inline
(
_Out_ _Deref_out_range_(==, lOperand) UCHAR* pch)
{
;
if
((
>=
0
) && (
<=
255
))
{
*
= (
)
;
}
else
{
*
=
'\0'
;
hr = INTSAFE_E_ARITHMETIC_OVERFLOW;
}
return
hr
;
}
__forceinline
(
_Out_ _Deref_out_range_(==, lOperand) CHAR* pch)
{
#ifdef _CHAR_UNSIGNED
return LongPtrToUChar(lOperand, (UCHAR*)pch);
#else
return
(
, (
*)
);
#endif
}
_Must_inspect_result_
__inline
(
_Out_ _Deref_out_range_(==, lOperand) UINT8* pui8Result)
{
;
if ((lOperand >= 0) && (lOperand <= UINT8_MAX))
if
((
>=
0
) && (
<=
0xffui8
))
{
*
= (
)
;
}
else
{
*pui8Result = UINT8_ERROR;
hr = INTSAFE_E_ARITHMETIC_OVERFLOW;
}
return
hr
;
}
#define LongPtrToByte LongPtrToUInt8
_Must_inspect_result_
__inline
(
_Out_ _Deref_out_range_(==, lOperand) SHORT* psResult)
{
;
if ((lOperand >= SHORT_MIN) && (lOperand <= SHORT_MAX))
if
((
>= (-
32768
)) && (
<=
32767
))
{
*
= (
)
;
}
else
{
hr = INTSAFE_E_ARITHMETIC_OVERFLOW;
}
return
hr
;
}
#define LongPtrToInt16 LongPtrToShort
_Must_inspect_result_
__inline
(
_Out_ _Deref_out_range_(==, lOperand) USHORT* pusResult)
{
;
if ((lOperand >= 0) && (lOperand <= USHORT_MAX))
if
((
>=
0
) && (
<=
0xffff
))
{
*
= (
)
;
}
else
{
*pusResult = USHORT_ERROR;
hr = INTSAFE_E_ARITHMETIC_OVERFLOW;
}
return
hr
;
}
#define LongPtrToUInt16 LongPtrToUShort
#define LongPtrToWord LongPtrToUShort
#ifdef _WIN64
#define LongPtrToInt LongLongToInt
#else
_Must_inspect_result_
__inline
(
_Out_ _Deref_out_range_(==, lOperand) INT* piResult)
{
C_ASSERT(sizeof(INT) == sizeof(LONG_PTR));
typedef
char
[(
sizeof
(
) ==
sizeof
(
))?
1
:-
1
];
*
= (
)
;
}
#endif
#define LongPtrToInt32 LongPtrToInt
_Must_inspect_result_
__inline
(
_Out_ _Deref_out_range_(==, lOperand) INT_PTR* piResult)
{
C_ASSERT(sizeof(LONG_PTR) == sizeof(INT_PTR));
typedef
char
[(
sizeof
(
) ==
sizeof
(
))?
1
:-
1
];
*
= (
)
;
}
#ifdef _WIN64
#define LongPtrToUInt LongLongToUInt
#else
_Must_inspect_result_
__inline
(
_Out_ _Deref_out_range_(==, lOperand) UINT* puResult)
{
;
if
(
>=
0
)
{
*
= (
)
;
}
else
{
hr = INTSAFE_E_ARITHMETIC_OVERFLOW;
}
return
hr
;
}
#endif
#define LongPtrToUInt32 LongPtrToUInt
_Must_inspect_result_
__inline
(
_Out_ _Deref_out_range_(==, lOperand) UINT_PTR* puResult)
{
;
if
(
>=
0
)
{
*
= (
)
;
}
else
{
*puResult = UINT_PTR_ERROR;
hr = INTSAFE_E_ARITHMETIC_OVERFLOW;
}
return
hr
;
}
#ifdef _WIN64
#define LongPtrToLong LongLongToLong
#else
_Must_inspect_result_
__inline
(
_Out_ _Deref_out_range_(==, lOperand) LONG* plResult)
{
*
= (
)
;
}
#endif
#ifdef _WIN64
#define LongPtrToULong LongLongToULong
#else
_Must_inspect_result_
__inline
(
_Out_ _Deref_out_range_(==, lOperand) ULONG* pulResult)
{
;
if
(
>=
0
)
{
*
= (
)
;
}
else
{
*pulResult = ULONG_ERROR;
hr = INTSAFE_E_ARITHMETIC_OVERFLOW;
}
return
hr
;
}
#endif
_Must_inspect_result_
__inline
(
_Out_ _Deref_out_range_(==, lOperand) ULONG_PTR* pulResult)
{
;
if
(
>=
0
)
{
*
= (
)
;
}
else
{
*pulResult = ULONG_PTR_ERROR;
hr = INTSAFE_E_ARITHMETIC_OVERFLOW;
}
return
hr
;
}
#define LongPtrToDWord LongPtrToULong
#define LongPtrToDWordPtr LongPtrToULongPtr
_Must_inspect_result_
__inline
(
_Out_ _Deref_out_range_(==, lOperand) ULONGLONG* pullResult)
{
;
if
(
>=
0
)
{
*
= (
)
;
}
else
{
*pullResult = ULONGLONG_ERROR;
*
=
0xffffffffffffffffui64
;
hr = INTSAFE_E_ARITHMETIC_OVERFLOW;
}
return
hr
;
}
#define LongPtrToDWordLong LongPtrToULongLong
#define LongPtrToULong64 LongPtrToULongLong
#define LongPtrToDWord64 LongPtrToULongLong
#define LongPtrToUInt64 LongPtrToULongLong
#define LongPtrToSizeT LongPtrToUIntPtr
#define LongPtrToSIZET LongPtrToULongPtr
_Must_inspect_result_
__inline
(
_Out_ _Deref_out_range_(==, ulOperand) INT8* pi8Result)
{
;
if (ulOperand <= INT8_MAX)
{
*
= (
)
;
}
else
{
hr = INTSAFE_E_ARITHMETIC_OVERFLOW;
}
return
hr
;
}
_Must_inspect_result_
__inline
(
_Out_ _Deref_out_range_(==, ulOperand) UCHAR* pch)
{
;
if
(
<=
255
)
{
*
= (
)
;
}
else
{
*
=
'\0'
;
hr = INTSAFE_E_ARITHMETIC_OVERFLOW;
}
return
hr
;
}
__forceinline
(
_Out_ _Deref_out_range_(==, ulOperand) CHAR* pch)
{
#ifdef _CHAR_UNSIGNED
return ULongToUChar(ulOperand, (UCHAR*)pch);
#else
return
(
, (
*)
);
#endif
}
_Must_inspect_result_
__inline
(
_Out_ _Deref_out_range_(==, ulOperand) UINT8* pui8Result)
{
;
if (ulOperand <= UINT8_MAX)
{
*
= (
)
;
}
else
{
*pui8Result = UINT8_ERROR;
hr = INTSAFE_E_ARITHMETIC_OVERFLOW;
}
return
hr
;
}
#define ULongToByte ULongToUInt8
_Must_inspect_result_
__inline
(
_Out_ _Deref_out_range_(==, ulOperand) SHORT* psResult)
{
;
if (ulOperand <= SHORT_MAX)
{
*
= (
)
;
}
else
{
hr = INTSAFE_E_ARITHMETIC_OVERFLOW;
}
return
hr
;
}
#define ULongToInt16 ULongToShort
_Must_inspect_result_
__inline
(
_Out_ _Deref_out_range_(==, ulOperand) USHORT* pusResult)
{
;
if (ulOperand <= USHORT_MAX)
{
*
= (
)
;
}
else
{
*pusResult = USHORT_ERROR;
hr = INTSAFE_E_ARITHMETIC_OVERFLOW;
}
return
hr
;
}
#define ULongToUInt16 ULongToUShort
#define ULongToWord ULongToUShort
_Must_inspect_result_
__inline
(
_Out_ _Deref_out_range_(==, ulOperand) INT* piResult)
{
;
if (ulOperand <= INT_MAX)
{
*
= (
)
;
}
else
{
hr = INTSAFE_E_ARITHMETIC_OVERFLOW;
}
return
hr
;
}
#define ULongToInt32 ULongToInt
#ifdef _WIN64
_Must_inspect_result_
__inline
HRESULT
ULongToIntPtr(
_In_ ULONG ulOperand,
_Out_ _Deref_out_range_(==, ulOperand) INT_PTR* piResult)
{
*piResult = (INT_PTR)ulOperand;
return S_OK;
}
#else
#define ULongToIntPtr ULongToInt
#endif
_Must_inspect_result_
__inline
(
_Out_ _Deref_out_range_(==, ulOperand) UINT* puResult)
{
C_ASSERT(sizeof(ULONG) == sizeof(UINT));
typedef
char
[(
sizeof
(
) ==
sizeof
(
))?
1
:-
1
];
*
= (
)
;
}
#define ULongToUInt32 ULongToUInt
#ifdef _WIN64
_Must_inspect_result_
__inline
HRESULT
ULongToUIntPtr(
_In_ ULONG ulOperand,
_Out_ _Deref_out_range_(==, ulOperand) UINT_PTR* puiResult)
{
C_ASSERT(sizeof(UINT_PTR) > sizeof(ULONG));
*puiResult = (UINT_PTR)ulOperand;
return S_OK;
}
#else
#define ULongToUIntPtr ULongToUInt
#endif
_Must_inspect_result_
__inline
(
_Out_ _Deref_out_range_(==, ulOperand) LONG* plResult)
{
;
if (ulOperand <= LONG_MAX)
{
*
= (
)
;
}
else
{
hr = INTSAFE_E_ARITHMETIC_OVERFLOW;
}
return
hr
;
}
#ifdef _WIN64
_Must_inspect_result_
__inline
HRESULT
ULongToLongPtr(
_In_ ULONG ulOperand,
_Out_ _Deref_out_range_(==, ulOperand) LONG_PTR* plResult)
{
C_ASSERT(sizeof(LONG_PTR) > sizeof(ULONG));
*plResult = (LONG_PTR)ulOperand;
return S_OK;
}
#else
#define ULongToLongPtr ULongToLong
#endif
#define ULongToPtrdiffT ULongToIntPtr
#define ULongToSSIZET ULongToLongPtr
_Must_inspect_result_
__inline
(
_In_ ULONG_PTR ulOperand,
_Out_ _Deref_out_range_(==, ulOperand) INT8* pi8Result)
{
;
if (ulOperand <= INT8_MAX)
{
*
= (
)
;
}
else
{
hr = INTSAFE_E_ARITHMETIC_OVERFLOW;
}
return
hr
;
}
_Must_inspect_result_
__inline
(
_In_ ULONG_PTR ulOperand,
_Out_ _Deref_out_range_(==, ulOperand) UCHAR* pch)
{
;
if
(
<=
255
)
{
*
= (
)
;
}
else
{
*
=
'\0'
;
hr = INTSAFE_E_ARITHMETIC_OVERFLOW;
}
return
hr
;
}
__forceinline
(
_In_ ULONG_PTR ulOperand,
_Out_ _Deref_out_range_(==, ulOperand) CHAR* pch)
{
#ifdef _CHAR_UNSIGNED
return ULongPtrToUChar(ulOperand, (UCHAR*)pch);
#else
return
(
, (
*)
);
#endif
}
_Must_inspect_result_
__inline
(
_In_ ULONG_PTR ulOperand,
_Out_ _Deref_out_range_(==, ulOperand) UINT8* pui8Result)
{
;
if (ulOperand <= UINT8_MAX)
{
*
= (
)
;
}
else
{
*pui8Result = UINT8_ERROR;
hr = INTSAFE_E_ARITHMETIC_OVERFLOW;
}
return
hr
;
}
#define ULongPtrToByte ULongPtrToUInt8
_Must_inspect_result_
__inline
(
_In_ ULONG_PTR ulOperand,
_Out_ _Deref_out_range_(==, ulOperand) SHORT* psResult)
{
;
if (ulOperand <= SHORT_MAX)
{
*
= (
)
;
}
else
{
hr = INTSAFE_E_ARITHMETIC_OVERFLOW;
}
return
hr
;
}
#define ULongPtrToInt16 ULongPtrToShort
_Must_inspect_result_
__inline
(
_In_ ULONG_PTR ulOperand,
_Out_ _Deref_out_range_(==, ulOperand) USHORT* pusResult)
{
;
if (ulOperand <= USHORT_MAX)
{
*
= (
)
;
}
else
{
*pusResult = USHORT_ERROR;
hr = INTSAFE_E_ARITHMETIC_OVERFLOW;
}
return
hr
;
}
#define ULongPtrToUInt16 ULongPtrToUShort
#define ULongPtrToWord ULongPtrToUShort
_Must_inspect_result_
__inline
(
_In_ ULONG_PTR ulOperand,
_Out_ _Deref_out_range_(==, ulOperand) INT* piResult)
{
;
if (ulOperand <= INT_MAX)
{
*
= (
)
;
}
else
{
hr = INTSAFE_E_ARITHMETIC_OVERFLOW;
}
return
hr
;
}
#define ULongPtrToInt32 ULongPtrToInt
_Must_inspect_result_
__inline
(
_In_ ULONG_PTR ulOperand,
_Out_ _Deref_out_range_(==, ulOperand) INT_PTR* piResult)
{
;
if (ulOperand <= INT_PTR_MAX)
{
*
= (
)
;
}
else
{
*piResult = INT_PTR_ERROR;
hr = INTSAFE_E_ARITHMETIC_OVERFLOW;
}
return
hr
;
}
#ifdef _WIN64
#define ULongPtrToUInt ULongLongToUInt
#else
_Must_inspect_result_
__inline
(
_In_ ULONG_PTR ulOperand,
_Out_ _Deref_out_range_(==, ulOperand) UINT* puResult)
{
C_ASSERT(sizeof(ULONG_PTR) == sizeof(UINT));
typedef
char
[(
sizeof
(
) ==
sizeof
(
))?
1
:-
1
];
*
= (
)
;
}
#endif
#define ULongPtrToUInt32 ULongPtrToUInt
_Must_inspect_result_
__inline
(
_In_ ULONG_PTR ulOperand,
_Out_ _Deref_out_range_(==, ulOperand) UINT_PTR* puResult)
{
*
= (
)
;
}
_Must_inspect_result_
__inline
(
_In_ ULONG_PTR ulOperand,
_Out_ _Deref_out_range_(==, ulOperand) LONG* plResult)
{
;
if (ulOperand <= LONG_MAX)
{
*
= (
)
;
}
else
{
hr = INTSAFE_E_ARITHMETIC_OVERFLOW;
}
return
hr
;
}
_Must_inspect_result_
__inline
(
_In_ ULONG_PTR ulOperand,
_Out_ _Deref_out_range_(==, ulOperand) LONG_PTR* plResult)
{
;
if (ulOperand <= LONG_PTR_MAX)
{
*
= (
)
;
}
else
{
*plResult = LONG_PTR_ERROR;
hr = INTSAFE_E_ARITHMETIC_OVERFLOW;
}
return
hr
;
}
#ifdef _WIN64
#define ULongPtrToULong ULongLongToULong
#else
_Must_inspect_result_
__inline
(
_In_ ULONG_PTR ulOperand,
_Out_ _Deref_out_range_(==, ulOperand) ULONG* pulResult)
{
*
= (
)
;
}
#endif
#define ULongPtrToDWord ULongPtrToULong
#ifdef _WIN64
#define ULongPtrToLongLong ULongLongToLongLong
#else
_Must_inspect_result_
__inline
(
_In_ ULONG_PTR ulOperand,
_Out_ _Deref_out_range_(==, ulOperand) LONGLONG* pllResult)
{
*
= (
)
;
}
#endif
#define ULongPtrToLong64 ULongPtrToLongLong
#define ULongPtrToInt64 ULongPtrToLongLong
#define ULongPtrToPtrdiffT ULongPtrToIntPtr
#define ULongPtrToSSIZET ULongPtrToLongPtr
#define DWordToInt8 ULongToInt8
#define DWordToChar ULongToChar
#define DWordToUChar ULongToUChar
#define DWordToUInt8 ULongToUInt8
#define DWordToByte ULongToUInt8
#define DWordToShort ULongToShort
#define DWordToInt16 ULongToShort
#define DWordToUShort ULongToUShort
#define DWordToUInt16 ULongToUShort
#define DWordToWord ULongToUShort
#define DWordToInt ULongToInt
#define DWordToInt32 ULongToInt
#define DWordToIntPtr ULongToIntPtr
#define DWordToUInt ULongToUInt
#define DWordToUInt32 ULongToUInt
#define DWordToUIntPtr ULongToUIntPtr
#define DWordToLong ULongToLong
#define DWordToLongPtr ULongToLongPtr
#define DWordToPtrdiffT ULongToIntPtr
#define DWordToSSIZET ULongToLongPtr
#define DWordPtrToInt8 ULongPtrToInt8
#define DWordPtrToUChar ULongPtrToUChar
#define DWordPtrToChar ULongPtrToChar
#define DWordPtrToUInt8 ULongPtrToUInt8
#define DWordPtrToByte ULongPtrToUInt8
#define DWordPtrToShort ULongPtrToShort
#define DWordPtrToInt16 ULongPtrToShort
#define DWordPtrToUShort ULongPtrToUShort
#define DWordPtrToUInt16 ULongPtrToUShort
#define DWordPtrToWord ULongPtrToUShort
#define DWordPtrToInt ULongPtrToInt
#define DWordPtrToInt32 ULongPtrToInt
#define DWordPtrToIntPtr ULongPtrToIntPtr
#define DWordPtrToUInt ULongPtrToUInt
#define DWordPtrToUInt32 ULongPtrToUInt
#define DWordPtrToUIntPtr ULongPtrToUIntPtr
#define DWordPtrToLong ULongPtrToLong
#define DWordPtrToLongPtr ULongPtrToLongPtr
#define DWordPtrToULong ULongPtrToULong
#define DWordPtrToDWord ULongPtrToULong
#define DWordPtrToLongLong ULongPtrToLongLong
#define DWordPtrToLong64 ULongPtrToLongLong
#define DWordPtrToInt64 ULongPtrToLongLong
#define DWordPtrToPtrdiffT ULongPtrToIntPtr
#define DWordPtrToSSIZET ULongPtrToLongPtr
_Must_inspect_result_
__inline
(
_Out_ _Deref_out_range_(==, llOperand) INT8* pi8Result)
{
;
if ((llOperand >= INT8_MIN) && (llOperand <= INT8_MAX))
if
((
>= (-
127i8
-
1
)) && (
<=
127i8
))
{
*
= (
)
;
}
else
{
hr = INTSAFE_E_ARITHMETIC_OVERFLOW;
}
return
hr
;
}
_Must_inspect_result_
__inline
(
_Out_ _Deref_out_range_(==, llOperand) UCHAR* pch)
{
;
if
((
>=
0
) && (
<=
255
))
{
*
= (
)
;
}
else
{
*
=
'\0'
;
hr = INTSAFE_E_ARITHMETIC_OVERFLOW;
}
return
hr
;
}
__forceinline
(
_Out_ _Deref_out_range_(==, llOperand) CHAR* pch)
{
#ifdef _CHAR_UNSIGNED
return LongLongToUChar(llOperand, (UCHAR*)pch);
#else
return
(
, (
*)
);
#endif
}
_Must_inspect_result_
__inline
(
_Out_ _Deref_out_range_(==, llOperand) UINT8* pu8Result)
{
;
if ((llOperand >= 0) && (llOperand <= UINT8_MAX))
if
((
>=
0
) && (
<=
0xffui8
))
{
*
= (
)
;
}
else
{
*pu8Result = UINT8_ERROR;
hr = INTSAFE_E_ARITHMETIC_OVERFLOW;
}
return
hr
;
}
#define LongLongToByte LongLongToUInt8
_Must_inspect_result_
__inline
(
_Out_ _Deref_out_range_(==, llOperand) SHORT* psResult)
{
;
if ((llOperand >= SHORT_MIN) && (llOperand <= SHORT_MAX))
if
((
>= (-
32768
)) && (
<=
32767
))
{
*
= (
)
;
}
else
{
hr = INTSAFE_E_ARITHMETIC_OVERFLOW;
}
return
hr
;
}
#define LongLongToInt16 LongLongToShort
_Must_inspect_result_
__inline
(
_Out_ _Deref_out_range_(==, llOperand) USHORT* pusResult)
{
;
if ((llOperand >= 0) && (llOperand <= USHORT_MAX))
if
((
>=
0
) && (
<=
0xffff
))
{
*
= (
)
;
}
else
{
*pusResult = USHORT_ERROR;
hr = INTSAFE_E_ARITHMETIC_OVERFLOW;
}
return
hr
;
}
#define LongLongToUInt16 LongLongToUShort
#define LongLongToWord LongLongToUShort
_Must_inspect_result_
__inline
(
_Out_ _Deref_out_range_(==, llOperand) INT* piResult)
{
;
if ((llOperand >= INT_MIN) && (llOperand <= INT_MAX))
if
((
>= (-
2147483647
-
1
)) && (
<=
2147483647
))
{
*
= (
)
;
}
else
{
hr = INTSAFE_E_ARITHMETIC_OVERFLOW;
}
return
hr
;
}
#define LongLongToInt32 LongLongToInt
#ifdef _WIN64
_Must_inspect_result_
__inline
HRESULT
LongLongToIntPtr(
_In_ LONGLONG llOperand,
_Out_ _Deref_out_range_(==, llOperand) INT_PTR* piResult)
{
*piResult = llOperand;
return S_OK;
}
#else
#define LongLongToIntPtr LongLongToInt
#endif
_Must_inspect_result_
__inline
(
_Out_ _Deref_out_range_(==, llOperand) UINT* puResult)
{
;
if ((llOperand >= 0) && (llOperand <= UINT_MAX))
if
((
>=
0
) && (
<=
0xffffffff
))
{
*
= (
)
;
}
else
{
hr = INTSAFE_E_ARITHMETIC_OVERFLOW;
}
return
hr
;
}
#define LongLongToUInt32 LongLongToUInt
#ifdef _WIN64
#define LongLongToUIntPtr LongLongToULongLong
#else
#define LongLongToUIntPtr LongLongToUInt
#endif
_Must_inspect_result_
__inline
(
_Out_ _Deref_out_range_(==, llOperand) LONG* plResult)
{
;
if ((llOperand >= LONG_MIN) && (llOperand <= LONG_MAX))
if
((
>= (-
2147483647L
-
1
)) && (
<=
2147483647L
))
{
*
= (
)
;
}
else
{
hr = INTSAFE_E_ARITHMETIC_OVERFLOW;
}
return
hr
;
}
#ifdef _WIN64
_Must_inspect_result_
__inline
HRESULT
LongLongToLongPtr(
_In_ LONGLONG llOperand,
_Out_ _Deref_out_range_(==, llOperand) LONG_PTR* plResult)
{
*plResult = (LONG_PTR)llOperand;
return S_OK;
}
#else
#define LongLongToLongPtr LongLongToLong
#endif
_Must_inspect_result_
__inline
(
_Out_ _Deref_out_range_(==, llOperand) ULONG* pulResult)
{
;
if ((llOperand >= 0) && (llOperand <= ULONG_MAX))
if
((
>=
0
) && (
<=
0xffffffffUL
))
{
*
= (
)
;
}
else
{
*pulResult = ULONG_ERROR;
hr = INTSAFE_E_ARITHMETIC_OVERFLOW;
}
return
hr
;
}
#ifdef _WIN64
#define LongLongToULongPtr LongLongToULongLong
#else
#define LongLongToULongPtr LongLongToULong
#endif
#define LongLongToDWord LongLongToULong
#define LongLongToDWordPtr LongLongToULongPtr
_Must_inspect_result_
__inline
(
_Out_ _Deref_out_range_(==, llOperand) ULONGLONG* pullResult)
{
;
if
(
>=
0
)
{
*
= (
)
;
}
else
{
*pullResult = ULONGLONG_ERROR;
*
=
0xffffffffffffffffui64
;
hr = INTSAFE_E_ARITHMETIC_OVERFLOW;
}
return
hr
;
}
#define LongLongToDWordLong LongLongToULongLong
#define LongLongToULong64 LongLongToULongLong
#define LongLongToDWord64 LongLongToULongLong
#define LongLongToUInt64 LongLongToULongLong
#define LongLongToPtrdiffT LongLongToIntPtr
#define LongLongToSizeT LongLongToUIntPtr
#define LongLongToSSIZET LongLongToLongPtr
#define LongLongToSIZET LongLongToULongPtr
#define Long64ToChar LongLongToChar
#define Long64ToInt8 LongLongToInt8
#define Long64ToUChar LongLongToUChar
#define Long64ToUInt8 LongLongToUInt8
#define Long64ToByte LongLongToUInt8
#define Long64ToShort LongLongToShort
#define Long64ToInt16 LongLongToShort
#define Long64ToUShort LongLongToUShort
#define Long64ToUInt16 LongLongToUShort
#define Long64ToWord LongLongToUShort
#define Long64ToInt LongLongToInt
#define Long64ToInt32 LongLongToInt
#define Long64ToIntPtr LongLongToIntPtr
#define Long64ToUInt LongLongToUInt
#define Long64ToUInt32 LongLongToUInt
#define Long64ToUIntPtr LongLongToUIntPtr
#define Long64ToLong LongLongToLong
#define Long64ToLongPtr LongLongToLongPtr
#define Long64ToULong LongLongToULong
#define Long64ToULongPtr LongLongToULongPtr
#define Long64ToDWord LongLongToULong
#define Long64ToDWordPtr LongLongToULongPtr
#define Long64ToULongLong LongLongToULongLong
#define Long64ToPtrdiffT LongLongToIntPtr
#define Long64ToSizeT LongLongToUIntPtr
#define Long64ToSSIZET LongLongToLongPtr
#define Long64ToSIZET LongLongToULongPtr
#define Int64ToChar LongLongToChar
#define Int64ToInt8 LongLongToInt8
#define Int64ToUChar LongLongToUChar
#define Int64ToUInt8 LongLongToUInt8
#define Int64ToByte LongLongToUInt8
#define Int64ToShort LongLongToShort
#define Int64ToInt16 LongLongToShort
#define Int64ToUShort LongLongToUShort
#define Int64ToUInt16 LongLongToUShort
#define Int64ToWord LongLongToUShort
#define Int64ToInt LongLongToInt
#define Int64ToInt32 LongLongToInt
#define Int64ToIntPtr LongLongToIntPtr
#define Int64ToUInt LongLongToUInt
#define Int64ToUInt32 LongLongToUInt
#define Int64ToUIntPtr LongLongToUIntPtr
#define Int64ToLong LongLongToLong
#define Int64ToLongPtr LongLongToLongPtr
#define Int64ToULong LongLongToULong
#define Int64ToULongPtr LongLongToULongPtr
#define Int64ToDWord LongLongToULong
#define Int64ToDWordPtr LongLongToULongPtr
#define Int64ToULongLong LongLongToULongLong
#define Int64ToDWordLong LongLongToULongLong
#define Int64ToULong64 LongLongToULongLong
#define Int64ToDWord64 LongLongToULongLong
#define Int64ToUInt64 LongLongToULongLong
#define Int64ToPtrdiffT LongLongToIntPtr
#define Int64ToSizeT LongLongToUIntPtr
#define Int64ToSSIZET LongLongToLongPtr
#define Int64ToSIZET LongLongToULongPtr
_Must_inspect_result_
__inline
(
_In_ ULONGLONG ullOperand,
_Out_ _Deref_out_range_(==, ullOperand) INT8* pi8Result)
{
;
if (ullOperand <= INT8_MAX)
{
*
= (
)
;
}
else
{
hr = INTSAFE_E_ARITHMETIC_OVERFLOW;
}
return
hr
;
}
_Must_inspect_result_
__inline
(
_In_ ULONGLONG ullOperand,
_Out_ _Deref_out_range_(==, ullOperand) UCHAR* pch)
{
;
if
(
<=
255
)
{
*
= (
)
;
}
else
{
*
=
'\0'
;
hr = INTSAFE_E_ARITHMETIC_OVERFLOW;
}
return
hr
;
}
__forceinline
(
_In_ ULONGLONG ullOperand,
_Out_ _Deref_out_range_(==, ullOperand) CHAR* pch)
{
#ifdef _CHAR_UNSIGNED
return ULongLongToUChar(ullOperand, (UCHAR*)pch);
#else
return
(
, (
*)
);
#endif
}
_Must_inspect_result_
__inline
(
_In_ ULONGLONG ullOperand,
_Out_ _Deref_out_range_(==, ullOperand) UINT8* pu8Result)
{
;
if (ullOperand <= UINT8_MAX)
{
*
= (
)
;
}
else
{
*pu8Result = UINT8_ERROR;
hr = INTSAFE_E_ARITHMETIC_OVERFLOW;
}
return
hr
;
}
#define ULongLongToByte ULongLongToUInt8
_Must_inspect_result_
__inline
(
_In_ ULONGLONG ullOperand,
_Out_ _Deref_out_range_(==, ullOperand) SHORT* psResult)
{
;
if (ullOperand <= SHORT_MAX)
{
*
= (
)
;
}
else
{
hr = INTSAFE_E_ARITHMETIC_OVERFLOW;
}
return
hr
;
}
#define ULongLongToInt16 ULongLongToShort
_Must_inspect_result_
__inline
(
_In_ ULONGLONG ullOperand,
_Out_ _Deref_out_range_(==, ullOperand) USHORT* pusResult)
{
;
if (ullOperand <= USHORT_MAX)
{
*
= (
)
;
}
else
{
*pusResult = USHORT_ERROR;
hr = INTSAFE_E_ARITHMETIC_OVERFLOW;
}
return
hr
;
}
#define ULongLongToUInt16 ULongLongToUShort
#define ULongLongToWord ULongLongToUShort
_Must_inspect_result_
__inline
(
_In_ ULONGLONG ullOperand,
_Out_ _Deref_out_range_(==, ullOperand) INT* piResult)
{
;
if (ullOperand <= INT_MAX)
{
*
= (
)
;
}
else
{
hr = INTSAFE_E_ARITHMETIC_OVERFLOW;
}
return
hr
;
}
#define ULongLongToInt32 ULongLongToInt
#ifdef _WIN64
#define ULongLongToIntPtr ULongLongToLongLong
#else
#define ULongLongToIntPtr ULongLongToInt
#endif
_Must_inspect_result_
__inline
(
_In_ ULONGLONG ullOperand,
_Out_ _Deref_out_range_(==, ullOperand) UINT* puResult)
{
;
if (ullOperand <= UINT_MAX)
{
*
= (
)
;
}
else
{
hr = INTSAFE_E_ARITHMETIC_OVERFLOW;
}
return
hr
;
}
#define ULongLongToUInt32 ULongLongToUInt
#ifdef _WIN64
_Must_inspect_result_
__inline
HRESULT
ULongLongToUIntPtr(
_In_ ULONGLONG ullOperand,
_Out_ _Deref_out_range_(==, ullOperand) UINT_PTR* puResult)
{
*puResult = ullOperand;
return S_OK;
}
#else
#define ULongLongToUIntPtr ULongLongToUInt
#endif
_Must_inspect_result_
__inline
(
_In_ ULONGLONG ullOperand,
_Out_ _Deref_out_range_(==, ullOperand) LONG* plResult)
{
;
if (ullOperand <= LONG_MAX)
{
*
= (
)
;
}
else
{
hr = INTSAFE_E_ARITHMETIC_OVERFLOW;
}
return
hr
;
}
_Must_inspect_result_
__inline
(
_In_ ULONGLONG ullOperand,
_Out_ _Deref_out_range_(==, ullOperand) LONG_PTR* plResult)
{
;
if (ullOperand <= LONG_PTR_MAX)
{
*
= (
)
;
}
else
{
*plResult = LONG_PTR_ERROR;
hr = INTSAFE_E_ARITHMETIC_OVERFLOW;
}
return
hr
;
}
_Must_inspect_result_
__inline
(
_In_ ULONGLONG ullOperand,
_Out_ _Deref_out_range_(==, ullOperand) ULONG* pulResult)
{
;
if (ullOperand <= ULONG_MAX)
{
*
= (
)
;
}
else
{
*pulResult = ULONG_ERROR;
hr = INTSAFE_E_ARITHMETIC_OVERFLOW;
}
return
hr
;
}
#ifdef _WIN64
_Must_inspect_result_
__inline
HRESULT
ULongLongToULongPtr(
_In_ ULONGLONG ullOperand,
_Out_ _Deref_out_range_(==, ullOperand) ULONG_PTR* pulResult)
{
*pulResult = ullOperand;
return S_OK;
}
#else
#define ULongLongToULongPtr ULongLongToULong
#endif
#define ULongLongToDWord ULongLongToULong
#define ULongLongToDWordPtr ULongLongToULongPtr
_Must_inspect_result_
__inline
(
_In_ ULONGLONG ullOperand,
_Out_ _Deref_out_range_(==, ullOperand) LONGLONG* pllResult)
{
;
if (ullOperand <= LONGLONG_MAX)
if
(
<=
9223372036854775807i64
)
{
*
= (
)
;
}
else
{
*pllResult = LONGLONG_ERROR;
hr = INTSAFE_E_ARITHMETIC_OVERFLOW;
}
return
hr
;
}
#define ULongLongToInt64 ULongLongToLongLong
#define ULongLongToLong64 ULongLongToLongLong
#define ULongLongToPtrdiffT ULongLongToIntPtr
#define ULongLongToSizeT ULongLongToUIntPtr
#define ULongLongToSSIZET ULongLongToLongPtr
#define ULongLongToSIZET ULongLongToULongPtr
#define DWordLongToChar ULongLongToChar
#define DWordLongToInt8 ULongLongToInt8
#define DWordLongToUChar ULongLongToUChar
#define DWordLongToUInt8 ULongLongToUInt8
#define DWordLongToByte ULongLongToUInt8
#define DWordLongToShort ULongLongToShort
#define DWordLongToInt16 ULongLongToShort
#define DWordLongToUShort ULongLongToUShort
#define DWordLongToUInt16 ULongLongToUShort
#define DWordLongToWord ULongLongToUShort
#define DWordLongToInt ULongLongToInt
#define DWordLongToInt32 ULongLongToInt
#define DWordLongToIntPtr ULongLongToIntPtr
#define DWordLongToUInt ULongLongToUInt
#define DWordLongToUInt32 ULongLongToUInt
#define DWordLongToUIntPtr ULongLongToUIntPtr
#define DWordLongToLong ULongLongToLong
#define DWordLongToLongPtr ULongLongToLongPtr
#define DWordLongToULong ULongLongToULong
#define DWordLongToULongPtr ULongLongToULongPtr
#define DWordLongToDWord ULongLongToULong
#define DWordLongToDWordPtr ULongLongToULongPtr
#define DWordLongToLongLong ULongLongToLongLong
#define DWordLongToLong64 ULongLongToLongLong
#define DWordLongToInt64 ULongLongToLongLong
#define DWordLongToPtrdiffT ULongLongToIntPtr
#define DWordLongToSizeT ULongLongToUIntPtr
#define DWordLongToSSIZET ULongLongToLongPtr
#define DWordLongToSIZET ULongLongToULongPtr
#define ULong64ToChar ULongLongToChar
#define ULong64ToInt8 ULongLongToInt8
#define ULong64ToUChar ULongLongToUChar
#define ULong64ToUInt8 ULongLongToUInt8
#define ULong64ToByte ULongLongToUInt8
#define ULong64ToShort ULongLongToShort
#define ULong64ToInt16 ULongLongToShort
#define ULong64ToUShort ULongLongToUShort
#define ULong64ToUInt16 ULongLongToUShort
#define ULong64ToWord ULongLongToUShort
#define ULong64ToInt ULongLongToInt
#define ULong64ToInt32 ULongLongToInt
#define ULong64ToIntPtr ULongLongToIntPtr
#define ULong64ToUInt ULongLongToUInt
#define ULong64ToUInt32 ULongLongToUInt
#define ULong64ToUIntPtr ULongLongToUIntPtr
#define ULong64ToLong ULongLongToLong
#define ULong64ToLongPtr ULongLongToLongPtr
#define ULong64ToULong ULongLongToULong
#define ULong64ToULongPtr ULongLongToULongPtr
#define ULong64ToDWord ULongLongToULong
#define ULong64ToDWordPtr ULongLongToULongPtr
#define ULong64ToLongLong ULongLongToLongLong
#define ULong64ToLong64 ULongLongToLongLong
#define ULong64ToInt64 ULongLongToLongLong
#define ULong64ToPtrdiffT ULongLongToIntPtr
#define ULong64ToSizeT ULongLongToUIntPtr
#define ULong64ToSSIZET ULongLongToLongPtr
#define ULong64ToSIZET ULongLongToULongPtr
#define DWord64ToChar ULongLongToChar
#define DWord64ToInt8 ULongLongToInt8
#define DWord64ToUChar ULongLongToUChar
#define DWord64ToUInt8 ULongLongToUInt8
#define DWord64ToByte ULongLongToUInt8
#define DWord64ToShort ULongLongToShort
#define DWord64ToInt16 ULongLongToShort
#define DWord64ToUShort ULongLongToUShort
#define DWord64ToUInt16 ULongLongToUShort
#define DWord64ToWord ULongLongToUShort
#define DWord64ToInt ULongLongToInt
#define DWord64ToInt32 ULongLongToInt
#define DWord64ToIntPtr ULongLongToIntPtr
#define DWord64ToUInt ULongLongToUInt
#define DWord64ToUInt32 ULongLongToUInt
#define DWord64ToUIntPtr ULongLongToUIntPtr
#define DWord64ToLong ULongLongToLong
#define DWord64ToLongPtr ULongLongToLongPtr
#define DWord64ToULong ULongLongToULong
#define DWord64ToULongPtr ULongLongToULongPtr
#define DWord64ToDWord ULongLongToULong
#define DWord64ToDWordPtr ULongLongToULongPtr
#define DWord64ToLongLong ULongLongToLongLong
#define DWord64ToLong64 ULongLongToLongLong
#define DWord64ToInt64 ULongLongToLongLong
#define DWord64ToPtrdiffT ULongLongToIntPtr
#define DWord64ToSizeT ULongLongToUIntPtr
#define DWord64ToSSIZET ULongLongToLongPtr
#define DWord64ToSIZET ULongLongToULongPtr
#define UInt64ToChar ULongLongToChar
#define UInt64ToInt8 ULongLongToInt8
#define UInt64ToUChar ULongLongToUChar
#define UInt64ToUInt8 ULongLongToUInt8
#define UInt64ToByte ULongLongToUInt8
#define UInt64ToShort ULongLongToShort
#define UInt64ToInt16 ULongLongToShort
#define UInt64ToUShort ULongLongToUShort
#define UInt64ToUInt16 ULongLongToUShort
#define UInt64ToWord ULongLongToUShort
#define UInt64ToInt ULongLongToInt
#define UInt64ToInt32 ULongLongToInt
#define UInt64ToIntPtr ULongLongToIntPtr
#define UInt64ToUInt ULongLongToUInt
#define UInt64ToUInt32 ULongLongToUInt
#define UInt64ToUIntPtr ULongLongToUIntPtr
#define UInt64ToLong ULongLongToLong
#define UInt64ToLongPtr ULongLongToLongPtr
#define UInt64ToULong ULongLongToULong
#define UInt64ToULongPtr ULongLongToULongPtr
#define UInt64ToDWord ULongLongToULong
#define UInt64ToDWordPtr ULongLongToULongPtr
#define UInt64ToLongLong ULongLongToLongLong
#define UInt64ToLong64 ULongLongToLongLong
#define UInt64ToInt64 ULongLongToLongLong
#define UInt64ToPtrdiffT ULongLongToIntPtr
#define UInt64ToSizeT ULongLongToUIntPtr
#define UInt64ToSSIZET ULongLongToLongPtr
#define UInt64ToSIZET ULongLongToULongPtr
#define PtrdiffTToChar IntPtrToChar
#define PtrdiffTToInt8 IntPtrToInt8
#define PtrdiffTToUChar IntPtrToUChar
#define PtrdiffTToUInt8 IntPtrToUInt8
#define PtrdiffTToByte IntPtrToUInt8
#define PtrdiffTToShort IntPtrToShort
#define PtrdiffTToInt16 IntPtrToShort
#define PtrdiffTToUShort IntPtrToUShort
#define PtrdiffTToUInt16 IntPtrToUShort
#define PtrdiffTToWord IntPtrToUShort
#define PtrdiffTToInt IntPtrToInt
#define PtrdiffTToInt32 IntPtrToInt
#define PtrdiffTToUInt IntPtrToUInt
#define PtrdiffTToUInt32 IntPtrToUInt
#define PtrdiffTToUIntPtr IntPtrToUIntPtr
#define PtrdiffTToLong IntPtrToLong
#define PtrdiffTToLongPtr IntPtrToLongPtr
#define PtrdiffTToULong IntPtrToULong
#define PtrdiffTToULongPtr IntPtrToULongPtr
#define PtrdiffTToDWord IntPtrToULong
#define PtrdiffTToDWordPtr IntPtrToULongPtr
#define PtrdiffTToULongLong IntPtrToULongLong
#define PtrdiffTToDWordLong IntPtrToULongLong
#define PtrdiffTToULong64 IntPtrToULongLong
#define PtrdiffTToDWord64 IntPtrToULongLong
#define PtrdiffTToUInt64 IntPtrToULongLong
#define PtrdiffTToSizeT IntPtrToUIntPtr
#define PtrdiffTToSIZET IntPtrToULongPtr
#define SizeTToInt8 UIntPtrToInt8
#define SizeTToUChar UIntPtrToUChar
#define SizeTToChar UIntPtrToChar
#define SizeTToUInt8 UIntPtrToUInt8
#define SizeTToByte UIntPtrToUInt8
#define SizeTToShort UIntPtrToShort
#define SizeTToInt16 UIntPtrToShort
#define SizeTToUShort UIntPtrToUShort
#define SizeTToUInt16 UIntPtrToUShort
#define SizeTToWord UIntPtrToUShort
#define SizeTToInt UIntPtrToInt
#define SizeTToInt32 UIntPtrToInt
#define SizeTToIntPtr UIntPtrToIntPtr
#define SizeTToUInt UIntPtrToUInt
#define SizeTToUInt32 UIntPtrToUInt
#define SizeTToLong UIntPtrToLong
#define SizeTToLongPtr UIntPtrToLongPtr
#define SizeTToULong UIntPtrToULong
#define SizeTToDWord UIntPtrToULong
#define SizeTToLongLong UIntPtrToLongLong
#define SizeTToLong64 UIntPtrToLongLong
#define SizeTToInt64 UIntPtrToLongLong
#define SizeTToPtrdiffT UIntPtrToIntPtr
#define SizeTToSSIZET UIntPtrToLongPtr
#define SSIZETToInt8 LongPtrToInt8
#define SSIZETToUChar LongPtrToUChar
#define SSIZETToChar LongPtrToChar
#define SSIZETToUInt8 LongPtrToUInt8
#define SSIZETToByte LongPtrToUInt8
#define SSIZETToShort LongPtrToShort
#define SSIZETToInt16 LongPtrToShort
#define SSIZETToUShort LongPtrToUShort
#define SSIZETToUInt16 LongPtrToUShort
#define SSIZETToWord LongPtrToUShort
#define SSIZETToInt LongPtrToInt
#define SSIZETToInt32 LongPtrToInt
#define SSIZETToIntPtr LongPtrToIntPtr
#define SSIZETToUInt LongPtrToUInt
#define SSIZETToUInt32 LongPtrToUInt
#define SSIZETToUIntPtr LongPtrToUIntPtr
#define SSIZETToLong LongPtrToLong
#define SSIZETToULong LongPtrToULong
#define SSIZETToULongPtr LongPtrToULongPtr
#define SSIZETToDWord LongPtrToULong
#define SSIZETToDWordPtr LongPtrToULongPtr
#define SSIZETToULongLong LongPtrToULongLong
#define SSIZETToDWordLong LongPtrToULongLong
#define SSIZETToULong64 LongPtrToULongLong
#define SSIZETToDWord64 LongPtrToULongLong
#define SSIZETToUInt64 LongPtrToULongLong
#define SSIZETToSizeT LongPtrToUIntPtr
#define SSIZETToSIZET LongPtrToULongPtr
#define SIZETToInt8 ULongPtrToInt8
#define SIZETToUChar ULongPtrToUChar
#define SIZETToChar ULongPtrToChar
#define SIZETToUInt8 ULongPtrToUInt8
#define SIZETToByte ULongPtrToUInt8
#define SIZETToShort ULongPtrToShort
#define SIZETToInt16 ULongPtrToShort
#define SIZETToUShort ULongPtrToUShort
#define SIZETToUInt16 ULongPtrToUShort
#define SIZETToWord ULongPtrToUShort
#define SIZETToInt ULongPtrToInt
#define SIZETToInt32 ULongPtrToInt
#define SIZETToIntPtr ULongPtrToIntPtr
#define SIZETToUInt ULongPtrToUInt
#define SIZETToUInt32 ULongPtrToUInt
#define SIZETToUIntPtr ULongPtrToUIntPtr
#define SIZETToLong ULongPtrToLong
#define SIZETToLongPtr ULongPtrToLongPtr
#define SIZETToULong ULongPtrToULong
#define SIZETToDWord ULongPtrToULong
#define SIZETToLongLong ULongPtrToLongLong
#define SIZETToLong64 ULongPtrToLongLong
#define SIZETToInt64 ULongPtrToLongLong
#define SIZETToPtrdiffT ULongPtrToIntPtr
#define SIZETToSSIZET ULongPtrToLongPtr
_Must_inspect_result_
__inline
(
_Out_ _Deref_out_range_(==, u8Augend + u8Addend) UINT8* pu8Result)
{
;
if
(((
)(
+
)) >=
)
{
*
= (
)(
+
);
}
else
{
*pu8Result = UINT8_ERROR;
hr = INTSAFE_E_ARITHMETIC_OVERFLOW;
}
return
hr
;
}
_Must_inspect_result_
__inline
(
_Out_ _Deref_out_range_(==, usAugend + usAddend) USHORT* pusResult)
{
;
if
(((
)(
+
)) >=
)
{
*
= (
)(
+
);
}
else
{
*pusResult = USHORT_ERROR;
hr = INTSAFE_E_ARITHMETIC_OVERFLOW;
}
return
hr
;
}
#define UInt16Add UShortAdd
#define WordAdd UShortAdd
_Must_inspect_result_
__inline
(
_Out_ _Deref_out_range_(==, uAugend + uAddend) UINT* puResult)
{
;
if
((
+
) >=
)
{
*
= (
+
);
}
else
{
hr = INTSAFE_E_ARITHMETIC_OVERFLOW;
}
return
hr
;
}
#define UInt32Add UIntAdd
#ifdef _WIN64
#define UIntPtrAdd ULongLongAdd
#else
_Must_inspect_result_
__inline
(
_Out_ _Deref_out_range_(==, uAugend + uAddend) UINT_PTR* puResult)
{
;
if
((
+
) >=
)
{
*
= (
+
);
}
else
{
*puResult = UINT_PTR_ERROR;
hr = INTSAFE_E_ARITHMETIC_OVERFLOW;
}
return
hr
;
}
#endif // _WIN64
_Must_inspect_result_
__inline
(
_Out_ _Deref_out_range_(==, ulAugend + ulAddend) ULONG* pulResult)
{
;
if
((
+
) >=
)
{
*
= (
+
);
}
else
{
*pulResult = ULONG_ERROR;
hr = INTSAFE_E_ARITHMETIC_OVERFLOW;
}
return
hr
;
}
#ifdef _WIN64
#define ULongPtrAdd ULongLongAdd
#else
_Must_inspect_result_
__inline
(
_Out_ _Deref_out_range_(==, ulAugend + ulAddend) ULONG_PTR* pulResult)
{
;
if
((
+
) >=
)
{
*
= (
+
);
}
else
{
*pulResult = ULONG_PTR_ERROR;
hr = INTSAFE_E_ARITHMETIC_OVERFLOW;
}
return
hr
;
}
#endif // _WIN64
#define DWordAdd ULongAdd
#ifdef _WIN64
#define DWordPtrAdd ULongLongAdd
#else
_Must_inspect_result_
__inline
(
_Out_ _Deref_out_range_(==, dwAugend + dwAddend) DWORD_PTR* pdwResult)
{
;
if
((
+
) >=
)
{
*
= (
+
);
}
else
{
*pdwResult = DWORD_PTR_ERROR;
hr = INTSAFE_E_ARITHMETIC_OVERFLOW;
}
return
hr
;
}
#endif // _WIN64
_Must_inspect_result_
__inline
(
_Out_ _Deref_out_range_(==, Augend + Addend) size_t* pResult)
{
;
if
((
+
) >=
)
{
*
= (
+
);
}
else
{
hr = INTSAFE_E_ARITHMETIC_OVERFLOW;
}
return
hr
;
}
#ifdef _WIN64
#define SIZETAdd ULongLongAdd
#else
_Must_inspect_result_
__inline
(
_Out_ _Deref_out_range_(==, Augend + Addend) SIZE_T* pResult)
{
;
if
((
+
) >=
)
{
*
= (
+
);
}
else
{
*pResult = _SIZE_T_ERROR;
hr = INTSAFE_E_ARITHMETIC_OVERFLOW;
}
return
hr
;
}
#endif // _WIN64
_Must_inspect_result_
__inline
(
_In_ ULONGLONG ullAugend,
_In_ ULONGLONG ullAddend,
_Out_ _Deref_out_range_(==, ullAugend + ullAddend) ULONGLONG* pullResult)
{
;
if
((
+
) >=
)
{
*
= (
+
);
}
else
{
*pullResult = ULONGLONG_ERROR;
*
=
0xffffffffffffffffui64
;
hr = INTSAFE_E_ARITHMETIC_OVERFLOW;
}
return
hr
;
}
#define DWordLongAdd ULongLongAdd
#define ULong64Add ULongLongAdd
#define DWord64Add ULongLongAdd
#define UInt64Add ULongLongAdd
_Must_inspect_result_
__inline
(
_Out_ _Deref_out_range_(==, u8Minuend - u8Subtrahend) UINT8* pu8Result)
{
;
if
(
>=
)
{
*
= (
)(
-
);
}
else
{
*pu8Result = UINT8_ERROR;
hr = INTSAFE_E_ARITHMETIC_OVERFLOW;
}
return
hr
;
}
_Must_inspect_result_
__inline
(
_In_ USHORT usSubtrahend,
_Out_ _Deref_out_range_(==, usMinuend - usSubtrahend) USHORT* pusResult)
{
;
if
(
>=
)
{
*
= (
)(
-
);
}
else
{
*pusResult = USHORT_ERROR;
hr = INTSAFE_E_ARITHMETIC_OVERFLOW;
}
return
hr
;
}
#define UInt16Sub UShortSub
#define WordSub UShortSub
_Must_inspect_result_
__inline
(
_Out_ _Deref_out_range_(==, uMinuend - uSubtrahend) UINT* puResult)
{
;
if
(
>=
)
{
*
= (
-
);
}
else
{
hr = INTSAFE_E_ARITHMETIC_OVERFLOW;
}
return
hr
;
}
#define UInt32Sub UIntSub
#ifdef _WIN64
#define UIntPtrSub ULongLongSub
#else
_Must_inspect_result_
__inline
(
_In_ UINT_PTR uSubtrahend,
_Out_ _Deref_out_range_(==, uMinuend - uSubtrahend) UINT_PTR* puResult)
{
;
if
(
>=
)
{
*
= (
-
);
}
else
{
*puResult = UINT_PTR_ERROR;
hr = INTSAFE_E_ARITHMETIC_OVERFLOW;
}
return
hr
;
}
#endif // _WIN64
_Must_inspect_result_
__inline
(
_Out_ _Deref_out_range_(==, ulMinuend - ulSubtrahend) ULONG* pulResult)
{
;
if
(
>=
)
{
*
= (
-
);
}
else
{
*pulResult = ULONG_ERROR;
hr = INTSAFE_E_ARITHMETIC_OVERFLOW;
}
return
hr
;
}
#ifdef _WIN64
#define ULongPtrSub ULongLongSub
#else
_Must_inspect_result_
__inline
(
_In_ ULONG_PTR ulMinuend,
_In_ ULONG_PTR ulSubtrahend,
_Out_ _Deref_out_range_(==, ulMinuend - ulSubtrahend) ULONG_PTR* pulResult)
{
;
if
(
>=
)
{
*
= (
-
);
}
else
{
*pulResult = ULONG_PTR_ERROR;
hr = INTSAFE_E_ARITHMETIC_OVERFLOW;
}
return
hr
;
}
#endif // _WIN64
#define DWordSub ULongSub
#ifdef _WIN64
#define DWordPtrSub ULongLongSub
#else
_Must_inspect_result_
__inline
(
_In_ DWORD_PTR dwMinuend,
_In_ DWORD_PTR dwSubtrahend,
_Out_ _Deref_out_range_(==, dwMinuend - dwSubtrahend) DWORD_PTR* pdwResult)
{
;
if
(
>=
)
{
*
= (
-
);
}
else
{
*pdwResult = DWORD_PTR_ERROR;
hr = INTSAFE_E_ARITHMETIC_OVERFLOW;
}
return
hr
;
}
#endif // _WIN64
_Must_inspect_result_
__inline
(
_Out_ _Deref_out_range_(==, Minuend - Subtrahend) size_t* pResult)
{
;
if
(
>=
)
{
*
= (
-
);
}
else
{
hr = INTSAFE_E_ARITHMETIC_OVERFLOW;
}
return
hr
;
}
#ifdef _WIN64
#define SIZETSub ULongLongSub
#else
_Must_inspect_result_
__inline
(
_Out_ _Deref_out_range_(==, Minuend - Subtrahend) SIZE_T* pResult)
{
;
if
(
>=
)
{
*
= (
-
);
}
else
{
*pResult = _SIZE_T_ERROR;
hr = INTSAFE_E_ARITHMETIC_OVERFLOW;
}
return
hr
;
}
#endif // _WIN64
_Must_inspect_result_
__inline
(
_In_ ULONGLONG ullMinuend,
_In_ ULONGLONG ullSubtrahend,
_Out_ _Deref_out_range_(==, ullMinuend - ullSubtrahend) ULONGLONG* pullResult)
{
;
if
(
>=
)
{
*
= (
-
);
}
else
{
*pullResult = ULONGLONG_ERROR;
*
=
0xffffffffffffffffui64
;
hr = INTSAFE_E_ARITHMETIC_OVERFLOW;
}
return
hr
;
}
#define DWordLongSub ULongLongSub
#define ULong64Sub ULongLongSub
#define DWord64Sub ULongLongSub
#define UInt64Sub ULongLongSub
_Must_inspect_result_
__inline
(
_In_ UINT8 u8Multiplicand,
_Out_ _Deref_out_range_(==, u8Multiplicand * u8Multiplier) UINT8* pu8Result)
{
= ((
)
) * ((
)
);
return
(
uResult
,
);
}
_Must_inspect_result_
__inline
(
_In_ USHORT usMultiplicand,
_In_ USHORT usMultiplier,
_Out_ _Deref_out_range_(==, usMultiplicand * usMultiplier) USHORT* pusResult)
{
= ((
)
) * ((
)
);
return
(
ulResult
,
);
}
#define UInt16Mult UShortMult
#define WordMult UShortMult
_Must_inspect_result_
__inline
(
_Out_ _Deref_out_range_(==, uMultiplicand * uMultiplier) UINT* puResult)
{
ULONGLONG ull64Result = UInt32x32To64(uMultiplicand, uMultiplier);
= ((
unsigned
__int64
)(((
unsigned
__int64
)((
unsigned
int
)(
))) * ((
unsigned
int
)(
))));
return
(
ull64Result
,
);
}
#define UInt32Mult UIntMult
#ifdef _WIN64
#define UIntPtrMult ULongLongMult
#else
_Must_inspect_result_
__inline
(
_In_ UINT_PTR uMultiplicand,
_In_ UINT_PTR uMultiplier,
_Out_ _Deref_out_range_(==, uMultiplicand * uMultiplier) UINT_PTR* puResult)
{
ULONGLONG ull64Result = UInt32x32To64(uMultiplicand, uMultiplier);
= ((
unsigned
__int64
)(((
unsigned
__int64
)((
unsigned
int
)(
))) * ((
unsigned
int
)(
))));
return ULongLongToUIntPtr(ull64Result, puResult);
}
#endif // _WIN64
_Must_inspect_result_
__inline
(
_In_ ULONG ulMultiplicand,
_Out_ _Deref_out_range_(==, ulMultiplicand * ulMultiplier) ULONG* pulResult)
{
ULONGLONG ull64Result = UInt32x32To64(ulMultiplicand, ulMultiplier);
= ((
unsigned
__int64
)(((
unsigned
__int64
)((
unsigned
int
)(
))) * ((
unsigned
int
)(
))));
return
(
ull64Result
,
);
}
#ifdef _WIN64
#define ULongPtrMult ULongLongMult
#else
_Must_inspect_result_
__inline
(
_In_ ULONG_PTR ulMultiplicand,
_In_ ULONG_PTR ulMultiplier,
_Out_ _Deref_out_range_(==, ulMultiplicand * ulMultiplier) ULONG_PTR* pulResult)
{
ULONGLONG ull64Result = UInt32x32To64(ulMultiplicand, ulMultiplier);
= ((
unsigned
__int64
)(((
unsigned
__int64
)((
unsigned
int
)(
))) * ((
unsigned
int
)(
))));
return ULongLongToULongPtr(ull64Result, pulResult);
}
#endif // _WIN64
#define DWordMult ULongMult
#ifdef _WIN64
#define DWordPtrMult ULongLongMult
#else
_Must_inspect_result_
__inline
(
_In_ DWORD_PTR dwMultiplicand,
_In_ DWORD_PTR dwMultiplier,
_Out_ _Deref_out_range_(==, dwMultiplicand * dwMultiplier) DWORD_PTR* pdwResult)
{
ULONGLONG ull64Result = UInt32x32To64(dwMultiplicand, dwMultiplier);
= ((
unsigned
__int64
)(((
unsigned
__int64
)((
unsigned
int
)(
))) * ((
unsigned
int
)(
))));
return ULongLongToDWordPtr(ull64Result, pdwResult);
}
#endif // _WIN64
#ifdef _WIN64
#define SizeTMult ULongLongMult
#else
_Must_inspect_result_
__inline
(
_In_ size_t Multiplicand,
_Out_ _Deref_out_range_(==, Multiplicand * Multiplier) size_t* pResult)
{
ULONGLONG ull64Result = UInt32x32To64(Multiplicand, Multiplier);
= ((
unsigned
__int64
)(((
unsigned
__int64
)((
unsigned
int
)(
))) * ((
unsigned
int
)(
))));
return ULongLongToSizeT(ull64Result, pResult);
}
#endif // _WIN64
#ifdef _WIN64
#define SIZETMult ULongLongMult
#else
_Must_inspect_result_
__inline
(
_In_ SIZE_T Multiplicand,
_Out_ _Deref_out_range_(==, Multiplicand * Multiplier) SIZE_T* pResult)
{
ULONGLONG ull64Result = UInt32x32To64(Multiplicand, Multiplier);
= ((
unsigned
__int64
)(((
unsigned
__int64
)((
unsigned
int
)(
))) * ((
unsigned
int
)(
))));
return ULongLongToSIZET(ull64Result, pResult);
}
#endif // _WIN64
_Must_inspect_result_
__inline
(
_In_ ULONGLONG ullMultiplicand,
_In_ ULONGLONG ullMultiplier,
_Out_ _Deref_out_range_(==, ullMultiplicand * ullMultiplier) ULONGLONG* pullResult)
{
;
#if defined(_USE_INTRINSIC_MULTIPLY128)
ULONGLONG ullResultHigh;
ULONGLONG ullResultLow;
ullResultLow = UnsignedMultiply128(ullMultiplicand, ullMultiplier, &ullResultHigh);
if (ullResultHigh == 0)
{
_Analysis_assume_(ullMultiplicand * ullMultiplier == ullResultLow);
*pullResult = ullResultLow;
hr = S_OK;
}
else
{
*pullResult = ULONGLONG_ERROR;
hr = INTSAFE_E_ARITHMETIC_OVERFLOW;
}
#else
;
;
;
;
=
0
;
=
0
;
=
0
;
=
0
;
hr = INTSAFE_E_ARITHMETIC_OVERFLOW;
dw_a
= (
)(
>>
32
);
dw_c
= (
)(
>>
32
);
if
((
dw_a
==
0
) && (
dw_c
==
0
))
{
dw_b
= (
)
;
dw_d
= (
)
;
*
= (((
)
dw_b
) * (
)
dw_d
);
}
else
{
if
((
dw_a
==
0
) ||
(
dw_c
==
0
))
{
dw_d
= (
)
;
ad
= (((
)
dw_a
) * (
)
dw_d
);
if
((
ad
&
0xffffffff00000000
) ==
0
)
{
dw_b
= (
)
;
bc
= (((
)
dw_b
) * (
)
dw_c
);
if
((
bc
&
0xffffffff00000000
) ==
0
)
{
if (SUCCEEDED(ULongLongAdd(bc << 32, ad << 32, &ullResult)))
if
((((
)(
(
bc
<<
32
,
ad
<<
32
, &
ullResult
))) >=
0
))
{
bd
= (((
)
dw_b
) * (
)
dw_d
);
if (SUCCEEDED(ULongLongAdd(ullResult, bd, &ullResult)))
if
((((
)(
(
ullResult
,
bd
, &
ullResult
))) >=
0
))
{
*
=
ullResult
;
}
}
}
}
}
}
{
*pullResult = ULONGLONG_ERROR;
*
=
0xffffffffffffffffui64
;
}
#pragma warning(suppress:
26071
)
#endif // _USE_INTRINSIC_MULTIPLY128
return
hr
;
}
#define DWordLongMult ULongLongMult
#define ULong64Mult ULongLongMult
#define DWord64Mult ULongLongMult
#define UInt64Mult ULongLongMult
#if defined(ENABLE_INTSAFE_SIGNED_FUNCTIONS)
#if defined(_USE_INTRINSIC_MULTIPLY128)
#ifdef __cplusplus
extern "C" {
#endif
#define Multiply128 _mul128
LONG64
Multiply128(
_In_ LONG64 Multiplier,
_In_ LONG64 Multiplicand,
_Out_ LONG64 *HighProduct
);
#pragma intrinsic(_mul128)
#ifdef __cplusplus
}
#endif
#endif // _USE_INTRINSIC_MULTIPLY128
//=============================================================================
// Signed addition functions
//=============================================================================
//
// INT8 Addition
//
_Must_inspect_result_
__inline
HRESULT
Int8Add(
_In_ INT8 i8Augend,
_In_ INT8 i8Addend,
_Out_ _Deref_out_range_(==, i8Augend + i8Addend) INT8* pi8Result
)
{
C_ASSERT(sizeof(LONG) > sizeof(INT8));
return LongToInt8(((LONG)i8Augend) + ((LONG)i8Addend), pi8Result);
}
//
// SHORT Addition
//
_Must_inspect_result_
__inline
HRESULT
ShortAdd(
_In_ SHORT sAugend,
_In_ SHORT sAddend,
_Out_ _Deref_out_range_(==, sAugend + sAddend) SHORT* psResult
)
{
C_ASSERT(sizeof(LONG) > sizeof(SHORT));
return LongToShort(((LONG)sAugend) + ((LONG)sAddend), psResult);
}
//
// INT16 Addition
//
#define Int16Add ShortAdd
//
// INT Addition
//
_Must_inspect_result_
__inline
HRESULT
IntAdd(
_In_ INT iAugend,
_In_ INT iAddend,
_Out_ _Deref_out_range_(==, iAugend + iAddend) INT* piResult
)
{
C_ASSERT(sizeof(LONGLONG) > sizeof(INT));
return LongLongToInt(((LONGLONG)iAugend) + ((LONGLONG)iAddend), piResult);
}
//
// INT32 Addition
//
#define Int32Add IntAdd
//
// INT_PTR addition
//
#ifdef _WIN64
#define IntPtrAdd LongLongAdd
#else
_Must_inspect_result_
__inline
HRESULT
IntPtrAdd(
_In_ INT_PTR iAugend,
_In_ INT_PTR iAddend,
_Out_ _Deref_out_range_(==, iAugend + iAddend) INT_PTR* piResult
)
{
C_ASSERT(sizeof(LONGLONG) > sizeof(INT_PTR));
return LongLongToIntPtr(((LONGLONG)iAugend) + ((LONGLONG)iAddend), piResult);
}
#endif
//
// LONG Addition
//
_Must_inspect_result_
__inline
HRESULT
LongAdd(
_In_ LONG lAugend,
_In_ LONG lAddend,
_Out_ _Deref_out_range_(==, lAugend + lAddend) LONG* plResult
)
{
C_ASSERT(sizeof(LONGLONG) > sizeof(LONG));
return LongLongToLong(((LONGLONG)lAugend) + ((LONGLONG)lAddend), plResult);
}
//
// LONG32 Addition
//
#define Long32Add IntAdd
//
// LONG_PTR Addition
//
#ifdef _WIN64
#define LongPtrAdd LongLongAdd
#else
_Must_inspect_result_
__inline
HRESULT
LongPtrAdd(
_In_ LONG_PTR lAugend,
_In_ LONG_PTR lAddend,
_Out_ _Deref_out_range_(==, lAugend + lAddend) LONG_PTR* plResult
)
{
C_ASSERT(sizeof(LONGLONG) > sizeof(LONG_PTR));
return LongLongToLongPtr(((LONGLONG)lAugend) + ((LONGLONG)lAddend), plResult);
}
#endif
//
// LONGLONG Addition
//
_Must_inspect_result_
__inline
HRESULT
LongLongAdd(
_In_ LONGLONG llAugend,
_In_ LONGLONG llAddend,
_Out_ _Deref_out_range_(==, llAugend + llAddend) LONGLONG* pllResult
)
{
HRESULT hr;
LONGLONG llResult = llAugend + llAddend;
//
// Adding positive to negative never overflows.
// If you add two positive numbers, you expect a positive result.
// If you add two negative numbers, you expect a negative result.
// Overflow if inputs are the same sign and output is not that sign.
//
if (((llAugend < 0) == (llAddend < 0)) &&
((llAugend < 0) != (llResult < 0)))
{
*pllResult = LONGLONG_ERROR;
hr = INTSAFE_E_ARITHMETIC_OVERFLOW;
}
else
{
*pllResult = llResult;
hr = S_OK;
}
return hr;
}
//
// LONG64 Addition
//
#define Long64Add LongLongAdd
//
// INT64 Addition
//
#define Int64Add LongLongAdd
//
// ptrdiff_t Addition
//
#ifdef _WIN64
#define PtrdiffTAdd LongLongAdd
#else
_Must_inspect_result_
__inline
HRESULT
PtrdiffTAdd(
_In_ ptrdiff_t Augend,
_In_ ptrdiff_t Addend,
_Out_ _Deref_out_range_(==, Augend + Addend) ptrdiff_t* pResult
)
{
C_ASSERT(sizeof(LONGLONG) > sizeof(ptrdiff_t));
return LongLongToPtrdiffT(((LONGLONG)Augend) + ((LONGLONG)Addend), pResult);
}
#endif
//
// SSIZE_T Addition
//
#ifdef _WIN64
#define SSIZETAdd LongLongAdd
#else
_Must_inspect_result_
__inline
HRESULT
SSIZETAdd(
_In_ SSIZE_T Augend,
_In_ SSIZE_T Addend,
_Out_ _Deref_out_range_(==, Augend + Addend) SSIZE_T* pResult
)
{
C_ASSERT(sizeof(LONGLONG) > sizeof(SSIZE_T));
return LongLongToSSIZET(((LONGLONG)Augend) + ((LONGLONG)Addend), pResult);
}
#endif
//=============================================================================
// Signed subtraction functions
//=============================================================================
//
// INT8 Subtraction
//
_Must_inspect_result_
__inline
HRESULT
Int8Sub(
_In_ INT8 i8Minuend,
_In_ INT8 i8Subtrahend,
_Out_ _Deref_out_range_(==, i8Minuend - i8Subtrahend) INT8* pi8Result
)
{
C_ASSERT(sizeof(LONG) > sizeof(INT8));
return LongToInt8(((LONG)i8Minuend) - ((LONG)i8Subtrahend), pi8Result);
}
//
// SHORT Subtraction
//
_Must_inspect_result_
__inline
HRESULT
ShortSub(
_In_ SHORT sMinuend,
_In_ SHORT sSubtrahend,
_Out_ _Deref_out_range_(==, sMinuend - sSubtrahend) SHORT* psResult
)
{
C_ASSERT(sizeof(LONG) > sizeof(SHORT));
return LongToShort(((LONG)sMinuend) - ((LONG)sSubtrahend), psResult);
}
//
// INT16 Subtraction
//
#define Int16Sub ShortSub
//
// INT Subtraction
//
_Must_inspect_result_
__inline
HRESULT
IntSub(
_In_ INT iMinuend,
_In_ INT iSubtrahend,
_Out_ _Deref_out_range_(==, iMinuend - iSubtrahend) INT* piResult
)
{
C_ASSERT(sizeof(LONGLONG) > sizeof(INT));
return LongLongToInt(((LONGLONG)iMinuend) - ((LONGLONG)iSubtrahend), piResult);
}
//
// INT32 Subtraction
//
#define Int32Sub IntSub
//
// INT_PTR Subtraction
//
#ifdef _WIN64
#define IntPtrSub LongLongSub
#else
_Must_inspect_result_
__inline
HRESULT
IntPtrSub(
_In_ INT_PTR iMinuend,
_In_ INT_PTR iSubtrahend,
_Out_ _Deref_out_range_(==, iMinuend - iSubtrahend) INT_PTR* piResult
)
{
C_ASSERT(sizeof(LONGLONG) > sizeof(INT_PTR));
return LongLongToIntPtr(((LONGLONG)iMinuend) - ((LONGLONG)iSubtrahend), piResult);
}
#endif
//
// LONG Subtraction
//
_Must_inspect_result_
__inline
HRESULT
LongSub(
_In_ LONG lMinuend,
_In_ LONG lSubtrahend,
_Out_ _Deref_out_range_(==, lMinuend - lSubtrahend) LONG* plResult
)
{
C_ASSERT(sizeof(LONGLONG) > sizeof(LONG));
return LongLongToLong(((LONGLONG)lMinuend) - ((LONGLONG)lSubtrahend), plResult);
}
//
// LONG32 Subtraction
//
#define Long32Sub IntSub
//
// LONG_PTR Subtraction
//
#ifdef _WIN64
#define LongPtrSub LongLongSub
#else
_Must_inspect_result_
__inline
HRESULT
LongPtrSub(
_In_ LONG_PTR lMinuend,
_In_ LONG_PTR lSubtrahend,
_Out_ _Deref_out_range_(==, lMinuend - lSubtrahend) LONG_PTR* plResult
)
{
C_ASSERT(sizeof(LONGLONG) > sizeof(LONG_PTR));
return LongLongToLongPtr(((LONGLONG)lMinuend) - ((LONGLONG)lSubtrahend), plResult);
}
#endif
//
// LongLongSub
//
_Must_inspect_result_
__inline
HRESULT
LongLongSub(
_In_ LONGLONG llMinuend,
_In_ LONGLONG llSubtrahend,
_Out_ _Deref_out_range_(==, llMinuend - llSubtrahend) LONGLONG* pllResult
)
{
HRESULT hr;
LONGLONG llResult = llMinuend - llSubtrahend;
//
// Subtracting a positive number from a positive number never overflows.
// Subtracting a negative number from a negative number never overflows.
// If you subtract a negative number from a positive number, you expect a positive result.
// If you subtract a positive number from a negative number, you expect a negative result.
// Overflow if inputs vary in sign and the output does not have the same sign as the first input.
//
if (((llMinuend < 0) != (llSubtrahend < 0)) &&
((llMinuend < 0) != (llResult < 0)))
{
*pllResult = LONGLONG_ERROR;
hr = INTSAFE_E_ARITHMETIC_OVERFLOW;
}
else
{
*pllResult = llResult;
hr = S_OK;
}
return hr;
}
//
// LONG64 Subtraction
//
#define Long64Sub LongLongSub
//
// INT64 Subtraction
//
#define Int64Sub LongLongSub
//
// ptrdiff_t Subtraction
//
#ifdef _WIN64
#define PtrdiffTSub LongLongSub
#else
_Must_inspect_result_
__inline
HRESULT
PtrdiffTSub(
_In_ ptrdiff_t Minuend,
_In_ ptrdiff_t Subtrahend,
_Out_ _Deref_out_range_(==, Minuend - Subtrahend) ptrdiff_t* pResult
)
{
C_ASSERT(sizeof(LONGLONG) > sizeof(ptrdiff_t));
return LongLongToPtrdiffT(((LONGLONG)Minuend) - ((LONGLONG)Subtrahend), pResult);
}
#endif
//
// SSIZE_T Subtraction
//
#ifdef _WIN64
#define SSIZETSub LongLongSub
#else
_Must_inspect_result_
__inline
HRESULT
SSIZETSub(
_In_ SSIZE_T Minuend,
_In_ SSIZE_T Subtrahend,
_Out_ _Deref_out_range_(==, Minuend - Subtrahend) SSIZE_T* pResult)
{
C_ASSERT(sizeof(LONGLONG) > sizeof(SSIZE_T));
return LongLongToSSIZET(((LONGLONG)Minuend) - ((LONGLONG)Subtrahend), pResult);
}
#endif
//=============================================================================
// Signed multiplication functions
//=============================================================================
//
// INT8 multiplication
//
_Must_inspect_result_
__inline
HRESULT
Int8Mult(
_In_ INT8 i8Multiplicand,
_In_ INT8 i8Multiplier,
_Out_ _Deref_out_range_(==, i8Multiplicand * i8Multiplier) INT8* pi8Result
)
{
C_ASSERT(sizeof(LONG) > sizeof(INT8));
return LongToInt8(((LONG)i8Multiplier) * ((LONG)i8Multiplicand), pi8Result);
}
//
// SHORT multiplication
//
_Must_inspect_result_
__inline
HRESULT
ShortMult(
_In_ SHORT sMultiplicand,
_In_ SHORT sMultiplier,
_Out_ _Deref_out_range_(==, sMultiplicand * sMultiplier) SHORT* psResult
)
{
C_ASSERT(sizeof(LONG) > sizeof(SHORT));
return LongToShort(((LONG)sMultiplicand) * ((LONG)sMultiplier), psResult);
}
//
// INT16 multiplication
//
#define Int16Mult ShortMult
//
// INT multiplication
//
_Must_inspect_result_
__inline
HRESULT
IntMult(
_In_ INT iMultiplicand,
_In_ INT iMultiplier,
_Out_ _Deref_out_range_(==, iMultiplicand * iMultiplier) INT* piResult
)
{
C_ASSERT(sizeof(LONGLONG) > sizeof(INT));
return LongLongToInt(((LONGLONG)iMultiplicand) * ((LONGLONG)iMultiplier), piResult);
}
//
// INT32 multiplication
//
#define Int32Mult IntMult
//
// INT_PTR multiplication
//
#ifdef _WIN64
#define IntPtrMult LongLongMult
#else
_Must_inspect_result_
__inline
HRESULT
IntPtrMult(
_In_ INT_PTR iMultiplicand,
_In_ INT_PTR iMultiplier,
_Out_ _Deref_out_range_(==, iMultiplicand * iMultiplier) INT_PTR* piResult
)
{
C_ASSERT(sizeof(LONGLONG) > sizeof(INT_PTR));
return LongLongToIntPtr(((LONGLONG)iMultiplicand) * ((LONGLONG)iMultiplier), piResult);
}
#endif
//
// LONG multiplication
//
_Must_inspect_result_
__inline
HRESULT
LongMult(
_In_ LONG lMultiplicand,
_In_ LONG lMultiplier,
_Out_ _Deref_out_range_(==, lMultiplicand * lMultiplier) LONG* plResult
)
{
C_ASSERT(sizeof(LONGLONG) > sizeof(LONG));
return LongLongToLong(((LONGLONG)lMultiplicand) * ((LONGLONG)lMultiplier), plResult);
}
//
// LONG32 multiplication
//
#define Long32Mult IntMult
//
// LONG_PTR multiplication
//
#ifdef _WIN64
#define LongPtrMult LongLongMult
#else
_Must_inspect_result_
__inline
HRESULT
LongPtrMult(
_In_ LONG_PTR lMultiplicand,
_In_ LONG_PTR lMultiplier,
_Out_ _Deref_out_range_(==, lMultiplicand * lMultiplier) LONG_PTR* plResult
)
{
C_ASSERT(sizeof(LONGLONG) > sizeof(LONG_PTR));
return LongLongToLongPtr(((LONGLONG)lMultiplicand) * ((LONGLONG)lMultiplier), plResult);
}
#endif
//
// LONGLONG multiplication
//
_Must_inspect_result_
__inline
HRESULT
LongLongMult(
_In_ LONGLONG llMultiplicand,
_In_ LONGLONG llMultiplier,
_Out_ _Deref_out_range_(==, llMultiplicand * llMultiplier) LONGLONG* pllResult
)
{
HRESULT hr;
#if defined(_USE_INTRINSIC_MULTIPLY128)
LONGLONG llResultHigh;
LONGLONG llResultLow;
llResultLow = Multiply128(llMultiplicand, llMultiplier, &llResultHigh);
if (((llResultLow < 0) && (llResultHigh != -1)) ||
((llResultLow >= 0) && (llResultHigh != 0)))
{
*pllResult = LONGLONG_ERROR;
hr = INTSAFE_E_ARITHMETIC_OVERFLOW;
}
else
{
*pllResult = llResultLow;
hr = S_OK;
}
#else // _USE_INTRINSIC_MULTIPLY128
//
// Split into sign and magnitude, do unsigned operation, apply sign.
//
ULONGLONG ullMultiplicand;
ULONGLONG ullMultiplier;
ULONGLONG ullResult;
const ULONGLONG LONGLONG_MIN_MAGNITUDE = ((((ULONGLONG) - (LONGLONG_MIN + 1))) + 1);
if (llMultiplicand < 0)
{
//
// Avoid negating the most negative number.
//
ullMultiplicand = ((ULONGLONG)(- (llMultiplicand + 1))) + 1;
}
else
{
ullMultiplicand = (ULONGLONG)llMultiplicand;
}
if (llMultiplier < 0)
{
//
// Avoid negating the most negative number.
//
ullMultiplier = ((ULONGLONG)(- (llMultiplier + 1))) + 1;
}
else
{
ullMultiplier = (ULONGLONG)llMultiplier;
}
hr = ULongLongMult(ullMultiplicand, ullMultiplier, &ullResult);
if (SUCCEEDED(hr))
{
if ((llMultiplicand < 0) != (llMultiplier < 0))
{
if (ullResult > LONGLONG_MIN_MAGNITUDE)
{
*pllResult = LONGLONG_ERROR;
hr = INTSAFE_E_ARITHMETIC_OVERFLOW;
}
else
{
*pllResult = - ((LONGLONG)ullResult);
}
}
else
{
if (ullResult > LONGLONG_MAX)
{
*pllResult = LONGLONG_ERROR;
hr = INTSAFE_E_ARITHMETIC_OVERFLOW;
}
else
{
*pllResult = (LONGLONG)ullResult;
}
}
}
else
{
*pllResult = LONGLONG_ERROR;
}
#endif // _USE_INTRINSIC_MULTIPLY128
return hr;
}
//
// LONG64 multiplication
//
#define Long64Mult LongLongMult
//
// INT64 multiplication
//
#define Int64Mult LongLongMult
//
// ptrdiff_t multiplication
//
#ifdef _WIN64
#define PtrdiffTMult LongLongMult
#else
_Must_inspect_result_
__inline
HRESULT
PtrdiffTMult(
_In_ ptrdiff_t Multiplicand,
_In_ ptrdiff_t Multiplier,
_Out_ _Deref_out_range_(==, Multiplicand * Multiplier) ptrdiff_t* pResult
)
{
C_ASSERT(sizeof(LONGLONG) > sizeof(ptrdiff_t));
return LongLongToPtrdiffT(((LONGLONG)Multiplicand) * ((LONGLONG)Multiplier), pResult);
}
#endif
//
// SSIZE_T multiplication
//
#ifdef _WIN64
#define SSIZETMult LongLongMult
#else
_Must_inspect_result_
__inline
HRESULT
SSIZETMult(
_In_ SSIZE_T Multiplicand,
_In_ SSIZE_T Multiplier,
_Out_ _Deref_out_range_(==, Multiplicand * Multiplier) SSIZE_T* pResult
)
{
C_ASSERT(sizeof(LONGLONG) > sizeof(SSIZE_T));
return LongLongToSSIZET(((LONGLONG)Multiplicand) * ((LONGLONG)Multiplier), pResult);
}
#endif
#endif // ENABLE_INTSAFE_SIGNED_FUNCTIONS
#define LOWORD(_dw) ((WORD)(((DWORD_PTR)(_dw)) & 0xffff))
#define HIWORD(_dw) ((WORD)((((DWORD_PTR)(_dw)) >> 16) & 0xffff))
#define LODWORD(_qw) ((DWORD)(_qw))
#define HIDWORD(_qw) ((DWORD)(((_qw) >> 32) & 0xffffffff))
#if _MSC_VER >= 1200
#pragma warning(pop)
#endif
#endif /* WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_APP | WINAPI_PARTITION_SYSTEM) */
#pragma endregion
#endif // _INTSAFE_H_INCLUDED_