Skip to content

writeFloat* and writeDouble* do no longer throw range error when out of boundsΒ #5587

@ghost

Description

I'l let the code speak for itself.

"use strict";

let buffer;

buffer = new Buffer(8);
buffer.fill(1);
console.log(buffer.writeFloatLE(0, 4), buffer, buffer.length);
// Node.js v4.3.1: "8 <Buffer 01 01 01 01 00 00 00 00> 8"
// Node.js v5.7.1: "8 <Buffer 01 01 01 01 00 00 00 00> 8"

buffer = new Buffer(8);
buffer.fill(1);
try {
    console.log(buffer.writeFloatLE(0, 5), buffer, buffer.length);
    // Node.js v5.7.1: "9 <Buffer 01 01 01 01 01 00 00 00> 8"
} catch (error) {
    console.log(error);
    // Node.js v4.3.1: "[RangeError: index out of range]"
}

buffer = new Buffer(16);
buffer.fill(1);
console.log(buffer.writeDoubleLE(0, 8), buffer, buffer.length);
// Node.js v4.3.1: "16 <Buffer 01 01 01 01 01 01 01 01 00 00 00 00 00 00 00 00> 16"
// Node.js v5.7.1: "16 <Buffer 01 01 01 01 01 01 01 01 00 00 00 00 00 00 00 00> 16"

buffer = new Buffer(16);
buffer.fill(1);
try {
    console.log(buffer.writeDoubleLE(0, 9), buffer, buffer.length);
    // Node.js v5.7.1: "17 <Buffer 01 01 01 01 01 01 01 01 01 00 00 00 00 00 00 00> 16"
} catch (error) {
    console.log(error);
    // Node.js v4.3.1: "[RangeError: index out of range]"
}

System 1

  • Version: v4.3.1
  • Platform: Windows Server 2012 R2 64-bit
  • Subsystem: Buffer

System 2

  • Version: v5.7.1
  • Platform: Windows 7 Pro SP1 64-bit
  • Subsystem: Buffer

Metadata

Metadata

Assignees

No one assigned

    Labels

    bufferIssues and PRs related to the buffer subsystem.confirmed-bugIssues with confirmed bugs.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions