From 3755b53af779ce75fa3ea4581a0e6525bc67278d Mon Sep 17 00:00:00 2001 From: Eric Sunshine Date: Tue, 9 Jul 2013 01:55:05 -0400 Subject: 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 Signed-off-by: Junio C Hamano --- line-log.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'line-log.c') diff --git a/line-log.c b/line-log.c index 4bbb09be59..8cc29a0000 100644 --- a/line-log.c +++ b/line-log.c @@ -116,7 +116,8 @@ static void sort_and_merge_range_set(struct range_set *rs) for (i = 1; i < rs->nr; i++) { if (rs->ranges[i].start <= rs->ranges[o-1].end) { - rs->ranges[o-1].end = rs->ranges[i].end; + if (rs->ranges[o-1].end < rs->ranges[i].end) + rs->ranges[o-1].end = rs->ranges[i].end; } else { rs->ranges[o].start = rs->ranges[i].start; rs->ranges[o].end = rs->ranges[i].end; -- cgit v1.2.1