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

Unified Diff: mojo/public/cpp/bindings/lib/bindings_serialization.cc

Issue 265403003: Make sure that ScratchBuffer::Allocate() always return 8-byte aligned address. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix on-stack allocation alignment. Created 6 years, 7 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
Index: mojo/public/cpp/bindings/lib/bindings_serialization.cc
diff --git a/mojo/public/cpp/bindings/lib/bindings_serialization.cc b/mojo/public/cpp/bindings/lib/bindings_serialization.cc
index fc574d77e7ed5bce951a37dd3183c1aeb6d921e2..5e60c65a5c4b52e8e89a46b36ab368958d2c6696 100644
--- a/mojo/public/cpp/bindings/lib/bindings_serialization.cc
+++ b/mojo/public/cpp/bindings/lib/bindings_serialization.cc
@@ -11,9 +11,22 @@
namespace mojo {
namespace internal {
-size_t Align(size_t size) {
+namespace {
+
+template<typename T>
+T AlignImpl(T t) {
const size_t kAlignment = 8;
- return size + (kAlignment - (size % kAlignment)) % kAlignment;
+ return t + (kAlignment - (t % kAlignment)) % kAlignment;
+}
+
+} // namespace
+
+size_t Align(size_t size) {
+ return AlignImpl(size);
+}
+
+char* AlignPointer(char* ptr) {
+ return reinterpret_cast<char*>(AlignImpl(reinterpret_cast<uintptr_t>(ptr)));
}
void EncodePointer(const void* ptr, uint64_t* offset) {

Powered by Google App Engine
This is Rietveld 408576698