diff options
Diffstat (limited to 'test/nilptr')
-rw-r--r-- | test/nilptr/arrayindex.go | 7 | ||||
-rw-r--r-- | test/nilptr/arrayindex1.go | 9 | ||||
-rw-r--r-- | test/nilptr/arraytoslice.go | 11 | ||||
-rw-r--r-- | test/nilptr/arraytoslice1.go | 11 | ||||
-rw-r--r-- | test/nilptr/arraytoslice2.go | 13 | ||||
-rw-r--r-- | test/nilptr/slicearray.go | 9 | ||||
-rw-r--r-- | test/nilptr/structfield.go | 13 | ||||
-rw-r--r-- | test/nilptr/structfield1.go | 13 | ||||
-rw-r--r-- | test/nilptr/structfield2.go | 15 | ||||
-rw-r--r-- | test/nilptr/structfieldaddr.go | 13 |
10 files changed, 52 insertions, 62 deletions
diff --git a/test/nilptr/arrayindex.go b/test/nilptr/arrayindex.go index 1767acc27..fa26532c6 100644 --- a/test/nilptr/arrayindex.go +++ b/test/nilptr/arrayindex.go @@ -1,4 +1,3 @@ -// [ $GOOS != nacl ] || exit 0 # do not bother on NaCl // $G $D/$F.go && $L $F.$A && // ((! sh -c ./$A.out) >/dev/null 2>&1 || echo BUG: should fail) @@ -13,8 +12,8 @@ import "unsafe" var x byte func main() { - var p *[1<<30]byte = nil; - x = 123; + var p *[1<<30]byte = nil + x = 123 // The problem here is not the use of unsafe: // it is that indexing into p[] with a large @@ -23,5 +22,5 @@ func main() { // Pointer offsets and array indices, if they are // very large, need to dereference the base pointer // to trigger a trap. - println(p[uintptr(unsafe.Pointer(&x))]); // should crash + println(p[uintptr(unsafe.Pointer(&x))]) // should crash } diff --git a/test/nilptr/arrayindex1.go b/test/nilptr/arrayindex1.go index c16cac405..64f46e14d 100644 --- a/test/nilptr/arrayindex1.go +++ b/test/nilptr/arrayindex1.go @@ -1,4 +1,3 @@ -// [ $GOOS != nacl ] || exit 0 # do not bother on NaCl // $G $D/$F.go && $L $F.$A && // ((! sh -c ./$A.out) >/dev/null 2>&1 || echo BUG: should fail) @@ -10,7 +9,7 @@ package main import "unsafe" -var dummy [512<<20]byte; // give us a big address space +var dummy [512<<20]byte // give us a big address space func main() { // the test only tests what we intend to test // if dummy starts in the first 256 MB of memory. @@ -18,7 +17,7 @@ func main() { // at the address that might be accidentally // dereferenced below. if uintptr(unsafe.Pointer(&dummy)) > 256<<20 { - panic("dummy too far out"); + panic("dummy too far out") } // The problem here is that indexing into p[] with a large @@ -27,6 +26,6 @@ func main() { // Pointer offsets and array indices, if they are // very large, need to dereference the base pointer // to trigger a trap. - var p *[1<<30]byte = nil; - println(p[256<<20]); // very likely to be inside dummy, but should crash + var p *[1<<30]byte = nil + println(p[256<<20]) // very likely to be inside dummy, but should crash } diff --git a/test/nilptr/arraytoslice.go b/test/nilptr/arraytoslice.go index 65b2f8a76..03879fb42 100644 --- a/test/nilptr/arraytoslice.go +++ b/test/nilptr/arraytoslice.go @@ -1,4 +1,3 @@ -// [ $GOOS != nacl ] || exit 0 # do not bother on NaCl // $G $D/$F.go && $L $F.$A && // ((! sh -c ./$A.out) >/dev/null 2>&1 || echo BUG: should fail) @@ -11,10 +10,10 @@ package main import "unsafe" func f([]byte) { - panic("unreachable"); + panic("unreachable") } -var dummy [512<<20]byte; // give us a big address space +var dummy [512<<20]byte // give us a big address space func main() { // the test only tests what we intend to test // if dummy starts in the first 256 MB of memory. @@ -22,7 +21,7 @@ func main() { // at the address that might be accidentally // dereferenced below. if uintptr(unsafe.Pointer(&dummy)) > 256<<20 { - panic("dummy too far out"); + panic("dummy too far out") } // The problem here is that indexing into p[] with a large @@ -32,6 +31,6 @@ func main() { // To avoid needing a check on every slice beyond the // usual len and cap, we require the *array -> slice // conversion to do the check. - var p *[1<<30]byte = nil; - f(p); // should crash + var p *[1<<30]byte = nil + f(p[0:]) // should crash } diff --git a/test/nilptr/arraytoslice1.go b/test/nilptr/arraytoslice1.go index b5240a803..c86070fa4 100644 --- a/test/nilptr/arraytoslice1.go +++ b/test/nilptr/arraytoslice1.go @@ -1,4 +1,3 @@ -// [ $GOOS != nacl ] || exit 0 # do not bother on NaCl // $G $D/$F.go && $L $F.$A && // ((! sh -c ./$A.out) >/dev/null 2>&1 || echo BUG: should fail) @@ -10,7 +9,7 @@ package main import "unsafe" -var dummy [512<<20]byte; // give us a big address space +var dummy [512<<20]byte // give us a big address space func main() { // the test only tests what we intend to test // if dummy starts in the first 256 MB of memory. @@ -18,7 +17,7 @@ func main() { // at the address that might be accidentally // dereferenced below. if uintptr(unsafe.Pointer(&dummy)) > 256<<20 { - panic("dummy too far out"); + panic("dummy too far out") } // The problem here is that indexing into p[] with a large @@ -28,7 +27,7 @@ func main() { // To avoid needing a check on every slice beyond the // usual len and cap, we require the *array -> slice // conversion to do the check. - var p *[1<<30]byte = nil; - var x []byte = p; // should crash - _ = x; + var p *[1<<30]byte = nil + var x []byte = p[0:] // should crash + _ = x } diff --git a/test/nilptr/arraytoslice2.go b/test/nilptr/arraytoslice2.go index 38e1a5cb2..68ea44083 100644 --- a/test/nilptr/arraytoslice2.go +++ b/test/nilptr/arraytoslice2.go @@ -1,4 +1,3 @@ -// [ $GOOS != nacl ] || exit 0 # do not bother on NaCl // $G $D/$F.go && $L $F.$A && // ((! sh -c ./$A.out) >/dev/null 2>&1 || echo BUG: should fail) @@ -10,8 +9,8 @@ package main import "unsafe" -var dummy [512<<20]byte; // give us a big address space -var q *[1<<30]byte; +var dummy [512<<20]byte // give us a big address space +var q *[1<<30]byte func main() { // the test only tests what we intend to test // if dummy starts in the first 256 MB of memory. @@ -19,7 +18,7 @@ func main() { // at the address that might be accidentally // dereferenced below. if uintptr(unsafe.Pointer(&dummy)) > 256<<20 { - panic("dummy too far out"); + panic("dummy too far out") } // The problem here is that indexing into p[] with a large @@ -29,7 +28,7 @@ func main() { // To avoid needing a check on every slice beyond the // usual len and cap, we require the *array -> slice // conversion to do the check. - var x []byte; - var y = &x; - *y = q; // should crash (uses arraytoslice runtime routine) + var x []byte + var y = &x + *y = q[0:] // should crash (uses arraytoslice runtime routine) } diff --git a/test/nilptr/slicearray.go b/test/nilptr/slicearray.go index 5f88010df..26ca42773 100644 --- a/test/nilptr/slicearray.go +++ b/test/nilptr/slicearray.go @@ -1,4 +1,3 @@ -// [ $GOOS != nacl ] || exit 0 # do not bother on NaCl // $G $D/$F.go && $L $F.$A && // ((! sh -c ./$A.out) >/dev/null 2>&1 || echo BUG: should fail) @@ -10,7 +9,7 @@ package main import "unsafe" -var dummy [512<<20]byte; // give us a big address space +var dummy [512<<20]byte // give us a big address space func main() { // the test only tests what we intend to test // if dummy starts in the first 256 MB of memory. @@ -18,7 +17,7 @@ func main() { // at the address that might be accidentally // dereferenced below. if uintptr(unsafe.Pointer(&dummy)) > 256<<20 { - panic("dummy too far out"); + panic("dummy too far out") } // The problem here is that indexing into p[] with a large @@ -28,6 +27,6 @@ func main() { // To avoid needing a check on every slice beyond the // usual len and cap, we require the slice operation // to do the check. - var p *[1<<30]byte = nil; - var _ []byte = p[10:len(p)-10]; // should crash + var p *[1<<30]byte = nil + var _ []byte = p[10:len(p)-10] // should crash } diff --git a/test/nilptr/structfield.go b/test/nilptr/structfield.go index 9f70ecc70..35196bb68 100644 --- a/test/nilptr/structfield.go +++ b/test/nilptr/structfield.go @@ -1,4 +1,3 @@ -// [ $GOOS != nacl ] || exit 0 # do not bother on NaCl // $G $D/$F.go && $L $F.$A && // ((! sh -c ./$A.out) >/dev/null 2>&1 || echo BUG: should fail) @@ -10,10 +9,10 @@ package main import "unsafe" -var dummy [512<<20]byte; // give us a big address space +var dummy [512<<20]byte // give us a big address space type T struct { - x [256<<20] byte; - i int; + x [256<<20] byte + i int } func main() { @@ -23,13 +22,13 @@ func main() { // at the address that might be accidentally // dereferenced below. if uintptr(unsafe.Pointer(&dummy)) > 256<<20 { - panic("dummy too far out"); + panic("dummy too far out") } // The problem here is that indexing into t with a large // enough index can jump out of the unmapped section // at the beginning of memory and into valid memory. // We require the pointer dereference to check. - var t *T; - println(t.i); // should crash + var t *T + println(t.i) // should crash } diff --git a/test/nilptr/structfield1.go b/test/nilptr/structfield1.go index 1a120890a..7c7abed1a 100644 --- a/test/nilptr/structfield1.go +++ b/test/nilptr/structfield1.go @@ -1,4 +1,3 @@ -// [ $GOOS != nacl ] || exit 0 # do not bother on NaCl // $G $D/$F.go && $L $F.$A && // ((! sh -c ./$A.out) >/dev/null 2>&1 || echo BUG: should fail) @@ -10,14 +9,14 @@ package main import "unsafe" -var dummy [512<<20]byte; // give us a big address space +var dummy [512<<20]byte // give us a big address space type T struct { - x [256<<20] byte; - i int; + x [256<<20] byte + i int } func f() *T { - return nil; + return nil } func main() { @@ -27,12 +26,12 @@ func main() { // at the address that might be accidentally // dereferenced below. if uintptr(unsafe.Pointer(&dummy)) > 256<<20 { - panic("dummy too far out"); + panic("dummy too far out") } // The problem here is that indexing into t with a large // enough index can jump out of the unmapped section // at the beginning of memory and into valid memory. // We require the pointer dereference to check. - println(f().i); // should crash + println(f().i) // should crash } diff --git a/test/nilptr/structfield2.go b/test/nilptr/structfield2.go index 25ea8f665..02a44f173 100644 --- a/test/nilptr/structfield2.go +++ b/test/nilptr/structfield2.go @@ -1,4 +1,3 @@ -// [ $GOOS != nacl ] || exit 0 # do not bother on NaCl // $G $D/$F.go && $L $F.$A && // ((! sh -c ./$A.out) >/dev/null 2>&1 || echo BUG: should fail) @@ -10,14 +9,14 @@ package main import "unsafe" -var dummy [512<<20]byte; // give us a big address space +var dummy [512<<20]byte // give us a big address space type T struct { - x [256<<20] byte; - i int; + x [256<<20] byte + i int } -var y *T; -var x = &y; +var y *T +var x = &y func main() { // the test only tests what we intend to test @@ -26,12 +25,12 @@ func main() { // at the address that might be accidentally // dereferenced below. if uintptr(unsafe.Pointer(&dummy)) > 256<<20 { - panic("dummy too far out"); + panic("dummy too far out") } // The problem here is that indexing into t with a large // enough index can jump out of the unmapped section // at the beginning of memory and into valid memory. // We require the pointer dereference to check. - println((*x).i); // should crash + println((*x).i) // should crash } diff --git a/test/nilptr/structfieldaddr.go b/test/nilptr/structfieldaddr.go index b5d370ca8..f3177bafb 100644 --- a/test/nilptr/structfieldaddr.go +++ b/test/nilptr/structfieldaddr.go @@ -1,4 +1,3 @@ -// [ $GOOS != nacl ] || exit 0 # do not bother on NaCl // $G $D/$F.go && $L $F.$A && // ((! sh -c ./$A.out) >/dev/null 2>&1 || echo BUG: should fail) @@ -10,10 +9,10 @@ package main import "unsafe" -var dummy [512<<20]byte; // give us a big address space +var dummy [512<<20]byte // give us a big address space type T struct { - x [256<<20] byte; - i int; + x [256<<20] byte + i int } func main() { @@ -23,13 +22,13 @@ func main() { // at the address that might be accidentally // dereferenced below. if uintptr(unsafe.Pointer(&dummy)) > 256<<20 { - panic("dummy too far out"); + panic("dummy too far out") } // The problem here is that indexing into t with a large // enough index can jump out of the unmapped section // at the beginning of memory and into valid memory. // We require the address calculation to check. - var t *T; - println(&t.i); // should crash + var t *T + println(&t.i) // should crash } |