ReactOS  0.4.12-dev-409-g9f418243
intsafe.h File Reference

Windows helper functions for integer overflow prevention. More...

#include <specstrings.h>
Include dependency graph for intsafe.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Namespaces

 This
 

Macros

#define _INTSAFE_H_INCLUDED_
 
#define SUCCEEDED(hr)   (((HRESULT)(hr)) >= 0)
 
#define FAILED(hr)   (((HRESULT)(hr)) < 0)
 
#define S_OK   ((HRESULT)0L)
 
#define INTSAFE_RESULT   HRESULT
 
#define INTSAFE_SUCCESS   S_OK
 
#define INTSAFE_E_ARITHMETIC_OVERFLOW   ((HRESULT)0x80070216L)
 
#define INTSAFE_NAME(name)   name
 
#define _W64
 
#define C_ASSERT(e)   extern void __C_ASSERT__(int [(e)?1:-1])
 
#define INT8_MIN   ((signed char)(-127 - 1))
 
#define SHORT_MIN   (-32768)
 
#define INT16_MIN   ((short)(-32767 - 1))
 
#define INT_MIN   (-2147483647 - 1)
 
#define INT32_MIN   (-2147483647 - 1)
 
#define LONG_MIN   (-2147483647L - 1)
 
#define LONGLONG_MIN   (-9223372036854775807LL - 1)
 
#define LONG64_MIN   (-9223372036854775807LL - 1)
 
#define INT64_MIN   (-9223372036854775807LL - 1)
 
#define INT128_MIN   (-170141183460469231731687303715884105727i128 - 1)
 
#define INT_PTR_MIN   (-2147483647 - 1)
 
#define LONG_PTR_MIN   (-2147483647L - 1)
 
#define PTRDIFF_T_MIN   (-2147483647 - 1)
 
#define SSIZE_T_MIN   (-2147483647L - 1)
 
#define INT8_MAX   ((signed char)127)
 
#define UINT8_MAX   ((unsigned char)0xffU)
 
#define BYTE_MAX   ((unsigned char)0xff)
 
#define SHORT_MAX   ((short)32767)
 
#define INT16_MAX   ((short)32767)
 
#define USHORT_MAX   ((unsigned short)0xffff)
 
#define UINT16_MAX   ((unsigned short)0xffff)
 
#define WORD_MAX   ((unsigned short)0xffff)
 
#define INT_MAX   2147483647
 
#define INT32_MAX   2147483647
 
#define UINT_MAX   0xffffffff
 
#define UINT32_MAX   0xffffffffU
 
#define LONG_MAX   2147483647L
 
#define ULONG_MAX   0xffffffffUL
 
#define DWORD_MAX   0xffffffffUL
 
#define LONGLONG_MAX   9223372036854775807LL
 
#define LONG64_MAX   9223372036854775807LL
 
#define INT64_MAX   9223372036854775807LL
 
#define ULONGLONG_MAX   0xffffffffffffffffULL
 
#define DWORDLONG_MAX   0xffffffffffffffffULL
 
#define ULONG64_MAX   0xffffffffffffffffULL
 
#define DWORD64_MAX   0xffffffffffffffffULL
 
#define UINT64_MAX   0xffffffffffffffffULL
 
#define INT128_MAX   170141183460469231731687303715884105727i128
 
#define UINT128_MAX   0xffffffffffffffffffffffffffffffffui128
 
#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
 
#define INT8_ERROR   ((signed char)(-1))
 
#define UINT8_ERROR   ((unsigned char)0xff)
 
#define BYTE_ERROR   ((unsigned char)0xff)
 
#define SHORT_ERROR   ((short)(-1))
 
#define INT16_ERROR   ((short)(-1))
 
#define USHORT_ERROR   ((unsigned short)0xffff)
 
#define UINT16_ERROR   ((unsigned short)0xffff)
 
#define WORD_ERROR   ((unsigned short)0xffff)
 
#define INT_ERROR   (-1)
 
#define INT32_ERROR   (-1)
 
#define UINT_ERROR   0xffffffffU
 
#define UINT32_ERROR   0xffffffffU
 
#define LONG_ERROR   (-1L)
 
#define ULONG_ERROR   0xffffffffUL
 
#define DWORD_ERROR   0xffffffffUL
 
#define LONGLONG_ERROR   (-1LL)
 
#define LONG64_ERROR   (-1LL)
 
#define INT64_ERROR   (-1LL)
 
#define ULONGLONG_ERROR   0xffffffffffffffffULL
 
#define DWORDLONG_ERROR   0xffffffffffffffffULL
 
#define ULONG64_ERROR   0xffffffffffffffffULL
 
#define UINT64_ERROR   0xffffffffffffffffULL
 
#define INT_PTR_ERROR   (-1)
 
#define UINT_PTR_ERROR   0xffffffffU
 
#define LONG_PTR_ERROR   (-1L)
 
#define ULONG_PTR_ERROR   0xffffffffUL
 
#define DWORD_PTR_ERROR   0xffffffffUL
 
#define PTRDIFF_T_ERROR   (-1)
 
#define SIZE_T_ERROR   0xffffffffU
 
#define SSIZE_T_ERROR   (-1L)
 
#define _SIZE_T_ERROR   0xffffffffUL
 
#define _INTSAFE_CHAR   CHAR
 
#define _INTSAFE_CHAR_ERROR   ((signed char)(-1))
 
#define _INTSAFE_CHAR_MIN   ((signed char)(-128))
 
#define _INTSAFE_CHAR_MAX   ((signed char)127)
 
#define size_t_ERROR   SIZE_T_ERROR
 
#define UCHAR_ERROR   '\0'
 
#define CHAR_ERROR   '\0'
 
