Skip to content

Commit

Permalink
refactor: use integer-based ranges where possible
Browse files Browse the repository at this point in the history
  • Loading branch information
G-Rath committed Dec 5, 2024
1 parent 646b696 commit fe57eca
Show file tree
Hide file tree
Showing 8 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion .golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ linters:
# - inamedparam
- ineffassign
- interfacebloat
# - intrange
- intrange
- loggercheck
- makezero
- mirror
Expand Down
2 changes: 1 addition & 1 deletion artifact/image/layerscanning/file_node_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ func TestReadingAfterClose(t *testing.T) {
}
for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
for i := 0; i < readAndCloseEvents; i++ {
for range readAndCloseEvents {
gotBytes := make([]byte, bufferSize)
gotNumBytesRead, gotErr := tc.node.Read(gotBytes)

Expand Down
2 changes: 1 addition & 1 deletion artifact/image/layerscanning/layer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,7 @@ func TestChainFSReadDir(t *testing.T) {
return strings.Compare(a.Name(), b.Name())
})

for i := range len(wantDirEntries) {
for i := range wantDirEntries {
gotEntry := gotDirEntries[i]
wantEntry := wantDirEntries[i]
if gotEntry.Name() != wantEntry.Name() {
Expand Down
4 changes: 2 additions & 2 deletions artifact/image/unpack/unpack.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ func (u *Unpacker) UnpackSquashedFromTarball(dir string, tarPath string) error {
// requiredTargets stores targets that symlinks point to.
// This is needed because the symlink may be required by u.requirer, but the target may not be.
requiredTargets := make(map[string]bool)
for pass := 0; pass < u.MaxPass; pass++ {
for pass := range u.MaxPass {
finalPass := false
// Resolve symlinks on the last pass once all potential target files have been unpacked.
if pass == u.MaxPass-1 {
Expand Down Expand Up @@ -262,7 +262,7 @@ func (u *Unpacker) UnpackLayers(dir string, image v1.Image) ([]string, error) {
// requiredTargets stores targets that symlinks point to.
// This is needed because the symlink may be required by u.requirer, but the target may not be.
requiredTargets := make(map[string]bool)
for pass := 0; pass < u.MaxPass; pass++ {
for pass := range u.MaxPass {
finalPass := false
// Resolve symlinks on the last pass once all potential target files have been unpacked.
if pass == u.MaxPass-1 {
Expand Down
2 changes: 1 addition & 1 deletion detector/cve/cve202338408/semantic/version-packagist.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func comparePackagistComponents(a, b []string) int {

var compare int

for i := 0; i < minLen; i++ {
for i := range minLen {
ai, aIsNumber := convertToBigInt(a[i])
bi, bIsNumber := convertToBigInt(b[i])

Expand Down
2 changes: 1 addition & 1 deletion detector/cve/cve20236019/cve20236019.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ func generateRandomString(length int) string {

const letters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
bytes := make([]byte, length)
for i := 0; i < length; i++ {
for i := range length {
bytes[i] = letters[rand.Intn(len(letters))]
}
return string(bytes)
Expand Down
2 changes: 1 addition & 1 deletion detector/weakcredentials/winlocal/samreg/crypto.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func transformRID(key []byte) []byte {
outputKey = append(outputKey, ((key[5]&0x3F)<<1)|(key[6]>>7))
outputKey = append(outputKey, key[6]&0x7F)

for i := 0; i < 8; i++ {
for i := range 8 {
outputKey[i] = (outputKey[i] << 1) & 0xfe
}

Expand Down
2 changes: 1 addition & 1 deletion detector/weakcredentials/winlocal/systemreg/systemreg.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func (s *SystemRegistry) Syskey() ([]byte, error) {
transforms := []int{8, 5, 4, 2, 11, 9, 13, 3, 0, 6, 1, 12, 14, 10, 15, 7}
var resultKey []byte

for i := range len(unhexKey) {
for i := range unhexKey {
resultKey = append(resultKey, unhexKey[transforms[i]])
}

Expand Down

0 comments on commit fe57eca

Please sign in to comment.