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

Function SubVerifyInt64Int8

Archive/releases/2/SubVerify.cpp:2756–2812  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2754};
2755
2756void SubVerifyInt64Int8()
2757{
2758 size_t i;
2759
2760 for( i = 0; i < COUNTOF(int64_int8); ++i )
2761 {
2762 __int64 ret;
2763 if( SafeSubtract(int64_int8[i].x, int64_int8[i].y, ret) != int64_int8[i].fExpected )
2764 {
2765 cerr << "Error in case int64_int8: ";
2766 cerr << hex << setw(16) << setfill('0') << int64_int8[i].x << ", ";
2767 cerr << hex << setw(2) << setfill('0') << (0xFF & (int)int64_int8[i].y) << ", ";
2768 cerr << "expected = " << int64_int8[i].fExpected << endl;
2769 }
2770
2771 // Now test throwing version
2772 bool fSuccess = true;
2773 try
2774 {
2775 SafeInt<__int64> si(int64_int8[i].x);
2776 si -= int64_int8[i].y;
2777 }
2778 catch(...)
2779 {
2780 fSuccess = false;
2781 }
2782
2783 if( fSuccess != int64_int8[i].fExpected )
2784 {
2785 cerr << "Error in case int64_int8 throw (1): ";
2786 cerr << hex << setw(16) << setfill('0') << int64_int8[i].x << ", ";
2787 cerr << hex << setw(2) << setfill('0') << (0xFF & (int)int64_int8[i].y) << ", ";
2788 cerr << "expected = " << int64_int8[i].fExpected << endl;
2789 }
2790
2791 // Also need to test the version that assigns back out
2792 // to a plain int, as it has different logic
2793 fSuccess = true;
2794 try
2795 {
2796 __int64 x(int64_int8[i].x);
2797 x -= SafeInt<__int64>(int64_int8[i].y);
2798 }
2799 catch(...)
2800 {
2801 fSuccess = false;
2802 }
2803
2804 if( fSuccess != int64_int8[i].fExpected )
2805 {
2806 cerr << "Error in case int64_int8 throw (2): ";
2807 cerr << hex << setw(16) << setfill('0') << int64_int8[i].x << ", ";
2808 cerr << hex << setw(2) << setfill('0') << (0xFF & (int)int64_int8[i].y) << ", ";
2809 cerr << "expected = " << int64_int8[i].fExpected << endl;
2810 }
2811 }
2812}
2813

Callers 1

SubVerifyFunction · 0.70

Calls 1

SafeSubtractFunction · 0.50

Tested by

no test coverage detected