Skip to content

doc: Buffer buf.readInt32LE(offset[, noAssert]) example incorrect #5889

Closed
@bendiy

Description

  • Version: 4.2.1
  • Platform: Ubuntu 14.04 64-bit
  • Subsystem: Buffer

The example for buf.readInt32LE(offset[, noAssert]) appears to be incorrect.

const buf = new Buffer([1,-2,3,4]);

buf.readInt32BE();
  // returns 33424132
buf.readInt32LE(1);
  // returns 67370497

Running locally in a REPL:

$ node
> const buf = new Buffer([1,-2,3,4]);
undefined
> buf.readInt32BE();
33424132
> buf.readInt32LE(1);
RangeError: index out of range
    at checkOffset (buffer.js:619:11)
    at Buffer.readInt32LE (buffer.js:772:5)
    at repl:1:5
    at REPLServer.defaultEval (repl.js:164:27)
    at bound (domain.js:280:14)
    at REPLServer.runBound [as eval] (domain.js:293:12)
    at REPLServer.<anonymous> (repl.js:393:12)
    at emitOne (events.js:82:20)
    at REPLServer.emit (events.js:169:7)
    at REPLServer.Interface._onLine (readline.js:210:10)
>

The offset check is something like offset + 3 < buffer.length, so 4 < 4 fails as it should.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    docIssues and PRs related to the documentations.good first issueIssues that are suitable for first-time contributors.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions