Add safe_cast (RIPD-1702):

This change ensures that no overflow can occur when casting
between enums and integral types.
This commit is contained in:
Howard Hinnant
2018-12-21 17:13:58 -05:00
committed by Nik Bougalis
parent 494724578a
commit 148bbf4e8f
35 changed files with 213 additions and 86 deletions

View File

@@ -19,6 +19,7 @@
#include <ripple/basics/Log.h>
#include <ripple/basics/StringUtilities.h>
#include <ripple/basics/safe_cast.h>
#include <ripple/protocol/LedgerFormats.h>
#include <ripple/protocol/STInteger.h>
#include <ripple/protocol/TxFormats.h>
@@ -98,7 +99,7 @@ STUInt16::getText () const
if (getFName () == sfLedgerEntryType)
{
auto item = LedgerFormats::getInstance ().findByType (
static_cast <LedgerEntryType> (value_));
safe_cast<LedgerEntryType> (value_));
if (item != nullptr)
return item->getName ();
@@ -107,7 +108,7 @@ STUInt16::getText () const
if (getFName () == sfTransactionType)
{
auto item =TxFormats::getInstance().findByType (
static_cast <TxType> (value_));
safe_cast<TxType> (value_));
if (item != nullptr)
return item->getName ();
@@ -123,7 +124,7 @@ STUInt16::getJson (int) const
if (getFName () == sfLedgerEntryType)
{
auto item = LedgerFormats::getInstance ().findByType (
static_cast <LedgerEntryType> (value_));
safe_cast<LedgerEntryType> (value_));
if (item != nullptr)
return item->getName ();
@@ -132,7 +133,7 @@ STUInt16::getJson (int) const
if (getFName () == sfTransactionType)
{
auto item = TxFormats::getInstance().findByType (
static_cast <TxType> (value_));
safe_cast<TxType> (value_));
if (item != nullptr)
return item->getName ();