Skip to content

Commit b96750d

Browse files
committed
Simplify XORMappedAddress IP slice initialization
Signed-off-by: Xiaobo Liu <cppcoffee@gmail.com>
1 parent 6f87a7d commit b96750d

1 file changed

Lines changed: 6 additions & 7 deletions

File tree

xoraddr.go

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -103,15 +103,14 @@ func (a *XORMappedAddress) GetFromAs(msg *Message, attr AttrType) error {
103103
}
104104
// Ensuring len(a.IP) == ipLen and reusing a.IP.
105105
if len(a.IP) < ipLen {
106-
a.IP = a.IP[:cap(a.IP)]
107-
for len(a.IP) < ipLen {
108-
a.IP = append(a.IP, 0)
106+
a.IP = make(net.IP, ipLen)
107+
} else {
108+
a.IP = a.IP[:ipLen]
109+
for i := range a.IP {
110+
a.IP[i] = 0
109111
}
110112
}
111-
a.IP = a.IP[:ipLen]
112-
for i := range a.IP {
113-
a.IP[i] = 0
114-
}
113+
115114
if len(value) <= 4 {
116115
return io.ErrUnexpectedEOF
117116
}

0 commit comments

Comments
 (0)