reflect; SetLen() requires an addressable value

Этот коммит содержится в:
Damian Gryski 2023-03-21 11:11:19 -07:00 коммит произвёл Ayke
родитель 4d43df75d5
коммит 17f5fb1071
2 изменённых файлов: 3 добавлений и 1 удалений

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

@ -999,7 +999,7 @@ func (v Value) SetLen(n int) {
if v.typecode.Kind() != Slice {
panic(&ValueError{Method: "reflect.Value.SetLen", Kind: v.Kind()})
}
v.checkAddressable()
hdr := (*sliceHeader)(v.value)
if int(uintptr(n)) != n || uintptr(n) > hdr.cap {
panic("reflect.Value.SetLen: slice length out of range")

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

@ -180,6 +180,8 @@ func TestSlice(t *testing.T) {
}
// should be equivalent to s28 now, except for the capacity which doesn't change
s268ref = ValueOf(&s268).Elem()
s268ref.SetLen(6)
if len(s28) != s268ref.Len() || cap(s268) != s268ref.Cap() {
t.Errorf("SetLen: len(s268)=%d s268ref.Len()=%d cap(s268)=%d s268ref.Cap()=%d\n", len(s28), s268ref.Len(), cap(s268), s268ref.Cap())