#define UInt32x32To64(a, b)   ((unsigned __int64)(unsigned int)(a)*(unsigned __int64)(unsigned int)(b))
 
#define DEFINE_SAFE_CONVERT_UTOX(_Name, _TypeFrom, _TypeTo)
 
#define DEFINE_SAFE_CONVERT_STOU(_Name, _TypeFrom, _TypeTo)
 
#define DEFINE_SAFE_CONVERT_STOS(_Name, _TypeFrom, _TypeTo)
 
#define Int8ToByte   Int8ToUInt8
 
#define Int8ToUInt16   Int8ToUShort
 
#define Int8ToWord   Int8ToUShort
 
#define Int8ToUInt32   Int8ToUInt
 
#define Int8ToDWord   Int8ToULong
 
#define Int8ToDWordPtr   Int8ToULongPtr
 
#define Int8ToDWordLong   Int8ToULongLong
 
#define Int8ToULong64   Int8ToULongLong
 
#define Int8ToDWord64   Int8ToULongLong
 
#define Int8ToUInt64   Int8ToULongLong
 
#define Int8ToSizeT   Int8ToUIntPtr
 
#define Int8ToSIZET   Int8ToULongPtr
 
#define IntToSizeT   IntToUIntPtr
 
#define IntToSIZET   IntToULongPtr
 
#define ULongToSSIZET   ULongToLongPtr
 
#define ULongToByte   ULongToUInt8
 
#define ULongLongToInt64   ULongLongToLongLong
 
#define ULongLongToLong64   ULongLongToLongLong
 
#define ULongLongToPtrdiffT   ULongLongToIntPtr
 
#define ULongLongToSizeT   ULongLongToUIntPtr
 
#define ULongLongToSSIZET   ULongLongToLongPtr
 
#define ULongLongToSIZET   ULongLongToULongPtr
 
#define SIZETToULong   ULongPtrToULong
 
#define SSIZETToULongLong   LongPtrToULongLong
 
#define SSIZETToULong   LongPtrToULong
 
#define IntToUIntPtr   IntToUInt
 
#define ULongLongToIntPtr   ULongLongToInt
 
#define ULongLongToUIntPtr   ULongLongToUInt
 
#define ULongLongToULongPtr   ULongLongToULong
 
#define DEFINE_SAFE_ADD(_Name, _Type)
 
#define DEFINE_SAFE_SUB(_Name, _Type)
 
#define DEFINE_SAFE_MULT_U32(_Name, _Type, _Convert)
 
#define DEFINE_SAFE_MULT_U16(_Name, _Type, _Convert)
 
#define UInt16Add   UShortAdd
 
#define WordAdd   UShortAdd
 
#define UInt32Add   UIntAdd
 
#define DWordAdd   ULongAdd
 
#define DWordLongAdd   ULongLongAdd
 
#define ULong64Add   ULongLongAdd
 
#define DWord64Add   ULongLongAdd
 
#define UInt64Add   ULongLongAdd
 
#define UInt16Sub   UShortSub
 
#define WordSub   UShortSub
 
#define UInt32Sub   UIntSub
 
#define DWordSub   ULongSub
 
#define DWordLongSub   ULongLongSub
 
#define ULong64Sub   ULongLongSub
 
#define DWord64Sub   ULongLongSub
 
#define UInt64Sub   ULongLongSub
 
#define UInt16Mult   UShortMult
 
#define WordMult   UShortMult
 

Typedefs

typedef char CHAR
 
typedef unsigned char UCHAR
 
typedef unsigned char UINT8
 
typedef signed char INT8
 
typedef short SHORT
 
typedef signed short INT16
 
typedef unsigned short USHORT
 
typedef unsigned short UINT16
 
typedef int INT
 
typedef unsigned int UINT32
 
typedef signed int INT32
 
typedef long LONG
 
typedef unsigned long ULONG
 
typedef long long LONGLONG
 
typedef long long LONG64
 
typedef signed long long INT64
 
typedef unsigned long long ULONGLONG
 
typedef unsigned long long DWORDLONG
 
typedef unsigned long long ULONG64
 
typedef unsigned long long DWORD64
 
typedef unsigned long long UINT64
 
typedef _W64 int INT_PTR
 
typedef _W64 int ptrdiff_t
 
typedef _W64 unsigned int UINT_PTR
 
typedef _W64 unsigned int size_t
 
typedef _W64 long LONG_PTR
 
typedef _W64 long SSIZE_T
 
typedef _W64 unsigned long ULONG_PTR
 
typedef _W64 unsigned long DWORD_PTR
 
typedef _W64 unsigned long SIZE_T
 
typedef unsigned char BYTE
 
typedef unsigned short WORD
 
typedef unsigned int UINT
 
typedef unsigned long DWORD
 

Functions

typedef _Return_type_success_ (return >=0) long HRESULT
 
 C_ASSERT (sizeof(USHORT)==2)
 
 C_ASSERT (sizeof(INT)==4)
 
 C_ASSERT (sizeof(UINT)==4)
 
 C_ASSERT (sizeof(LONG)==4)
 
 C_ASSERT (sizeof(DWORD)==4)
 
 C_ASSERT (sizeof(UINT_PTR)==sizeof(ULONG_PTR))
 
_Must_inspect_result_ __forceinline INTSAFE_RESULT INTSAFE_NAME() ULongLongMult (_In_ ULONGLONG Multiplicand, _In_ ULONGLONG Multiplier, _Out_ _Deref_out_range_(==, Multiplicand *Multiplier) ULONGLONG *pOutput)
 

Detailed Description

Windows helper functions for integer overflow prevention.

Definition in file intsafe.h.

Macro Definition Documentation

◆ _INTSAFE_CHAR

