diff options
author | Drew DeVault <sir@cmpwn.com> | 2020-08-29 10:44:40 -0400 |
---|---|---|
committer | Drew DeVault <sir@cmpwn.com> | 2020-09-16 15:53:27 -0400 |
commit | ec26b16d734a8a6b4838a1060af46e516c9c58e2 (patch) | |
tree | 4008ee64056b18261f95594b16bbbde91ed769a8 /src/diff_stats.c | |
parent | 931bd3b83d624ec890a537ba4c1357ebf8032dca (diff) | |
download | libgit2-ec26b16d734a8a6b4838a1060af46e516c9c58e2.tar.gz |
diff stats: fix segfaults with new files
Diffstat (limited to 'src/diff_stats.c')
-rw-r--r-- | src/diff_stats.c | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/src/diff_stats.c b/src/diff_stats.c index 1028b01a7..f5fda7925 100644 --- a/src/diff_stats.c +++ b/src/diff_stats.c @@ -53,7 +53,7 @@ static int diff_file_stats_full_to_buf( const git_diff_stats *stats, size_t width) { - const char *old_path = NULL, *new_path = NULL; + const char *old_path = NULL, *new_path = NULL, *adddel_path = NULL; size_t padding; git_object_size_t old_size, new_size; @@ -62,7 +62,7 @@ static int diff_file_stats_full_to_buf( old_size = delta->old_file.size; new_size = delta->new_file.size; - if (strcmp(old_path, new_path) != 0) { + if (old_path && new_path && strcmp(old_path, new_path) != 0) { size_t common_dirlen; int error; @@ -82,10 +82,11 @@ static int diff_file_stats_full_to_buf( if (error < 0) goto on_error; } else { - if (git_buf_printf(out, " %s", old_path) < 0) + adddel_path = new_path ? new_path : old_path; + if (git_buf_printf(out, " %s", adddel_path) < 0) goto on_error; - padding = stats->max_name - strlen(old_path); + padding = stats->max_name - strlen(adddel_path); if (stats->renames > 0) padding += strlen(DIFF_RENAME_FILE_SEPARATOR); @@ -211,7 +212,7 @@ int git_diff_get_stats( /* TODO ugh */ namelen = strlen(delta->new_file.path); - if (strcmp(delta->old_file.path, delta->new_file.path) != 0) { + if (delta->old_file.path && strcmp(delta->old_file.path, delta->new_file.path) != 0) { namelen += strlen(delta->old_file.path); stats->renames++; } |