aboutsummaryrefslogtreecommitdiff
path: root/src/reflect/value.go
diff options
context:
space:
mode:
authorIan Lance Taylor <iant@golang.org>2021-04-09 11:20:35 -0700
committerIan Lance Taylor <iant@golang.org>2021-04-09 23:54:31 +0000
commit554d2c4f060ec42e30970dacff1e782250169323 (patch)
tree68702e526b7ccdc8c92f2e7fa306f10660e74a41 /src/reflect/value.go
parent5305bdedb0be18c0636d2b4a707bf08228909c27 (diff)
downloadgo-554d2c4f060ec42e30970dacff1e782250169323.tar.gz
go-554d2c4f060ec42e30970dacff1e782250169323.zip
reflect: panic on New of go:notinheap type
For #42076 Fixes #45451 Change-Id: I69646226d3480d5403205412ddd13c0cfc2c8a53 Reviewed-on: https://go-review.googlesource.com/c/go/+/308970 Trust: Ian Lance Taylor <iant@golang.org> Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Keith Randall <khr@golang.org>
Diffstat (limited to 'src/reflect/value.go')
-rw-r--r--src/reflect/value.go7
1 files changed, 6 insertions, 1 deletions
diff --git a/src/reflect/value.go b/src/reflect/value.go
index 9670d4656b..7890c125d8 100644
--- a/src/reflect/value.go
+++ b/src/reflect/value.go
@@ -2702,9 +2702,14 @@ func New(typ Type) Value {
panic("reflect: New(nil)")
}
t := typ.(*rtype)
+ pt := t.ptrTo()
+ if ifaceIndir(pt) {
+ // This is a pointer to a go:notinheap type.
+ panic("reflect: New of type that may not be allocated in heap (possibly undefined cgo C type)")
+ }
ptr := unsafe_New(t)
fl := flag(Ptr)
- return Value{t.ptrTo(), ptr, fl}
+ return Value{pt, ptr, fl}
}
// NewAt returns a Value representing a pointer to a value of the