merge3: fix assert in merge of identical deletions

This commit is contained in:
Ori Bernstein 2024-09-14 15:57:24 +00:00
parent f63dcb4b9b
commit d03b67430f
6 changed files with 43 additions and 4 deletions

View file

@ -16,6 +16,8 @@ addchange(Diff *df, int a, int b, int c, int d)
if (a > b && c > d)
return;
if(c > d)
d = c;
if(df->nchanges%1024 == 0)
df->changes = erealloc(df->changes, (df->nchanges+1024)*sizeof(df->changes[0]));
ch = &df->changes[df->nchanges++];
@ -45,7 +47,7 @@ collect(Diff *d)
addchange(d, i1 , i0, j1, j0);
}
if (m == 0)
change(d, 1, 0, 1, d->len[1]);
addchange(d, 1, 0, 1, d->len[1]);
qsort(d->changes, d->nchanges, sizeof(Change), changecmp);
}
@ -70,8 +72,8 @@ same(Diff *l, Change *lc, Diff *r, Change *rc)
ry = rc->newy;
if(ly - lx != ry - rx)
return 0;
assert(lx <= ly && ly < l->len[1]);
assert(rx <= ry && ry < r->len[1]);
assert(lx <= ly && ly <= l->len[1]);
assert(rx <= ry && ry <= r->len[1]);
Bseek(l->input[1], l->ixnew[lx-1], 0);
Bseek(r->input[1], r->ixnew[rx-1], 0);
for(i = 0; i <= (ly - lx); i++){

View file

@ -0,0 +1,10 @@
1
2
3
4
5
6
7
8
9
10

View file

@ -0,0 +1,9 @@
1
2
3
4
5
6
7
8
10

View file

@ -0,0 +1,9 @@
1
2
3
4
5
6
7
8
10

View file

@ -0,0 +1,9 @@
1
2
3
4
5
6
7
8
10

View file

@ -1,6 +1,6 @@
#!/bin/rc
tests=`{seq 11}
tests=`{seq 12}
for(t in $tests){
echo ../$O.merge3 merge-t$t.l merge-t$t.c merge-t$t.r
../$O.merge3 merge-t$t.l merge-t$t.c merge-t$t.r > merge-t$t.out