Merge branch 'jk/tighten-alloc' into maint
* jk/tighten-alloc: (23 commits)
compat/mingw: brown paper bag fix for 50a6c8e
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
...
This commit is contained in:
23
diff.c
23
diff.c
@ -2607,12 +2607,9 @@ static void builtin_checkdiff(const char *name_a, const char *name_b,
|
||||
|
||||
struct diff_filespec *alloc_filespec(const char *path)
|
||||
{
|
||||
int namelen = strlen(path);
|
||||
struct diff_filespec *spec = xmalloc(sizeof(*spec) + namelen + 1);
|
||||
struct diff_filespec *spec;
|
||||
|
||||
memset(spec, 0, sizeof(*spec));
|
||||
spec->path = (char *)(spec + 1);
|
||||
memcpy(spec->path, path, namelen+1);
|
||||
FLEXPTR_ALLOC_STR(spec, path, path);
|
||||
spec->count = 1;
|
||||
spec->is_binary = -1;
|
||||
return spec;
|
||||
@ -2707,21 +2704,21 @@ static int reuse_worktree_file(const char *name, const unsigned char *sha1, int
|
||||
|
||||
static int diff_populate_gitlink(struct diff_filespec *s, int size_only)
|
||||
{
|
||||
int len;
|
||||
char *data = xmalloc(100), *dirty = "";
|
||||
struct strbuf buf = STRBUF_INIT;
|
||||
char *dirty = "";
|
||||
|
||||
/* Are we looking at the work tree? */
|
||||
if (s->dirty_submodule)
|
||||
dirty = "-dirty";
|
||||
|
||||
len = snprintf(data, 100,
|
||||
"Subproject commit %s%s\n", sha1_to_hex(s->sha1), dirty);
|
||||
s->data = data;
|
||||
s->size = len;
|
||||
s->should_free = 1;
|
||||
strbuf_addf(&buf, "Subproject commit %s%s\n", sha1_to_hex(s->sha1), dirty);
|
||||
s->size = buf.len;
|
||||
if (size_only) {
|
||||
s->data = NULL;
|
||||
free(data);
|
||||
strbuf_release(&buf);
|
||||
} else {
|
||||
s->data = strbuf_detach(&buf, NULL);
|
||||
s->should_free = 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
Reference in New Issue
Block a user