#define _INTSAFE_CHAR   CHAR

Definition at line 242 of file intsafe.h.

◆ _INTSAFE_CHAR_ERROR

#define _INTSAFE_CHAR_ERROR   ((signed char)(-1))

Definition at line 243 of file intsafe.h.

◆ _INTSAFE_CHAR_MAX

#define _INTSAFE_CHAR_MAX   ((signed char)127)

Definition at line 249 of file intsafe.h.

◆ _INTSAFE_CHAR_MIN

#define _INTSAFE_CHAR_MIN   ((signed char)(-128))

Definition at line 248 of file intsafe.h.

◆ _INTSAFE_H_INCLUDED_

#define _INTSAFE_H_INCLUDED_

Definition at line 29 of file intsafe.h.

◆ _SIZE_T_ERROR

#define _SIZE_T_ERROR   0xffffffffUL

Definition at line 238 of file intsafe.h.

◆ _SIZE_T_MAX

#define _SIZE_T_MAX   0xffffffffUL

Definition at line 193 of file intsafe.h.

◆ _W64

#define _W64

Definition at line 70 of file intsafe.h.

◆ BYTE_ERROR

#define BYTE_ERROR   ((unsigned char)0xff)

Definition at line 199 of file intsafe.h.

◆ BYTE_MAX

#define BYTE_MAX   ((unsigned char)0xff)

Definition at line 150 of file intsafe.h.

◆ C_ASSERT

#define C_ASSERT (   e)    extern void __C_ASSERT__(int [(e)?1:-1])

Definition at line 79 of file intsafe.h.

◆ CHAR_ERROR

#define CHAR_ERROR   '\0'

Definition at line 254 of file intsafe.h.

◆ DEFINE_SAFE_ADD

#define DEFINE_SAFE_ADD (   _Name,
  _Type 
)
Value:
INTSAFE_NAME(_Name)( \
_In_ _Type Augend, \
_In_ _Type Addend, \
_Out_ _Deref_out_range_(==, Augend + Addend) _Type *pOutput) \
{ \
if ((_Type)(Augend + Addend) >= Augend) \
{ \
*pOutput = Augend + Addend; \
return INTSAFE_SUCCESS; \
} \
else \
{ \
*pOutput = _Type ## _ERROR; \
} \
}
IN OUT PLONG Addend
Definition: CrNtStubs.h:22
#define INTSAFE_E_ARITHMETIC_OVERFLOW
Definition: intsafe.h:62
#define INTSAFE_NAME(name)
Definition: intsafe.h:63
#define _Deref_out_range_(lb, ub)
Definition: no_sal2.h:33
#define INTSAFE_SUCCESS
Definition: intsafe.h:61

Definition at line 521 of file intsafe.h.

◆ DEFINE_SAFE_CONVERT_STOS

