diff --git a/internal/literals/obfuscators.go b/internal/literals/obfuscators.go index 1920979..cc2def4 100644 --- a/internal/literals/obfuscators.go +++ b/internal/literals/obfuscators.go @@ -160,7 +160,7 @@ func randExtKey(rand *mathrand.Rand, idx int) *externalKey { func randExtKeys(rand *mathrand.Rand) []*externalKey { count := minExtKeyCount + rand.Intn(maxExtKeyCount-minExtKeyCount) keys := make([]*externalKey, count) - for i := 0; i < count; i++ { + for i := range count { keys[i] = randExtKey(rand, i) } return keys @@ -211,7 +211,7 @@ func dataToByteSliceWithExtKeys(rand *mathrand.Rand, data []byte, extKeys []*ext extKeyOpCount := minByteSliceExtKeyOps + rand.Intn(maxByteSliceExtKeyOps-minByteSliceExtKeyOps) var stmts []ast.Stmt - for i := 0; i < extKeyOpCount; i++ { + for range extKeyOpCount { key := extKeys[rand.Intn(len(extKeys))] key.AddRef() diff --git a/internal/literals/proxy.go b/internal/literals/proxy.go index 3e600ba..4e49412 100644 --- a/internal/literals/proxy.go +++ b/internal/literals/proxy.go @@ -54,7 +54,7 @@ type proxyDispatcher struct { func (d *proxyDispatcher) initialize() { flattenStructs := make([]*proxyStruct, d.rand.Intn(maxStructCount-minStructCount)+minStructCount) - for i := 0; i < len(flattenStructs); i++ { + for i := range flattenStructs { flattenStructs[i] = &proxyStruct{ typeName: d.nameFunc(d.rand, "proxyStructName"+strconv.Itoa(i)), name: d.nameFunc(d.rand, "proxyStructFieldName"+strconv.Itoa(i)), @@ -75,10 +75,7 @@ func (d *proxyDispatcher) initialize() { current := queue[0] queue = queue[1:] - childCount := d.rand.Intn(maxChildCount-minChildCount) + minChildCount - if childCount > len(unassigned) { - childCount = len(unassigned) - } + childCount := min(d.rand.Intn(maxChildCount-minChildCount)+minChildCount, len(unassigned)) for i := 0; i < childCount; i++ { child := unassigned[0] @@ -194,7 +191,7 @@ func (d *proxyDispatcher) AddToFile(file *ast.File) { for _, strct := range d.flattenStructs { dummyCount := d.rand.Intn(maxJunkValueCount-minJunkValueCount+1) + minJunkValueCount - for i := 0; i < dummyCount; i++ { + for range dummyCount { strct.values = append(strct.values, d.junkValue()) }