mixclient: remove shadowed roots declaration - #3780
Open
yzxcj797 wants to merge 1 commit into
Open
Conversation
The receiveOwnRoots loop declared a fresh inner 'roots' (capacity sesRun.mtot) that shadowed the outer 'roots' which had just been reset with roots[:0], and guarded it with a comparison against the new slice's length, which is always zero and therefore dead. Remove the shadowing declaration and the dead check so the loop appends to the reset outer slice and the return at the bottom of the loop hands back the same slice that was built, as intended. Fixes decred#3777.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #3777.
Problem
In
mixing/mixclient/client.go(receiveOwnRootswait loop), each factored-polynomial iteration begins withroots = roots[:0]on the outerroots, then declares a fresh innerroots := make([]*big.Int, 0, sesRun.mtot)that shadows it (#3777):The
len(fp.Roots) <= len(roots)guard compares against a freshly-created slice, so it is dead code; and the per-iteration reset of the outer slice does nothing.Fix
Remove the shadowing declaration and the dead length check. The loop appends to the reset outer
roots(capacitylen(a)-1, exactly the number of roots a valid factored polynomial carries), and thereturn roots, nilat the bottom of the loop returns the same slice that was built. Behavior is unchanged — the returned values are identical — but there is one variable, one reset, and no dead branch left to mislead.Validation
go build ./...andgo vet ./...in themixingmodule are clean.