mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
cmd/cgo: allow C.malloc(0) always
Because we can, and because it otherwise might crash the program if we think we're out of memory. Fixes #6390. R=golang-dev, iant, minux.ma CC=golang-dev https://golang.org/cl/13345048
This commit is contained in:
parent
b2794a1c2e
commit
647eaed93b
3 changed files with 5 additions and 0 deletions
|
|
@ -46,5 +46,6 @@ func Test3250(t *testing.T) { test3250(t) }
|
||||||
func TestCallbackStack(t *testing.T) { testCallbackStack(t) }
|
func TestCallbackStack(t *testing.T) { testCallbackStack(t) }
|
||||||
func TestFpVar(t *testing.T) { testFpVar(t) }
|
func TestFpVar(t *testing.T) { testFpVar(t) }
|
||||||
func Test4339(t *testing.T) { test4339(t) }
|
func Test4339(t *testing.T) { test4339(t) }
|
||||||
|
func Test6390(t *testing.T) { test6390(t) }
|
||||||
|
|
||||||
func BenchmarkCgoCall(b *testing.B) { benchCgoCall(b) }
|
func BenchmarkCgoCall(b *testing.B) { benchCgoCall(b) }
|
||||||
|
|
|
||||||
|
|
@ -1225,6 +1225,8 @@ Slice GoBytes(char *p, int32_t n) {
|
||||||
extern void runtime_throw(const char *):
|
extern void runtime_throw(const char *):
|
||||||
void *Cmalloc(size_t n) {
|
void *Cmalloc(size_t n) {
|
||||||
void *p = malloc(n);
|
void *p = malloc(n);
|
||||||
|
if(p == NULL && n == 0)
|
||||||
|
p = malloc(1);
|
||||||
if(p == NULL)
|
if(p == NULL)
|
||||||
runtime_throw("runtime: C malloc failed");
|
runtime_throw("runtime: C malloc failed");
|
||||||
return p;
|
return p;
|
||||||
|
|
|
||||||
|
|
@ -14,6 +14,8 @@ x_cgo_malloc(void *p)
|
||||||
} *a = p;
|
} *a = p;
|
||||||
|
|
||||||
a->ret = malloc(a->n);
|
a->ret = malloc(a->n);
|
||||||
|
if(a->ret == NULL && a->n == 0)
|
||||||
|
a->ret = malloc(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Stub for calling free from Go */
|
/* Stub for calling free from Go */
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue