Skip to content

Commit

Permalink
Avoid implicit memory aliasing in for loop
Browse files Browse the repository at this point in the history
  • Loading branch information
upils committed Sep 19, 2023
1 parent 98cbb55 commit aad913d
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
12 changes: 6 additions & 6 deletions internal/statemachine/classic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1035,7 +1035,7 @@ func TestCustomizeCloudInit(t *testing.T) {
},
}

for _, cloudInitConfig := range cloudInitConfigs {
for i, cloudInitConfig := range cloudInitConfigs {
t.Run("test_customize_cloud_init", func(t *testing.T) {
// Test setup
asserter := helper.Asserter{T: t}
Expand All @@ -1049,11 +1049,11 @@ func TestCustomizeCloudInit(t *testing.T) {
asserter.AssertErrNil(err, true)
defer func() {
if tmpErr := osRemoveAll(tmpDir); tmpErr != nil {
if err != nil {
if err != nil {
err = fmt.Errorf("%w after previous error: %w", tmpErr, err)

Check failure on line 1053 in internal/statemachine/classic_test.go

View workflow job for this annotation

GitHub Actions / check_quality

fmt.Errorf call has more than one error-wrapping directive %w
} else {
err = tmpErr
}
}
}
}()
stateMachine.tempDirs.chroot = tmpDir
Expand All @@ -1063,7 +1063,7 @@ func TestCustomizeCloudInit(t *testing.T) {
asserter.AssertErrNil(err, true)

stateMachine.ImageDef.Customization = &imagedefinition.Customization{
CloudInit: &cloudInitConfig,
CloudInit: &cloudInitConfigs[i],
}

// Running function to test
Expand Down Expand Up @@ -2158,12 +2158,12 @@ func TestCheckEmptyFields(t *testing.T) {
{"missing_implicitly_required", testStruct{A: "foo", C: "baz"}, false},
{"missing_omitempty", testStruct{A: "foo", B: "bar"}, true},
}
for _, tc := range testCases {
for i, tc := range testCases {
t.Run("test_check_empty_fields_"+tc.name, func(t *testing.T) {
asserter := helper.Asserter{T: t}

result := new(gojsonschema.Result)
err := helper.CheckEmptyFields(&tc.structData, result, schema)
err := helper.CheckEmptyFields(&testCases[i].structData, result, schema)
asserter.AssertErrNil(err, false)
schema.Required = append(schema.Required, "fieldA")

Expand Down
2 changes: 1 addition & 1 deletion internal/statemachine/common_states.go
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ func (stateMachine *StateMachine) populateBootfsContents() error {
}
}
if laidOutStructure.HasFilesystem() {
mountedFilesystemWriter, err := gadgetNewMountedFilesystemWriter(&laidOutStructure, nil)
mountedFilesystemWriter, err := gadgetNewMountedFilesystemWriter(&laidOutVolume.LaidOutStructure[ii], nil)
if err != nil {
return fmt.Errorf("Error creating NewMountedFilesystemWriter: %s", err.Error())
}
Expand Down
4 changes: 2 additions & 2 deletions internal/statemachine/helper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -532,7 +532,7 @@ func TestGenerateUniqueDiskID(t *testing.T) {
{"collision", [][]byte{{0, 1, 2, 3}}, [][]byte{{0, 1, 2, 3}, {4, 5, 6, 7}}, []byte{4, 5, 6, 7}, false},
{"broken", [][]byte{{0, 0, 0, 0}}, nil, []byte{0, 0, 0, 0}, true},
}
for _, tc := range testCases {
for i, tc := range testCases {
t.Run("test_generate_unique_diskid_"+tc.name, func(t *testing.T) {
asserter := helper.Asserter{T: t}
// create a test rng reader, using data from our testcase
Expand All @@ -552,7 +552,7 @@ func TestGenerateUniqueDiskID(t *testing.T) {
randRead = rand.Read
}()

randomBytes, err := generateUniqueDiskID(&tc.existing)
randomBytes, err := generateUniqueDiskID(&testCases[i].existing)
if tc.expectedErr {
asserter.AssertErrContains(err, "Failed to generate unique disk ID")
} else {
Expand Down

0 comments on commit aad913d

Please sign in to comment.