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].
Commit
e2122bd6200ec0332ccab6cea9d0a558525a0dd9
Parent
1d93222627a3be2…
2 files changed
+4
-3
+3
-1
+4
-3
| --- src/merge3.c | ||
| +++ src/merge3.c | ||
| @@ -39,18 +39,19 @@ | ||
| 39 | 39 | ** The cursors on both pV1 and pV2 is unchanged by this comparison. |
| 40 | 40 | */ |
| 41 | 41 | static int sameLines(Blob *pV1, Blob *pV2, int N){ |
| 42 | 42 | char *z1, *z2; |
| 43 | 43 | int i; |
| 44 | + char c; | |
| 44 | 45 | |
| 45 | 46 | if( N==0 ) return 1; |
| 46 | 47 | z1 = &blob_buffer(pV1)[blob_tell(pV1)]; |
| 47 | 48 | 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 ){ | |
| 50 | 51 | N--; |
| 51 | - if( N==0 ) return 1; | |
| 52 | + if( N==0 || c==0 ) return 1; | |
| 52 | 53 | } |
| 53 | 54 | } |
| 54 | 55 | return 0; |
| 55 | 56 | } |
| 56 | 57 | |
| 57 | 58 |
| --- 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 |
+3
-1
| --- test/merge1.test | ||
| +++ test/merge1.test | ||
| @@ -346,20 +346,22 @@ | ||
| 346 | 346 | STUV |
| 347 | 347 | XYZ. |
| 348 | 348 | } |
| 349 | 349 | write_file_indented t23 { |
| 350 | 350 | abcd |
| 351 | + <<<<<<< BEGIN MERGE CONFLICT: original content first <<<<<<< | |
| 351 | 352 | efgh 2 |
| 352 | 353 | ijkl 2 |
| 353 | - <<<<<<< BEGIN MERGE CONFLICT: original content first <<<<<<< | |
| 354 | 354 | mnop |
| 355 | 355 | qrst |
| 356 | 356 | uvwx |
| 357 | 357 | yzAB 2 |
| 358 | 358 | CDEF 2 |
| 359 | 359 | GHIJ 2 |
| 360 | 360 | ======= original content above; conflict below ============= |
| 361 | + efgh | |
| 362 | + ijkl | |
| 361 | 363 | mnop 3 |
| 362 | 364 | qrst 3 |
| 363 | 365 | uvwx 3 |
| 364 | 366 | yzAB 3 |
| 365 | 367 | CDEF |
| 366 | 368 |
| --- 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 |