Skip to content

Commit

Permalink
buffer: align chunks on 8-byte boundary
Browse files Browse the repository at this point in the history
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: #1126
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Trevor Norris <trev.norris@gmail.com>
Reviewed-by: Bert Belder <bertbelder@gmail.com>
  • Loading branch information
indutny committed Mar 11, 2015
1 parent d33a647 commit 07c0667
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions lib/buffer.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,12 @@ function palloc(that, length) {
var buf = sliceOnto(allocPool, that, start, end);
poolOffset = end;

// Ensure aligned slices
if (poolOffset & 0x7) {
poolOffset |= 0x7;
poolOffset++;
}

return buf;
}

Expand Down

0 comments on commit 07c0667

Please sign in to comment.