From 26cc7751c763a1fefabbbaa0a82d3efb2a4277ad Mon Sep 17 00:00:00 2001 From: Dogan Can Bakir <65292895+dogancanbakir@users.noreply.github.com> Date: Thu, 23 Nov 2023 08:57:22 +0100 Subject: [PATCH] fix index out of range err (#286) * fix index out of range err * minor * fix tests --- ip.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/ip.go b/ip.go index fc04147..2e8a7b4 100644 --- a/ip.go +++ b/ip.go @@ -285,8 +285,11 @@ func ipNetToRange(ipNet net.IPNet) netWithRange { lastIPMask := make(net.IPMask, len(ipNet.Mask)) copy(lastIPMask, ipNet.Mask) for i := range lastIPMask { - lastIPMask[len(lastIPMask)-i-1] = ^lastIPMask[len(lastIPMask)-i-1] - lastIP[net.IPv6len-i-1] |= lastIPMask[len(lastIPMask)-i-1] + index := len(lastIPMask) - 1 - i + lastIPMask[index] = ^lastIPMask[index] + if net.IPv6len-i-1 < len(lastIP) { + lastIP[net.IPv6len-i-1] |= lastIPMask[index] + } } return netWithRange{First: &firstIP, Last: &lastIP, Network: &ipNet}