diff options
author | 6543 <6543@obermui.de> | 2020-02-28 04:12:23 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-02-28 00:12:23 -0300 |
commit | 11300ee58280532cf28640b3d0eee9e2b60b67e0 (patch) | |
tree | 2eb51c0e3890470b222ade5035b4d61fddd46ed9 /models | |
parent | c6b78c3d31ea7d48c8feb04af516baef51550067 (diff) | |
download | gitea-11300ee58280532cf28640b3d0eee9e2b60b67e0.tar.gz gitea-11300ee58280532cf28640b3d0eee9e2b60b67e0.zip |
Fix potential bugs (#10513) (#10518)
* use e if it is an option
* potential nil so check err first
* check err first
* m == nil already checked
Diffstat (limited to 'models')
-rw-r--r-- | models/action.go | 2 | ||||
-rw-r--r-- | models/attachment.go | 2 | ||||
-rw-r--r-- | models/issue_comment.go | 6 |
3 files changed, 7 insertions, 3 deletions
diff --git a/models/action.go b/models/action.go index cd722cbe7c..161a7220c0 100644 --- a/models/action.go +++ b/models/action.go @@ -215,7 +215,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 3ba6790216..2494467bf2 100644 --- a/models/issue_comment.go +++ b/models/issue_comment.go @@ -749,8 +749,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 { |