// Copyright 2016 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. namespace WTF { template bool IsInBounds(From value) { return true; } template To SafeCast(From value) { if (!IsInBounds(value)) return 0; return static_cast(value); } template class Checked { public: template Checked(const Checked& rhs) { if (rhs.HasOverflowed()) this->Overflowed(); if (!IsInBounds(rhs.value_)) this->Overflowed(); value_ = static_cast(rhs.value_); } bool HasOverflowed() const { return false; } void Overflowed() {} private: T value_; }; template To bitwise_cast(From from) { static_assert(sizeof(To) == sizeof(From), "msg"); return reinterpret_cast(from); } } // namespace WTF namespace mojo { template struct ArrayTraits; template struct ArrayTraits> { static bool HasOverflowed(WTF::Checked& input) { // |hasOverflowed| below should be rewritten to |HasOverflowed| // (because this is a method of WTF::Checked; it doesn't matter // that we are not in WTF namespace *here*). return input.HasOverflowed(); } }; } // namespace mojo using WTF::bitwise_cast; using WTF::SafeCast;