aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorcookeem <cookeem@qq.com>2021-05-13 04:40:23 +0800
committerGitHub <noreply@github.com>2021-05-12 22:40:23 +0200
commite6e23391e4d044cc85e09b4420a2533715e7312d (patch)
tree35ae78eec0e982312d2d3a22975eb53a3e0cbaba
parent320db9af8ba8b0046e833013504eb07c61a3573c (diff)
downloadgo-git-e6e23391e4d044cc85e09b4420a2533715e7312d.tar.gz
plumbing: object/patch, printStat strings.Repeat cause panic (#310)
-rw-r--r--plumbing/object/patch.go12
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)
}