Skip to content

Fixed #239 fixed func New in list/list.go #240

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions list/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,14 @@ func New(items interface{}, size int) (*List, error) {
slice := reflect.ValueOf(items)
values := make([]*interface{}, slice.Len())

for i := range values {
item := slice.Index(i).Interface()
values[i] = &item
// Each item from the input slice is wrapped in an interface{},
// and a pointer to this interface{} is stored. This ensures that
// each element in `values` points to a unique interface{} holding the item's value.
for i := 0; i < slice.Len(); i++ {
val := slice.Index(i).Interface()
values[i] = new(interface{}) // Allocate new memory for an interface{}
*values[i] = val // Store the item's value in the new interface{}
}

return &List{size: size, items: values, scope: values}, nil
}

Expand Down