Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit e371545

Browse filesBrowse files
addaleaxevanlucas
authored andcommitted
buffer: allow .write() offset to be at buffer end
Do not throw if the offset passed to `buf.write()` points to the end of the buffer. Fixes: #8127 PR-URL: #8154 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Michaël Zasso <mic.besace@gmail.com>
1 parent c2f5471 commit e371545
Copy full SHA for e371545

File tree

Expand file treeCollapse file tree

2 files changed

+7
-1
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

2 files changed

+7
-1
lines changed
Open diff view settings
Collapse file

‎src/node_buffer.cc‎

Copy file name to clipboardExpand all lines: src/node_buffer.cc
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -714,7 +714,7 @@ void StringWrite(const FunctionCallbackInfo<Value>& args) {
714714
size_t max_length;
715715

716716
CHECK_NOT_OOB(ParseArrayIndex(args[1], 0, &offset));
717-
if (offset >= ts_obj_length)
717+
if (offset > ts_obj_length)
718718
return env->ThrowRangeError("Offset is out of bounds");
719719

720720
CHECK_NOT_OOB(ParseArrayIndex(args[2], ts_obj_length - offset, &max_length));
Collapse file

‎test/parallel/test-buffer-alloc.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-buffer-alloc.js
+6Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,12 @@ writeTest.write('e', 3, 'ascii');
358358
writeTest.write('j', 4, 'ascii');
359359
assert.equal(writeTest.toString(), 'nodejs');
360360

361+
// Offset points to the end of the buffer
362+
// (see https://github.com/nodejs/node/issues/8127).
363+
assert.doesNotThrow(() => {
364+
Buffer.alloc(1).write('', 1, 0);
365+
});
366+
361367
// ASCII slice test
362368
{
363369
const asciiString = 'hello world';

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.