1
0
Fork 0
mirror of https://github.com/restic/restic.git synced 2024-12-26 17:57:50 +00:00

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

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