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

Function SubVerifyInt64Int16

Archive/releases/2/SubVerify.cpp:2533–2589  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2531};
2532
2533void SubVerifyInt64Int16()
2534{
2535 size_t i;
2536
2537 for( i = 0; i < COUNTOF(int64_int16); ++i )
2538 {
2539 __int64 ret;
2540 if( SafeSubtract(int64_int16[i].x, int64_int16[i].y, ret) != int64_int16[i].fExpected )
2541 {
2542 cerr << "Error in case int64_int16: ";
2543 cerr << hex << setw(16) << setfill('0') << int64_int16[i].x << ", ";
2544 cerr << hex << setw(4) << setfill('0') << int64_int16[i].y << ", ";
2545 cerr << "expected = " << int64_int16[i].fExpected << endl;
2546 }
2547
2548 // Now test throwing version
2549 bool fSuccess = true;
2550 try
2551 {
2552 SafeInt<__int64> si(int64_int16[i].x);
2553 si -= int64_int16[i].y;
2554 }
2555 catch(...)
2556 {
2557 fSuccess = false;
2558 }
2559
2560 if( fSuccess != int64_int16[i].fExpected )
2561 {
2562 cerr << "Error in case int64_int16 throw (1): ";
2563 cerr << hex << setw(16) << setfill('0') << int64_int16[i].x << ", ";
2564 cerr << hex << setw(4) << setfill('0') << int64_int16[i].y << ", ";
2565 cerr << "expected = " << int64_int16[i].fExpected << endl;
2566 }
2567
2568 // Also need to test the version that assigns back out
2569 // to a plain int, as it has different logic
2570 fSuccess = true;
2571 try
2572 {
2573 __int64 x(int64_int16[i].x);
2574 x -= SafeInt<__int64>(int64_int16[i].y);
2575 }
2576 catch(...)
2577 {
2578 fSuccess = false;
2579 }
2580
2581 if( fSuccess != int64_int16[i].fExpected )
2582 {
2583 cerr << "Error in case int64_int16 throw (2): ";
2584 cerr << hex << setw(16) << setfill('0') << int64_int16[i].x << ", ";
2585 cerr << hex << setw(4) << setfill('0') << int64_int16[i].y << ", ";
2586 cerr << "expected = " << int64_int16[i].fExpected << endl;
2587 }
2588 }
2589}
2590

Callers 1

SubVerifyFunction · 0.70

Calls 1

SafeSubtractFunction · 0.50

Tested by

no test coverage detected