From 2fb4928aa873bef89d016e0af2c0724b44725043 Mon Sep 17 00:00:00 2001 From: BugKillerPro <43431429+BugKillerPro@users.noreply.github.com> Date: Fri, 15 Dec 2023 16:31:23 +0800 Subject: [PATCH] refactor: Resolve implicit memory aliasing in for loop (#6730) --- schema/schema_helper_test.go | 4 ++-- schema/schema_test.go | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/schema/schema_helper_test.go b/schema/schema_helper_test.go index 605aa03a..bc326686 100644 --- a/schema/schema_helper_test.go +++ b/schema/schema_helper_test.go @@ -163,8 +163,8 @@ func checkSchemaRelation(t *testing.T, s *schema.Schema, relation Relation) { t.Errorf("schema %v relation's join table tablename expects %v, but got %v", s, relation.JoinTable.Table, r.JoinTable.Table) } - for _, f := range relation.JoinTable.Fields { - checkSchemaField(t, r.JoinTable, &f, nil) + for i := range relation.JoinTable.Fields { + checkSchemaField(t, r.JoinTable, &relation.JoinTable.Fields[i], nil) } } diff --git a/schema/schema_test.go b/schema/schema_test.go index 5bc0fb83..45e152e9 100644 --- a/schema/schema_test.go +++ b/schema/schema_test.go @@ -46,8 +46,8 @@ func checkUserSchema(t *testing.T, user *schema.Schema) { {Name: "Active", DBName: "active", BindNames: []string{"Active"}, DataType: schema.Bool}, } - for _, f := range fields { - checkSchemaField(t, user, &f, func(f *schema.Field) { + for i := range fields { + checkSchemaField(t, user, &fields[i], func(f *schema.Field) { f.Creatable = true f.Updatable = true f.Readable = true @@ -136,8 +136,8 @@ func TestParseSchemaWithAdvancedDataType(t *testing.T) { {Name: "Admin", DBName: "admin", BindNames: []string{"Admin"}, DataType: schema.Bool}, } - for _, f := range fields { - checkSchemaField(t, user, &f, func(f *schema.Field) { + for i := range fields { + checkSchemaField(t, user, &fields[i], func(f *schema.Field) { f.Creatable = true f.Updatable = true f.Readable = true