-
-
Notifications
You must be signed in to change notification settings - Fork 32.2k
Closed
Labels
bufferIssues and PRs related to the buffer subsystem.Issues and PRs related to the buffer subsystem.errorsIssues and PRs related to JavaScript errors originated in Node.js core.Issues and PRs related to JavaScript errors originated in Node.js core.
Description
- Version:
v10.13.0
- Platform:
Linux Mint 4.13.0-43-generic #48~16.04.1-Ubuntu SMP Thu May 17 12:56:46 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux
- Subsystem: don't know
From its name and its behavior, I'm think writeUInt16BE
can only take up to 2 bytes (0xFFFF, 65535), but it accepts up to 4, although it ignores anything after 2.
In the REPL:
> const o = Buffer.alloc(8)
undefined
> o.writeUInt16BE(0xFFFFFF) // 16777215
2
> o
<Buffer ff ff 00 00 00 00> // 0xFFFF, 65535 got written. Rest got ignored.
> b.writeUInt16BE(0xFFFFFFFF) // 4294967295
2
> b
<Buffer ff ff 00 00 00 00 00 00> // same
> b.writeUInt16BE(0xFFFFFFFFFF)
RangeError [ERR_OUT_OF_RANGE]: The value of "value" is out of range. It must be >= 0 and <= 4294967295. Received 1099511627775
at checkInt (internal/buffer.js:35:11)
at writeU_Int16BE (internal/buffer.js:653:3)
at Buffer.writeUInt16BE (internal/buffer.js:661:10)
The error message matches the behavior, although I'm confused by it. I can't find mention of this in the docs.
writeUInt16LE
behaves and reports differently:
> b.writeUInt16LE(0xFFFFFFFF)
RangeError [ERR_OUT_OF_RANGE]: The value of "value" is out of range. It must be >= 0 and <= 65535. Received 4294967295
at checkInt (internal/buffer.js:35:11)
at writeU_Int16LE (internal/buffer.js:543:3)
at Buffer.writeUInt16LE (internal/buffer.js:551:10)
Metadata
Metadata
Assignees
Labels
bufferIssues and PRs related to the buffer subsystem.Issues and PRs related to the buffer subsystem.errorsIssues and PRs related to JavaScript errors originated in Node.js core.Issues and PRs related to JavaScript errors originated in Node.js core.