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

Function SubVerifyInt8Int32

Archive/releases/2/SubVerify.cpp:3138–3194  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3136};
3137
3138void SubVerifyInt8Int32()
3139{
3140 size_t i;
3141
3142 for( i = 0; i < COUNTOF(int8_int32); ++i )
3143 {
3144 __int8 ret;
3145 if( SafeSubtract(int8_int32[i].x, int8_int32[i].y, ret) != int8_int32[i].fExpected )
3146 {
3147 cerr << "Error in case int8_int32: ";
3148 cerr << hex << setw(2) << setfill('0') << (0xFF & (int)int8_int32[i].x) << ", ";
3149 cerr << hex << setw(8) << setfill('0') << int8_int32[i].y << ", ";
3150 cerr << "expected = " << int8_int32[i].fExpected << endl;
3151 }
3152
3153 // Now test throwing version
3154 bool fSuccess = true;
3155 try
3156 {
3157 SafeInt<__int8> si(int8_int32[i].x);
3158 si -= int8_int32[i].y;
3159 }
3160 catch(...)
3161 {
3162 fSuccess = false;
3163 }
3164
3165 if( fSuccess != int8_int32[i].fExpected )
3166 {
3167 cerr << "Error in case int8_int32 throw (1): ";
3168 cerr << hex << setw(2) << setfill('0') << (0xFF & (int)int8_int32[i].x) << ", ";
3169 cerr << hex << setw(8) << setfill('0') << int8_int32[i].y << ", ";
3170 cerr << "expected = " << int8_int32[i].fExpected << endl;
3171 }
3172
3173 // Also need to test the version that assigns back out
3174 // to a plain int, as it has different logic
3175 fSuccess = true;
3176 try
3177 {
3178 __int8 x(int8_int32[i].x);
3179 x -= SafeInt<__int64>(int8_int32[i].y);
3180 }
3181 catch(...)
3182 {
3183 fSuccess = false;
3184 }
3185
3186 if( fSuccess != int8_int32[i].fExpected )
3187 {
3188 cerr << "Error in case int8_int32 throw (2): ";
3189 cerr << hex << setw(2) << setfill('0') << (0xFF & (int)int8_int32[i].x) << ", ";
3190 cerr << hex << setw(8) << setfill('0') << int8_int32[i].y << ", ";
3191 cerr << "expected = " << int8_int32[i].fExpected << endl;
3192 }
3193 }
3194}
3195

Callers 1

SubVerifyFunction · 0.70

Calls 1

SafeSubtractFunction · 0.50

Tested by

no test coverage detected