mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-17 03:03:27 +00:00
reflect: fix Copy of non-pointer array with size > 64bits
This commit is contained in:
committed by
Damian Gryski
parent
e98fea0bba
commit
4f96a50fd0
@@ -1712,7 +1712,7 @@ func buflen(v Value) (unsafe.Pointer, uintptr) {
|
|||||||
buf = hdr.data
|
buf = hdr.data
|
||||||
len = hdr.len
|
len = hdr.len
|
||||||
case Array:
|
case Array:
|
||||||
if v.isIndirect() {
|
if v.isIndirect() || v.typecode.Size() > unsafe.Sizeof(uintptr(0)) {
|
||||||
buf = v.value
|
buf = v.value
|
||||||
} else {
|
} else {
|
||||||
buf = unsafe.Pointer(&v.value)
|
buf = unsafe.Pointer(&v.value)
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import (
|
|||||||
"bytes"
|
"bytes"
|
||||||
"encoding/base64"
|
"encoding/base64"
|
||||||
. "reflect"
|
. "reflect"
|
||||||
|
"slices"
|
||||||
"sort"
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
@@ -804,6 +805,36 @@ func TestClearMap(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestCopyArrayToSlice(t *testing.T) {
|
||||||
|
// Test copying array <=64 bits and >64bits
|
||||||
|
// See issue #4554
|
||||||
|
a1 := [1]int64{1}
|
||||||
|
s1 := make([]int64, 1)
|
||||||
|
a2 := [2]int64{1, 2}
|
||||||
|
s2 := make([]int64, 2)
|
||||||
|
a8 := [8]byte{0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08}
|
||||||
|
s8 := make([]byte, 8)
|
||||||
|
a9 := [9]byte{0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09}
|
||||||
|
s9 := make([]byte, 9)
|
||||||
|
|
||||||
|
Copy(ValueOf(s1), ValueOf(a1))
|
||||||
|
if !slices.Equal(s1, a1[:]) {
|
||||||
|
t.Errorf("copied slice %x does not match input array %x", s1, a1[:])
|
||||||
|
}
|
||||||
|
Copy(ValueOf(s2), ValueOf(a2))
|
||||||
|
if !slices.Equal(s2, a2[:]) {
|
||||||
|
t.Errorf("copied slice %x does not match input array %x", s2, a2[:])
|
||||||
|
}
|
||||||
|
Copy(ValueOf(s8), ValueOf(a8))
|
||||||
|
if !bytes.Equal(s8, a8[:]) {
|
||||||
|
t.Errorf("copied slice %x does not match input array %x", s8, a8[:])
|
||||||
|
}
|
||||||
|
Copy(ValueOf(s9), ValueOf(a9))
|
||||||
|
if !bytes.Equal(s9, a9[:]) {
|
||||||
|
t.Errorf("copied slice %x does not match input array %x", s9, a9[:])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestIssue4040(t *testing.T) {
|
func TestIssue4040(t *testing.T) {
|
||||||
var value interface{} = uint16(0)
|
var value interface{} = uint16(0)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user