diff options
author | cookeem <cookeem@qq.com> | 2021-05-13 04:40:23 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-05-12 22:40:23 +0200 |
commit | e6e23391e4d044cc85e09b4420a2533715e7312d (patch) | |
tree | 35ae78eec0e982312d2d3a22975eb53a3e0cbaba /plumbing | |
parent | 320db9af8ba8b0046e833013504eb07c61a3573c (diff) | |
download | go-git-e6e23391e4d044cc85e09b4420a2533715e7312d.tar.gz |
plumbing: object/patch, printStat strings.Repeat cause panic (#310)
Diffstat (limited to 'plumbing')
-rw-r--r-- | plumbing/object/patch.go | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/plumbing/object/patch.go b/plumbing/object/patch.go index 9b5f438..56b62c1 100644 --- a/plumbing/object/patch.go +++ b/plumbing/object/patch.go @@ -287,8 +287,16 @@ func printStat(fileStats []FileStat) string { for _, fs := range fileStats { addn := float64(fs.Addition) deln := float64(fs.Deletion) - adds := strings.Repeat("+", int(math.Floor(addn/scaleFactor))) - dels := strings.Repeat("-", int(math.Floor(deln/scaleFactor))) + addc := int(math.Floor(addn/scaleFactor)) + delc := int(math.Floor(deln/scaleFactor)) + if addc < 0 { + addc = 0 + } + if delc < 0 { + delc = 0 + } + adds := strings.Repeat("+", addc) + dels := strings.Repeat("-", delc) finalOutput += fmt.Sprintf(" %s | %d %s%s\n", fs.Name, (fs.Addition + fs.Deletion), adds, dels) } |