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

Function SubVerifyInt8Int16

Archive/releases/2/SubVerify.cpp:3289–3345  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3287};
3288
3289void SubVerifyInt8Int16()
3290{
3291 size_t i;
3292
3293 for( i = 0; i < COUNTOF(int8_int16); ++i )
3294 {
3295 __int8 ret;
3296 if( SafeSubtract(int8_int16[i].x, int8_int16[i].y, ret) != int8_int16[i].fExpected )
3297 {
3298 cerr << "Error in case int8_int16: ";
3299 cerr << hex << setw(2) << setfill('0') << (0xFF & (int)int8_int16[i].x) << ", ";
3300 cerr << hex << setw(4) << setfill('0') << int8_int16[i].y << ", ";
3301 cerr << "expected = " << int8_int16[i].fExpected << endl;
3302 }
3303
3304 // Now test throwing version
3305 bool fSuccess = true;
3306 try
3307 {
3308 SafeInt<__int8> si(int8_int16[i].x);
3309 si -= int8_int16[i].y;
3310 }
3311 catch(...)
3312 {
3313 fSuccess = false;
3314 }
3315
3316 if( fSuccess != int8_int16[i].fExpected )
3317 {
3318 cerr << "Error in case int8_int16 throw (1): ";
3319 cerr << hex << setw(2) << setfill('0') << (0xFF & (int)int8_int16[i].x) << ", ";
3320 cerr << hex << setw(4) << setfill('0') << int8_int16[i].y << ", ";
3321 cerr << "expected = " << int8_int16[i].fExpected << endl;
3322 }
3323
3324 // Also need to test the version that assigns back out
3325 // to a plain int, as it has different logic
3326 fSuccess = true;
3327 try
3328 {
3329 __int8 x(int8_int16[i].x);
3330 x -= SafeInt<__int64>(int8_int16[i].y);
3331 }
3332 catch(...)
3333 {
3334 fSuccess = false;
3335 }
3336
3337 if( fSuccess != int8_int16[i].fExpected )
3338 {
3339 cerr << "Error in case int8_int16 throw (2): ";
3340 cerr << hex << setw(2) << setfill('0') << (0xFF & (int)int8_int16[i].x) << ", ";
3341 cerr << hex << setw(4) << setfill('0') << int8_int16[i].y << ", ";
3342 cerr << "expected = " << int8_int16[i].fExpected << endl;
3343 }
3344 }
3345}
3346

Callers 1

SubVerifyFunction · 0.70

Calls 1

SafeSubtractFunction · 0.50

Tested by

no test coverage detected