MCPcopy Create free account
hub / github.com/dcleblanc/SafeInt / SubVerifyInt8Int64

Function SubVerifyInt8Int64

Archive/releases/2/SubVerify.cpp:2987–3043  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2985};
2986
2987void SubVerifyInt8Int64()
2988{
2989 size_t i;
2990
2991 for( i = 0; i < COUNTOF(int8_int64); ++i )
2992 {
2993 __int8 ret;
2994 if( SafeSubtract(int8_int64[i].x, int8_int64[i].y, ret) != int8_int64[i].fExpected )
2995 {
2996 cerr << "Error in case int8_int64: ";
2997 cerr << hex << setw(2) << setfill('0') << (0xFF & (int)int8_int64[i].x) << ", ";
2998 cerr << hex << setw(16) << setfill('0') << int8_int64[i].y << ", ";
2999 cerr << "expected = " << int8_int64[i].fExpected << endl;
3000 }
3001
3002 // Now test throwing version
3003 bool fSuccess = true;
3004 try
3005 {
3006 SafeInt<__int8> si(int8_int64[i].x);
3007 si -= int8_int64[i].y;
3008 }
3009 catch(...)
3010 {
3011 fSuccess = false;
3012 }
3013
3014 if( fSuccess != int8_int64[i].fExpected )
3015 {
3016 cerr << "Error in case int8_int64 throw (1): ";
3017 cerr << hex << setw(2) << setfill('0') << (0xFF & (int)int8_int64[i].x) << ", ";
3018 cerr << hex << setw(16) << setfill('0') << int8_int64[i].y << ", ";
3019 cerr << "expected = " << int8_int64[i].fExpected << endl;
3020 }
3021
3022 // Also need to test the version that assigns back out
3023 // to a plain int, as it has different logic
3024 fSuccess = true;
3025 try
3026 {
3027 __int8 x(int8_int64[i].x);
3028 x -= SafeInt<__int64>(int8_int64[i].y);
3029 }
3030 catch(...)
3031 {
3032 fSuccess = false;
3033 }
3034
3035 if( fSuccess != int8_int64[i].fExpected )
3036 {
3037 cerr << "Error in case int8_int64 throw (2): ";
3038 cerr << hex << setw(2) << setfill('0') << (0xFF & (int)int8_int64[i].x) << ", ";
3039 cerr << hex << setw(16) << setfill('0') << int8_int64[i].y << ", ";
3040 cerr << "expected = " << int8_int64[i].fExpected << endl;
3041 }
3042 }
3043}
3044

Callers 1

SubVerifyFunction · 0.70

Calls 1

SafeSubtractFunction · 0.50

Tested by

no test coverage detected