reflect: fix Value.Index() in a specific case
In the case where: - Value.Index() was called on an array - that array was bigger than a pointer - the element type fits in a pointer - the 'indirect' flag isn't set the Value.Index() method would still (incorrectly) load the value. This commit fixes that. The next commit adds a test which would have triggered this bug so works as a regression test.
Этот коммит содержится в:
родитель
823c9c25cf
коммит
5866a47e77
1 изменённых файлов: 8 добавлений и 2 удалений
|
@ -528,11 +528,17 @@ func (v Value) Index(i int) Value {
|
||||||
if size > unsafe.Sizeof(uintptr(0)) {
|
if size > unsafe.Sizeof(uintptr(0)) {
|
||||||
// The element fits in a pointer, but the array does not.
|
// The element fits in a pointer, but the array does not.
|
||||||
// Load the value from the pointer.
|
// Load the value from the pointer.
|
||||||
addr := uintptr(v.value) + elemSize*uintptr(i) // pointer to new value
|
addr := unsafe.Pointer(uintptr(v.value) + elemSize*uintptr(i)) // pointer to new value
|
||||||
|
value := addr
|
||||||
|
if !v.isIndirect() {
|
||||||
|
// Use a pointer to the value (don't load the value) if the
|
||||||
|
// 'indirect' flag is set.
|
||||||
|
value = unsafe.Pointer(loadValue(addr, elemSize))
|
||||||
|
}
|
||||||
return Value{
|
return Value{
|
||||||
typecode: v.typecode.elem(),
|
typecode: v.typecode.elem(),
|
||||||
flags: v.flags,
|
flags: v.flags,
|
||||||
value: unsafe.Pointer(loadValue(unsafe.Pointer(addr), elemSize)),
|
value: value,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Загрузка…
Создание таблицы
Сослаться в новой задаче