diff options
author | Matthew Dempsky <mdempsky@google.com> | 2019-10-22 12:47:05 -0700 |
---|---|---|
committer | Matthew Dempsky <mdempsky@google.com> | 2019-10-22 20:50:04 +0000 |
commit | daeb5efb20a561ffc865f94163e836b68eee4193 (patch) | |
tree | b71466090bafe7640af8dea3b3e4cd940155b415 /src/runtime/checkptr.go | |
parent | 9093b1def0b5e6f3ac30d5f9c18b375e8f5964e9 (diff) | |
download | go-daeb5efb20a561ffc865f94163e836b68eee4193.tar.gz go-daeb5efb20a561ffc865f94163e836b68eee4193.zip |
runtime: somewhat better checkptr error messages
They're still lacking in details, but at least better than being
printed as raw interface values.
Updates #22218.
Change-Id: I4fd813253afdd6455c0c9b5a05c61659805abad1
Reviewed-on: https://go-review.googlesource.com/c/go/+/202677
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Diffstat (limited to 'src/runtime/checkptr.go')
-rw-r--r-- | src/runtime/checkptr.go | 24 |
1 files changed, 18 insertions, 6 deletions
diff --git a/src/runtime/checkptr.go b/src/runtime/checkptr.go index d1fc651509..94581ba5c9 100644 --- a/src/runtime/checkptr.go +++ b/src/runtime/checkptr.go @@ -6,33 +6,45 @@ package runtime import "unsafe" -type ptrAlign struct { +type ptrAlignError struct { ptr unsafe.Pointer elem *_type n uintptr } +func (e ptrAlignError) RuntimeError() {} + +func (e ptrAlignError) Error() string { + return "runtime error: unsafe pointer conversion" +} + func checkptrAlignment(p unsafe.Pointer, elem *_type, n uintptr) { // Check that (*[n]elem)(p) is appropriately aligned. // TODO(mdempsky): What about fieldAlign? if uintptr(p)&(uintptr(elem.align)-1) != 0 { - panic(ptrAlign{p, elem, n}) + panic(ptrAlignError{p, elem, n}) } // Check that (*[n]elem)(p) doesn't straddle multiple heap objects. if size := n * elem.size; size > 1 && checkptrBase(p) != checkptrBase(add(p, size-1)) { - panic(ptrAlign{p, elem, n}) + panic(ptrAlignError{p, elem, n}) } } -type ptrArith struct { +type ptrArithError struct { ptr unsafe.Pointer originals []unsafe.Pointer } +func (e ptrArithError) RuntimeError() {} + +func (e ptrArithError) Error() string { + return "runtime error: unsafe pointer arithmetic" +} + func checkptrArithmetic(p unsafe.Pointer, originals []unsafe.Pointer) { if 0 < uintptr(p) && uintptr(p) < minLegalPointer { - panic(ptrArith{p, originals}) + panic(ptrArithError{p, originals}) } // Check that if the computed pointer p points into a heap @@ -49,7 +61,7 @@ func checkptrArithmetic(p unsafe.Pointer, originals []unsafe.Pointer) { } } - panic(ptrArith{p, originals}) + panic(ptrArithError{p, originals}) } func checkptrBase(p unsafe.Pointer) uintptr { |