}
offset = Number(offset) || 0
+
+ if (length < 0 || offset < 0 || offset > this.length)
+ throw new RangeError('attempt to write outside buffer bounds');
+
var remaining = this.length - offset
if (!length) {
length = remaining
function checkInt (buf, value, offset, ext, max, min) {
if (!Buffer.isBuffer(buf)) throw new TypeError('buffer must be a Buffer instance')
- if (value > max || value < min) throw new TypeError('value is out of bounds')
- if (offset + ext > buf.length) throw new TypeError('index out of range')
+ if (value > max || value < min) throw new RangeError('value is out of bounds')
+ if (offset + ext > buf.length) throw new RangeError('index out of range')
}
Buffer.prototype.writeUInt8 = function (value, offset, noAssert) {
}
function checkIEEE754 (buf, value, offset, ext, max, min) {
- if (value > max || value < min) throw new TypeError('value is out of bounds')
- if (offset + ext > buf.length) throw new TypeError('index out of range')
+ if (value > max || value < min) throw new RangeError('value is out of bounds')
+ if (offset + ext > buf.length) throw new RangeError('index out of range')
+ if (offset < 0) throw new RangeError('index out of range')
}
function writeFloat (buf, value, offset, littleEndian, noAssert) {
}
// copy(targetBuffer, targetStart=0, sourceStart=0, sourceEnd=buffer.length)
-Buffer.prototype.copy = function (target, target_start, start, end) {
+Buffer.prototype.copy = function(target, target_start, start, end) {
var source = this
if (!start) start = 0
if (!end && end !== 0) end = this.length
+ if (target_start >= target.length) target_start = target.length
if (!target_start) target_start = 0
+ if (end > 0 && end < start) end = start
// Copy 0 bytes; we're done
- if (end === start) return
- if (target.length === 0 || source.length === 0) return
+ if (end === start) return 0
+ if (target.length === 0 || source.length === 0) return 0
// Fatal error conditions
- if (end < start) throw new TypeError('sourceEnd < sourceStart')
- if (target_start < 0 || target_start >= target.length)
- throw new TypeError('targetStart out of bounds')
- if (start < 0 || start >= source.length) throw new TypeError('sourceStart out of bounds')
- if (end < 0 || end > source.length) throw new TypeError('sourceEnd out of bounds')
+ if (target_start < 0)
+ throw new RangeError('targetStart out of bounds')
+ if (start < 0 || start >= source.length) throw new RangeError('sourceStart out of bounds')
+ if (end < 0) throw new RangeError('sourceEnd out of bounds')
// Are we oob?
if (end > this.length)
if (!start) start = 0
if (!end) end = this.length
- if (end < start) throw new TypeError('end < start')
+ if (end < start) throw new RangeError('end < start')
// Fill 0 bytes; we're done
if (end === start) return
if (this.length === 0) return
- if (start < 0 || start >= this.length) throw new TypeError('start out of bounds')
- if (end < 0 || end > this.length) throw new TypeError('end out of bounds')
+ if (start < 0 || start >= this.length) throw new RangeError('start out of bounds')
+ if (end < 0 || end > this.length) throw new RangeError('end out of bounds')
var i
if (typeof value === 'number') {