GeezerVison is showing github.com — buffer: allow .write() offset to be at buffer end · nodejs/node@e371545
File tree
Expand file treeCollapse file tree
Open diff view settings
Expand file treeCollapse file tree
Open diff view settings
Collapse file
Copy file name to clipboardExpand all lines: src/node_buffer.cc +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -714,7 +714,7 @@ void StringWrite(const FunctionCallbackInfo<Value>& args) { |
714 | 714 | size_t max_length; |
715 | 715 |
|
716 | 716 | CHECK_NOT_OOB(ParseArrayIndex(args[1], 0, &offset)); |
717 | | - if (offset >= ts_obj_length) |
| 717 | + if (offset > ts_obj_length) |
718 | 718 | return env->ThrowRangeError("Offset is out of bounds"); |
719 | 719 |
|
720 | 720 | CHECK_NOT_OOB(ParseArrayIndex(args[2], ts_obj_length - offset, &max_length)); |
|
Collapse file
Copy file name to clipboardExpand all lines: test/parallel/test-buffer-alloc.js +6Lines changed: 6 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -358,6 +358,12 @@ writeTest.write('e', 3, 'ascii'); |
358 | 358 | writeTest.write('j', 4, 'ascii'); |
359 | 359 | assert.equal(writeTest.toString(), 'nodejs'); |
360 | 360 |
|
| 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 | + |
361 | 367 | // ASCII slice test |
362 | 368 | { |
363 | 369 | const asciiString = 'hello world'; |
|