mirror of
https://github.com/golang/go
synced 2024-11-23 01:40:03 -07:00
3fc276ccf8
Fixes #30065 Change-Id: I3d0fb03bab397548653d5f3b386cfe2980ac1030 Reviewed-on: https://go-review.googlesource.com/c/160830 Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Keith Randall <khr@golang.org>
39 lines
856 B
Go
39 lines
856 B
Go
// Copyright 2019 The Go Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style
|
|
// license that can be found in the LICENSE file.
|
|
|
|
// Don't make a private copy of an array when taking the address of an
|
|
// element.
|
|
|
|
package cgotest
|
|
|
|
// #include <string.h>
|
|
import "C"
|
|
|
|
import (
|
|
"testing"
|
|
"unsafe"
|
|
)
|
|
|
|
func test30065(t *testing.T) {
|
|
var a [256]byte
|
|
b := []byte("a")
|
|
C.memcpy(unsafe.Pointer(&a), unsafe.Pointer(&b[0]), 1)
|
|
if a[0] != 'a' {
|
|
t.Errorf("&a failed: got %c, want %c", a[0], 'a')
|
|
}
|
|
|
|
b = []byte("b")
|
|
C.memcpy(unsafe.Pointer(&a[0]), unsafe.Pointer(&b[0]), 1)
|
|
if a[0] != 'b' {
|
|
t.Errorf("&a[0] failed: got %c, want %c", a[0], 'b')
|
|
}
|
|
|
|
d := make([]byte, 256)
|
|
b = []byte("c")
|
|
C.memcpy(unsafe.Pointer(&d[0]), unsafe.Pointer(&b[0]), 1)
|
|
if d[0] != 'c' {
|
|
t.Errorf("&d[0] failed: got %c, want %c", d[0], 'c')
|
|
}
|
|
}
|