From b8b0a5b5c35ba7a0b7d0b8ff46fbcafbbfcb75be Mon Sep 17 00:00:00 2001 From: Serge Bazanski Date: Thu, 23 Apr 2020 21:44:15 +0200 Subject: [PATCH] format: fix crash when emitting empty messages in text format --- format.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/format.go b/format.go index db93eb4..a3dc444 100644 --- a/format.go +++ b/format.go @@ -179,7 +179,7 @@ func (tf *textFormatter) format(m proto.Message) (string, error) { // no trailing newline needed str := buf.String() - if str[len(str)-1] == '\n' { + if len(str) > 0 && str[len(str)-1] == '\n' { str = str[:len(str)-1] }