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

Function SubVerifyInt8Int8

Archive/releases/2/SubVerify.cpp:3440–3496  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3438};
3439
3440void SubVerifyInt8Int8()
3441{
3442 size_t i;
3443
3444 for( i = 0; i < COUNTOF(int8_int8); ++i )
3445 {
3446 __int8 ret;
3447 if( SafeSubtract(int8_int8[i].x, int8_int8[i].y, ret) != int8_int8[i].fExpected )
3448 {
3449 cerr << "Error in case int8_int8: ";
3450 cerr << hex << setw(2) << setfill('0') << (0xFF & (int)int8_int8[i].x) << ", ";
3451 cerr << hex << setw(2) << setfill('0') << (0xFF & (int)int8_int8[i].y) << ", ";
3452 cerr << "expected = " << int8_int8[i].fExpected << endl;
3453 }
3454
3455 // Now test throwing version
3456 bool fSuccess = true;
3457 try
3458 {
3459 SafeInt<__int8> si(int8_int8[i].x);
3460 si -= int8_int8[i].y;
3461 }
3462 catch(...)
3463 {
3464 fSuccess = false;
3465 }
3466
3467 if( fSuccess != int8_int8[i].fExpected )
3468 {
3469 cerr << "Error in case int8_int8 throw (1): ";
3470 cerr << hex << setw(2) << setfill('0') << (0xFF & (int)int8_int8[i].x) << ", ";
3471 cerr << hex << setw(2) << setfill('0') << (0xFF & (int)int8_int8[i].y) << ", ";
3472 cerr << "expected = " << int8_int8[i].fExpected << endl;
3473 }
3474
3475 // Also need to test the version that assigns back out
3476 // to a plain int, as it has different logic
3477 fSuccess = true;
3478 try
3479 {
3480 __int8 x(int8_int8[i].x);
3481 x -= SafeInt<__int64>(int8_int8[i].y);
3482 }
3483 catch(...)
3484 {
3485 fSuccess = false;
3486 }
3487
3488 if( fSuccess != int8_int8[i].fExpected )
3489 {
3490 cerr << "Error in case int8_int8 throw (2): ";
3491 cerr << hex << setw(2) << setfill('0') << (0xFF & (int)int8_int8[i].x) << ", ";
3492 cerr << hex << setw(2) << setfill('0') << (0xFF & (int)int8_int8[i].y) << ", ";
3493 cerr << "expected = " << int8_int8[i].fExpected << endl;
3494 }
3495 }
3496}
3497

Callers 1

SubVerifyFunction · 0.70

Calls 1

SafeSubtractFunction · 0.50

Tested by

no test coverage detected