forked from TrueCloudLab/frostfs-node
[#1357] go: Fix panic caused by using range over slice len
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)
|
nodes := placement.FlattenNodes(ns)
|
||||||
bs := (*keys.PublicKey)(&s.key.PublicKey).Bytes()
|
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) {
|
if bytes.Equal(nodes[i].PublicKey(), bs) {
|
||||||
copy(nodes[i:], nodes[i+1:])
|
copy(nodes[i:], nodes[i+1:])
|
||||||
nodes = nodes[:len(nodes)-1]
|
nodes = nodes[:len(nodes)-1]
|
||||||
|
|
Loading…
Reference in a new issue