Replace xmalloc+memset(0) with xcalloc.
Signed-off-by: Peter Eriksen <s022018@student.dtu.dk> Signed-off-by: Junio C Hamano <junkio@cox.net>
This commit is contained in:
parent
8e44025925
commit
90321c106c
9
apply.c
9
apply.c
@ -925,8 +925,7 @@ static int parse_single_patch(char *line, unsigned long size, struct patch *patc
|
||||
struct fragment *fragment;
|
||||
int len;
|
||||
|
||||
fragment = xmalloc(sizeof(*fragment));
|
||||
memset(fragment, 0, sizeof(*fragment));
|
||||
fragment = xcalloc(1, sizeof(*fragment));
|
||||
len = parse_fragment(line, size, patch, fragment);
|
||||
if (len <= 0)
|
||||
die("corrupt patch at line %d", linenr);
|
||||
@ -1652,8 +1651,7 @@ static void add_index_file(const char *path, unsigned mode, void *buf, unsigned
|
||||
if (!write_index)
|
||||
return;
|
||||
|
||||
ce = xmalloc(ce_size);
|
||||
memset(ce, 0, ce_size);
|
||||
ce = xcalloc(1, ce_size);
|
||||
memcpy(ce->name, path, namelen);
|
||||
ce->ce_mode = create_ce_mode(mode);
|
||||
ce->ce_flags = htons(namelen);
|
||||
@ -1809,8 +1807,7 @@ static int apply_patch(int fd, const char *filename)
|
||||
struct patch *patch;
|
||||
int nr;
|
||||
|
||||
patch = xmalloc(sizeof(*patch));
|
||||
memset(patch, 0, sizeof(*patch));
|
||||
patch = xcalloc(1, sizeof(*patch));
|
||||
nr = parse_chunk(buffer + offset, size, patch);
|
||||
if (nr < 0)
|
||||
break;
|
||||
|
3
blob.c
3
blob.c
@ -8,8 +8,7 @@ struct blob *lookup_blob(const unsigned char *sha1)
|
||||
{
|
||||
struct object *obj = lookup_object(sha1);
|
||||
if (!obj) {
|
||||
struct blob *ret = xmalloc(sizeof(struct blob));
|
||||
memset(ret, 0, sizeof(struct blob));
|
||||
struct blob *ret = xcalloc(1, sizeof(struct blob));
|
||||
created_object(sha1, &ret->object);
|
||||
ret->object.type = blob_type;
|
||||
return ret;
|
||||
|
3
commit.c
3
commit.c
@ -73,8 +73,7 @@ struct commit *lookup_commit(const unsigned char *sha1)
|
||||
{
|
||||
struct object *obj = lookup_object(sha1);
|
||||
if (!obj) {
|
||||
struct commit *ret = xmalloc(sizeof(struct commit));
|
||||
memset(ret, 0, sizeof(struct commit));
|
||||
struct commit *ret = xcalloc(1, sizeof(struct commit));
|
||||
created_object(sha1, &ret->object);
|
||||
ret->object.type = commit_type;
|
||||
return ret;
|
||||
|
@ -21,8 +21,7 @@ static struct entry * convert_entry(unsigned char *sha1);
|
||||
|
||||
static struct entry *insert_new(unsigned char *sha1, int pos)
|
||||
{
|
||||
struct entry *new = xmalloc(sizeof(struct entry));
|
||||
memset(new, 0, sizeof(*new));
|
||||
struct entry *new = xcalloc(1, sizeof(struct entry));
|
||||
memcpy(new->old_sha1, sha1, 20);
|
||||
memmove(convert + pos + 1, convert + pos, (nr_convert - pos) * sizeof(struct entry *));
|
||||
convert[pos] = new;
|
||||
|
@ -1008,8 +1008,7 @@ static int fetch_indices(void)
|
||||
struct active_request_slot *slot;
|
||||
struct slot_results results;
|
||||
|
||||
data = xmalloc(4096);
|
||||
memset(data, 0, 4096);
|
||||
data = xcalloc(1, 4096);
|
||||
buffer.size = 4096;
|
||||
buffer.posn = 0;
|
||||
buffer.buffer = data;
|
||||
@ -2042,8 +2041,7 @@ static void update_remote_info_refs(struct remote_lock *lock)
|
||||
char *if_header;
|
||||
struct curl_slist *dav_headers = NULL;
|
||||
|
||||
buffer.buffer = xmalloc(4096);
|
||||
memset(buffer.buffer, 0, 4096);
|
||||
buffer.buffer = xcalloc(1, 4096);
|
||||
buffer.size = 4096;
|
||||
buffer.posn = 0;
|
||||
remote_ls("refs/", (PROCESS_FILES | RECURSIVE),
|
||||
|
6
object.c
6
object.c
@ -85,8 +85,7 @@ struct object_refs *alloc_object_refs(unsigned count)
|
||||
struct object_refs *refs;
|
||||
size_t size = sizeof(*refs) + count*sizeof(struct object *);
|
||||
|
||||
refs = xmalloc(size);
|
||||
memset(refs, 0, size);
|
||||
refs = xcalloc(1, size);
|
||||
refs->count = count;
|
||||
return refs;
|
||||
}
|
||||
@ -178,8 +177,7 @@ struct object *lookup_unknown_object(const unsigned char *sha1)
|
||||
{
|
||||
struct object *obj = lookup_object(sha1);
|
||||
if (!obj) {
|
||||
union any_object *ret = xmalloc(sizeof(*ret));
|
||||
memset(ret, 0, sizeof(*ret));
|
||||
union any_object *ret = xcalloc(1, sizeof(*ret));
|
||||
created_object(sha1, &ret->object);
|
||||
ret->object.type = NULL;
|
||||
return &ret->object;
|
||||
|
@ -133,11 +133,9 @@ static int unpack_trees_rec(struct tree_entry_list **posns, int len,
|
||||
pathlen = strlen(first);
|
||||
ce_size = cache_entry_size(baselen + pathlen);
|
||||
|
||||
src = xmalloc(sizeof(struct cache_entry *) * src_size);
|
||||
memset(src, 0, sizeof(struct cache_entry *) * src_size);
|
||||
src = xcalloc(src_size, sizeof(struct cache_entry *));
|
||||
|
||||
subposns = xmalloc(sizeof(struct tree_list_entry *) * len);
|
||||
memset(subposns, 0, sizeof(struct tree_list_entry *) * len);
|
||||
subposns = xcalloc(len, sizeof(struct tree_list_entry *));
|
||||
|
||||
if (cache_name && !strcmp(cache_name, first)) {
|
||||
any_files = 1;
|
||||
@ -177,8 +175,7 @@ static int unpack_trees_rec(struct tree_entry_list **posns, int len,
|
||||
else
|
||||
ce_stage = 2;
|
||||
|
||||
ce = xmalloc(ce_size);
|
||||
memset(ce, 0, ce_size);
|
||||
ce = xcalloc(1, ce_size);
|
||||
ce->ce_mode = create_ce_mode(posns[i]->mode);
|
||||
ce->ce_flags = create_ce_flags(baselen + pathlen,
|
||||
ce_stage);
|
||||
|
3
tag.c
3
tag.c
@ -19,8 +19,7 @@ struct tag *lookup_tag(const unsigned char *sha1)
|
||||
{
|
||||
struct object *obj = lookup_object(sha1);
|
||||
if (!obj) {
|
||||
struct tag *ret = xmalloc(sizeof(struct tag));
|
||||
memset(ret, 0, sizeof(struct tag));
|
||||
struct tag *ret = xcalloc(1, sizeof(struct tag));
|
||||
created_object(sha1, &ret->object);
|
||||
ret->object.type = tag_type;
|
||||
return ret;
|
||||
|
7
tree.c
7
tree.c
@ -18,9 +18,7 @@ static int read_one_entry(unsigned char *sha1, const char *base, int baselen, co
|
||||
|
||||
len = strlen(pathname);
|
||||
size = cache_entry_size(baselen + len);
|
||||
ce = xmalloc(size);
|
||||
|
||||
memset(ce, 0, size);
|
||||
ce = xcalloc(1, size);
|
||||
|
||||
ce->ce_mode = create_ce_mode(mode);
|
||||
ce->ce_flags = create_ce_flags(baselen + len, stage);
|
||||
@ -130,8 +128,7 @@ struct tree *lookup_tree(const unsigned char *sha1)
|
||||
{
|
||||
struct object *obj = lookup_object(sha1);
|
||||
if (!obj) {
|
||||
struct tree *ret = xmalloc(sizeof(struct tree));
|
||||
memset(ret, 0, sizeof(struct tree));
|
||||
struct tree *ret = xcalloc(1, sizeof(struct tree));
|
||||
created_object(sha1, &ret->object);
|
||||
ret->object.type = tree_type;
|
||||
return ret;
|
||||
|
@ -114,8 +114,7 @@ static int add_file_to_cache(const char *path)
|
||||
|
||||
namelen = strlen(path);
|
||||
size = cache_entry_size(namelen);
|
||||
ce = xmalloc(size);
|
||||
memset(ce, 0, size);
|
||||
ce = xcalloc(1, size);
|
||||
memcpy(ce->name, path, namelen);
|
||||
ce->ce_flags = htons(namelen);
|
||||
fill_stat_cache_info(ce, &st);
|
||||
@ -312,8 +311,7 @@ static int add_cacheinfo(unsigned int mode, const unsigned char *sha1,
|
||||
|
||||
len = strlen(path);
|
||||
size = cache_entry_size(len);
|
||||
ce = xmalloc(size);
|
||||
memset(ce, 0, size);
|
||||
ce = xcalloc(1, size);
|
||||
|
||||
memcpy(ce->sha1, sha1, 20);
|
||||
memcpy(ce->name, path, len);
|
||||
|
Loading…
Reference in New Issue
Block a user