]> granicus.if.org Git - git/commitdiff
Merge branch 'jk/tighten-alloc'
authorJunio C Hamano <gitster@pobox.com>
Fri, 26 Feb 2016 21:37:16 +0000 (13:37 -0800)
committerJunio C Hamano <gitster@pobox.com>
Fri, 26 Feb 2016 21:37:16 +0000 (13:37 -0800)
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
  ...

38 files changed:
1  2 
bisect.c
builtin/apply.c
builtin/blame.c
builtin/clean.c
builtin/fetch-pack.c
builtin/fetch.c
builtin/grep.c
builtin/mktree.c
builtin/pack-objects.c
builtin/worktree.c
cache-tree.c
compat/mingw.c
config.c
daemon.c
diff.c
diff.h
dir.c
exec_cmd.c
fast-import.c
git-compat-util.h
git.c
notes.c
pack-revindex.c
ref-filter.c
refs/files-backend.c
remote-curl.c
remote.c
revision.c
run-command.c
sequencer.c
setup.c
sha1_file.c
sha1_name.c
strbuf.c
submodule.c
test-path-utils.c
transport.c
wrapper.c

diff --cc bisect.c
Simple merge
diff --cc builtin/apply.c
Simple merge
diff --cc builtin/blame.c
Simple merge
diff --cc builtin/clean.c
Simple merge
Simple merge
diff --cc builtin/fetch.c
Simple merge
diff --cc builtin/grep.c
Simple merge
Simple merge
Simple merge
Simple merge
diff --cc cache-tree.c
Simple merge
diff --cc compat/mingw.c
Simple merge
diff --cc config.c
Simple merge
diff --cc daemon.c
Simple merge
diff --cc diff.c
Simple merge
diff --cc diff.h
Simple merge
diff --cc dir.c
Simple merge
diff --cc exec_cmd.c
Simple merge
diff --cc fast-import.c
Simple merge
Simple merge
diff --cc git.c
index 9bc04fd5285ff8c16d92554e0248e90f416089e7,e61a59c0145af8d24575e11d38ff91910b2cae8a..6cc0c077f9761f9b56e5fb7e666722b437c4fae4
--- 1/git.c
--- 2/git.c
+++ b/git.c
@@@ -247,20 -239,15 +247,16 @@@ static int handle_alias(int *argcp, con
        alias_string = alias_lookup(alias_command);
        if (alias_string) {
                if (alias_string[0] == '!') {
-                       const char **alias_argv;
-                       int argc = *argcp, i;
+                       struct child_process child = CHILD_PROCESS_INIT;
  
                        commit_pager_choice();
 +                      restore_env(1);
  
-                       /* build alias_argv */
-                       alias_argv = xmalloc(sizeof(*alias_argv) * (argc + 1));
-                       alias_argv[0] = alias_string + 1;
-                       for (i = 1; i < argc; ++i)
-                               alias_argv[i] = (*argv)[i];
-                       alias_argv[argc] = NULL;
+                       child.use_shell = 1;
+                       argv_array_push(&child.args, alias_string + 1);
+                       argv_array_pushv(&child.args, (*argv) + 1);
  
-                       ret = run_command_v_opt(alias_argv, RUN_USING_SHELL);
+                       ret = run_command(&child);
                        if (ret >= 0)   /* normal exit */
                                exit(ret);
  
diff --cc notes.c
index c1e503559076398b1edc5fabbaab8f3cac5ac7d6,8b59ccdb1166dfc413035e2699f3eb1dc9bd853e..88cf4747c16724931682e606a2c1fba4c07b2f49
+++ b/notes.c
@@@ -1035,10 -1032,10 +1035,10 @@@ struct notes_tree **load_notes_trees(st
        struct string_list_item *item;
        int counter = 0;
        struct notes_tree **trees;
-       trees = xmalloc((refs->nr+1) * sizeof(struct notes_tree *));
+       ALLOC_ARRAY(trees, refs->nr + 1);
        for_each_string_list_item(item, refs) {
                struct notes_tree *t = xcalloc(1, sizeof(struct notes_tree));
 -              init_notes(t, item->string, combine_notes_ignore, 0);
 +              init_notes(t, item->string, combine_notes_ignore, flags);
                trees[counter++] = t;
        }
        trees[counter] = NULL;
diff --cc pack-revindex.c
index 155a8a3d69bf7d1c4c72aaa36ad483dae33ca9b5,f6a3613bebe4ae8d398ab3b0ada22ba81b1339ee..96d51c3467b9ef864f62962aa3567247338d2c3a
@@@ -121,7 -165,7 +125,7 @@@ static void create_pack_revindex(struc
        unsigned i;
        const char *index = p->index_data;
  
-       p->revindex = xmalloc(sizeof(*p->revindex) * (num_ent + 1));
 -      ALLOC_ARRAY(rix->revindex, num_ent + 1);
++      ALLOC_ARRAY(p->revindex, num_ent + 1);
        index += 4 * 256;
  
        if (p->index_version > 1) {
diff --cc ref-filter.c
Simple merge
Simple merge
diff --cc remote-curl.c
Simple merge
diff --cc remote.c
Simple merge
diff --cc revision.c
Simple merge
diff --cc run-command.c
Simple merge
diff --cc sequencer.c
Simple merge
diff --cc setup.c
Simple merge
diff --cc sha1_file.c
Simple merge
diff --cc sha1_name.c
Simple merge
diff --cc strbuf.c
Simple merge
diff --cc submodule.c
Simple merge
Simple merge
diff --cc transport.c
Simple merge
diff --cc wrapper.c
Simple merge