From f8395edc6f5c59a92adcf42ea20a01872ec22700 Mon Sep 17 00:00:00 2001 From: Eric Sunshine Date: Tue, 23 Jul 2013 10:28:06 -0400 Subject: range-set: satisfy non-empty ranges invariant range-set invariants are: ranges must be (1) non-empty, (2) disjoint, (3) sorted in ascending order. During processing, various range-set utility functions break the invariants (for instance, by adding empty ranges), with the expectation that a finalizing sort_and_merge_range_set() will restore sanity. sort_and_merge_range_set(), however, neglects to fold out empty ranges, thus it fails to satisfy the non-empty constraint. Subsequent range-set functions crash or throw an assertion failure upon encountering such an anomaly. Rectify the situation by having sort_and_merge_range_set() fold out empty ranges. Signed-off-by: Eric Sunshine Acked-by: Thomas Rast Signed-off-by: Junio C Hamano --- line-log.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'line-log.c') diff --git a/line-log.c b/line-log.c index 52348796c1..6f94d56063 100644 --- a/line-log.c +++ b/line-log.c @@ -115,6 +115,8 @@ static void sort_and_merge_range_set(struct range_set *rs) qsort(rs->ranges, rs->nr, sizeof(struct range), range_cmp); for (i = 0; i < rs->nr; i++) { + if (rs->ranges[i].start == rs->ranges[i].end) + continue; if (o > 0 && rs->ranges[i].start <= rs->ranges[o-1].end) { if (rs->ranges[o-1].end < rs->ranges[i].end) rs->ranges[o-1].end = rs->ranges[i].end; -- cgit v1.2.3