Skip to content

Commit f879f5e

Browse files
jasnellMyles Borins
authored and
Myles Borins
committed
doc: document unspecified behavior for buf.write* methods
Per #1161, when the buf.write*() methods are given anything other than what they expect, indicate that the behavior is unspecified. Fixes: #1161 PR-URL: #5925 Reviewed-By: Claudio Rodriguez <[email protected]>
1 parent f12c386 commit f879f5e

File tree

1 file changed

+21
-10
lines changed

1 file changed

+21
-10
lines changed

doc/api/buffer.markdown

+21-10
Original file line numberDiff line numberDiff line change
@@ -1384,7 +1384,8 @@ console.log(`${len} bytes: ${buf.toString('utf8', 0, len)}`);
13841384

13851385
Writes `value` to the Buffer at the specified `offset` with specified endian
13861386
format (`writeDoubleBE()` writes big endian, `writeDoubleLE()` writes little
1387-
endian). The `value` argument must be a valid 64-bit double.
1387+
endian). The `value` argument *should* be a valid 64-bit double. Behavior is
1388+
not defined when `value` is anything other than a 64-bit double.
13881389

13891390
Set `noAssert` to true to skip validation of `value` and `offset`. This means
13901391
that `value` may be too large for the specific function and `offset` may be
@@ -1416,7 +1417,7 @@ console.log(buf);
14161417

14171418
Writes `value` to the Buffer at the specified `offset` with specified endian
14181419
format (`writeFloatBE()` writes big endian, `writeFloatLE()` writes little
1419-
endian). Behavior is unspecified if `value` is anything other than a 32-bit
1420+
endian). Behavior is not defined when `value` is anything other than a 32-bit
14201421
float.
14211422

14221423
Set `noAssert` to true to skip validation of `value` and `offset`. This means
@@ -1446,8 +1447,9 @@ console.log(buf);
14461447
* `noAssert` {Boolean} Default: false
14471448
* Return: {Number} The offset plus the number of written bytes
14481449

1449-
Writes `value` to the Buffer at the specified `offset`. The `value` must be a
1450-
valid signed 8-bit integer.
1450+
Writes `value` to the Buffer at the specified `offset`. The `value` should be a
1451+
valid signed 8-bit integer. Behavior is not defined when `value` is anything
1452+
other than a signed 8-bit integer.
14511453

14521454
Set `noAssert` to true to skip validation of `value` and `offset`. This means
14531455
that `value` may be too large for the specific function and `offset` may be
@@ -1474,7 +1476,8 @@ console.log(buf);
14741476

14751477
Writes `value` to the Buffer at the specified `offset` with specified endian
14761478
format (`writeInt16BE()` writes big endian, `writeInt16LE()` writes little
1477-
endian). The `value` must be a valid signed 16-bit integer.
1479+
endian). The `value` should be a valid signed 16-bit integer. Behavior is
1480+
not defined when `value` is anything other than a signed 16-bit integer.
14781481

14791482
Set `noAssert` to true to skip validation of `value` and `offset`. This means
14801483
that `value` may be too large for the specific function and `offset` may be
@@ -1501,7 +1504,8 @@ console.log(buf);
15011504

15021505
Writes `value` to the Buffer at the specified `offset` with specified endian
15031506
format (`writeInt32BE()` writes big endian, `writeInt32LE()` writes little
1504-
endian). The `value` must be a valid signed 32-bit integer.
1507+
endian). The `value` should be a valid signed 32-bit integer. Behavior is
1508+
not defined when `value` is anything other than a signed 32-bit integer.
15051509

15061510
Set `noAssert` to true to skip validation of `value` and `offset`. This means
15071511
that `value` may be too large for the specific function and `offset` may be
@@ -1547,15 +1551,18 @@ that `value` may be too large for the specific function and `offset` may be
15471551
beyond the end of the Buffer leading to the values being silently dropped. This
15481552
should not be used unless you are certain of correctness.
15491553

1554+
Behavior is not defined when `value` is anything other than an integer.
1555+
15501556
### buf.writeUInt8(value, offset[, noAssert])
15511557

15521558
* `value` {Number} Bytes to be written to Buffer
15531559
* `offset` {Number} `0 <= offset <= buf.length - 1`
15541560
* `noAssert` {Boolean} Default: false
15551561
* Return: {Number} The offset plus the number of written bytes
15561562

1557-
Writes `value` to the Buffer at the specified `offset`. The `value` must be a
1558-
valid unsigned 8-bit integer.
1563+
Writes `value` to the Buffer at the specified `offset`. The `value` should be a
1564+
valid unsigned 8-bit integer. Behavior is not defined when `value` is anything
1565+
other than an unsigned 8-bit integer.
15591566

15601567
Set `noAssert` to true to skip validation of `value` and `offset`. This means
15611568
that `value` may be too large for the specific function and `offset` may be
@@ -1585,7 +1592,8 @@ console.log(buf);
15851592

15861593
Writes `value` to the Buffer at the specified `offset` with specified endian
15871594
format (`writeUInt16BE()` writes big endian, `writeUInt16LE()` writes little
1588-
endian). The `value` must be a valid unsigned 16-bit integer.
1595+
endian). The `value` should be a valid unsigned 16-bit integer. Behavior is
1596+
not defined when `value` is anything other than an unsigned 16-bit integer.
15891597

15901598
Set `noAssert` to true to skip validation of `value` and `offset`. This means
15911599
that `value` may be too large for the specific function and `offset` may be
@@ -1619,7 +1627,8 @@ console.log(buf);
16191627

16201628
Writes `value` to the Buffer at the specified `offset` with specified endian
16211629
format (`writeUInt32BE()` writes big endian, `writeUInt32LE()` writes little
1622-
endian). The `value` must be a valid unsigned 32-bit integer.
1630+
endian). The `value` should be a valid unsigned 32-bit integer. Behavior is
1631+
not defined when `value` is anything other than an unsigned 32-bit integer.
16231632

16241633
Set `noAssert` to true to skip validation of `value` and `offset`. This means
16251634
that `value` may be too large for the specific function and `offset` may be
@@ -1665,6 +1674,8 @@ that `value` may be too large for the specific function and `offset` may be
16651674
beyond the end of the Buffer leading to the values being silently dropped. This
16661675
should not be used unless you are certain of correctness.
16671676

1677+
Behavior is not defined when `value` is anything other than an unsigned integer.
1678+
16681679
## buffer.INSPECT_MAX_BYTES
16691680

16701681
* {Number} Default: 50

0 commit comments

Comments
 (0)