Skip to content

Commit

Permalink
swarm/storage: fix loop bound for database cleanup (#19085)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Matthalp-zz authored and zelig committed Feb 21, 2019
1 parent 9d5e10f commit fbedf62
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions swarm/storage/ldbstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit fbedf62

Please sign in to comment.