Skip to content

Commit

Permalink
append destslice size only if dest size smaller than src
Browse files Browse the repository at this point in the history
fix #92
  • Loading branch information
juju812 authored Mar 15, 2021
1 parent d711dc7 commit 1d40514
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions copier.go
Original file line number Diff line number Diff line change
Expand Up @@ -282,9 +282,17 @@ func copier(toValue interface{}, fromValue interface{}, opt Option) (err error)

if isSlice {
if dest.Addr().Type().AssignableTo(to.Type().Elem()) {
to.Set(reflect.Append(to, dest.Addr()))
if to.Len() < i+1 {
to.Set(reflect.Append(to, dest.Addr()))
} else {
set(to.Index(i), dest.Addr(), opt.DeepCopy)
}
} else if dest.Type().AssignableTo(to.Type().Elem()) {
to.Set(reflect.Append(to, dest))
if to.Len() < i+1 {
to.Set(reflect.Append(to, dest))
} else {
set(to.Index(i), dest, opt.DeepCopy)
}
}
} else if initDest {
to.Set(dest)
Expand Down

0 comments on commit 1d40514

Please sign in to comment.