summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--mojo/core/handle_table.cc12
1 files changed, 9 insertions, 3 deletions
diff --git a/mojo/core/handle_table.cc b/mojo/core/handle_table.cc
index e039c7108d..40700b7e86 100644
--- a/mojo/core/handle_table.cc
+++ b/mojo/core/handle_table.cc
@@ -65,13 +65,19 @@ bool HandleTable::AddDispatchersFromTransit(
const std::vector<Dispatcher::DispatcherInTransit>& dispatchers,
MojoHandle* handles) {
// Oops, we're out of handles.
- if (next_available_handle_ == MOJO_HANDLE_INVALID)
+ if (next_available_handle_ == MOJO_HANDLE_INVALID) {
return false;
+ }
+
+ // MOJO_HANDLE_INVALID is zero.
+ DCHECK_GE(next_available_handle_, 1u);
- DCHECK_LE(dispatchers.size(), std::numeric_limits<uint32_t>::max());
// If this insertion would cause handle overflow, we're out of handles.
- if (next_available_handle_ + dispatchers.size() < next_available_handle_)
+ const uint32_t num_handles_available =
+ std::numeric_limits<uint32_t>::max() - next_available_handle_ + 1;
+ if (num_handles_available < dispatchers.size()) {
return false;
+ }
for (size_t i = 0; i < dispatchers.size(); ++i) {
MojoHandle handle = MOJO_HANDLE_INVALID;