Skip to content

Commit aa89af8

Browse files
committed
Simplify MappedAddress IP slice initialization
Signed-off-by: Xiaobo Liu <cppcoffee@gmail.com>
1 parent d07109b commit aa89af8

1 file changed

Lines changed: 5 additions & 7 deletions

File tree

addr.go

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -84,15 +84,13 @@ func (a *MappedAddress) GetFromAs(m *Message, t AttrType) error {
8484
}
8585
// Ensuring len(a.IP) == ipLen and reusing a.IP.
8686
if len(a.IP) < ipLen {
87-
a.IP = a.IP[:cap(a.IP)]
88-
for len(a.IP) < ipLen {
89-
a.IP = append(a.IP, 0)
87+
a.IP = make(net.IP, ipLen)
88+
} else {
89+
a.IP = a.IP[:ipLen]
90+
for i := range a.IP {
91+
a.IP[i] = 0
9092
}
9193
}
92-
a.IP = a.IP[:ipLen]
93-
for i := range a.IP {
94-
a.IP[i] = 0
95-
}
9694
a.Port = int(bin.Uint16(value[2:4]))
9795
copy(a.IP, value[4:])
9896

0 commit comments

Comments
 (0)