diff options
author | Junio C Hamano <junkio@cox.net> | 2006-05-14 22:07:28 -0700 |
---|---|---|
committer | Junio C Hamano <junkio@cox.net> | 2006-05-14 22:07:28 -0700 |
commit | cc908b82a4a09df555fbc4c32cfbe8b8cffae865 (patch) | |
tree | f2b1491688ad2f5ac80b4b3a3f13e2da0584391a | |
parent | 975bf9cf5ad5d440f98f464ae8124609a4835ce1 (diff) | |
download | git-cc908b82a4a09df555fbc4c32cfbe8b8cffae865.tar.gz git-cc908b82a4a09df555fbc4c32cfbe8b8cffae865.tar.xz |
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>
-rw-r--r-- | diff.c | 9 |
1 files changed, 7 insertions, 2 deletions
@@ -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 { |