Merge branch 'jk/compiler-fixes-and-workarounds'

Small fixes and workarounds.

* jk/compiler-fixes-and-workarounds:
  revision: avoid leak when preparing bloom filter for "/"
  revision: avoid out-of-bounds read/write on empty pathspec
  config: work around gcc-10 -Wstringop-overflow warning
This commit is contained in:
Junio C Hamano
2020-08-10 10:24:02 -07:00
2 changed files with 4 additions and 6 deletions

View File

@ -3115,7 +3115,7 @@ static int git_config_copy_or_rename_section_in_file(const char *config_filename
} }
while (fgets(buf, sizeof(buf), config_file)) { while (fgets(buf, sizeof(buf), config_file)) {
int i; unsigned i;
int length; int length;
int is_section = 0; int is_section = 0;
char *output = buf; char *output = buf;

View File

@ -669,7 +669,6 @@ static void prepare_to_use_bloom_filter(struct rev_info *revs)
struct pathspec_item *pi; struct pathspec_item *pi;
char *path_alloc = NULL; char *path_alloc = NULL;
const char *path, *p; const char *path, *p;
int last_index;
size_t len; size_t len;
int path_component_nr = 1; int path_component_nr = 1;
@ -692,12 +691,10 @@ static void prepare_to_use_bloom_filter(struct rev_info *revs)
return; return;
pi = &revs->pruning.pathspec.items[0]; pi = &revs->pruning.pathspec.items[0];
last_index = pi->len - 1;
/* remove single trailing slash from path, if needed */ /* remove single trailing slash from path, if needed */
if (pi->match[last_index] == '/') { if (pi->len > 0 && pi->match[pi->len - 1] == '/') {
path_alloc = xstrdup(pi->match); path_alloc = xmemdupz(pi->match, pi->len - 1);
path_alloc[last_index] = '\0';
path = path_alloc; path = path_alloc;
} else } else
path = pi->match; path = pi->match;
@ -705,6 +702,7 @@ static void prepare_to_use_bloom_filter(struct rev_info *revs)
len = strlen(path); len = strlen(path);
if (!len) { if (!len) {
revs->bloom_filter_settings = NULL; revs->bloom_filter_settings = NULL;
free(path_alloc);
return; return;
} }