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

Function SubVerifyInt64Int32

Archive/releases/2/SubVerify.cpp:2310–2366  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2308};
2309
2310void SubVerifyInt64Int32()
2311{
2312 size_t i;
2313
2314 for( i = 0; i < COUNTOF(int64_int32); ++i )
2315 {
2316 __int64 ret;
2317 if( SafeSubtract(int64_int32[i].x, int64_int32[i].y, ret) != int64_int32[i].fExpected )
2318 {
2319 cerr << "Error in case int64_int32: ";
2320 cerr << hex << setw(16) << setfill('0') << int64_int32[i].x << ", ";
2321 cerr << hex << setw(8) << setfill('0') << int64_int32[i].y << ", ";
2322 cerr << "expected = " << int64_int32[i].fExpected << endl;
2323 }
2324
2325 // Now test throwing version
2326 bool fSuccess = true;
2327 try
2328 {
2329 SafeInt<__int64> si(int64_int32[i].x);
2330 si -= int64_int32[i].y;
2331 }
2332 catch(...)
2333 {
2334 fSuccess = false;
2335 }
2336
2337 if( fSuccess != int64_int32[i].fExpected )
2338 {
2339 cerr << "Error in case int64_int32 throw (1): ";
2340 cerr << hex << setw(16) << setfill('0') << int64_int32[i].x << ", ";
2341 cerr << hex << setw(8) << setfill('0') << int64_int32[i].y << ", ";
2342 cerr << "expected = " << int64_int32[i].fExpected << endl;
2343 }
2344
2345 // Also need to test the version that assigns back out
2346 // to a plain int, as it has different logic
2347 fSuccess = true;
2348 try
2349 {
2350 __int64 x(int64_int32[i].x);
2351 x -= SafeInt<__int64>(int64_int32[i].y);
2352 }
2353 catch(...)
2354 {
2355 fSuccess = false;
2356 }
2357
2358 if( fSuccess != int64_int32[i].fExpected )
2359 {
2360 cerr << "Error in case int64_int32 throw (2): ";
2361 cerr << hex << setw(16) << setfill('0') << int64_int32[i].x << ", ";
2362 cerr << hex << setw(8) << setfill('0') << int64_int32[i].y << ", ";
2363 cerr << "expected = " << int64_int32[i].fExpected << endl;
2364 }
2365 }
2366}
2367

Callers 1

SubVerifyFunction · 0.70

Calls 1

SafeSubtractFunction · 0.50

Tested by

no test coverage detected