diff options
author | Michael Muré <batolettre@gmail.com> | 2019-04-17 18:27:55 +0200 |
---|---|---|
committer | Michael Muré <batolettre@gmail.com> | 2019-04-17 18:27:55 +0200 |
commit | ef84fda0d430af6cd2b94a29e76f1a52a4b3106e (patch) | |
tree | 7ee82e886c0d5195a1ba735d2a2965e6c5b74548 /bug/op_edit_comment.go | |
parent | d862575d80a859dd4ce42fb10a6dbb49828544f1 (diff) | |
download | git-bug-ef84fda0d430af6cd2b94a29e76f1a52a4b3106e.tar.gz |
bug: fix a potential crash with malformed data in EditCommentOperation
crashed with indexOutOfRange when the target of the op existed but wasn't a
CreateOperation or a AddCommentOperation
Diffstat (limited to 'bug/op_edit_comment.go')
-rw-r--r-- | bug/op_edit_comment.go | 18 |
1 files changed, 9 insertions, 9 deletions
diff --git a/bug/op_edit_comment.go b/bug/op_edit_comment.go index 49b6a1af..01832959 100644 --- a/bug/op_edit_comment.go +++ b/bug/op_edit_comment.go @@ -36,7 +36,6 @@ func (op *EditCommentOperation) Apply(snapshot *Snapshot) { snapshot.addActor(op.Author) var target TimelineItem - var commentIndex int for i, item := range snapshot.Timeline { h := item.Hash() @@ -45,12 +44,6 @@ func (op *EditCommentOperation) Apply(snapshot *Snapshot) { target = snapshot.Timeline[i] break } - - // Track the index in the []Comment - switch item.(type) { - case *CreateTimelineItem, *AddCommentTimelineItem: - commentIndex++ - } } if target == nil { @@ -75,8 +68,15 @@ func (op *EditCommentOperation) Apply(snapshot *Snapshot) { item.Append(comment) } - snapshot.Comments[commentIndex].Message = op.Message - snapshot.Comments[commentIndex].Files = op.Files + // Updating the corresponding comment + + for i := range snapshot.Comments { + if snapshot.Comments[i].Id() == string(op.Target) { + snapshot.Comments[i].Message = op.Message + snapshot.Comments[i].Files = op.Files + break + } + } } func (op *EditCommentOperation) GetFiles() []git.Hash { |