#define DEFINE_SAFE_CONVERT_STOS (   _Name,
  _TypeFrom,
  _TypeTo 
)
Value:
INTSAFE_NAME(_Name)( \
_In_ _TypeFrom Input, \
_Out_ _Deref_out_range_(==, Input) _TypeTo *pOutput) \
{ \
if ((Input >= _TypeTo ## _MIN) && (Input <= _TypeTo ## _MAX)) \
{ \
*pOutput = (_TypeTo)Input; \
return INTSAFE_SUCCESS; \
} \
else \
{ \
*pOutput = _TypeTo ## _ERROR; \
} \
}
Definition: arc.h:84
#define INTSAFE_E_ARITHMETIC_OVERFLOW
Definition: intsafe.h:62
#define INTSAFE_NAME(name)
Definition: intsafe.h:63
#define _Deref_out_range_(lb, ub)
Definition: no_sal2.h:33
#define INTSAFE_SUCCESS
Definition: intsafe.h:61

Definition at line 400 of file intsafe.h.

◆ DEFINE_SAFE_CONVERT_STOU

#define DEFINE_SAFE_CONVERT_STOU (   _Name,
  _TypeFrom,
  _TypeTo 
)
Value:
INTSAFE_NAME(_Name)( \
_In_ _TypeFrom Input, \
_Out_ _Deref_out_range_(==, Input) _TypeTo *pOutput) \
{ \
if ((Input >= 0) && \
((sizeof(_TypeFrom) <= sizeof(_TypeTo)) || (Input <= (_TypeFrom)_TypeTo ## _MAX))) \
{ \
*pOutput = (_TypeTo)Input; \
return INTSAFE_SUCCESS; \
} \
else \
{ \
*pOutput = _TypeTo ## _ERROR; \
} \
}
Definition: arc.h:84
#define INTSAFE_E_ARITHMETIC_OVERFLOW
Definition: intsafe.h:62
#define INTSAFE_NAME(name)
Definition: intsafe.h:63
#define _Deref_out_range_(lb, ub)
Definition: no_sal2.h:33
#define INTSAFE_SUCCESS
Definition: intsafe.h:61

Definition at line 325 of file intsafe.h.

◆ DEFINE_SAFE_CONVERT_UTOX

#define DEFINE_SAFE_CONVERT_UTOX (   _Name,
  _TypeFrom,
  _TypeTo 
)
Value:
INTSAFE_NAME(_Name)( \
_In_ _TypeFrom Input, \
_Out_ _Deref_out_range_(==, Input) _TypeTo *pOutput) \
{ \
if (Input <= _TypeTo ## _MAX) \
{ \
*pOutput = (_TypeTo)Input; \
return INTSAFE_SUCCESS; \
} \
else \
{ \
*pOutput = _TypeTo ## _ERROR; \
} \
}
Definition: arc.h:84
#define INTSAFE_E_ARITHMETIC_OVERFLOW
Definition: intsafe.h:62
#define INTSAFE_NAME(name)
Definition: intsafe.h:63
#define _Deref_out_range_(lb, ub)
Definition: no_sal2.h:33
#define INTSAFE_SUCCESS
Definition: intsafe.h:61

Definition at line 262 of file intsafe.h.

◆ DEFINE_SAFE_MULT_U16

#define DEFINE_SAFE_MULT_U16 (   _Name,
  _Type,
  _Convert 
)
Value:
INTSAFE_NAME(_Name)( \
_In_ _Type Multiplicand, \
_In_ _Type Multiplier, \
_Out_ _Deref_out_range_(==, Multiplicand * Multiplier) _Type* pOutput) \
{ \
ULONG Result = ((ULONG)Multiplicand) * ((ULONG)Multiplier); \
return INTSAFE_NAME(_Convert)(Result, pOutput); \
}
#define INTSAFE_NAME(name)
Definition: intsafe.h:63
_At_(*)(_In_ PWSK_CLIENT Client, _In_opt_ PUNICODE_STRING NodeName, _In_opt_ PUNICODE_STRING ServiceName, _In_opt_ ULONG NameSpace, _In_opt_ GUID *Provider, _In_opt_ PADDRINFOEXW Hints, _Outptr_ PADDRINFOEXW *Result, _In_opt_ PEPROCESS OwningProcess, _In_opt_ PETHREAD OwningThread, _Inout_ PIRP Irp Result)(Mem)) NTSTATUS(WSKAPI *PFN_WSK_GET_ADDRESS_INFO
Definition: wsk.h:426
#define _Deref_out_range_(lb, ub)
Definition: no_sal2.h:33
unsigned long ULONG
Definition: intsafe.h:96

Definition at line 759 of file intsafe.h.

◆ DEFINE_SAFE_MULT_U32

#define DEFINE_SAFE_MULT_U32 (   _Name,
  _Type,
  _Convert 
)
Value:
INTSAFE_NAME(_Name)( \
_In_ _Type Multiplicand, \
_In_ _Type Multiplier, \
_Out_ _Deref_out_range_(==, Multiplicand * Multiplier) _Type* pOutput) \
{ \
ULONGLONG Result = UInt32x32To64(Multiplicand, Multiplier); \
return INTSAFE_NAME(_Convert)(Result, pOutput); \
}
#define INTSAFE_NAME(name)
Definition: intsafe.h:63
_At_(*)(_In_ PWSK_CLIENT Client, _In_opt_ PUNICODE_STRING NodeName, _In_opt_ PUNICODE_STRING ServiceName, _In_opt_ ULONG NameSpace, _In_opt_ GUID *Provider, _In_opt_ PADDRINFOEXW Hints, _Outptr_ PADDRINFOEXW *Result, _In_opt_ PEPROCESS OwningProcess, _In_opt_ PETHREAD OwningThread, _Inout_ PIRP Irp Result)(Mem)) NTSTATUS(WSKAPI *PFN_WSK_GET_ADDRESS_INFO
Definition: wsk.h:426
#define _Deref_out_range_(lb, ub)
Definition: no_sal2.h:33
#define UInt32x32To64(a, b)
Definition: intsafe.h:258

Definition at line 740 of file intsafe.h.

◆ DEFINE_SAFE_SUB

#define DEFINE_SAFE_SUB (   _Name,
  _Type 
)
Value:
INTSAFE_NAME(_Name)( \
_In_ _Type Minuend, \
_In_ _Type Subtrahend, \
_Out_ _Deref_out_range_(==, Minuend - Subtrahend) _Type* pOutput) \
{ \
if (Minuend >= Subtrahend) \
{ \
*pOutput = Minuend - Subtrahend; \
return INTSAFE_SUCCESS; \
} \
else \
{ \
*pOutput = _Type ## _ERROR; \
} \
}
#define INTSAFE_E_ARITHMETIC_OVERFLOW
Definition: intsafe.h:62
#define INTSAFE_NAME(name)
Definition: intsafe.h:63
#define _Deref_out_range_(lb, ub)
Definition: no_sal2.h:33
#define INTSAFE_SUCCESS
Definition: intsafe.h:61

Definition at line 554 of file intsafe.h.

◆ DWORD64_MAX

#define DWORD64_MAX   0xffffffffffffffffULL

Definition at line 169 of file intsafe.h.

◆ DWord64Add

#define DWord64Add   ULongLongAdd

Definition at line 813 of file intsafe.h.

◆ DWord64Sub

#define DWord64Sub   ULongLongSub

Definition at line 821 of file intsafe.h.

◆ DWORD_ERROR

#define DWORD_ERROR   0xffffffffUL

Definition at line 211 of file intsafe.h.

◆ DWORD_MAX

#define DWORD_MAX   0xffffffffUL

Definition at line 162 of file intsafe.h.

◆ DWORD_PTR_ERROR

#define DWORD_PTR_ERROR   0xffffffffUL

Definition at line 234 of file intsafe.h.

◆ DWORD_PTR_MAX

#define DWORD_PTR_MAX   0xffffffffUL

Definition at line 189 of file intsafe.h.

◆ DWordAdd

#define DWordAdd   ULongAdd

Definition at line 810 of file intsafe.h.

◆ DWORDLONG_ERROR

#define DWORDLONG_ERROR   0xffffffffffffffffULL

Definition at line 216 of file intsafe.h.

◆ DWORDLONG_MAX

#define DWORDLONG_MAX   0xffffffffffffffffULL

Definition at line 167 of file intsafe.h.

◆ DWordLongAdd

#define DWordLongAdd   ULongLongAdd

Definition at line 811 of file intsafe.h.

◆ DWordLongSub

#define DWordLongSub   ULongLongSub

Definition at line 819 of file intsafe.h.

◆ DWordSub

#define DWordSub   ULongSub

Definition at line 818 of file intsafe.h.

◆ FAILED

#define FAILED (   hr)    (((HRESULT)(hr)) < 0)

Definition at line 58 of file intsafe.h.

◆ INT128_MAX

#define INT128_MAX   170141183460469231731687303715884105727i128

Definition at line 171 of file intsafe.h.

◆ INT128_MIN

#define INT128_MIN   (-170141183460469231731687303715884105727i128 - 1)

Definition at line 135 of file intsafe.h.

◆ INT16_ERROR

#define INT16_ERROR   ((short)(-1))

Definition at line 201 of file intsafe.h.

◆ INT16_MAX

#define INT16_MAX   ((short)32767)

Definition at line 152 of file intsafe.h.

◆ INT16_MIN

#define INT16_MIN   ((short)(-32767 - 1))

Definition at line 128 of file intsafe.h.

◆ INT32_ERROR

#define INT32_ERROR   (-1)

Definition at line 206 of file intsafe.h.

◆ INT32_MAX

#define INT32_MAX   2147483647

Definition at line 157 of file intsafe.h.

◆ INT32_MIN

#define INT32_MIN   (-2147483647 - 1)

Definition at line 130 of file intsafe.h.

◆ INT64_ERROR

#define INT64_ERROR   (-1LL)

Definition at line 214 of file intsafe.h.

◆ INT64_MAX

#define INT64_MAX   9223372036854775807LL

Definition at line 165 of file intsafe.h.

◆ INT64_MIN

#define INT64_MIN   (-9223372036854775807LL - 1)

Definition at line 134 of file intsafe.h.

◆ INT8_ERROR

#define INT8_ERROR   ((signed char)(-1))

Definition at line 197 of file intsafe.h.

◆ INT8_MAX

#define INT8_MAX   ((signed char)127)

Definition at line 148 of file intsafe.h.

◆ INT8_MIN

#define INT8_MIN   ((signed char)(-127 - 1))

Definition at line 126 of file intsafe.h.

◆ Int8ToByte

#define Int8ToByte   Int8ToUInt8

Definition at line 483 of file intsafe.h.

◆ Int8ToDWord

#define Int8ToDWord   Int8ToULong

Definition at line 487 of file intsafe.h.

◆ Int8ToDWord64

#define Int8ToDWord64   Int8ToULongLong

Definition at line 491 of file intsafe.h.

◆ Int8ToDWordLong

#define Int8ToDWordLong   Int8ToULongLong

Definition at line 489 of file intsafe.h.

◆ Int8ToDWordPtr

#define Int8ToDWordPtr   Int8ToULongPtr

Definition at line 488 of file intsafe.h.

◆ Int8ToSizeT

#define Int8ToSizeT   Int8ToUIntPtr

Definition at line 493 of file intsafe.h.

◆ Int8ToSIZET

#define Int8ToSIZET   Int8ToULongPtr

Definition at line 494 of file intsafe.h.

◆ Int8ToUInt16

#define Int8ToUInt16   Int8ToUShort

Definition at line 484 of file intsafe.h.

◆ Int8ToUInt32

#define Int8ToUInt32   Int8ToUInt

Definition at line 486 of file intsafe.h.

◆ Int8ToUInt64

#define Int8ToUInt64   Int8ToULongLong

Definition at line 492 of file intsafe.h.

◆ Int8ToULong64

#define Int8ToULong64   Int8ToULongLong

Definition at line 490 of file intsafe.h.

◆ Int8ToWord

#define Int8ToWord   Int8ToUShort

Definition at line 485 of file intsafe.h.

◆ INT_ERROR

#define INT_ERROR   (-1)

Definition at line 205 of file intsafe.h.

◆ INT_MAX

#define INT_MAX   2147483647

Definition at line 156 of file intsafe.h.

◆ INT_MIN

#define INT_MIN   (-2147483647 - 1)

Definition at line 129 of file intsafe.h.

◆ INT_PTR_ERROR

#define INT_PTR_ERROR   (-1)

Definition at line 230 of file intsafe.h.

◆ INT_PTR_MAX

#define INT_PTR_MAX   2147483647

Definition at line 185 of file intsafe.h.

◆ INT_PTR_MIN

#define INT_PTR_MIN   (-2147483647 - 1)

Definition at line 142 of file intsafe.h.

◆ INTSAFE_E_ARITHMETIC_OVERFLOW

#define INTSAFE_E_ARITHMETIC_OVERFLOW   ((HRESULT)0x80070216L)

Definition at line 62 of file intsafe.h.

◆ INTSAFE_NAME

#define INTSAFE_NAME (   name)    name

Definition at line 63 of file intsafe.h.

◆ INTSAFE_RESULT

#define INTSAFE_RESULT   HRESULT

Definition at line 60 of file intsafe.h.

◆ INTSAFE_SUCCESS

#define INTSAFE_SUCCESS   S_OK

Definition at line 61 of file intsafe.h.

◆ IntToSizeT

#define IntToSizeT   IntToUIntPtr

Definition at line 495 of file intsafe.h.

◆ IntToSIZET

#define IntToSIZET   IntToULongPtr

Definition at line 496 of file intsafe.h.

◆ IntToUIntPtr

#define IntToUIntPtr   IntToUInt

Definition at line 512 of file intsafe.h.

◆ LONG64_ERROR

#define LONG64_ERROR   (-1LL)

Definition at line 213 of file intsafe.h.

◆ LONG64_MAX

#define LONG64_MAX   9223372036854775807LL

Definition at line 164 of file intsafe.h.

◆ LONG64_MIN

#define LONG64_MIN   (-9223372036854775807LL - 1)

Definition at line 133 of file intsafe.h.

◆ LONG_ERROR

#define LONG_ERROR   (-1L)

Definition at line 209 of file intsafe.h.

◆ LONG_MAX

#define LONG_MAX   2147483647L

Definition at line 160 of file intsafe.h.

◆ LONG_MIN

#define LONG_MIN   (-2147483647L - 1)

Definition at line 131 of file intsafe.h.

◆ LONG_PTR_ERROR

#define LONG_PTR_ERROR   (-1L)

Definition at line 232 of file intsafe.h.

◆ LONG_PTR_MAX

#define LONG_PTR_MAX   2147483647L

Definition at line 187 of file intsafe.h.

◆ LONG_PTR_MIN

#define LONG_PTR_MIN   (-2147483647L - 1)

Definition at line 143 of file intsafe.h.

◆ LONGLONG_ERROR

#define LONGLONG_ERROR   (-1LL)

Definition at line 212 of file intsafe.h.

◆ LONGLONG_MAX

#define LONGLONG_MAX   9223372036854775807LL

Definition at line 163 of file intsafe.h.

◆ LONGLONG_MIN

#define LONGLONG_MIN   (-9223372036854775807LL - 1)

Definition at line 132 of file intsafe.h.

◆ PTRDIFF_T_ERROR

#define PTRDIFF_T_ERROR   (-1)

Definition at line 235 of file intsafe.h.

◆ PTRDIFF_T_MAX

#define PTRDIFF_T_MAX   2147483647

Definition at line 190 of file intsafe.h.

◆ PTRDIFF_T_MIN

#define PTRDIFF_T_MIN   (-2147483647 - 1)

Definition at line 144 of file intsafe.h.

◆ S_OK

#define S_OK   ((HRESULT)0L)

Definition at line 59 of file intsafe.h.

◆ SHORT_ERROR

#define SHORT_ERROR   ((short)(-1))

Definition at line 200 of file intsafe.h.

◆ SHORT_MAX

#define SHORT_MAX   ((short)32767)

Definition at line 151 of file intsafe.h.

◆ SHORT_MIN

#define SHORT_MIN   (-32768)

Definition at line 127 of file intsafe.h.

◆ SIZE_T_ERROR

#define SIZE_T_ERROR   0xffffffffU

Definition at line 236 of file intsafe.h.

◆ size_t_ERROR

#define size_t_ERROR   SIZE_T_ERROR

Definition at line 252 of file intsafe.h.

◆ SIZE_T_MAX

#define SIZE_T_MAX   0xffffffff

Definition at line 191 of file intsafe.h.

◆ SIZETToULong

#define SIZETToULong   ULongPtrToULong

Definition at line 505 of file intsafe.h.

◆ SSIZE_T_ERROR

#define SSIZE_T_ERROR   (-1L)

Definition at line 237 of file intsafe.h.

◆ SSIZE_T_MAX

#define SSIZE_T_MAX   2147483647L

Definition at line 192 of file intsafe.h.

◆ SSIZE_T_MIN

#define SSIZE_T_MIN   (-2147483647L - 1)

Definition at line 145 of file intsafe.h.

◆ SSIZETToULong

#define SSIZETToULong   LongPtrToULong

Definition at line 507 of file intsafe.h.

◆ SSIZETToULongLong

#define SSIZETToULongLong   LongPtrToULongLong

Definition at line 506 of file intsafe.h.

◆ SUCCEEDED

#define SUCCEEDED (   hr)    (((HRESULT)(hr)) >= 0)

Definition at line 57 of file intsafe.h.

◆ UCHAR_ERROR

#define UCHAR_ERROR   '\0'

Definition at line 253 of file intsafe.h.

◆ UINT128_MAX

#define UINT128_MAX   0xffffffffffffffffffffffffffffffffui128

Definition at line 172 of file intsafe.h.

◆ UINT16_ERROR

#define UINT16_ERROR   ((unsigned short)0xffff)

Definition at line 203 of file intsafe.h.

◆ UINT16_MAX

#define UINT16_MAX   ((unsigned short)0xffff)

Definition at line 154 of file intsafe.h.

◆ UInt16Add

#define UInt16Add   UShortAdd

Definition at line 807 of file intsafe.h.

◆ UInt16Mult

#define UInt16Mult   UShortMult

Definition at line 823 of file intsafe.h.

◆ UInt16Sub

#define UInt16Sub   UShortSub

Definition at line 815 of file intsafe.h.

◆ UINT32_ERROR

#define UINT32_ERROR   0xffffffffU

Definition at line 208 of file intsafe.h.

◆ UINT32_MAX

#define UINT32_MAX   0xffffffffU

Definition at line 159 of file intsafe.h.

◆ UInt32Add

#define UInt32Add   UIntAdd

Definition at line 809 of file intsafe.h.

◆ UInt32Sub

#define UInt32Sub   UIntSub

Definition at line 817 of file intsafe.h.

◆ UInt32x32To64

#define UInt32x32To64 (   a,
  b 
)    ((unsigned __int64)(unsigned int)(a)*(unsigned __int64)(unsigned int)(b))

