1
1
mirror of https://github.com/go-gitea/gitea synced 2025-07-23 10:48:37 +00:00

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
This commit is contained in:
6543
2020-02-28 04:12:23 +01:00
committed by GitHub
parent c6b78c3d31
commit 11300ee582
6 changed files with 13 additions and 9 deletions

View File

@@ -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()

View File

@@ -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:

View File

@@ -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 {