Skip to content

Commit

Permalink
diffstat rename squashing fix.
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Junio C Hamano committed May 15, 2006
1 parent 975bf9c commit cc908b8
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions diff.c
Original file line number Diff line number Diff line change
Expand Up @@ -232,11 +232,16 @@ static char *pprint_rename(const char *a, const char *b)
* name-a => name-b
*/
if (pfx_length + sfx_length) {
int a_midlen = len_a - pfx_length - sfx_length;
int b_midlen = len_b - pfx_length - sfx_length;
if (a_midlen < 0) a_midlen = 0;
if (b_midlen < 0) b_midlen = 0;

name = xmalloc(len_a + len_b - pfx_length - sfx_length + 7);
sprintf(name, "%.*s{%.*s => %.*s}%s",
pfx_length, a,
len_a - pfx_length - sfx_length, a + pfx_length,
len_b - pfx_length - sfx_length, b + pfx_length,
a_midlen, a + pfx_length,
b_midlen, b + pfx_length,
a + len_a - sfx_length);
}
else {
Expand Down

0 comments on commit cc908b8

Please sign in to comment.