From a33f23cbbcd68c0f534d874052311672d0dcaf5d 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. PR-URL: https://github.com/joyent/node/pull/9375 Reviewed-By: Trevor Norris --- lib/buffer.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lib/buffer.js b/lib/buffer.js index dd6f7a37ab..1a9f7caeb5 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); }