Skip to content

Commit

Permalink
fix index out of range err (#286)
Browse files Browse the repository at this point in the history
* fix index out of range err

* minor

* fix tests
  • Loading branch information
dogancanbakir authored Nov 23, 2023
1 parent 3ae3e72 commit 26cc775
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions ip.go
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down

0 comments on commit 26cc775

Please sign in to comment.