Skip to content

Commit

Permalink
lib: use Buffer.alloc
Browse files Browse the repository at this point in the history
Fix: #109
  • Loading branch information
indutny committed May 10, 2022
1 parent af82ef4 commit 369d56d
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions lib/ip.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
});
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down

0 comments on commit 369d56d

Please sign in to comment.