Skip to content

Commit

Permalink
Fix: filter nil ip addr
Browse files Browse the repository at this point in the history
  • Loading branch information
luc99hen committed Sep 20, 2022
1 parent 98d7f5f commit e414efe
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pkg/util/ip/ip.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func RemoveDupIPs(ips []net.IP) []net.IP {
results := make([]net.IP, 0, len(ips))
temp := map[string]bool{}
for _, ip := range ips {
if _, ok := temp[string(ip)]; !ok {
if _, ok := temp[string(ip)]; ip != nil && !ok {
temp[string(ip)] = true
results = append(results, ip)
}
Expand Down
5 changes: 5 additions & 0 deletions pkg/util/ip/ip_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,11 @@ func TestRemoveDupIPs(t *testing.T) {
nil,
[]net.IP{},
},
{
"nil ip",
[]net.IP{[]byte("1.1.1.1"), nil},
[]net.IP{[]byte("1.1.1.1")},
},
}

for _, test := range tests {
Expand Down

0 comments on commit e414efe

Please sign in to comment.