netaddr-go icon indicating copy to clipboard operation
netaddr-go copied to clipboard

Fill panics if passed the same network

Open markgardner10 opened this issue 3 years ago • 0 comments

foundSubnets, _ := netaddr.NewIPv4NetList([]string{"10.0.0.0/16"})

supernet, _ := netaddr.ParseIPv4Net("10.0.0.0/16")

filled := supernet.Fill(foundSubnets) // panics because foundSubnets is the same as the supernet 10.0.0.0/16
func (net *IPv4Net) Fill(list IPv4NetList) IPv4NetList {
	var subs IPv4NetList
	// get rid of non subnets
	if list != nil && len(list) > 0 {
		for _, e := range list {
			isRel, rel := net.Rel(e)
			if isRel && rel == 1 { // changing this too ---> isRel && rel == 1 || isRel && rel == 0
				subs = append(subs, e)
			}
		}
		// discard subnets of subnets & sort
		subs = subs.discardSubnets().Sort() // <-------- panics here becasue subs is empty slice, 
	} else {
		return subs
	}

markgardner10 avatar Apr 07 '21 19:04 markgardner10