static void sort_and_merge_range_set(struct range_set *rs)
{
int i;
- int o = 1; /* output cursor */
+ int o = 0; /* output cursor */
qsort(rs->ranges, rs->nr, sizeof(struct range), range_cmp);
- 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;
+ 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;
} else {
rs->ranges[o].start = rs->ranges[i].start;
rs->ranges[o].end = rs->ranges[i].end;
p = xcalloc(1, sizeof(struct line_log_data));
p->path = path;
range_set_append(&p->ranges, begin, end);
+ sort_and_merge_range_set(&p->ranges);
if (ip) {
p->next = ip->next;
ip->next = p;