From: Junio C Hamano Date: Fri, 26 Feb 2016 21:37:16 +0000 (-0800) Subject: Merge branch 'jk/tighten-alloc' X-Git-Tag: v2.8.0-rc0~19 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=11529ecec914d2f0d7575e6d443c2d5a6ff75424;p=git 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 ... --- 11529ecec914d2f0d7575e6d443c2d5a6ff75424 diff --cc git.c index 9bc04fd528,e61a59c014..6cc0c077f9 --- a/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 c1e5035590,8b59ccdb11..88cf4747c1 --- a/notes.c +++ 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 155a8a3d69,f6a3613beb..96d51c3467 --- a/pack-revindex.c +++ b/pack-revindex.c @@@ -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) {