t4211: demonstrate empty -L range crash
[gitweb.git] / line-log.c
index 4bbb09be59e561b519f63c3685fb790de9e70ded..52348796c1b482c06f8944999603a5b92dcfdf04 100644 (file)
@@ -110,13 +110,14 @@ static void range_set_check_invariants(struct range_set *rs)
 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 (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;