]> Cypherpunks repositories - gostls13.git/commitdiff
misc/cgo/errors: fix malloc test for dragonfly
authorIan Lance Taylor <iant@golang.org>
Tue, 25 Oct 2016 19:59:36 +0000 (12:59 -0700)
committerIan Lance Taylor <iant@golang.org>
Tue, 25 Oct 2016 20:11:50 +0000 (20:11 +0000)
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>
misc/cgo/errors/malloc.go
misc/cgo/errors/test.bash

index 7a69736222944057ec25ca07ed29e0d39be5317a..65da0208b9708f8115abcdc00733acff25358ddc 100644 (file)
@@ -11,10 +11,21 @@ import "C"
 
 import (
        "fmt"
+       "runtime"
 )
 
 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 {
                fmt.Println("malloc: C.malloc returned nil")
                // Just exit normally--the test script expects this
index 8b892938fcb8ebaca8c88e68bc15b4f4bd52939c..05261e9d767c1eb7d34165f869ee9d70b84e8c1f 100755 (executable)
@@ -62,7 +62,7 @@ fi
 # The malloc.go test should crash.
 rm -f malloc.out
 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
        rm -f malloc.out
        exit 1