Skip to content

Commit 64bf4b3

Browse files
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 6fd26dc commit 64bf4b3

File tree

1 file changed

+21
-10
lines changed

1 file changed

+21
-10
lines changed

doc/api/buffer.markdown

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1402,7 +1402,8 @@ console.log(`${len} bytes: ${buf.toString('utf8', 0, len)}`);
14021402

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

14071408
Set `noAssert` to true to skip validation of `value` and `offset`. This means
14081409
that `value` may be too large for the specific function and `offset` may be
@@ -1434,7 +1435,7 @@ console.log(buf);
14341435

14351436
Writes `value` to the Buffer at the specified `offset` with specified endian
14361437
format (`writeFloatBE()` writes big endian, `writeFloatLE()` writes little
1437-
endian). Behavior is unspecified if `value` is anything other than a 32-bit
1438+
endian). Behavior is not defined when `value` is anything other than a 32-bit
14381439
float.
14391440

14401441
Set `noAssert` to true to skip validation of `value` and `offset`. This means
@@ -1464,8 +1465,9 @@ console.log(buf);
14641465
* `noAssert` {Boolean} Default: false
14651466
* Return: {Number} The offset plus the number of written bytes
14661467

1467-
Writes `value` to the Buffer at the specified `offset`. The `value` must be a
1468-
valid signed 8-bit integer.
1468+
Writes `value` to the Buffer at the specified `offset`. The `value` should be a
1469+
valid signed 8-bit integer. Behavior is not defined when `value` is anything
1470+
other than a signed 8-bit integer.
14691471

14701472
Set `noAssert` to true to skip validation of `value` and `offset`. This means
14711473
that `value` may be too large for the specific function and `offset` may be
@@ -1492,7 +1494,8 @@ console.log(buf);
14921494

14931495
Writes `value` to the Buffer at the specified `offset` with specified endian
14941496
format (`writeInt16BE()` writes big endian, `writeInt16LE()` writes little
1495-
endian). The `value` must be a valid signed 16-bit integer.
1497+
endian). The `value` should be a valid signed 16-bit integer. Behavior is
1498+
not defined when `value` is anything other than a signed 16-bit integer.
14961499

14971500
Set `noAssert` to true to skip validation of `value` and `offset`. This means
14981501
that `value` may be too large for the specific function and `offset` may be
@@ -1519,7 +1522,8 @@ console.log(buf);
15191522

15201523
Writes `value` to the Buffer at the specified `offset` with specified endian
15211524
format (`writeInt32BE()` writes big endian, `writeInt32LE()` writes little
1522-
endian). The `value` must be a valid signed 32-bit integer.
1525+
endian). The `value` should be a valid signed 32-bit integer. Behavior is
1526+
not defined when `value` is anything other than a signed 32-bit integer.
15231527

15241528
Set `noAssert` to true to skip validation of `value` and `offset`. This means
15251529
that `value` may be too large for the specific function and `offset` may be
@@ -1565,15 +1569,18 @@ that `value` may be too large for the specific function and `offset` may be
15651569
beyond the end of the Buffer leading to the values being silently dropped. This
15661570
should not be used unless you are certain of correctness.
15671571

1572+
Behavior is not defined when `value` is anything other than an integer.
1573+
15681574
### buf.writeUInt8(value, offset[, noAssert])
15691575

15701576
* `value` {Number} Bytes to be written to Buffer
15711577
* `offset` {Number} `0 <= offset <= buf.length - 1`
15721578
* `noAssert` {Boolean} Default: false
15731579
* Return: {Number} The offset plus the number of written bytes
15741580

1575-
Writes `value` to the Buffer at the specified `offset`. The `value` must be a
1576-
valid unsigned 8-bit integer.
1581+
Writes `value` to the Buffer at the specified `offset`. The `value` should be a
1582+
valid unsigned 8-bit integer. Behavior is not defined when `value` is anything
1583+
other than an unsigned 8-bit integer.
15771584

15781585
Set `noAssert` to true to skip validation of `value` and `offset`. This means
15791586
that `value` may be too large for the specific function and `offset` may be
@@ -1603,7 +1610,8 @@ console.log(buf);
16031610

16041611
Writes `value` to the Buffer at the specified `offset` with specified endian
16051612
format (`writeUInt16BE()` writes big endian, `writeUInt16LE()` writes little
1606-
endian). The `value` must be a valid unsigned 16-bit integer.
1613+
endian). The `value` should be a valid unsigned 16-bit integer. Behavior is
1614+
not defined when `value` is anything other than an unsigned 16-bit integer.
16071615

16081616
Set `noAssert` to true to skip validation of `value` and `offset`. This means
16091617
that `value` may be too large for the specific function and `offset` may be
@@ -1637,7 +1645,8 @@ console.log(buf);
16371645

16381646
Writes `value` to the Buffer at the specified `offset` with specified endian
16391647
format (`writeUInt32BE()` writes big endian, `writeUInt32LE()` writes little
1640-
endian). The `value` must be a valid unsigned 32-bit integer.
1648+
endian). The `value` should be a valid unsigned 32-bit integer. Behavior is
1649+
not defined when `value` is anything other than an unsigned 32-bit integer.
16411650

16421651
Set `noAssert` to true to skip validation of `value` and `offset`. This means
16431652
that `value` may be too large for the specific function and `offset` may be
@@ -1683,6 +1692,8 @@ that `value` may be too large for the specific function and `offset` may be
16831692
beyond the end of the Buffer leading to the values being silently dropped. This
16841693
should not be used unless you are certain of correctness.
16851694

1695+
Behavior is not defined when `value` is anything other than an unsigned integer.
1696+
16861697
## buffer.INSPECT_MAX_BYTES
16871698

16881699
* {Number} Default: 50

0 commit comments

Comments
 (0)