summaryrefslogtreecommitdiffstats
path: root/models
diff options
context:
space:
mode:
authorJustin Nuß <nuss.justin@gmail.com>2014-07-22 20:57:48 +0200
committerJustin Nuß <nuss.justin@gmail.com>2014-07-22 20:57:48 +0200
commit0d06c7e5f2f8239383a3727c69ef938d12c037e2 (patch)
tree7978eb2a5785bc7d19c4a2c50992667091dcf99d /models
parented73af6fa1d4ab8ae880be5381849cab2b6f7640 (diff)
downloadgitea-0d06c7e5f2f8239383a3727c69ef938d12c037e2.tar.gz
gitea-0d06c7e5f2f8239383a3727c69ef938d12c037e2.zip
Prevent panic when dividing through zero
Diffstat (limited to 'models')
-rw-r--r--models/issue.go6
1 files changed, 6 insertions, 0 deletions
diff --git a/models/issue.go b/models/issue.go
index baf710a5ee..8b2d57cd22 100644
--- a/models/issue.go
+++ b/models/issue.go
@@ -19,6 +19,7 @@ var (
ErrIssueNotExist = errors.New("Issue does not exist")
ErrLabelNotExist = errors.New("Label does not exist")
ErrMilestoneNotExist = errors.New("Milestone does not exist")
+ ErrWrongIssueCounter = errors.New("Invalid number of issues for this milestone")
)
// Issue represents an issue or pull request of repository.
@@ -703,6 +704,11 @@ func ChangeMilestoneAssign(oldMid, mid int64, issue *Issue) (err error) {
if issue.IsClosed {
m.NumClosedIssues++
}
+
+ if m.NumIssues == 0 {
+ return ErrWrongIssueCounter
+ }
+
m.Completeness = m.NumClosedIssues * 100 / m.NumIssues
if _, err = sess.Id(m.Id).Update(m); err != nil {
sess.Rollback()