Skip to content

Commit

Permalink
cmd/compile: avoid panic when printing *<N>
Browse files Browse the repository at this point in the history
When compiling the program:

package p

func _(){
	*;:=
}

Before:

x.go:4:3: syntax error: unexpected semicolon, expecting expression
x.go:4:4: non-name *%!v(PANIC=runtime error: invalid memory address or nil pointer dereference) on left side of :=
x.go:5:1: syntax error: unexpected }, expecting expression

After:

x.go:4:3: syntax error: unexpected semicolon, expecting expression
x.go:4:4: non-name *<N> on left side of :=
x.go:5:1: syntax error: unexpected }, expecting expression

No test because:

(1) we don't have a good mechanism to check for the
    absence of the string "PANIC" in an error message
(2) the string "*<N>", while better, is itself ugly enough
    that I don't want to actively check for it
(3) the bug isn't very important, the kind of thing only fuzzers encounter
(4) the fix is obvious and trivial

Fixes #20220

Change-Id: I35faa986b60b671414ee999d6264b06937f250e3
Reviewed-on: https://go-review.googlesource.com/42498
Run-TryBot: Josh Bleecher Snyder <[email protected]>
Reviewed-by: Robert Griesemer <[email protected]>
Reviewed-by: David Crawshaw <[email protected]>
TryBot-Result: Gobot Gobot <[email protected]>
  • Loading branch information
josharian committed May 3, 2017
1 parent 6e9b6e1 commit e41fb55
Showing 1 changed file with 2 additions and 8 deletions.
10 changes: 2 additions & 8 deletions src/cmd/compile/internal/gc/fmt.go
Original file line number Diff line number Diff line change
Expand Up @@ -1509,16 +1509,10 @@ func (n *Node) exprfmt(s fmt.State, prec int, mode fmtMode) {
}
mode.Fprintf(s, "make(%v)", n.Type)

case OPLUS, OMINUS, OADDR, OCOM, OIND, ONOT, ORECV:
// Unary
case OPLUS,
OMINUS,
OADDR,
OCOM,
OIND,
ONOT,
ORECV:
mode.Fprintf(s, "%#v", n.Op)
if n.Left.Op == n.Op {
if n.Left != nil && n.Left.Op == n.Op {
fmt.Fprint(s, " ")
}
n.Left.exprfmt(s, nprec+1, mode)
Expand Down

0 comments on commit e41fb55

Please sign in to comment.