Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(544)

Unified Diff: mojo/public/cpp/bindings/lib/validation_util.h

Issue 2202023005: Mojo C++ bindings: inline pointer encoding/decoding/validating functions. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@85_inline_data_view
Patch Set: . Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « mojo/public/cpp/bindings/lib/bindings_internal.cc ('k') | mojo/public/cpp/bindings/lib/validation_util.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: mojo/public/cpp/bindings/lib/validation_util.h
diff --git a/mojo/public/cpp/bindings/lib/validation_util.h b/mojo/public/cpp/bindings/lib/validation_util.h
index c883392ebc13fae00fd7e629644a5bca880556ae..1c6c53cb23eba61f6139a66e712ba6055d5628b9 100644
--- a/mojo/public/cpp/bindings/lib/validation_util.h
+++ b/mojo/public/cpp/bindings/lib/validation_util.h
@@ -19,7 +19,15 @@ namespace internal {
// Checks whether decoding the pointer will overflow and produce a pointer
// smaller than |offset|.
-bool ValidateEncodedPointer(const uint64_t* offset);
+inline bool ValidateEncodedPointer(const uint64_t* offset) {
+ // - Make sure |*offset| is no more than 32-bits.
+ // - Cast |offset| to uintptr_t so overflow behavior is well defined across
+ // 32-bit and 64-bit systems.
+ return *offset <= std::numeric_limits<uint32_t>::max() &&
+ (reinterpret_cast<uintptr_t>(offset) +
+ static_cast<uint32_t>(*offset) >=
+ reinterpret_cast<uintptr_t>(offset));
+}
template <typename T>
bool ValidatePointer(const Pointer<T>& input,
« no previous file with comments | « mojo/public/cpp/bindings/lib/bindings_internal.cc ('k') | mojo/public/cpp/bindings/lib/validation_util.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698