go/misc/cgo/errors/malloc.go
Ian Lance Taylor b4ce38ec57 cmd/cgo: throw if C.malloc returns nil
Change-Id: If7740ac7b6c4190db5a1ab4100d12cf16dc79c84
Reviewed-on: https://go-review.googlesource.com/31768
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Russ Cox <rsc@golang.org>
2016-10-25 02:38:49 +00:00

24 lines
507 B
Go

// Copyright 2016 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.
// Test that C.malloc does not return nil.
package main
// #include <stdlib.h>
import "C"
import (
"fmt"
)
func main() {
p := C.malloc(C.size_t(^uintptr(0)))
if p == nil {
fmt.Println("malloc: C.malloc returned nil")
// Just exit normally--the test script expects this
// program to crash, so exiting normally indicates failure.
}
}