17#pragma pack(push, _CRT_PACKING)
28#pragma warning(disable:4702)
30template <
typename T >
41#ifdef _NATIVE_WCHAR_T_DEFINED
63#pragma warning(suppress:4804)
85#pragma warning(disable:4310)
86#pragma warning(disable:4804)
204template <
typename T >
215template < typename T, int Method = GetAbsMethod< T >::method >
class AbsValueHelper;
243 _ASSERTE( (
"AbsValueHelper::Abs should not be called with an unsigned integer type", 0) );
262 E::SafeIntOnOverflow();
275#pragma warning(suppress:4127)
278#pragma warning(suppress:4146)
297template <
typename ToType,
typename FromType >
317 sizeof( FromType ) >=
sizeof( ToType ) ) ||
330template <
typename T,
typename U,
typename E,
357 E::SafeIntOnOverflow();
368 t = (
T)(
b ? 1 : 0 );
390 E::SafeIntOnOverflow();
406 E::SafeIntOnOverflow();
423 E::SafeIntOnOverflow();
440 E::SafeIntOnOverflow();
459template <
typename T,
typename U >
465#if _SAFEINT_USE_ANSI_CONVERSIONS
479template <typename T, typename U, int Method = ValidComparison< T, U >::method >
class EqualityTest;
490 static bool IsEquals(
const T t,
const U u )
throw() {
return ( (
int)
t == (
int)
u ); }
511 return (
t == (
T)
u );
527 return ( (
U)
t ==
u );
531template <typename T, typename U, int Method = ValidComparison< T, U >::method >
class GreaterThanTest;
585template <typename T, typename U, typename E, int Method = ValidComparison< T, U >::method >
class ModulusHelper;
594 E::SafeIntOnDivZero();
599#pragma warning(suppress:4127)
621 E::SafeIntOnDivZero();
626#pragma warning(suppress:4127)
648 E::SafeIntOnDivZero();
652#pragma warning(suppress:4127)
674 E::SafeIntOnDivZero();
701 E::SafeIntOnDivZero();
741template <
typename T,
typename U >
780template <typename T, typename U, typename E, int Method = MultiplicationMethod< T, U >::method >
class MultiplicationHelper;
792 E::SafeIntOnOverflow();
807 unsigned int tmp =
t *
u;
811 E::SafeIntOnOverflow();
830 E::SafeIntOnOverflow();
849 E::SafeIntOnOverflow();
867 unsigned __int32 aHigh, aLow, bHigh, bLow;
874 aHigh = (
unsigned __int32)(
a >> 32);
876 bHigh = (
unsigned __int32)(
b >> 32);
897 E::SafeIntOnOverflow();
907 E::SafeIntOnOverflow();
917 E::SafeIntOnOverflow();
940 aHigh = (
unsigned __int32)(
a >> 32);
953 E::SafeIntOnOverflow();
963 E::SafeIntOnOverflow();
980 if(
b < 0 &&
a != 0 )
982 E::SafeIntOnOverflow();
995 if(
b < 0 &&
a != 0 )
997 E::SafeIntOnOverflow();
1011 bool fIsNegative =
false;
1017 bHigh = (
unsigned __int32)(
b >> 32);
1022 if(bHigh != 0 &&
a != 0)
1024 E::SafeIntOnOverflow();
1054 E::SafeIntOnOverflow();
1070 if( (
unsigned __int32)(
b >> 32) != 0 &&
a != 0 )
1072 E::SafeIntOnOverflow();
1078 if( (
unsigned __int32)(tmp >> 32) != 0 )
1080 E::SafeIntOnOverflow();
1094 if(
b < 0 &&
a != 0 )
1096 E::SafeIntOnOverflow();
1109 bool aNegative =
false;
1110 bool bNegative =
false;
1132 if( aNegative ^ bNegative )
1152 E::SafeIntOnOverflow();
1162 bool aNegative =
false;
1195 E::SafeIntOnOverflow();
1205 bool aNegative =
false;
1206 bool bNegative =
false;
1228 if( aNegative ^ bNegative )
1248 E::SafeIntOnOverflow();
1258 bool aNegative =
false;
1259 bool bNegative =
false;
1280 if( aNegative ^ bNegative )
1285#pragma warning(suppress:4146)
1301 E::SafeIntOnOverflow();
1311 bool aNegative =
false;
1346 E::SafeIntOnOverflow();
1385 E::SafeIntOnOverflow();
1423 E::SafeIntOnOverflow();
1471 E::SafeIntOnOverflow();
1500 E::SafeIntOnOverflow();
1531template < typename T, typename U, typename E, int Method = DivisionMethod< T, U >::method >
class DivisionHelper;
1540 E::SafeIntOnDivZero();
1562 E::SafeIntOnDivZero();
1574 E::SafeIntOnOverflow();
1586 E::SafeIntOnDivZero();
1609 E::SafeIntOnDivZero();
1616#pragma warning(suppress:4127)
1617 if(
sizeof(
T ) <
sizeof(
__int64 ) )
1645 E::SafeIntOnDivZero();
1661 E::SafeIntOnDivZero();
1668 E::SafeIntOnOverflow();
1697template<
typename T,
typename U >
1734template < typename T, typename U, typename E, int Method = AdditionMethod< T, U >::method >
class AdditionHelper;
1750 E::SafeIntOnOverflow();
1769 E::SafeIntOnOverflow();
1788 E::SafeIntOnOverflow();
1808 E::SafeIntOnOverflow();
1828 E::SafeIntOnOverflow();
1847 E::SafeIntOnOverflow();
1852#pragma warning(push)
1853#pragma warning(disable:4702)
1868 E::SafeIntOnOverflow();
1889 E::SafeIntOnOverflow();
1926 E::SafeIntOnOverflow();
1939 if( lhs >= (
unsigned __int64)( -rhs ) )
1958 E::SafeIntOnOverflow();
1974 if( rhs >= 0 && tmp < lhs )
1976 E::SafeIntOnOverflow();
1983 if( rhs < 0 && tmp > lhs )
1985 E::SafeIntOnOverflow();
2012 E::SafeIntOnOverflow();
2031 E::SafeIntOnOverflow();
2050 E::SafeIntOnOverflow();
2062 if( (
unsigned __int32)( rhs >> 32 ) == 0 )
2073 E::SafeIntOnOverflow();
2179template < typename T, typename U, typename E, int Method = SubtractionMethod< T, U >::method >
class SubtractionHelper;
2193 E::SafeIntOnOverflow();
2207 T tmp = (
T)(lhs - rhs);
2211 E::SafeIntOnOverflow();
2231 E::SafeIntOnOverflow();
2264 E::SafeIntOnOverflow();
2310 E::SafeIntOnOverflow();
2324 if( (
unsigned __int64)rhs <= lhs )
2342 E::SafeIntOnOverflow();
2367 else if( (
unsigned __int64)rhs > lhs )
2387 E::SafeIntOnOverflow();
2401 if( (
unsigned __int64)rhs <= lhs )
2422 E::SafeIntOnOverflow();
2452 E::SafeIntOnOverflow();
2475 if( ( lhs >= 0 && rhs < 0 && tmp < lhs ) ||
2476 ( rhs >= 0 && tmp > lhs ) )
2478 E::SafeIntOnOverflow();
2506#pragma warning(suppress:4127)
2508 ( rhs < 0 && tmp < lhs ) )
2510 E::SafeIntOnOverflow();
2517#pragma warning(suppress:4127)
2519 ( rhs >=0 && tmp > lhs ) )
2521 E::SafeIntOnOverflow();
2590 E::SafeIntOnOverflow();
2603 if( ( lhs >= 0 && rhs < 0 && tmp < lhs ) ||
2604 ( rhs > 0 && tmp > lhs ) )
2606 E::SafeIntOnOverflow();
2631 E::SafeIntOnOverflow();
2650 E::SafeIntOnOverflow();
2677 if( rhs <= AbsMinIntT + (
unsigned __int64)lhs )
2684 E::SafeIntOnOverflow();
2695 if( lhs >= 0 && (
T)lhs >= rhs )
2701 E::SafeIntOnOverflow();
2719 E::SafeIntOnOverflow();
2731 if( lhs >= 0 && (
unsigned __int64)lhs >= rhs )
2737 E::SafeIntOnOverflow();
2759 method = (
sizeof(
T ) <=
sizeof(
U ) ||
2768template < typename T, typename U, int Method = BinaryMethod< T, U >::method >
class BinaryAndHelper;
2773 static T And(
T lhs,
U rhs ){
return (
T)( lhs & rhs ); }
2783 return (
T)( lhs & (
unsigned __int8)rhs );
2794 return (
T)( lhs & (
unsigned __int16)rhs );
2805 return (
T)( lhs & (
unsigned __int32)rhs );
2809template < typename T, typename U, int Method = BinaryMethod< T, U >::method >
class BinaryOrHelper;
2814 static T Or(
T lhs,
U rhs ){
return (
T)( lhs | rhs ); }
2824 return (
T)( lhs | (
unsigned __int8)rhs );
2835 return (
T)( lhs | (
unsigned __int16)rhs );
2846 return (
T)( lhs | (
unsigned __int32)rhs );
2850template <typename T, typename U, int Method = BinaryMethod< T, U >::method >
class BinaryXorHelper;
2855 static T Xor(
T lhs,
U rhs ){
return (
T)( lhs ^ rhs ); }
2865 return (
T)( lhs ^ (
unsigned __int8)rhs );
2876 return (
T)( lhs ^ (
unsigned __int16)rhs );
2887 return (
T)( lhs ^ (
unsigned __int32)rhs );
static unsigned __int64 Abs(T t)
static unsigned __int32 Abs(T t)
static SafeIntError Addition(const T &lhs, const U &rhs, T &result)
static SafeIntError Addition(const T &lhs, const U &rhs, T &result)
static SafeIntError Addition(const T &lhs, const U &rhs, T &result)
static SafeIntError Addition(const T &lhs, const U &rhs, T &result)
static SafeIntError Addition(const T &lhs, const U &rhs, T &result)
static SafeIntError Addition(const T &lhs, const U &rhs, T &result)
static SafeIntError Addition(const T &lhs, const U &rhs, T &result)
static SafeIntError Addition(const T &lhs, const U &rhs, T &result)
static SafeIntError Addition(const T &lhs, const U &rhs, T &result)
static SafeIntError Addition(const T &lhs, const U &rhs, T &result)
static SafeIntError Addition(const T &lhs, const U &rhs, T &result)
static SafeIntError Addition(const T &lhs, const U &rhs, T &result)
static SafeIntError Addition(const T &lhs, const U &rhs, T &result)
static SafeIntError Addition(const T &lhs, const U &rhs, T &result)
static SafeIntError Addition(const __int64 &lhs, const unsigned __int64 &rhs, __int64 &result)
static T And(T lhs, U rhs)
static T And(T lhs, U rhs)
static T And(T lhs, U rhs)
static T And(T lhs, U rhs)
static T Or(T lhs, U rhs)
static T Or(T lhs, U rhs)
static T Or(T lhs, U rhs)
static T Or(T lhs, U rhs)
static T Xor(T lhs, U rhs)
static T Xor(T lhs, U rhs)
static T Xor(T lhs, U rhs)
static T Xor(T lhs, U rhs)
static SafeIntError Divide(const T &t, const U &u, T &result)
static SafeIntError Divide(const T &t, const U &u, T &result)
static SafeIntError Divide(const T &t, const U &u, T &result)
static SafeIntError Divide(const T &t, const U &u, T &result)
static SafeIntError Divide(const T &t, const U &u, T &result)
static SafeIntError Divide(const T &t, const unsigned __int64 &u, T &result)
static bool IsEquals(const T t, const U u)
static bool IsEquals(const T t, const U u)
static bool IsEquals(const T t, const U u)
static bool IsEquals(const T t, const U u)
static bool IsEquals(const T t, const U u)
static bool GreaterThan(const T t, const U u)
static bool GreaterThan(const T t, const U u)
static bool GreaterThan(const T t, const U u)
static bool GreaterThan(const T t, const U u)
static bool GreaterThan(const T t, const U u)
@ IntZone_UintLT32_Uint32
@ IntZone_IntLT32_IntLT32
@ IntZone_UintLT32_IntLT32
@ IntZone_IntLT32_UintLT32
@ IntZone_UintLT64_Uint64
@ IntZone_UintLT32_UintLT32
@ IntZone_Uint32_UintLT64
static SafeIntError RegMultiply(signed __int32 a, const signed __int64 &b, signed __int32 &ret)
static SafeIntError RegMultiply(signed __int32 a, const unsigned __int64 &b, signed __int32 &ret)
static SafeIntError RegMultiply(const signed __int64 &a, signed __int32 b, signed __int64 &ret)
static SafeIntError RegMultiply(const signed __int64 &a, const signed __int64 &b, signed __int64 &ret)
static SafeIntError RegMultiply(const signed __int64 &a, unsigned __int32 b, signed __int64 &ret)
static SafeIntError RegMultiply(const signed __int64 &a, const unsigned __int64 &b, signed __int64 &ret)
static SafeIntError RegMultiply(unsigned __int32 a, const signed __int64 &b, unsigned __int32 &ret)
static SafeIntError RegMultiply(unsigned __int32 a, const unsigned __int64 &b, unsigned __int32 &ret)
static SafeIntError RegMultiply(const unsigned __int64 &a, signed __int32 b, unsigned __int64 &ret)
static SafeIntError RegMultiply(const unsigned __int64 &a, signed __int64 b, unsigned __int64 &ret)
static SafeIntError RegMultiply(const unsigned __int64 &a, unsigned __int32 b, unsigned __int64 &ret)
static SafeIntError RegMultiply(const unsigned __int64 &a, const unsigned __int64 &b, unsigned __int64 &ret)
static SafeIntError Modulus(const T &t, const U &u, T &result)
static SafeIntError Modulus(const T &t, const U &u, T &result)
static SafeIntError Modulus(const T &t, const U &u, T &result)
static SafeIntError Modulus(const T &t, const U &u, T &result)
static SafeIntError Modulus(const T &t, const U &u, T &result)
static SafeIntError Multiply(const T &t, const U &u, T &ret)
static SafeIntError Multiply(const T &t, const U &u, T &ret)
static SafeIntError Multiply(const T &t, const U &u, T &ret)
static SafeIntError Multiply(const T &t, const U &u, T &ret)
static SafeIntError Multiply(T t, const __int64 &u, T &ret)
static SafeIntError Multiply(const T &t, const __int64 &u, T &ret)
static SafeIntError Multiply(T t, const unsigned __int64 &u, T &ret)
static SafeIntError Multiply(const T &t, const unsigned __int64 &u, T &ret)
static SafeIntError Multiply(const __int64 &t, U u, __int64 &ret)
static SafeIntError Multiply(const __int64 &t, const U &u, __int64 &ret)
static SafeIntError Multiply(const __int64 &t, const __int64 &u, __int64 &ret)
static SafeIntError Multiply(const __int64 &t, const unsigned __int64 &u, __int64 &ret)
static SafeIntError Multiply(const unsigned __int64 &t, const U &u, unsigned __int64 &ret)
static SafeIntError Multiply(const unsigned __int64 &t, const U &u, unsigned __int64 &ret)
static SafeIntError Multiply(const unsigned __int64 &t, const __int64 &u, unsigned __int64 &ret)
static SafeIntError Multiply(const unsigned __int64 &t, const unsigned __int64 &u, unsigned __int64 &ret)
static SafeIntError Negative(T t, T &ret)
static SafeIntError Negative(T t, T &ret)
static SafeIntError Cast(U u, T &t)
static SafeIntError Cast(U u, T &t)
static SafeIntError Cast(U u, T &t)
static SafeIntError Cast(U u, T &t)
static SafeIntError Cast(bool b, T &t)
static SafeIntError Cast(U u, T &t)
static SafeIntError Cast(U u, T &t)
static SafeIntError Cast(T t, bool &b)
static SafeIntError Subtract(const T &lhs, const U &rhs, U &result)
static SafeIntError Subtract(const T &lhs, const U &rhs, T &result)
static SafeIntError Subtract(const T &lhs, const U &rhs, T &result)
static SafeIntError Subtract(const T &lhs, const U &rhs, T &result)
static SafeIntError Subtract(const T &lhs, const U &rhs, T &result)
static SafeIntError Subtract(const T &lhs, const U &rhs, T &result)
static SafeIntError Subtract(const T &lhs, const U &rhs, T &result)
static SafeIntError Subtract(const T &lhs, const U &rhs, T &result)
static SafeIntError Subtract(const T &lhs, const U &rhs, T &result)
static SafeIntError Subtract(const T &lhs, const U &rhs, T &result)
static SafeIntError Subtract(const T &lhs, const U &rhs, T &result)
static SafeIntError Subtract(const T &lhs, const U &rhs, T &result)
static SafeIntError Subtract(const U &lhs, const T &rhs, T &result)
static SafeIntError Subtract(const U &lhs, const T &rhs, T &result)
static SafeIntError Subtract(const U &lhs, const T &rhs, T &result)
static SafeIntError Subtract(const U &lhs, const T &rhs, T &result)
static SafeIntError Subtract(const U &lhs, const T &rhs, T &result)
static SafeIntError Subtract(const U &lhs, const T &rhs, T &result)
static SafeIntError Subtract(const U &lhs, const T &rhs, T &result)
static SafeIntError Subtract(const U &lhs, const T &rhs, T &result)
static SafeIntError Subtract(const __int64 &lhs, const unsigned __int64 &rhs, unsigned __int64 &result)
static SafeIntError Subtract(const __int64 &lhs, const unsigned __int64 &rhs, __int64 &result)
unsigned int(__cdecl typeof(jpeg_read_scanlines))(struct jpeg_decompress_struct *
unsigned short(__cdecl typeof(TIFFCurrentDirectory))(struct tiff *)
GLboolean GLboolean GLboolean b
GLboolean GLboolean GLboolean GLboolean a
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble * u
static const struct update_accum a1
static CRYPT_DATA_BLOB b1[]
static const char mbstate_t *static wchar_t const char mbstate_t *static const wchar_t int *static double
static unsigned(__cdecl *hash_bstr)(bstr_t s)
static float(__cdecl *square_half_float)(float x
@ SubtractionState_BothUnsigned
@ SubtractionState_Int64Uint642
@ SubtractionState_Int64Uint2
@ SubtractionState_IntInt64
@ SubtractionState_UintInt64
@ SubtractionState_CastInt64CheckMinMax2
@ SubtractionState_UintInt642
@ SubtractionState_BothUnsigned2
@ SubtractionState_CastIntCheckMinMax
@ SubtractionState_CastIntCheckMin
@ SubtractionState_Int64Uint64
@ SubtractionState_CastInt64CheckMin
@ SubtractionState_Int64Int
@ SubtractionState_CastIntCheckMinMax2
@ SubtractionState_Int64Int2
@ SubtractionState_IntUint642
@ SubtractionState_CastInt64CheckMinMax
@ SubtractionState_Int64Uint
@ SubtractionState_Uint64Int2
@ SubtractionState_Uint64Int
@ SubtractionState_IntUint64
@ SubtractionState_IntInt642
@ MultiplicationState_UintInt64
@ MultiplicationState_CastInt
@ MultiplicationState_CastUint
@ MultiplicationState_Uint64Int
@ MultiplicationState_Int64Int
@ MultiplicationState_Uint64Int64
@ MultiplicationState_CastInt64
@ MultiplicationState_CastUint64
@ MultiplicationState_Int64Uint64
@ MultiplicationState_Int64Int64
@ MultiplicationState_Uint64Uint64
@ MultiplicationState_IntUint64
@ MultiplicationState_Error
@ MultiplicationState_Uint64Uint
@ MultiplicationState_Int64Uint
@ MultiplicationState_IntInt64
@ MultiplicationState_UintUint64
@ ComparisonMethod_UnsignedU
@ ComparisonMethod_CastInt64
@ ComparisonMethod_UnsignedT
@ ComparisonMethod_CastInt
@ AdditionState_ManualCheck
@ AdditionState_CastInt64CheckOverflowMax
@ AdditionState_CastUint64CheckOverflow
@ AdditionState_CastUint64CheckMinMax2
@ AdditionState_CastIntCheckMax
@ AdditionState_CastUintCheckOverflow
@ AdditionState_CastInt64CheckMax
@ AdditionState_ManualCheckInt64Uint64
@ AdditionState_CastIntCheckMinMax
@ AdditionState_CastInt64CheckOverflowMinMax
@ AdditionState_CastInt64CheckOverflow
@ AdditionState_CastUint64CheckMinMax
@ AdditionState_CastInt64CheckMinMax
@ AdditionState_CastUint64CheckOverflowMax
@ AdditionState_CastUintCheckOverflowMax
@ DivisionState_SignedUnsigned
@ DivisionState_SignedSigned
@ DivisionState_SignedUnsigned32
@ DivisionState_UnsignedSigned
@ DivisionState_SignedUnsigned64
@ CastCheckMinMaxUnsigned
@ SafeIntArithmeticOverflow
#define _SAFEINT_UNSIGNED_NEGATION_BEHAVIOR()
#define _SAFEINT_BINARY_ASSERT(x)
static void SafeIntOnDivZero()
static void SafeIntOnOverflow()