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 <trev.norris@gmail.com>
1 parent c1ce423 commit 1cd794f

1 file changed

Lines changed: 11 additions & 0 deletions

File tree

‎lib/buffer.js‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,15 @@ function createPool() {
2121
}
2222

2323

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

0 commit comments

Comments
 (0)