]> Cypherpunks.ru repositories - gostls13.git/commit
cmd/compile: fix off-by-one error in traceback argument counting
authorCherry Mui <cherryyz@google.com>
Wed, 14 Jul 2021 22:52:44 +0000 (18:52 -0400)
committerCherry Mui <cherryyz@google.com>
Mon, 19 Jul 2021 18:00:46 +0000 (18:00 +0000)
commit404127c30f3f66eb234da2dc1a78e6eea0ef4ee0
treefb846d3500b168872b95530986bb8a6a5811f109
parent6298cfe6724e3ca24dedd3f62b2b358aafe17276
cmd/compile: fix off-by-one error in traceback argument counting

For traceback argument printing, we want to print at most 10
words, then print "..." if there are still more args and/or
fields. The current code has off-by-one error that for 11
non-aggregate typed args, it prints the first 10 but without the
"...". Also, for aggregate-typed args, in some cases it may print
an extra "..." when there is actually no more fields.

The problem for this is that visitType return false (meaning not
to continue visiting) if it reaches the limit anywhere during the
recursive visit. It doesn't distinguish whether it has printed
anything for the current arg. If it reaches the limit before it
prints anything, it means that we're visiting the extra arg/field,
so the caller should print "..." and stop. If it prints
something then reaches the limit, however, the caller should keep
going, and only print "..." at the next iteration when there is
actually an extra arg/field. This CL does so.

Fixes #47159.

Change-Id: I93fc25b73ada2b5a98df780c45e5b0c9565dc2fc
Reviewed-on: https://go-review.googlesource.com/c/go/+/334710
Trust: Cherry Mui <cherryyz@google.com>
Run-TryBot: Cherry Mui <cherryyz@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
src/cmd/compile/internal/ssagen/ssa.go
src/runtime/traceback_test.go