Skip to content

Commit 5a64187

Browse files
joyeecheungFishrock123
authored andcommitted
doc: buffer allocation throws for negative size
PR-URL: #10151 Reviewed-By: Jeremiah Senkpiel <[email protected]> Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Sam Roberts <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Colin Ihrig <[email protected]>
1 parent 28c6df2 commit 5a64187

File tree

1 file changed

+15
-16
lines changed

1 file changed

+15
-16
lines changed

doc/api/buffer.md

+15-16
Original file line numberDiff line numberDiff line change
@@ -392,9 +392,9 @@ deprecated: v6.0.0
392392
393393
* `size` {Integer} The desired length of the new `Buffer`
394394

395-
Allocates a new `Buffer` of `size` bytes. The `size` must be less than or equal
396-
to the value of [`buffer.kMaxLength`]. Otherwise, a [`RangeError`] is thrown.
397-
A zero-length `Buffer` will be created if `size <= 0`.
395+
Allocates a new `Buffer` of `size` bytes. If the `size` is larger than
396+
[`buffer.kMaxLength`] or smaller than 0, a [`RangeError`] will be thrown.
397+
A zero-length `Buffer` will be created if `size` is 0.
398398

399399
Unlike [`ArrayBuffers`][`ArrayBuffer`], the underlying memory for `Buffer` instances
400400
created in this way is *not initialized*. The contents of a newly created `Buffer`
@@ -470,9 +470,9 @@ const buf = Buffer.alloc(5);
470470
console.log(buf);
471471
```
472472

473-
The `size` must be less than or equal to the value of [`buffer.kMaxLength`].
474-
Otherwise, a [`RangeError`] is thrown. A zero-length `Buffer` will be created if
475-
`size <= 0`.
473+
Allocates a new `Buffer` of `size` bytes. If the `size` is larger than
474+
[`buffer.kMaxLength`] or smaller than 0, a [`RangeError`] will be thrown.
475+
A zero-length `Buffer` will be created if `size` is 0.
476476

477477
If `fill` is specified, the allocated `Buffer` will be initialized by calling
478478
[`buf.fill(fill)`][`buf.fill()`].
@@ -511,9 +511,9 @@ added: v5.10.0
511511

512512
* `size` {Integer} The desired length of the new `Buffer`
513513

514-
Allocates a new *non-zero-filled* `Buffer` of `size` bytes. The `size` must
515-
be less than or equal to the value of [`buffer.kMaxLength`]. Otherwise, a
516-
[`RangeError`] is thrown. A zero-length `Buffer` will be created if `size <= 0`.
514+
Allocates a new `Buffer` of `size` bytes. If the `size` is larger than
515+
[`buffer.kMaxLength`] or smaller than 0, a [`RangeError`] will be thrown.
516+
A zero-length `Buffer` will be created if `size` is 0.
517517

518518
The underlying memory for `Buffer` instances created in this way is *not
519519
initialized*. The contents of the newly created `Buffer` are unknown and
@@ -557,10 +557,9 @@ added: v5.10.0
557557

558558
* `size` {Integer} The desired length of the new `Buffer`
559559

560-
Allocates a new *non-zero-filled* and non-pooled `Buffer` of `size` bytes. The
561-
`size` must be less than or equal to the value of [`buffer.kMaxLength`].
562-
Otherwise, a [`RangeError`] is thrown. A zero-length `Buffer` will be created if
563-
`size <= 0`.
560+
Allocates a new `Buffer` of `size` bytes. If the `size` is larger than
561+
[`buffer.kMaxLength`] or smaller than 0, a [`RangeError`] will be thrown.
562+
A zero-length `Buffer` will be created if `size` is 0.
564563

565564
The underlying memory for `Buffer` instances created in this way is *not
566565
initialized*. The contents of the newly created `Buffer` are unknown and
@@ -2390,9 +2389,9 @@ deprecated: v6.0.0
23902389
23912390
* `size` {Integer} The desired length of the new `SlowBuffer`
23922391

2393-
Allocates a new `SlowBuffer` of `size` bytes. The `size` must be less than
2394-
or equal to the value of [`buffer.kMaxLength`]. Otherwise, a [`RangeError`] is
2395-
thrown. A zero-length `Buffer` will be created if `size <= 0`.
2392+
Allocates a new `Buffer` of `size` bytes. If the `size` is larger than
2393+
[`buffer.kMaxLength`] or smaller than 0, a [`RangeError`] will be thrown.
2394+
A zero-length `Buffer` will be created if `size` is 0.
23962395

23972396
The underlying memory for `SlowBuffer` instances is *not initialized*. The
23982397
contents of a newly created `SlowBuffer` are unknown and could contain

0 commit comments

Comments
 (0)