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

Function AddVerifyUint64Int32

Archive/releases/2/AddVerify.cpp:1625–1681  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1623};
1624
1625void AddVerifyUint64Int32()
1626{
1627 size_t i;
1628
1629 for( i = 0; i < COUNTOF(uint64_int32); ++i )
1630 {
1631 unsigned __int64 ret;
1632 if( SafeAdd(uint64_int32[i].x, uint64_int32[i].y, ret) != uint64_int32[i].fExpected )
1633 {
1634 cerr << "Error in case uint64_int32: ";
1635 cerr << HEX(16) << uint64_int32[i].x << ", ";
1636 cerr << HEX(8) << uint64_int32[i].y << ", ";
1637 cerr << "expected = " << uint64_int32[i].fExpected << endl;
1638 }
1639
1640 // Now test throwing version
1641 bool fSuccess = true;
1642 try
1643 {
1644 SafeInt<unsigned __int64> si(uint64_int32[i].x);
1645 si += uint64_int32[i].y;
1646 }
1647 catch(...)
1648 {
1649 fSuccess = false;
1650 }
1651
1652 if( fSuccess != uint64_int32[i].fExpected )
1653 {
1654 cerr << "Error in case uint64_int32 throw (1): ";
1655 cerr << HEX(16) << uint64_int32[i].x << ", ";
1656 cerr << HEX(8) << uint64_int32[i].y << ", ";
1657 cerr << "expected = " << uint64_int32[i].fExpected << endl;
1658 }
1659
1660 // Also need to test the version that assigns back out
1661 // to a plain int, as it has different logic
1662 fSuccess = true;
1663 try
1664 {
1665 unsigned __int64 x(uint64_int32[i].x);
1666 x += SafeInt<__int32>(uint64_int32[i].y);
1667 }
1668 catch(...)
1669 {
1670 fSuccess = false;
1671 }
1672
1673 if( fSuccess != uint64_int32[i].fExpected )
1674 {
1675 cerr << "Error in case uint64_int32 throw (2): ";
1676 cerr << HEX(16) << uint64_int32[i].x << ", ";
1677 cerr << HEX(8) << uint64_int32[i].y << ", ";
1678 cerr << "expected = " << uint64_int32[i].fExpected << endl;
1679 }
1680 }
1681}
1682

Callers 1

AddVerifyFunction · 0.70

Calls 1

SafeAddFunction · 0.50

Tested by

no test coverage detected