function createUnsafeBuffer(size) {
zeroFill[0] = 0;
try {
//directly return new FastBuffer(size)
return new FastBuffer(size);
} finally {
zeroFill[0] = 1;
}
}
Buffer.alloc = function alloc(size, fill, encoding) {
assertSize(size);
if (fill !== undefined && fill !== 0 && size > 0) {
const buf = createUnsafeBuffer(size);
return _fill(buf, fill, 0, buf.length, encoding);
}
// return new FastBuffer(size) while fill is undefined or 0
return new FastBuffer(size);
};
FastBuffer从Uint8Array扩展,并且在创建Uint8Array的实例时将其内容设置为0。 那么为什么createUnsafeBuffer不安全却FastBuffer是安全的呢? 请帮助我。谢谢。