Skip to content

Commit

Permalink
Try to fix string out-of-bounds when truncating list
Browse files Browse the repository at this point in the history
  • Loading branch information
mt-inside committed Feb 21, 2024
1 parent 97dfd6e commit fbe747b
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions pkg/output/styler_tty.go
Original file line number Diff line number Diff line change
Expand Up @@ -271,19 +271,20 @@ func (s TtyStyler) List(ins []string, style aurora.Color) string {

for i, in := range ins {
newPrintLen := printLen + len(in) // without the escape sequences
if i != len(ins)-1 {
newPrintLen += len(", ")
}

if newPrintLen > printWidth {
b.WriteString(s.au.Colorize(in[:printWidth-printLen], style).String())
b.WriteString("...")
break
}

b.WriteString(s.au.Colorize(in, style).String())

if i != len(ins)-1 {
b.WriteString(", ")
newPrintLen += len(", ")
if newPrintLen > printWidth {
break
} else {
b.WriteString(", ")
}
}

printLen = newPrintLen
Expand Down

0 comments on commit fbe747b

Please sign in to comment.