Definition at line 258 of file intsafe.h.

◆ UINT64_ERROR

#define UINT64_ERROR   0xffffffffffffffffULL

Definition at line 218 of file intsafe.h.

◆ UINT64_MAX

#define UINT64_MAX   0xffffffffffffffffULL

Definition at line 170 of file intsafe.h.

◆ UInt64Add

#define UInt64Add   ULongLongAdd

Definition at line 814 of file intsafe.h.

◆ UInt64Sub

#define UInt64Sub   ULongLongSub

Definition at line 822 of file intsafe.h.

◆ UINT8_ERROR

#define UINT8_ERROR   ((unsigned char)0xff)

Definition at line 198 of file intsafe.h.

◆ UINT8_MAX

#define UINT8_MAX   ((unsigned char)0xffU)

Definition at line 149 of file intsafe.h.

◆ UINT_ERROR

#define UINT_ERROR   0xffffffffU

Definition at line 207 of file intsafe.h.

◆ UINT_MAX

#define UINT_MAX   0xffffffff

Definition at line 158 of file intsafe.h.

◆ UINT_PTR_ERROR

#define UINT_PTR_ERROR   0xffffffffU

Definition at line 231 of file intsafe.h.

◆ UINT_PTR_MAX

#define UINT_PTR_MAX   0xffffffff

