From fbedf62f3ddde6502359741981c2354ef9045f90 Mon Sep 17 00:00:00 2001 From: Matthew Halpern Date: Wed, 20 Feb 2019 21:37:32 -0800 Subject: [PATCH] swarm/storage: fix loop bound for database cleanup (#19085) The current loop continuation condition is always true as a uint8 is always being checked whether it is less than 255 (its maximum value). Since the loop starts with the value 1, the loop termination can be guarranteed to exit once the value overflows to 0. --- swarm/storage/ldbstore.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/swarm/storage/ldbstore.go b/swarm/storage/ldbstore.go index 9e4d638410..1d53577130 100644 --- a/swarm/storage/ldbstore.go +++ b/swarm/storage/ldbstore.go @@ -527,8 +527,8 @@ func (s *LDBStore) Cleanup(f func(*chunk) bool) { if err != nil { found := false - // highest possible proximity is 255 - for po = 1; po <= 255; po++ { + // The highest possible proximity is 255, so exit loop upon overflow. + for po = uint8(1); po != 0; po++ { datakey = getDataKey(index.Idx, po) data, err = s.db.Get(datakey) if err == nil {