mirror of
https://github.com/Xahau/xahaud.git
synced 2025-12-06 17:27:52 +00:00
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:
committed by
Nik Bougalis
parent
494724578a
commit
148bbf4e8f
@@ -17,6 +17,7 @@
|
||||
*/
|
||||
//==============================================================================
|
||||
|
||||
#include <ripple/basics/safe_cast.h>
|
||||
#include <ripple/protocol/SField.h>
|
||||
#include <cassert>
|
||||
#include <map>
|
||||
@@ -358,7 +359,7 @@ SField::getField (int code)
|
||||
if (it != unknownCodeToField.end ())
|
||||
return * (it->second);
|
||||
return *(unknownCodeToField[code] = std::unique_ptr<SField const>(
|
||||
new SField(static_cast<SerializedTypeID>(type), field)));
|
||||
new SField(safe_cast<SerializedTypeID>(type), field)));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -385,7 +386,7 @@ std::string SField::getName () const
|
||||
if (fieldValue == 0)
|
||||
return "";
|
||||
|
||||
return std::to_string(static_cast<int> (fieldType)) + "/" +
|
||||
return std::to_string(safe_cast<int> (fieldType)) + "/" +
|
||||
std::to_string(fieldValue);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user