While perusing the source code I noticed the following fragment from pkg/tools/speedtest.go:
if SIndex > (len(s.Servers) - 1) {
SIndex = len(s.Servers)
}
if len(s.Servers) < 1 {
return nil, errorf("can't not find server,please check net")
}
return &s.Servers[SIndex], nil
I believe the assignment inside the original if is missing a -1. Say SIndex is 3 due to retries. And len(s.Servers) is also 3. The if will fire because 3 > 3-1, but SIndex will be set to 3. The return statement will fail because the valid indices for a len() of 3 is 0..2 but it will attempt to reference s.Servers[3].
While perusing the source code I noticed the following fragment from pkg/tools/speedtest.go:
I believe the assignment inside the original if is missing a -1. Say SIndex is 3 due to retries. And len(s.Servers) is also 3. The if will fire because 3 > 3-1, but SIndex will be set to 3. The return statement will fail because the valid indices for a len() of 3 is 0..2 but it will attempt to reference s.Servers[3].
https://github.com/bzznectar/nectar/blob/87ca581552f007b345d7c7cf08292f07bcf3681f/pkg/tools/speedtest.go#L299