Skip to content

Commit 3755b53

Browse files
sunshinecogitster
authored andcommitted
range_set: fix coalescing bug when range is a subset of another
When coalescing ranges, sort_and_merge_range_set() unconditionally assumes that the end of a range being folded into a preceding range should become the end of the coalesced range. This assumption, however, is invalid when one range is a subset of another. For example, given ranges 1-5 and 2-3 added via range_set_append_unsafe(), sort_and_merge_range_set() incorrectly coalesces them to range 1-3 rather than the correct union range 1-5. Fix this bug. Signed-off-by: Eric Sunshine <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 18d472d commit 3755b53

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

line-log.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,8 @@ static void sort_and_merge_range_set(struct range_set *rs)
116116

117117
for (i = 1; i < rs->nr; i++) {
118118
if (rs->ranges[i].start <= rs->ranges[o-1].end) {
119-
rs->ranges[o-1].end = rs->ranges[i].end;
119+
if (rs->ranges[o-1].end < rs->ranges[i].end)
120+
rs->ranges[o-1].end = rs->ranges[i].end;
120121
} else {
121122
rs->ranges[o].start = rs->ranges[i].start;
122123
rs->ranges[o].end = rs->ranges[i].end;

t/t4211-line-log.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ canned_test "-M -L ':f:b.c' parallel-change" parallel-change-f-to-main
5050
canned_test "-L 4,12:a.c -L :main:a.c simple" multiple
5151
canned_test "-L 4,18:a.c -L :main:a.c simple" multiple-overlapping
5252
canned_test "-L :main:a.c -L 4,18:a.c simple" multiple-overlapping
53-
canned_test_failure "-L 4:a.c -L 8,12:a.c simple" multiple-superset
54-
canned_test_failure "-L 8,12:a.c -L 4:a.c simple" multiple-superset
53+
canned_test "-L 4:a.c -L 8,12:a.c simple" multiple-superset
54+
canned_test "-L 8,12:a.c -L 4:a.c simple" multiple-superset
5555

5656
test_bad_opts "-L" "switch.*requires a value"
5757
test_bad_opts "-L b.c" "argument.*not of the form"

0 commit comments

Comments
 (0)