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

Function SubVerifyInt64Int64

Archive/releases/2/SubVerify.cpp:2087–2143  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2085};
2086
2087void SubVerifyInt64Int64()
2088{
2089 size_t i;
2090
2091 for( i = 0; i < COUNTOF(int64_int64); ++i )
2092 {
2093 __int64 ret;
2094 if( SafeSubtract(int64_int64[i].x, int64_int64[i].y, ret) != int64_int64[i].fExpected )
2095 {
2096 cerr << "Error in case int64_int64: ";
2097 cerr << hex << setw(16) << setfill('0') << int64_int64[i].x << ", ";
2098 cerr << hex << setw(16) << setfill('0') << int64_int64[i].y << ", ";
2099 cerr << "expected = " << int64_int64[i].fExpected << endl;
2100 }
2101
2102 // Now test throwing version
2103 bool fSuccess = true;
2104 try
2105 {
2106 SafeInt<__int64> si(int64_int64[i].x);
2107 si -= int64_int64[i].y;
2108 }
2109 catch(...)
2110 {
2111 fSuccess = false;
2112 }
2113
2114 if( fSuccess != int64_int64[i].fExpected )
2115 {
2116 cerr << "Error in case int64_int64 throw (1): ";
2117 cerr << hex << setw(16) << setfill('0') << int64_int64[i].x << ", ";
2118 cerr << hex << setw(16) << setfill('0') << int64_int64[i].y << ", ";
2119 cerr << "expected = " << int64_int64[i].fExpected << endl;
2120 }
2121
2122 // Also need to test the version that assigns back out
2123 // to a plain int, as it has different logic
2124 fSuccess = true;
2125 try
2126 {
2127 __int64 x(int64_int64[i].x);
2128 x -= SafeInt<__int64>(int64_int64[i].y);
2129 }
2130 catch(...)
2131 {
2132 fSuccess = false;
2133 }
2134
2135 if( fSuccess != int64_int64[i].fExpected )
2136 {
2137 cerr << "Error in case int64_int64 throw (2): ";
2138 cerr << hex << setw(16) << setfill('0') << int64_int64[i].x << ", ";
2139 cerr << hex << setw(16) << setfill('0') << int64_int64[i].y << ", ";
2140 cerr << "expected = " << int64_int64[i].fExpected << endl;
2141 }
2142 }
2143}
2144

Callers 1

SubVerifyFunction · 0.70

Calls 1

SafeSubtractFunction · 0.50

Tested by

no test coverage detected