From c7a4525bbe053c3a79504e558236c48d3c6acc5c Mon Sep 17 00:00:00 2001 From: cjihrig Date: Mon, 12 Aug 2019 17:03:47 -0400 Subject: [PATCH] buffer: improve ERR_BUFFER_OUT_OF_BOUNDS default This commit changes the default message used by ERR_BUFFER_OUT_OF_BOUNDS. Previously, the default message implied that the problematic was always a write, which is not accurate. PR-URL: https://github.com/nodejs/node/pull/29098 Fixes: https://github.com/nodejs/node/issues/29097 Reviewed-By: Anna Henningsen Reviewed-By: Sam Roberts Reviewed-By: Jiawen Geng Reviewed-By: James M Snell Reviewed-By: Luigi Pinca Reviewed-By: Yongsheng Zhang Reviewed-By: Rich Trott --- lib/internal/errors.js | 2 +- test/parallel/test-buffer-fill.js | 2 +- test/parallel/test-buffer-read.js | 2 +- test/parallel/test-buffer-readdouble.js | 2 +- test/parallel/test-buffer-readfloat.js | 2 +- test/parallel/test-buffer-writedouble.js | 2 +- test/parallel/test-buffer-writefloat.js | 2 +- 7 files changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/internal/errors.js b/lib/internal/errors.js index 3082084aff20ba..c099963091a16d 100644 --- a/lib/internal/errors.js +++ b/lib/internal/errors.js @@ -705,7 +705,7 @@ E('ERR_BUFFER_OUT_OF_BOUNDS', if (name) { return `"${name}" is outside of buffer bounds`; } - return 'Attempt to write outside buffer bounds'; + return 'Attempt to access memory outside buffer bounds'; }, RangeError); E('ERR_BUFFER_TOO_LARGE', `Cannot create a Buffer larger than 0x${kMaxLength.toString(16)} bytes`, diff --git a/test/parallel/test-buffer-fill.js b/test/parallel/test-buffer-fill.js index 3dd11bce267a82..26243d7f199f12 100644 --- a/test/parallel/test-buffer-fill.js +++ b/test/parallel/test-buffer-fill.js @@ -362,7 +362,7 @@ common.expectsError(() => { }, { code: 'ERR_BUFFER_OUT_OF_BOUNDS', type: RangeError, - message: 'Attempt to write outside buffer bounds' + message: 'Attempt to access memory outside buffer bounds' }); assert.deepStrictEqual( diff --git a/test/parallel/test-buffer-read.js b/test/parallel/test-buffer-read.js index 7ab04d3eb3e747..9718887e0fe446 100644 --- a/test/parallel/test-buffer-read.js +++ b/test/parallel/test-buffer-read.js @@ -60,7 +60,7 @@ const OOR_ERROR = const OOB_ERROR = { name: 'RangeError', - message: 'Attempt to write outside buffer bounds' + message: 'Attempt to access memory outside buffer bounds' }; // Attempt to overflow buffers, similar to previous bug in array buffers diff --git a/test/parallel/test-buffer-readdouble.js b/test/parallel/test-buffer-readdouble.js index 09556dc640c51b..4a86ebe4ce382f 100644 --- a/test/parallel/test-buffer-readdouble.js +++ b/test/parallel/test-buffer-readdouble.js @@ -127,7 +127,7 @@ assert.strictEqual(buffer.readDoubleLE(0), -Infinity); { code: 'ERR_BUFFER_OUT_OF_BOUNDS', name: 'RangeError', - message: 'Attempt to write outside buffer bounds' + message: 'Attempt to access memory outside buffer bounds' }); [NaN, 1.01].forEach((offset) => { diff --git a/test/parallel/test-buffer-readfloat.js b/test/parallel/test-buffer-readfloat.js index 720b16462aaec2..c709956e025c70 100644 --- a/test/parallel/test-buffer-readfloat.js +++ b/test/parallel/test-buffer-readfloat.js @@ -90,7 +90,7 @@ assert.strictEqual(buffer.readFloatLE(0), -Infinity); { code: 'ERR_BUFFER_OUT_OF_BOUNDS', name: 'RangeError', - message: 'Attempt to write outside buffer bounds' + message: 'Attempt to access memory outside buffer bounds' }); [NaN, 1.01].forEach((offset) => { diff --git a/test/parallel/test-buffer-writedouble.js b/test/parallel/test-buffer-writedouble.js index 4bb7fe7e5684eb..3f156d8297d40e 100644 --- a/test/parallel/test-buffer-writedouble.js +++ b/test/parallel/test-buffer-writedouble.js @@ -99,7 +99,7 @@ assert.ok(Number.isNaN(buffer.readDoubleLE(8))); { code: 'ERR_BUFFER_OUT_OF_BOUNDS', name: 'RangeError', - message: 'Attempt to write outside buffer bounds' + message: 'Attempt to access memory outside buffer bounds' }); ['', '0', null, {}, [], () => {}, true, false].forEach((off) => { diff --git a/test/parallel/test-buffer-writefloat.js b/test/parallel/test-buffer-writefloat.js index cd198b01ef5ce5..8676a819fc776d 100644 --- a/test/parallel/test-buffer-writefloat.js +++ b/test/parallel/test-buffer-writefloat.js @@ -81,7 +81,7 @@ assert.ok(Number.isNaN(buffer.readFloatLE(4))); { code: 'ERR_BUFFER_OUT_OF_BOUNDS', name: 'RangeError', - message: 'Attempt to write outside buffer bounds' + message: 'Attempt to access memory outside buffer bounds' }); ['', '0', null, {}, [], () => {}, true, false].forEach((off) => {