Fossil SCM

Fix merge so that it does not segfault when merging text files that do not end in \n and yet have changes at the very end. Ticket [c43d2d9477c2d59a].

drh 2011-03-01 22:07 trunk
Commit e2122bd6200ec0332ccab6cea9d0a558525a0dd9
2 files changed +4 -3 +3 -1
+4 -3
--- src/merge3.c
+++ src/merge3.c
@@ -39,18 +39,19 @@
3939
** The cursors on both pV1 and pV2 is unchanged by this comparison.
4040
*/
4141
static int sameLines(Blob *pV1, Blob *pV2, int N){
4242
char *z1, *z2;
4343
int i;
44
+ char c;
4445
4546
if( N==0 ) return 1;
4647
z1 = &blob_buffer(pV1)[blob_tell(pV1)];
4748
z2 = &blob_buffer(pV2)[blob_tell(pV2)];
48
- for(i=0; z1[i]==z2[i]; i++){
49
- if( z1[i]=='\n' ){
49
+ for(i=0; (c=z1[i])==z2[i]; i++){
50
+ if( c=='\n' || c==0 ){
5051
N--;
51
- if( N==0 ) return 1;
52
+ if( N==0 || c==0 ) return 1;
5253
}
5354
}
5455
return 0;
5556
}
5657
5758
--- src/merge3.c
+++ src/merge3.c
@@ -39,18 +39,19 @@
39 ** The cursors on both pV1 and pV2 is unchanged by this comparison.
40 */
41 static int sameLines(Blob *pV1, Blob *pV2, int N){
42 char *z1, *z2;
43 int i;
 
44
45 if( N==0 ) return 1;
46 z1 = &blob_buffer(pV1)[blob_tell(pV1)];
47 z2 = &blob_buffer(pV2)[blob_tell(pV2)];
48 for(i=0; z1[i]==z2[i]; i++){
49 if( z1[i]=='\n' ){
50 N--;
51 if( N==0 ) return 1;
52 }
53 }
54 return 0;
55 }
56
57
--- src/merge3.c
+++ src/merge3.c
@@ -39,18 +39,19 @@
39 ** The cursors on both pV1 and pV2 is unchanged by this comparison.
40 */
41 static int sameLines(Blob *pV1, Blob *pV2, int N){
42 char *z1, *z2;
43 int i;
44 char c;
45
46 if( N==0 ) return 1;
47 z1 = &blob_buffer(pV1)[blob_tell(pV1)];
48 z2 = &blob_buffer(pV2)[blob_tell(pV2)];
49 for(i=0; (c=z1[i])==z2[i]; i++){
50 if( c=='\n' || c==0 ){
51 N--;
52 if( N==0 || c==0 ) return 1;
53 }
54 }
55 return 0;
56 }
57
58
--- test/merge1.test
+++ test/merge1.test
@@ -346,20 +346,22 @@
346346
STUV
347347
XYZ.
348348
}
349349
write_file_indented t23 {
350350
abcd
351
+ <<<<<<< BEGIN MERGE CONFLICT: original content first <<<<<<<
351352
efgh 2
352353
ijkl 2
353
- <<<<<<< BEGIN MERGE CONFLICT: original content first <<<<<<<
354354
mnop
355355
qrst
356356
uvwx
357357
yzAB 2
358358
CDEF 2
359359
GHIJ 2
360360
======= original content above; conflict below =============
361
+ efgh
362
+ ijkl
361363
mnop 3
362364
qrst 3
363365
uvwx 3
364366
yzAB 3
365367
CDEF
366368
--- test/merge1.test
+++ test/merge1.test
@@ -346,20 +346,22 @@
346 STUV
347 XYZ.
348 }
349 write_file_indented t23 {
350 abcd
 
351 efgh 2
352 ijkl 2
353 <<<<<<< BEGIN MERGE CONFLICT: original content first <<<<<<<
354 mnop
355 qrst
356 uvwx
357 yzAB 2
358 CDEF 2
359 GHIJ 2
360 ======= original content above; conflict below =============
 
 
361 mnop 3
362 qrst 3
363 uvwx 3
364 yzAB 3
365 CDEF
366
--- test/merge1.test
+++ test/merge1.test
@@ -346,20 +346,22 @@
346 STUV
347 XYZ.
348 }
349 write_file_indented t23 {
350 abcd
351 <<<<<<< BEGIN MERGE CONFLICT: original content first <<<<<<<
352 efgh 2
353 ijkl 2
 
354 mnop
355 qrst
356 uvwx
357 yzAB 2
358 CDEF 2
359 GHIJ 2
360 ======= original content above; conflict below =============
361 efgh
362 ijkl
363 mnop 3
364 qrst 3
365 uvwx 3
366 yzAB 3
367 CDEF
368

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button