@matheusbsbs / matheus-bagliano / commits / cc908b82a4
Fork 0

diffstat rename squashing fix.

When renaming leading/a/filename to leading/b/filename (and "filename" is sufficiently long), we tried to squash the rename to "leading/{a => b}/filename". However, when "/a" or "/b" part is empty, we underflowed and tried to print a substring of length -1. Signed-off-by: Junio C Hamano <junkio@cox.net>

Junio C Hamano committed May 14, 2006 at 22:07 UTC cc908b82a4a09df555fbc4c32cfbe8b8cffae865
1 file changed +7 -2
diff.c
+7 -2
@@ -232,11 +232,16 @@ static char *pprint_rename(const char *a, const char *b)
232 * name-a => name-b
233 */
234 if (pfx_length + sfx_length) {
235 + int a_midlen = len_a - pfx_length - sfx_length;
236 + int b_midlen = len_b - pfx_length - sfx_length;
237 + if (a_midlen < 0) a_midlen = 0;
238 + if (b_midlen < 0) b_midlen = 0;
239 +
240 name = xmalloc(len_a + len_b - pfx_length - sfx_length + 7);
241 sprintf(name, "%.*s{%.*s => %.*s}%s",
242 pfx_length, a,
238 - len_a - pfx_length - sfx_length, a + pfx_length,
239 - len_b - pfx_length - sfx_length, b + pfx_length,
243 + a_midlen, a + pfx_length,
244 + b_midlen, b + pfx_length,
245 a + len_a - sfx_length);
246 }
247 else {