avoid "index out of range" error

in case of len(format) == 0, we will get an
"index out of range" error
Usage of strings.HasSuffix is allowing to avoid that
This commit is contained in:
Alexander Bruyako 2020-01-27 19:24:42 +03:00
parent 38ddfbc4d3
commit 688014487b
1 changed files with 1 additions and 1 deletions

View File

@ -232,7 +232,7 @@ func Warnf(format string, args ...interface{}) {
// Exitf uses Warnf to write the message and then terminates the process with
// the given exit code.
func Exitf(exitcode int, format string, args ...interface{}) {
if format[len(format)-1] != '\n' {
if !(strings.HasSuffix(format, "\n")) {
format += "\n"
}