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

Function AddVerifyInt64Int16

Archive/releases/2/AddVerify.cpp:3920–3976  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3918};
3919
3920void AddVerifyInt64Int16()
3921{
3922 size_t i;
3923
3924 for( i = 0; i < COUNTOF(int64_int16); ++i )
3925 {
3926 __int64 ret;
3927 if( SafeAdd(int64_int16[i].x, int64_int16[i].y, ret) != int64_int16[i].fExpected )
3928 {
3929 cerr << "Error in case int64_int16: ";
3930 cerr << HEX(16) << int64_int16[i].x << ", ";
3931 cerr << HEX(4) << int64_int16[i].y << ", ";
3932 cerr << "expected = " << int64_int16[i].fExpected << endl;
3933 }
3934
3935 // Now test throwing version
3936 bool fSuccess = true;
3937 try
3938 {
3939 SafeInt<__int64> si(int64_int16[i].x);
3940 si += int64_int16[i].y;
3941 }
3942 catch(...)
3943 {
3944 fSuccess = false;
3945 }
3946
3947 if( fSuccess != int64_int16[i].fExpected )
3948 {
3949 cerr << "Error in case int64_int16 throw (1): ";
3950 cerr << HEX(16) << int64_int16[i].x << ", ";
3951 cerr << HEX(4) << int64_int16[i].y << ", ";
3952 cerr << "expected = " << int64_int16[i].fExpected << endl;
3953 }
3954
3955 // Also need to test the version that assigns back out
3956 // to a plain int, as it has different logic
3957 fSuccess = true;
3958 try
3959 {
3960 __int64 x(int64_int16[i].x);
3961 x += SafeInt<__int16>(int64_int16[i].y);
3962 }
3963 catch(...)
3964 {
3965 fSuccess = false;
3966 }
3967
3968 if( fSuccess != int64_int16[i].fExpected )
3969 {
3970 cerr << "Error in case int64_int16 throw (2): ";
3971 cerr << HEX(16) << int64_int16[i].x << ", ";
3972 cerr << HEX(4) << int64_int16[i].y << ", ";
3973 cerr << "expected = " << int64_int16[i].fExpected << endl;
3974 }
3975 }
3976}
3977

Callers 1

AddVerifyFunction · 0.70

Calls 1

SafeAddFunction · 0.50

Tested by

no test coverage detected