Definition at line 186 of file intsafe.h.

◆ ULONG64_ERROR

#define ULONG64_ERROR   0xffffffffffffffffULL

Definition at line 217 of file intsafe.h.

◆ ULONG64_MAX

#define ULONG64_MAX   0xffffffffffffffffULL

Definition at line 168 of file intsafe.h.

◆ ULong64Add

#define ULong64Add   ULongLongAdd

Definition at line 812 of file intsafe.h.

◆ ULong64Sub

#define ULong64Sub   ULongLongSub

Definition at line 820 of file intsafe.h.

◆ ULONG_ERROR

#define ULONG_ERROR   0xffffffffUL

Definition at line 210 of file intsafe.h.

◆ ULONG_MAX

#define ULONG_MAX   0xffffffffUL

Definition at line 161 of file intsafe.h.

◆ ULONG_PTR_ERROR

#define ULONG_PTR_ERROR   0xffffffffUL

Definition at line 233 of file intsafe.h.

◆ ULONG_PTR_MAX

#define ULONG_PTR_MAX   0xffffffffUL

Definition at line 188 of file intsafe.h.

◆ ULONGLONG_ERROR

#define ULONGLONG_ERROR   0xffffffffffffffffULL

Definition at line 215 of file intsafe.h.

◆ ULONGLONG_MAX

