From 369d56d177df2e392979e353488622f0fdf2af16 Mon Sep 17 00:00:00 2001 From: Fedor Indutny Date: Mon, 9 May 2022 21:47:42 -0700 Subject: [PATCH] lib: use Buffer.alloc Fix: #109 --- lib/ip.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/ip.js b/lib/ip.js index 0e52fc5..4b2adb5 100644 --- a/lib/ip.js +++ b/lib/ip.js @@ -8,7 +8,7 @@ ip.toBuffer = function (ip, buff, offset) { let result; if (this.isV4Format(ip)) { - result = buff || new Buffer(offset + 4); + result = buff || Buffer.alloc(offset + 4); ip.split(/\./g).map((byte) => { result[offset++] = parseInt(byte, 10) & 0xff; }); @@ -43,7 +43,7 @@ ip.toBuffer = function (ip, buff, offset) { sections.splice(...argv); } - result = buff || new Buffer(offset + 16); + result = buff || Buffer.alloc(offset + 16); for (i = 0; i < sections.length; i++) { const word = parseInt(sections[i], 16); result[offset++] = (word >> 8) & 0xff; @@ -114,7 +114,7 @@ ip.fromPrefixLen = function (prefixlen, family) { if (family === 'ipv6') { len = 16; } - const buff = new Buffer(len); + const buff = Buffer.alloc(len); for (let i = 0, n = buff.length; i < n; ++i) { let bits = 8; @@ -133,7 +133,7 @@ ip.mask = function (addr, mask) { addr = ip.toBuffer(addr); mask = ip.toBuffer(mask); - const result = new Buffer(Math.max(addr.length, mask.length)); + const result = Buffer.alloc(Math.max(addr.length, mask.length)); // Same protocol - do bitwise and let i;