Skip to content

Commit 369d56d

Browse files
committed
lib: use Buffer.alloc
Fix: #109
1 parent af82ef4 commit 369d56d

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

lib/ip.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ ip.toBuffer = function (ip, buff, offset) {
88
let result;
99

1010
if (this.isV4Format(ip)) {
11-
result = buff || new Buffer(offset + 4);
11+
result = buff || Buffer.alloc(offset + 4);
1212
ip.split(/\./g).map((byte) => {
1313
result[offset++] = parseInt(byte, 10) & 0xff;
1414
});
@@ -43,7 +43,7 @@ ip.toBuffer = function (ip, buff, offset) {
4343
sections.splice(...argv);
4444
}
4545

46-
result = buff || new Buffer(offset + 16);
46+
result = buff || Buffer.alloc(offset + 16);
4747
for (i = 0; i < sections.length; i++) {
4848
const word = parseInt(sections[i], 16);
4949
result[offset++] = (word >> 8) & 0xff;
@@ -114,7 +114,7 @@ ip.fromPrefixLen = function (prefixlen, family) {
114114
if (family === 'ipv6') {
115115
len = 16;
116116
}
117-
const buff = new Buffer(len);
117+
const buff = Buffer.alloc(len);
118118

119119
for (let i = 0, n = buff.length; i < n; ++i) {
120120
let bits = 8;
@@ -133,7 +133,7 @@ ip.mask = function (addr, mask) {
133133
addr = ip.toBuffer(addr);
134134
mask = ip.toBuffer(mask);
135135

136-
const result = new Buffer(Math.max(addr.length, mask.length));
136+
const result = Buffer.alloc(Math.max(addr.length, mask.length));
137137

138138
// Same protocol - do bitwise and
139139
let i;

0 commit comments

Comments
 (0)