#define ULONGLONG_MAX   0xffffffffffffffffULL

Definition at line 166 of file intsafe.h.

◆ ULongLongToInt64

#define ULongLongToInt64   ULongLongToLongLong

Definition at line 499 of file intsafe.h.

◆ ULongLongToIntPtr

#define ULongLongToIntPtr   ULongLongToInt

Definition at line 513 of file intsafe.h.

◆ ULongLongToLong64

#define ULongLongToLong64   ULongLongToLongLong

Definition at line 500 of file intsafe.h.

◆ ULongLongToPtrdiffT

#define ULongLongToPtrdiffT   ULongLongToIntPtr

Definition at line 501 of file intsafe.h.

◆ ULongLongToSizeT

#define ULongLongToSizeT   ULongLongToUIntPtr

Definition at line 502 of file intsafe.h.

◆ ULongLongToSIZET

#define ULongLongToSIZET   ULongLongToULongPtr

Definition at line 504 of file intsafe.h.

◆ ULongLongToSSIZET

#define ULongLongToSSIZET   ULongLongToLongPtr

Definition at line 503 of file intsafe.h.

◆ ULongLongToUIntPtr

#define ULongLongToUIntPtr   ULongLongToUInt

Definition at line 514 of file intsafe.h.

◆ ULongLongToULongPtr

#define ULongLongToULongPtr   ULongLongToULong

Definition at line 515 of file intsafe.h.

◆ ULongToByte

#define ULongToByte   ULongToUInt8

Definition at line 498 of file intsafe.h.

◆ ULongToSSIZET

#define ULongToSSIZET   ULongToLongPtr

Definition at line 497 of file intsafe.h.

◆ USHORT_ERROR

#define USHORT_ERROR   ((unsigned short)0xffff)

Definition at line 202 of file intsafe.h.

◆ USHORT_MAX

#define USHORT_MAX   ((unsigned short)0xffff)

Definition at line 153 of file intsafe.h.

◆ WORD_ERROR

#define WORD_ERROR   ((unsigned short)0xffff)

Definition at line 204 of file intsafe.h.

◆ WORD_MAX

#define WORD_MAX   ((unsigned short)0xffff)

Definition at line 155 of file intsafe.h.

◆ WordAdd

#define WordAdd   UShortAdd

Definition at line 808 of file intsafe.h.

◆ WordMult

#define WordMult   UShortMult

Definition at line 824 of file intsafe.h.

◆ WordSub

#define WordSub   UShortSub

Definition at line 816 of file intsafe.h.

Typedef Documentation

◆ BYTE

typedef unsigned char BYTE

Definition at line 110 of file intsafe.h.

◆ CHAR

typedef char CHAR

Definition at line 86 of file intsafe.h.

◆ DWORD

typedef unsigned long DWORD

Definition at line 113 of file intsafe.h.

◆ DWORD64

typedef unsigned long long DWORD64

Definition at line 99 of file intsafe.h.

◆ DWORD_PTR

typedef _W64 unsigned long DWORD_PTR

Definition at line 107 of file intsafe.h.

◆ DWORDLONG

typedef unsigned long long DWORDLONG

Definition at line 99 of file intsafe.h.

◆ INT

typedef int INT

Definition at line 92 of file intsafe.h.

◆ INT16

typedef signed short INT16

Definition at line 90 of file intsafe.h.

◆ INT32

typedef signed int INT32

Definition at line 94 of file intsafe.h.

◆ INT64

typedef signed long long INT64

Definition at line 98 of file intsafe.h.

◆ INT8

typedef signed char INT8

Definition at line 88 of file intsafe.h.

◆ INT_PTR

typedef _W64 int INT_PTR

Definition at line 104 of file intsafe.h.

