summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFedor Indutny <fedor@indutny.com>2015-03-11 07:28:05 -0700
committerFedor Indutny <fedor@indutny.com>2015-03-11 11:47:54 -0700
commita33f23cbbcd68c0f534d874052311672d0dcaf5d (patch)
tree30b522a96bdf0b4cf8a2026fcb64085658e66c1b
parentcc6ee3f010fe8b6f5d92097b56311e566bb2a8ac (diff)
downloadnode-a33f23cbbcd68c0f534d874052311672d0dcaf5d.tar.gz
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 <trev.norris@gmail.com>
-rw-r--r--lib/buffer.js6
1 files changed, 6 insertions, 0 deletions
diff --git a/lib/buffer.js b/lib/buffer.js
index dd6f7a37a..1a9f7caeb 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);
}