Skip to content

Commit e6e2339

Browse files
authored
plumbing: object/patch, printStat strings.Repeat cause panic (go-git#310)
1 parent 320db9a commit e6e2339

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

plumbing/object/patch.go

+10-2
Original file line numberDiff line numberDiff line change
@@ -287,8 +287,16 @@ func printStat(fileStats []FileStat) string {
287287
for _, fs := range fileStats {
288288
addn := float64(fs.Addition)
289289
deln := float64(fs.Deletion)
290-
adds := strings.Repeat("+", int(math.Floor(addn/scaleFactor)))
291-
dels := strings.Repeat("-", int(math.Floor(deln/scaleFactor)))
290+
addc := int(math.Floor(addn/scaleFactor))
291+
delc := int(math.Floor(deln/scaleFactor))
292+
if addc < 0 {
293+
addc = 0
294+
}
295+
if delc < 0 {
296+
delc = 0
297+
}
298+
adds := strings.Repeat("+", addc)
299+
dels := strings.Repeat("-", delc)
292300
finalOutput += fmt.Sprintf(" %s | %d %s%s\n", fs.Name, (fs.Addition + fs.Deletion), adds, dels)
293301
}
294302

0 commit comments

Comments
 (0)