From b96750d516be5279919df92249e74b590a181a51 Mon Sep 17 00:00:00 2001 From: Xiaobo Liu Date: Fri, 30 May 2025 17:18:56 +0800 Subject: [PATCH] Simplify XORMappedAddress IP slice initialization Signed-off-by: Xiaobo Liu --- xoraddr.go | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/xoraddr.go b/xoraddr.go index 273ac50..3221428 100644 --- a/xoraddr.go +++ b/xoraddr.go @@ -103,15 +103,14 @@ func (a *XORMappedAddress) GetFromAs(msg *Message, attr AttrType) error { } // Ensuring len(a.IP) == ipLen and reusing a.IP. if len(a.IP) < ipLen { - a.IP = a.IP[:cap(a.IP)] - for len(a.IP) < ipLen { - a.IP = append(a.IP, 0) + a.IP = make(net.IP, ipLen) + } else { + a.IP = a.IP[:ipLen] + for i := range a.IP { + a.IP[i] = 0 } } - a.IP = a.IP[:ipLen] - for i := range a.IP { - a.IP[i] = 0 - } + if len(value) <= 4 { return io.ErrUnexpectedEOF }