reflect: loosen unaddressable array rules for Copy()

Этот коммит содержится в:
Damian Gryski 2023-03-06 17:34:14 -08:00 коммит произвёл Damian Gryski
родитель e849901ad6
коммит c6728643e6

Просмотреть файл

@ -1199,6 +1199,11 @@ func Copy(dst, src Value) int {
panic("Copy: type mismatch: " + dst.typecode.String() + "/" + src.typecode.String())
}
// Can read from an unaddressable array but not write to one.
if dst.typecode.Kind() == Array && !dst.isIndirect() {
panic("reflect.Copy: unaddressable array value")
}
dstbuf, dstlen := buflen(dst)
srcbuf, srclen := buflen(src)
@ -1216,10 +1221,10 @@ func buflen(v Value) (unsafe.Pointer, uintptr) {
case Array:
if v.isIndirect() {
buf = v.value
len = uintptr(v.Len())
} else {
panic("reflect.Copy: unaddressable array value")
buf = unsafe.Pointer(&v.value)
}
len = uintptr(v.Len())
case String:
hdr := (*stringHeader)(v.value)
buf = hdr.data