Skip to content

Commit 1cd794f

Browse files
indutnyrvagg
authored andcommitted
buffer: reapply 07c0667
Original commit message: 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 io.js should do this too for compatibility. PR-URL: #2487 Reviewed-By: Trevor Norris <[email protected]>
1 parent c1ce423 commit 1cd794f

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

lib/buffer.js

+11
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,15 @@ function createPool() {
2121
}
2222

2323

24+
function alignPool() {
25+
// Ensure aligned slices
26+
if (poolOffset & 0x7) {
27+
poolOffset |= 0x7;
28+
poolOffset++;
29+
}
30+
}
31+
32+
2433
function Buffer(arg) {
2534
// Common case.
2635
if (typeof arg === 'number') {
@@ -66,6 +75,7 @@ function allocate(size) {
6675
createPool();
6776
var b = binding.slice(allocPool, poolOffset, poolOffset + size);
6877
poolOffset += size;
78+
alignPool();
6979
return b;
7080
} else {
7181
return binding.create(size);
@@ -86,6 +96,7 @@ function fromString(string, encoding) {
8696
var actual = allocPool.write(string, poolOffset, encoding);
8797
var b = binding.slice(allocPool, poolOffset, poolOffset + actual);
8898
poolOffset += actual;
99+
alignPool();
89100
return b;
90101
}
91102

0 commit comments

Comments
 (0)