diff options
author | Andreas Gampe <agampe@google.com> | 2015-04-25 14:44:29 -0700 |
---|---|---|
committer | Andreas Gampe <agampe@google.com> | 2015-04-25 17:07:07 -0700 |
commit | e34a42cd37b2b3b6b21280df14fa6f40917b5d6e (patch) | |
tree | b9a9362bdd3db787caffbe9ab72b3b3ad810bff9 /runtime/base | |
parent | 3f4fa70a251443b7e35ee0464120e53daf4ae9c1 (diff) | |
download | art-e34a42cd37b2b3b6b21280df14fa6f40917b5d6e.tar.gz art-e34a42cd37b2b3b6b21280df14fa6f40917b5d6e.tar.bz2 art-e34a42cd37b2b3b6b21280df14fa6f40917b5d6e.zip |
ART: Fix Trace types, check minimum buf size
Also make streaming mode adhere to the given buffer (and fix the
case where the buffer is too small for a packet). This is important
to not lose too much tracing information when the runtime is destroyed
with an unflushed buffer.
Change-Id: I6525fe4326ac5c3d7c9cda41c54a2a911ca889b7
Diffstat (limited to 'runtime/base')
-rw-r--r-- | runtime/base/casts.h | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/runtime/base/casts.h b/runtime/base/casts.h index c7e39a29fb..f8846498df 100644 --- a/runtime/base/casts.h +++ b/runtime/base/casts.h @@ -18,9 +18,11 @@ #define ART_RUNTIME_BASE_CASTS_H_ #include <assert.h> +#include <limits> #include <string.h> #include <type_traits> +#include "base/logging.h" #include "base/macros.h" namespace art { @@ -83,6 +85,23 @@ inline Dest bit_cast(const Source& source) { return dest; } +// A version of static_cast that DCHECKs that the value can be precisely represented +// when converting to Dest. +template <typename Dest, typename Source> +inline Dest dchecked_integral_cast(const Source source) { + DCHECK( + // Check that the value is within the lower limit of Dest. + (static_cast<intmax_t>(std::numeric_limits<Dest>::min()) <= + static_cast<intmax_t>(std::numeric_limits<Source>::min()) || + source >= static_cast<Source>(std::numeric_limits<Dest>::min())) && + // Check that the value is within the upper limit of Dest. + (static_cast<uintmax_t>(std::numeric_limits<Dest>::max()) >= + static_cast<uintmax_t>(std::numeric_limits<Source>::max()) || + source <= static_cast<Source>(std::numeric_limits<Dest>::max()))); + + return static_cast<Dest>(source); +} + } // namespace art #endif // ART_RUNTIME_BASE_CASTS_H_ |