Fossil SCM
Short-circuit a rare pathological case in the diff generator to prevent it from taking too much time.
Commit
353438a83bf862cb680b25f5c24f51f59faf39d0
Parent
a1064042722ba2a…
1 file changed
+9
+9
| --- src/diff.c | ||
| +++ src/diff.c | ||
| @@ -989,10 +989,19 @@ | ||
| 989 | 989 | } |
| 990 | 990 | if( nRight==0 ){ |
| 991 | 991 | memset(aM, 1, nLeft); |
| 992 | 992 | return aM; |
| 993 | 993 | } |
| 994 | + | |
| 995 | + /* This algorithm is O(N**2). So if N is too big, bail out with a | |
| 996 | + ** simple (but stupid and ugly) result that doesn't take too long. */ | |
| 997 | + if( nLeft*nRight>100000 ){ | |
| 998 | + memset(aM, 3, nRight); | |
| 999 | + memset(aM+nRight, 1, nLeft); | |
| 1000 | + return aM; | |
| 1001 | + } | |
| 1002 | + | |
| 994 | 1003 | if( nRight < (sizeof(aBuf)/sizeof(aBuf[0]))-1 ){ |
| 995 | 1004 | pToFree = 0; |
| 996 | 1005 | a = aBuf; |
| 997 | 1006 | }else{ |
| 998 | 1007 | a = pToFree = fossil_malloc( sizeof(a[0])*(nRight+1) ); |
| 999 | 1008 |
| --- src/diff.c | |
| +++ src/diff.c | |
| @@ -989,10 +989,19 @@ | |
| 989 | } |
| 990 | if( nRight==0 ){ |
| 991 | memset(aM, 1, nLeft); |
| 992 | return aM; |
| 993 | } |
| 994 | if( nRight < (sizeof(aBuf)/sizeof(aBuf[0]))-1 ){ |
| 995 | pToFree = 0; |
| 996 | a = aBuf; |
| 997 | }else{ |
| 998 | a = pToFree = fossil_malloc( sizeof(a[0])*(nRight+1) ); |
| 999 |
| --- src/diff.c | |
| +++ src/diff.c | |
| @@ -989,10 +989,19 @@ | |
| 989 | } |
| 990 | if( nRight==0 ){ |
| 991 | memset(aM, 1, nLeft); |
| 992 | return aM; |
| 993 | } |
| 994 | |
| 995 | /* This algorithm is O(N**2). So if N is too big, bail out with a |
| 996 | ** simple (but stupid and ugly) result that doesn't take too long. */ |
| 997 | if( nLeft*nRight>100000 ){ |
| 998 | memset(aM, 3, nRight); |
| 999 | memset(aM+nRight, 1, nLeft); |
| 1000 | return aM; |
| 1001 | } |
| 1002 | |
| 1003 | if( nRight < (sizeof(aBuf)/sizeof(aBuf[0]))-1 ){ |
| 1004 | pToFree = 0; |
| 1005 | a = aBuf; |
| 1006 | }else{ |
| 1007 | a = pToFree = fossil_malloc( sizeof(a[0])*(nRight+1) ); |
| 1008 |