1
0
mirror of https://github.com/golang/go synced 2024-11-13 18:50:24 -07:00

misc/cgo/errors: fix malloc test for dragonfly

The Dragonfly libc returns a non-zero value for malloc(-1).

Fixes #17585.

Change-Id: Icfe68011ccbc75c676273ee3c3efdf24a520a004
Reviewed-on: https://go-review.googlesource.com/32050
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
This commit is contained in:
Ian Lance Taylor 2016-10-25 12:59:36 -07:00
parent d391dc260a
commit e24ccfc6fc
2 changed files with 13 additions and 2 deletions

View File

@ -11,10 +11,21 @@ import "C"
import ( import (
"fmt" "fmt"
"runtime"
) )
func main() { func main() {
p := C.malloc(C.size_t(^uintptr(0))) var size C.size_t
size--
// The Dragonfly libc succeeds when asked to allocate
// 0xffffffffffffffff bytes, so pass a different value that
// causes it to fail.
if runtime.GOOS == "dragonfly" {
size = C.size_t(0x7fffffff << (32 * (^uintptr(0) >> 63)))
}
p := C.malloc(size)
if p == nil { if p == nil {
fmt.Println("malloc: C.malloc returned nil") fmt.Println("malloc: C.malloc returned nil")
// Just exit normally--the test script expects this // Just exit normally--the test script expects this

View File

@ -62,7 +62,7 @@ fi
# The malloc.go test should crash. # The malloc.go test should crash.
rm -f malloc.out rm -f malloc.out
if go run malloc.go >malloc.out 2>&1; then if go run malloc.go >malloc.out 2>&1; then
echo "`go run malloc.go` succeeded unexpectedly" echo '`go run malloc.go` succeeded unexpectedly'
cat malloc.out cat malloc.out
rm -f malloc.out rm -f malloc.out
exit 1 exit 1