◆ LONG

typedef long LONG

Definition at line 95 of file intsafe.h.

◆ LONG64

typedef long long LONG64

Definition at line 97 of file intsafe.h.

◆ LONG_PTR

typedef _W64 long LONG_PTR

Definition at line 106 of file intsafe.h.

◆ LONGLONG

typedef long long LONGLONG

Definition at line 97 of file intsafe.h.

◆ ptrdiff_t

typedef _W64 int ptrdiff_t

Definition at line 104 of file intsafe.h.

◆ SHORT

typedef short SHORT

Definition at line 89 of file intsafe.h.

◆ size_t

typedef _W64 unsigned int size_t

Definition at line 105 of file intsafe.h.

◆ SIZE_T

typedef _W64 unsigned long SIZE_T

Definition at line 107 of file intsafe.h.

◆ SSIZE_T

typedef _W64 long SSIZE_T

Definition at line 106 of file intsafe.h.

◆ UCHAR

typedef unsigned char UCHAR

Definition at line 87 of file intsafe.h.

◆ UINT

typedef unsigned int UINT

Definition at line 112 of file intsafe.h.

◆ UINT16

typedef unsigned short UINT16

Definition at line 91 of file intsafe.h.

◆ UINT32

typedef unsigned int UINT32

Definition at line 93 of file intsafe.h.

◆ UINT64

typedef unsigned long long UINT64

Definition at line 99 of file intsafe.h.

◆ UINT8

typedef unsigned char UINT8

Definition at line 87 of file intsafe.h.

◆ UINT_PTR

typedef _W64 unsigned int UINT_PTR

Definition at line 105 of file intsafe.h.

◆ ULONG

typedef unsigned long ULONG

Definition at line 96 of file intsafe.h.

◆ ULONG64

typedef unsigned long long ULONG64

Definition at line 99 of file intsafe.h.

◆ ULONG_PTR

typedef _W64 unsigned long ULONG_PTR

Definition at line 107 of file intsafe.h.

◆ ULONGLONG

typedef unsigned long long ULONGLONG

Definition at line 99 of file intsafe.h.

◆ USHORT

typedef unsigned short USHORT

Definition at line 91 of file intsafe.h.

◆ WORD

typedef unsigned short WORD

Definition at line 111 of file intsafe.h.

Function Documentation

◆ _Return_type_success_()

typedef _Return_type_success_ ( return >=  0)

◆ C_ASSERT() [1/6]

C_ASSERT ( sizeof(USHORT = =2)

◆ C_ASSERT() [2/6]

C_ASSERT ( sizeof(INT = =4)

◆ C_ASSERT() [3/6]

C_ASSERT ( sizeof(UINT = =4)

◆ C_ASSERT() [4/6]

C_ASSERT ( sizeof(LONG = =4)

◆ C_ASSERT() [5/6]

C_ASSERT ( sizeof(DWORD = =4)

◆ C_ASSERT() [6/6]

C_ASSERT ( sizeof(UINT_PTR = =sizeof(ULONG_PTR))

◆ ULongLongMult()

_Must_inspect_result_ __forceinline INTSAFE_RESULT INTSAFE_NAME() ULongLongMult ( _In_ ULONGLONG  Multiplicand,
_In_ ULONGLONG  Multiplier,
_Out_ _Deref_out_range_(==, Multiplicand *Multiplier) ULONGLONG pOutput 
)

Definition at line 687 of file intsafe.h.

691 {
692  /* We can split the 64 bit numbers in low and high parts:
693  M1 = M1Low + M1Hi * 0x100000000
694  M2 = M2Low + M2Hi * 0x100000000
695 
696  Then the multiplication looks like this:
697  M1 * M2 = (M1Low + M1Hi * 0x100000000) * (M2Low + M2Hi * 0x100000000)
698  = M1Low * M2Low
699  + M1Low * M2Hi * 0x100000000
700  + M2Low * M1Hi * 0x100000000
701  + M1Hi * M2Hi * 0x100000000 * 0x100000000
702 
703  We get an overflow when
704  a) M1Hi * M2Hi != 0, so when M1Hi and M2Hi are both not 0
705  b) The product of the nonzero high part and the other low part
706  is larger than 32 bits.
707  c) The addition of the product from b) shifted left by 32 and
708  M1Low * M2Low is larger than 64 bits
709  */
710  ULONG M1Low = Multiplicand & 0xffffffff;
711  ULONG M2Low = Multiplier & 0xffffffff;
712  ULONG M1Hi = Multiplicand >> 32;
713  ULONG M2Hi = Multiplier >> 32;
714  ULONGLONG Temp;
715 
716  if (M1Hi == 0)
717  {
718  Temp = UInt32x32To64(M1Low, M2Hi);
719  }
720  else if (M2Hi == 0)
721  {
722  Temp = UInt32x32To64(M1Hi, M2Low);
723  }
724  else
725  {
726  *pOutput = ULONGLONG_ERROR;
728  }
729 
730  if (Temp > ULONG_MAX)
731  {
732  *pOutput = ULONGLONG_ERROR;
734  }
735 
736  return INTSAFE_NAME(ULongLongAdd)(Temp << 32, UInt32x32To64(M1Low, M2Low), pOutput);
737 }
#define ULONG_MAX
Definition: intsafe.h:161
#define INTSAFE_E_ARITHMETIC_OVERFLOW
Definition: intsafe.h:62
#define ULONGLONG_ERROR
Definition: intsafe.h:215
#define INTSAFE_NAME(name)
Definition: intsafe.h:63
uint64_t ULONGLONG
Definition: typedefs.h:65
unsigned int ULONG
Definition: retypes.h:1
#define UInt32x32To64(a, b)
Definition: intsafe.h:258