Skip to content

Commit

Permalink
smalloc: fix copyOnto optimization
Browse files Browse the repository at this point in the history
copyOnto is broken when one argument has 1 byte size and the other > 1
byte.

PR-URL: nodejs/node-v0.x-archive#8637
Reviewed-by: Trevor Norris <[email protected]>
  • Loading branch information
vkurchatkin authored and trevnorris committed Oct 30, 2014
1 parent c2b4f48 commit 849fcde
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/smalloc.cc
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ void CopyOnto(const FunctionCallbackInfo<Value>& args) {
size_t dest_size = ExternalArraySize(dest_type);

// optimization for Uint8 arrays (i.e. Buffers)
if (source_size != 1 && dest_size != 1) {
if (source_size != 1 || dest_size != 1) {
if (source_size == 0)
return env->ThrowTypeError("unknown source external array type");
if (dest_size == 0)
Expand Down
14 changes: 14 additions & 0 deletions test/simple/test-smalloc.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,20 @@ if (os.endianness() === 'LE') {
copyOnto(c, 0, b, 0, 2);
assert.equal(b[0], 0.1);

var b = alloc(1, Types.Uint16);
var c = alloc(2, Types.Uint8);
c[0] = c[1] = 0xff;
copyOnto(c, 0, b, 0, 2);
assert.equal(b[0], 0xffff);

var b = alloc(2, Types.Uint8);
var c = alloc(1, Types.Uint16);
c[0] = 0xffff;
copyOnto(c, 0, b, 0, 1);
assert.equal(b[0], 0xff);
assert.equal(b[1], 0xff);



// verify checking external if has external memory

Expand Down

0 comments on commit 849fcde

Please sign in to comment.