util/copy.go | 2 +- util/copy_test.go | 15 +++++++++++++++ diff --git a/util/copy.go b/util/copy.go index c7d64cc27538bc241916d5ea8f921b3dae9b97ff..793a99cd951c832922dabd474a83e3c9080dd977 100644 --- a/util/copy.go +++ b/util/copy.go @@ -15,7 +15,7 @@ if dV.Kind() == reflect.Array && !dV.CanAddr() { panic(fmt.Sprintf("dest not addressable: %T", dest)) } if sV.Kind() == reflect.String { - sV = sV.Convert(dV.Type()) + sV = sV.Convert(reflect.SliceOf(dV.Type().Elem())) } if dV.Len() != sV.Len() { panic(fmt.Sprintf("dest len (%d) != src len (%d)", dV.Len(), sV.Len())) diff --git a/util/copy_test.go b/util/copy_test.go index 450e5c4b5d83cb2322d17baf87aabb4a2a2ecbc5..284840a3ad3982f7b45e69639e483ca698f95406 100644 --- a/util/copy_test.go +++ b/util/copy_test.go @@ -44,3 +44,18 @@ t.Log(r) }() CopyExact(make([]byte, 2), "abc") } + +func TestCopySrcString(t *testing.T) { + dest := make([]byte, 3) + CopyExact(dest, "lol") + if string(dest) != "lol" { + t.FailNow() + } + defer func() { + r := recover() + if r == nil { + t.FailNow() + } + }() + CopyExact(dest, "rofl") +}