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
@@ -20,6 +20,7 @@
|
||||
#ifndef RIPPLE_PROTOCOL_SFIELD_H_INCLUDED
|
||||
#define RIPPLE_PROTOCOL_SFIELD_H_INCLUDED
|
||||
|
||||
#include <ripple/basics/safe_cast.h>
|
||||
#include <ripple/json/json_value.h>
|
||||
#include <cstdint>
|
||||
#include <utility>
|
||||
@@ -86,7 +87,7 @@ inline
|
||||
int
|
||||
field_code(SerializedTypeID id, int index)
|
||||
{
|
||||
return (static_cast<int>(id) << 16) | index;
|
||||
return (safe_cast<int>(id) << 16) | index;
|
||||
}
|
||||
|
||||
// constexpr
|
||||
|
||||
Reference in New Issue
Block a user