From 6ae2309f44db57c8eb4c5b44d77abe698a6bcb31 Mon Sep 17 00:00:00 2001 From: Fedor Indutny Date: Wed, 11 Mar 2015 07:28:05 -0700 Subject: [PATCH] buffer: align chunks on 8-byte boundary When slicing global pool - ensure that the underlying buffer's data ptr is 8-byte alignment to do not ruin expectations of 3rd party C++ addons. NOTE: 0.10 node.js always returned aligned pointers and v0.12 should do this too for compatibility. --- lib/buffer.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lib/buffer.js b/lib/buffer.js index dd6f7a37abe3..1a9f7caeb5ab 100644 --- a/lib/buffer.js +++ b/lib/buffer.js @@ -86,6 +86,12 @@ function Buffer(subject, encoding) { poolOffset, poolOffset + this.length); poolOffset += this.length; + + // Ensure aligned slices + if (poolOffset & 0x7) { + poolOffset |= 0x7; + poolOffset++; + } } else { alloc(this, this.length); }