Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/internal/buffer.js
Original file line number Diff line number Diff line change
Expand Up @@ -667,7 +667,7 @@ function writeU_Int16BE(buf, value, offset, min, max) {
}

function writeUInt16BE(value, offset = 0) {
return writeU_Int16BE(this, value, offset, 0, 0xffffffff);
return writeU_Int16BE(this, value, offset, 0, 0xffff);
}

function writeIntLE(value, offset, byteLength) {
Expand Down
12 changes: 12 additions & 0 deletions test/parallel/test-buffer-writeuint.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,18 @@ const assert = require('assert');

data.writeUInt16BE(value, 0);
assert.ok(data.equals(new Uint8Array([0xff, 0x80, 0x43, 0x23])));

value = 0xfffff;
['writeUInt16BE', 'writeUInt16LE'].forEach((fn) => {
assert.throws(
() => data[fn](value, 0),
{
code: 'ERR_OUT_OF_RANGE',
message: 'The value of "value" is out of range. ' +
`It must be >= 0 and <= 65535. Received ${value}`
}
);
});
}

// Test 32 bit
Expand Down