| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -832,8 +832,10 @@ Buffer.prototype.writeUIntLE = function(value, offset, byteLength, noAssert) { | |||
| 832 | 832 | value = +value; | |
| 833 | 833 | offset = offset >>> 0; | |
| 834 | 834 | byteLength = byteLength >>> 0; | |
| 835 | - if (!noAssert) | ||
| 836 | - checkInt(this, value, offset, byteLength, Math.pow(2, 8 * byteLength), 0); | ||
| 835 | + if (!noAssert) { | ||
| 836 | + const maxBytes = Math.pow(2, 8 * byteLength) - 1; | ||
| 837 | + checkInt(this, value, offset, byteLength, maxBytes, 0); | ||
| 838 | + } | ||
| 837 | 839 | ||
| 838 | 840 | var mul = 1; | |
| 839 | 841 | var i = 0; | |
@@ -849,8 +851,10 @@ Buffer.prototype.writeUIntBE = function(value, offset, byteLength, noAssert) { | |||
| 849 | 851 | value = +value; | |
| 850 | 852 | offset = offset >>> 0; | |
| 851 | 853 | byteLength = byteLength >>> 0; | |
| 852 | - if (!noAssert) | ||
| 853 | - checkInt(this, value, offset, byteLength, Math.pow(2, 8 * byteLength), 0); | ||
| 854 | + if (!noAssert) { | ||
| 855 | + const maxBytes = Math.pow(2, 8 * byteLength) - 1; | ||
| 856 | + checkInt(this, value, offset, byteLength, maxBytes, 0); | ||
| 857 | + } | ||
| 854 | 858 | ||
| 855 | 859 | var i = byteLength - 1; | |
| 856 | 860 | var mul = 1; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -122,6 +122,25 @@ function test32(clazz) { | |||
| 122 | 122 | } | |
| 123 | 123 | ||
| 124 | 124 | ||
| 125 | + function testUint(clazz) { | ||
| 126 | + const data = new clazz(8); | ||
| 127 | + var val = 1; | ||
| 128 | + | ||
| 129 | + // Test 0 to 5 bytes. | ||
| 130 | + for (var i = 0; i <= 5; i++) { | ||
| 131 | + const errmsg = `byteLength: ${i}`; | ||
| 132 | + ASSERT.throws(function() { | ||
| 133 | + data.writeUIntBE(val, 0, i); | ||
| 134 | + }, /value is out of bounds/, errmsg); | ||
| 135 | + ASSERT.throws(function() { | ||
| 136 | + data.writeUIntLE(val, 0, i); | ||
| 137 | + }, /value is out of bounds/, errmsg); | ||
| 138 | + val *= 0x100; | ||
| 139 | + } | ||
| 140 | + } | ||
| 141 | + | ||
| 142 | + | ||
| 125 | 143 | test8(Buffer); | |
| 126 | 144 | test16(Buffer); | |
| 127 | 145 | test32(Buffer); | |
| 146 | + testUint(Buffer); | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments