Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

writeUInt16BE: incorrect 'value of "value" is out of range.' error message? #24205

Closed
lautarodragan opened this issue Nov 6, 2018 · 1 comment
Labels
buffer Issues and PRs related to the buffer subsystem. errors Issues and PRs related to JavaScript errors originated in Node.js core.

Comments

@lautarodragan
Copy link

  • 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)
@addaleax addaleax added buffer Issues and PRs related to the buffer subsystem. errors Issues and PRs related to JavaScript errors originated in Node.js core. labels Nov 6, 2018
@Trott
Copy link
Member

Trott commented Nov 6, 2018

@nodejs/buffer

mscdex added a commit to mscdex/io.js that referenced this issue Nov 6, 2018
@Trott Trott closed this as completed in 5c201b6 Nov 8, 2018
BridgeAR pushed a commit that referenced this issue Nov 14, 2018
Fixes: #24205

PR-URL: #24208
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
kiyomizumia pushed a commit to kiyomizumia/node that referenced this issue Nov 15, 2018
Fixes: nodejs#24205

PR-URL: nodejs#24208
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
codebytere pushed a commit that referenced this issue Dec 13, 2018
Fixes: #24205

PR-URL: #24208
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
MylesBorins pushed a commit that referenced this issue Dec 26, 2018
Fixes: #24205

PR-URL: #24208
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
buffer Issues and PRs related to the buffer subsystem. errors Issues and PRs related to JavaScript errors originated in Node.js core.
Projects
None yet
Development

No branches or pull requests

3 participants