aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Muré <batolettre@gmail.com>2019-04-17 18:27:55 +0200
committerMichael Muré <batolettre@gmail.com>2019-04-17 18:27:55 +0200
commitef84fda0d430af6cd2b94a29e76f1a52a4b3106e (patch)
tree7ee82e886c0d5195a1ba735d2a2965e6c5b74548
parentd862575d80a859dd4ce42fb10a6dbb49828544f1 (diff)
downloadgit-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
-rw-r--r--bug/op_edit_comment.go18
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 {