Skip to content

Commit cc908b8

Browse files
author
Junio C Hamano
committed
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>
1 parent 975bf9c commit cc908b8

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

diff.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -232,11 +232,16 @@ static char *pprint_rename(const char *a, const char *b)
232232
* name-a => name-b
233233
*/
234234
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+
235240
name = xmalloc(len_a + len_b - pfx_length - sfx_length + 7);
236241
sprintf(name, "%.*s{%.*s => %.*s}%s",
237242
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,
240245
a + len_a - sfx_length);
241246
}
242247
else {

0 commit comments

Comments
 (0)