From e57ac841de1fc93df15ba8bef280077bbb733bf1 Mon Sep 17 00:00:00 2001 From: 6543 <6543@obermui.de> Date: Fri, 28 Feb 2020 00:10:27 +0100 Subject: Fix potential bugs (#10513) * use e if it is an option * potential nil so check err first * check err first * m == nil already checked --- models/action.go | 2 +- models/attachment.go | 2 +- models/issue_comment.go | 6 +++++- models/notification.go | 2 +- 4 files changed, 8 insertions(+), 4 deletions(-) (limited to 'models') diff --git a/models/action.go b/models/action.go index 267a19bc62..fd49c6d4ed 100644 --- a/models/action.go +++ b/models/action.go @@ -213,7 +213,7 @@ func (a *Action) getCommentLink(e Engine) string { return "#" } if a.Comment == nil && a.CommentID != 0 { - a.Comment, _ = GetCommentByID(a.CommentID) + a.Comment, _ = getCommentByID(e, a.CommentID) } if a.Comment != nil { return a.Comment.HTMLURL() diff --git a/models/attachment.go b/models/attachment.go index 81f2e15dad..7e59c7eef4 100644 --- a/models/attachment.go +++ b/models/attachment.go @@ -199,7 +199,7 @@ func GetAttachmentsByCommentID(commentID int64) ([]*Attachment, error) { func getAttachmentsByCommentID(e Engine, commentID int64) ([]*Attachment, error) { attachments := make([]*Attachment, 0, 10) - return attachments, x.Where("comment_id=?", commentID).Find(&attachments) + return attachments, e.Where("comment_id=?", commentID).Find(&attachments) } // getAttachmentByReleaseIDFileName return a file based on the the following infos: diff --git a/models/issue_comment.go b/models/issue_comment.go index 4abc3f9c1f..303cf3f9c1 100644 --- a/models/issue_comment.go +++ b/models/issue_comment.go @@ -765,8 +765,12 @@ func CreateRefComment(doer *User, repo *Repository, issue *Issue, content, commi // GetCommentByID returns the comment by given ID. func GetCommentByID(id int64) (*Comment, error) { + return getCommentByID(x, id) +} + +func getCommentByID(e Engine, id int64) (*Comment, error) { c := new(Comment) - has, err := x.ID(id).Get(c) + has, err := e.ID(id).Get(c) if err != nil { return nil, err } else if !has { diff --git a/models/notification.go b/models/notification.go index c52d6c557a..a7a65c38a4 100644 --- a/models/notification.go +++ b/models/notification.go @@ -396,7 +396,7 @@ func (n *Notification) loadIssue(e Engine) (err error) { func (n *Notification) loadComment(e Engine) (err error) { if n.Comment == nil && n.CommentID > 0 { - n.Comment, err = GetCommentByID(n.CommentID) + n.Comment, err = getCommentByID(e, n.CommentID) if err != nil { return fmt.Errorf("GetCommentByID [%d] for issue ID [%d]: %v", n.CommentID, n.IssueID, err) } -- cgit v1.2.3