##// END OF EJS Templates
bdiff: do not use recursion / avoid stackoverflow (issue1940)
Alistair Bell -
r10500:e96597c8 stable
parent child Browse files
Show More
@@ -226,19 +226,23 b' static void recurse(struct line *a, stru'
226 {
226 {
227 int i, j, k;
227 int i, j, k;
228
228
229 /* find the longest match in this chunk */
229 while (1) {
230 k = longest_match(a, b, pos, a1, a2, b1, b2, &i, &j);
230 /* find the longest match in this chunk */
231 if (!k)
231 k = longest_match(a, b, pos, a1, a2, b1, b2, &i, &j);
232 return;
232 if (!k)
233 return;
233
234
234 /* and recurse on the remaining chunks on either side */
235 /* and recurse on the remaining chunks on either side */
235 recurse(a, b, pos, a1, i, b1, j, l);
236 recurse(a, b, pos, a1, i, b1, j, l);
236 l->head->a1 = i;
237 l->head->a1 = i;
237 l->head->a2 = i + k;
238 l->head->a2 = i + k;
238 l->head->b1 = j;
239 l->head->b1 = j;
239 l->head->b2 = j + k;
240 l->head->b2 = j + k;
240 l->head++;
241 l->head++;
241 recurse(a, b, pos, i + k, a2, j + k, b2, l);
242 /* tail-recursion didn't happen, so doing equivalent iteration */
243 a1 = i + k;
244 b1 = j + k;
245 }
242 }
246 }
243
247
244 static struct hunklist diff(struct line *a, int an, struct line *b, int bn)
248 static struct hunklist diff(struct line *a, int an, struct line *b, int bn)
General Comments 0
You need to be logged in to leave comments. Login now