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:
@ -10,33 +10,24 @@ static const char fetch_pack_usage[] =
|
||||
"[--include-tag] [--upload-pack=<git-upload-pack>] [--depth=<n>] "
|
||||
"[--no-progress] [--diag-url] [-v] [<host>:]<directory> [<refs>...]";
|
||||
|
||||
static void add_sought_entry_mem(struct ref ***sought, int *nr, int *alloc,
|
||||
const char *name, int namelen)
|
||||
static void add_sought_entry(struct ref ***sought, int *nr, int *alloc,
|
||||
const char *name)
|
||||
{
|
||||
struct ref *ref = xcalloc(1, sizeof(*ref) + namelen + 1);
|
||||
struct ref *ref;
|
||||
struct object_id oid;
|
||||
const int chunksz = GIT_SHA1_HEXSZ + 1;
|
||||
|
||||
if (namelen > chunksz && name[chunksz - 1] == ' ' &&
|
||||
!get_oid_hex(name, &oid)) {
|
||||
oidcpy(&ref->old_oid, &oid);
|
||||
name += chunksz;
|
||||
namelen -= chunksz;
|
||||
}
|
||||
if (!get_oid_hex(name, &oid) && name[GIT_SHA1_HEXSZ] == ' ')
|
||||
name += GIT_SHA1_HEXSZ + 1;
|
||||
else
|
||||
oidclr(&oid);
|
||||
|
||||
memcpy(ref->name, name, namelen);
|
||||
ref->name[namelen] = '\0';
|
||||
ref = alloc_ref(name);
|
||||
oidcpy(&ref->old_oid, &oid);
|
||||
(*nr)++;
|
||||
ALLOC_GROW(*sought, *nr, *alloc);
|
||||
(*sought)[*nr - 1] = ref;
|
||||
}
|
||||
|
||||
static void add_sought_entry(struct ref ***sought, int *nr, int *alloc,
|
||||
const char *string)
|
||||
{
|
||||
add_sought_entry_mem(sought, nr, alloc, string, strlen(string));
|
||||
}
|
||||
|
||||
int cmd_fetch_pack(int argc, const char **argv, const char *prefix)
|
||||
{
|
||||
int i, ret;
|
||||
|
||||
Reference in New Issue
Block a user