From 8e2cf9b3c262d24267e65cf67749b9769a1544e5 Mon Sep 17 00:00:00 2001 From: Serge Bazanski Date: Thu, 23 Apr 2020 22:20:45 +0200 Subject: [PATCH] fix crash when emitting empty messages in text format (#153) --- 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] }