From: Ian Lance Taylor Date: Mon, 9 May 2022 20:23:10 +0000 (-0700) Subject: go/doc/comment: don't crash if there are no words to wrap X-Git-Tag: go1.19beta1~338 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=3f43096f1549ea32229202618d9cd81a5761c697;p=gostls13.git go/doc/comment: don't crash if there are no words to wrap Fixes #52783 Change-Id: I12e3da40d49cd92776052bf19cb07ee8a07f3ee0 Reviewed-on: https://go-review.googlesource.com/c/go/+/405215 Auto-Submit: Ian Lance Taylor Run-TryBot: Ian Lance Taylor Reviewed-by: Ian Lance Taylor Run-TryBot: Ian Lance Taylor TryBot-Result: Gopher Robot Reviewed-by: Bryan Mills Reviewed-by: Heschi Kreinick --- diff --git a/src/go/doc/comment/testdata/crash1.txt b/src/go/doc/comment/testdata/crash1.txt new file mode 100644 index 0000000000..6bb2f6fdda --- /dev/null +++ b/src/go/doc/comment/testdata/crash1.txt @@ -0,0 +1,16 @@ +-- input -- +[] + +[]: http:// +-- gofmt -- +[] + +[]: http:// +-- html -- +

+-- markdown -- +[](http://) +-- text -- + + +[]: http:// diff --git a/src/go/doc/comment/text.go b/src/go/doc/comment/text.go index e9684f066b..86e5eebe9a 100644 --- a/src/go/doc/comment/text.go +++ b/src/go/doc/comment/text.go @@ -141,7 +141,7 @@ func (p *textPrinter) text(out *bytes.Buffer, indent string, x []Text) { p.long.Reset() var seq []int - if p.width < 0 { + if p.width < 0 || len(words) == 0 { seq = []int{0, len(words)} // one long line } else { seq = wrap(words, p.width-utf8.RuneCountInString(indent))