[#1357] go: Fix panic caused by using range over slice len
All checks were successful
Vulncheck / Vulncheck (pull_request) Successful in 1m12s
DCO action / DCO (pull_request) Successful in 1m28s
Pre-commit hooks / Pre-commit (pull_request) Successful in 1m53s
Tests and linters / Run gofumpt (pull_request) Successful in 1m55s
Build / Build Components (pull_request) Successful in 2m14s
Tests and linters / gopls check (pull_request) Successful in 2m22s
Tests and linters / Staticcheck (pull_request) Successful in 2m30s
Tests and linters / Lint (pull_request) Successful in 3m15s
Tests and linters / Tests (pull_request) Successful in 3m25s
Tests and linters / Tests with -race (pull_request) Successful in 3m31s
All checks were successful
Vulncheck / Vulncheck (pull_request) Successful in 1m12s
DCO action / DCO (pull_request) Successful in 1m28s
Pre-commit hooks / Pre-commit (pull_request) Successful in 1m53s
Tests and linters / Run gofumpt (pull_request) Successful in 1m55s
Build / Build Components (pull_request) Successful in 2m14s
Tests and linters / gopls check (pull_request) Successful in 2m22s
Tests and linters / Staticcheck (pull_request) Successful in 2m30s
Tests and linters / Lint (pull_request) Successful in 3m15s
Tests and linters / Tests (pull_request) Successful in 3m25s
Tests and linters / Tests with -race (pull_request) Successful in 3m31s
If slice is altered in `for` loop, we cannot use range over its length: it may cause panic if slice gets shorter. Signed-off-by: Ekaterina Lebedeva <ekaterina.lebedeva@yadro.com>
This commit is contained in:
parent
273980cfb9
commit
f652518c24
1 changed files with 1 additions and 1 deletions
|
@ -169,7 +169,7 @@ func (s *Server) getContainerNodes(contID cid.ID) ([]netmap.NodeInfo, error) {
|
|||
|
||||
nodes := placement.FlattenNodes(ns)
|
||||
bs := (*keys.PublicKey)(&s.key.PublicKey).Bytes()
|
||||
for i := range len(nodes) {
|
||||
for i := 0; i < len(nodes); i++ { // don't use range, slice mutates in body
|
||||
if bytes.Equal(nodes[i].PublicKey(), bs) {
|
||||
copy(nodes[i:], nodes[i+1:])
|
||||
nodes = nodes[:len(nodes)-1]
|
||||
|
|
Loading…
Reference in a new issue