summaryrefslogtreecommitdiffstats
path: root/mojo/edk/system/data_pipe.cc
diff options
context:
space:
mode:
Diffstat (limited to 'mojo/edk/system/data_pipe.cc')
-rw-r--r--mojo/edk/system/data_pipe.cc17
1 files changed, 12 insertions, 5 deletions
diff --git a/mojo/edk/system/data_pipe.cc b/mojo/edk/system/data_pipe.cc
index 3f53798..54a6df4 100644
--- a/mojo/edk/system/data_pipe.cc
+++ b/mojo/edk/system/data_pipe.cc
@@ -8,6 +8,9 @@
#include <stdint.h>
#include <string.h>
+#include <algorithm>
+#include <limits>
+
#include "mojo/edk/system/configuration.h"
#include "mojo/edk/system/options_validation.h"
#include "mojo/edk/system/raw_channel.h"
@@ -18,17 +21,17 @@ namespace edk {
namespace {
-const size_t kInvalidDataPipeHandleIndex = static_cast<size_t>(-1);
+const uint32_t kInvalidDataPipeHandleIndex = static_cast<uint32_t>(-1);
struct MOJO_ALIGNAS(8) SerializedDataPipeHandleDispatcher {
- size_t platform_handle_index; // (Or |kInvalidDataPipeHandleIndex|.)
+ uint32_t platform_handle_index; // (Or |kInvalidDataPipeHandleIndex|.)
// These are from MojoCreateDataPipeOptions
MojoCreateDataPipeOptionsFlags flags;
uint32_t element_num_bytes;
uint32_t capacity_num_bytes;
- size_t shared_memory_handle_index; // (Or |kInvalidDataPipeHandleIndex|.)
+ uint32_t shared_memory_handle_index; // (Or |kInvalidDataPipeHandleIndex|.)
uint32_t shared_memory_size;
};
@@ -119,7 +122,9 @@ void DataPipe::EndSerialize(const MojoCreateDataPipeOptions& options,
SerializedDataPipeHandleDispatcher* serialization =
static_cast<SerializedDataPipeHandleDispatcher*>(destination);
if (channel_handle.is_valid()) {
- serialization->platform_handle_index = platform_handles->size();
+ DCHECK(platform_handles->size() < std::numeric_limits<uint32_t>::max());
+ serialization->platform_handle_index =
+ static_cast<uint32_t>(platform_handles->size());
platform_handles->push_back(channel_handle.release());
} else {
serialization->platform_handle_index = kInvalidDataPipeHandleIndex;
@@ -131,7 +136,9 @@ void DataPipe::EndSerialize(const MojoCreateDataPipeOptions& options,
serialization->shared_memory_size = static_cast<uint32_t>(shared_memory_size);
if (serialization->shared_memory_size) {
- serialization->shared_memory_handle_index = platform_handles->size();
+ DCHECK(platform_handles->size() < std::numeric_limits<uint32_t>::max());
+ serialization->shared_memory_handle_index =
+ static_cast<uint32_t>(platform_handles->size());
platform_handles->push_back(shared_memory_handle.release());
} else {
serialization->shared_memory_handle_index = kInvalidDataPipeHandleIndex;