Merge branch 'jk/tighten-alloc'

Update various codepaths to avoid manually-counted malloc().

* jk/tighten-alloc: (22 commits)
  ewah: convert to REALLOC_ARRAY, etc
  convert ewah/bitmap code to use xmalloc
  diff_populate_gitlink: use a strbuf
  transport_anonymize_url: use xstrfmt
  git-compat-util: drop mempcpy compat code
  sequencer: simplify memory allocation of get_message
  test-path-utils: fix normalize_path_copy output buffer size
  fetch-pack: simplify add_sought_entry
  fast-import: simplify allocation in start_packfile
  write_untracked_extension: use FLEX_ALLOC helper
  prepare_{git,shell}_cmd: use argv_array
  use st_add and st_mult for allocation size computation
  convert trivial cases to FLEX_ARRAY macros
  use xmallocz to avoid size arithmetic
  convert trivial cases to ALLOC_ARRAY
  convert manual allocations to argv_array
  argv-array: add detach function
  add helpers for allocating flex-array structs
  harden REALLOC_ARRAY and xcalloc against size_t overflow
  tree-diff: catch integer overflow in combine_diff_path allocation
  ...
This commit is contained in:
Junio C Hamano
2016-02-26 13:37:16 -08:00
91 changed files with 440 additions and 481 deletions

View File

@ -810,7 +810,7 @@ static const char *quote_arg(const char *arg)
return arg;
/* insert \ where necessary */
d = q = xmalloc(len+n+3);
d = q = xmalloc(st_add3(len, n, 3));
*d++ = '"';
while (*arg) {
if (*arg == '"')
@ -893,7 +893,7 @@ static char **get_path_split(void)
if (!n)
return NULL;
path = xmalloc((n+1)*sizeof(char *));
ALLOC_ARRAY(path, n + 1);
p = envpath;
i = 0;
do {
@ -978,7 +978,7 @@ static wchar_t *make_environment_block(char **deltaenv)
i++;
/* copy the environment, leaving space for changes */
tmpenv = xmalloc((size + i) * sizeof(char*));
ALLOC_ARRAY(tmpenv, size + i);
memcpy(tmpenv, environ, size * sizeof(char*));
/* merge supplied environment changes into the temporary environment */
@ -1069,7 +1069,7 @@ static pid_t mingw_spawnve_fd(const char *cmd, const char **argv, char **deltaen
free(quoted);
}
wargs = xmalloc((2 * args.len + 1) * sizeof(wchar_t));
wargs = xmalloc_array(st_add(st_mult(2, args.len), 1), sizeof(wchar_t));
xutftowcs(wargs, args.buf, 2 * args.len + 1);
strbuf_release(&args);
@ -1168,7 +1168,7 @@ static int try_shell_exec(const char *cmd, char *const *argv)
int argc = 0;
const char **argv2;
while (argv[argc]) argc++;
argv2 = xmalloc(sizeof(*argv) * (argc+1));
ALLOC_ARRAY(argv2, argc + 1);
argv2[0] = (char *)cmd; /* full path to the script file */
memcpy(&argv2[1], &argv[1], sizeof(*argv) * argc);
pid = mingw_spawnv(prog, argv2, 1);