Skip to content

Commit e1c0834

Browse files
ianlancetaylorandybons
authored andcommitted
[release-branch.go1.10] runtime: don't check for String/Error methods in printany
They have either already been called by preprintpanics, or they can not be called safely because of the various conditions checked at the start of gopanic. Fixes #24059 Change-Id: I4a6233d12c9f7aaaee72f343257ea108bae79241 Reviewed-on: https://go-review.googlesource.com/96755 Reviewed-by: Austin Clements <[email protected]> Reviewed-on: https://go-review.googlesource.com/102781 Run-TryBot: Andrew Bonventre <[email protected]> Reviewed-by: Ian Lance Taylor <[email protected]> TryBot-Result: Gobot Gobot <[email protected]>
1 parent fe0d248 commit e1c0834

File tree

3 files changed

+10
-7
lines changed

3 files changed

+10
-7
lines changed

src/runtime/error.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,14 +73,12 @@ func typestring(x interface{}) string {
7373
}
7474

7575
// printany prints an argument passed to panic.
76+
// If panic is called with a value that has a String or Error method,
77+
// it has already been converted into a string by preprintpanics.
7678
func printany(i interface{}) {
7779
switch v := i.(type) {
7880
case nil:
7981
print("nil")
80-
case stringer:
81-
print(v.String())
82-
case error:
83-
print(v.Error())
8482
case bool:
8583
print(v)
8684
case int:

src/runtime/iface.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,14 @@ func (t *itabTableType) find(inter *interfacetype, typ *_type) *itab {
113113
// itabAdd adds the given itab to the itab hash table.
114114
// itabLock must be held.
115115
func itabAdd(m *itab) {
116+
// Bugs can lead to calling this while mallocing is set,
117+
// typically because this is called while panicing.
118+
// Crash reliably, rather than only when we need to grow
119+
// the hash table.
120+
if getg().m.mallocing != 0 {
121+
throw("malloc deadlock")
122+
}
123+
116124
t := itabTable
117125
if t.count >= 3*(t.size/4) { // 75% load factor
118126
// Grow hash table.

src/runtime/panic.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,6 @@ func Goexit() {
389389

390390
// Call all Error and String methods before freezing the world.
391391
// Used when crashing with panicking.
392-
// This must match types handled by printany.
393392
func preprintpanics(p *_panic) {
394393
defer func() {
395394
if recover() != nil {
@@ -415,8 +414,6 @@ func printpanics(p *_panic) {
415414
print("\t")
416415
}
417416
print("panic: ")
418-
// Because of preprintpanics, p.arg cannot be an error or
419-
// stringer, so this won't call into user code.
420417
printany(p.arg)
421418
if p.recovered {
422419
print(" [recovered]")

0 commit comments

Comments
 (0)