diff options
author | Russ Cox <rsc@golang.org> | 2014-10-07 16:27:40 -0400 |
---|---|---|
committer | Russ Cox <rsc@golang.org> | 2014-10-07 16:27:40 -0400 |
commit | 1b7392444183c40afb85b6e20aa5f3b4a2112f27 (patch) | |
tree | 48e0c43b51192fd5dd9cebd014f6c5d530cdc33b /misc | |
parent | 70df1111b1bdba591f02e6ca0628a0a73c6427d6 (diff) | |
download | go-1b7392444183c40afb85b6e20aa5f3b4a2112f27.tar.gz |
runtime: fix _cgo_allocate(0)
Fixes a SWIG bug reported off-list.
LGTM=iant
R=iant
CC=golang-codereviews
https://codereview.appspot.com/155990043
Diffstat (limited to 'misc')
-rw-r--r-- | misc/cgo/test/callback_c_gc.c | 10 | ||||
-rw-r--r-- | misc/cgo/test/callback_c_gccgo.c | 7 |
2 files changed, 17 insertions, 0 deletions
diff --git a/misc/cgo/test/callback_c_gc.c b/misc/cgo/test/callback_c_gc.c index 32bfed0c0..28a62c6db 100644 --- a/misc/cgo/test/callback_c_gc.c +++ b/misc/cgo/test/callback_c_gc.c @@ -39,6 +39,16 @@ callCgoAllocate(void) int i; struct { size_t n; void *ret; } a; List *l, *head, **tail; + + // Make sure this doesn't crash. + // And make sure it returns non-nil. + a.n = 0; + a.ret = 0; + crosscall2(_cgo_allocate, &a, sizeof a); + if(a.ret == 0) { + fprintf(stderr, "callCgoAllocate: alloc 0 returned nil\n"); + exit(2); + } head = 0; tail = &head; diff --git a/misc/cgo/test/callback_c_gccgo.c b/misc/cgo/test/callback_c_gccgo.c index d92dca009..d367b7b68 100644 --- a/misc/cgo/test/callback_c_gccgo.c +++ b/misc/cgo/test/callback_c_gccgo.c @@ -35,6 +35,13 @@ callCgoAllocate(void) int i; List *l, *head, **tail; + // Make sure this doesn't crash. + // And make sure it returns non-nil. + if(_cgo_allocate(0) == 0) { + fprintf(stderr, "callCgoAllocate: alloc 0 returned nil\n"); + exit(2); + } + head = 0; tail = &head; for(i=0; i<100; i++) { |