Skip to content

Commit 90321c1

Browse files
Peter EriksenJunio C Hamano
authored andcommitted
Replace xmalloc+memset(0) with xcalloc.
Signed-off-by: Peter Eriksen <s022018@student.dtu.dk> Signed-off-by: Junio C Hamano <junkio@cox.net>
1 parent 8e44025 commit 90321c1

File tree

10 files changed

+18
-37
lines changed

10 files changed

+18
-37
lines changed

apply.c

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -925,8 +925,7 @@ static int parse_single_patch(char *line, unsigned long size, struct patch *patc
925925
struct fragment *fragment;
926926
int len;
927927

928-
fragment = xmalloc(sizeof(*fragment));
929-
memset(fragment, 0, sizeof(*fragment));
928+
fragment = xcalloc(1, sizeof(*fragment));
930929
len = parse_fragment(line, size, patch, fragment);
931930
if (len <= 0)
932931
die("corrupt patch at line %d", linenr);
@@ -1652,8 +1651,7 @@ static void add_index_file(const char *path, unsigned mode, void *buf, unsigned
16521651
if (!write_index)
16531652
return;
16541653

1655-
ce = xmalloc(ce_size);
1656-
memset(ce, 0, ce_size);
1654+
ce = xcalloc(1, ce_size);
16571655
memcpy(ce->name, path, namelen);
16581656
ce->ce_mode = create_ce_mode(mode);
16591657
ce->ce_flags = htons(namelen);
@@ -1809,8 +1807,7 @@ static int apply_patch(int fd, const char *filename)
18091807
struct patch *patch;
18101808
int nr;
18111809

1812-
patch = xmalloc(sizeof(*patch));
1813-
memset(patch, 0, sizeof(*patch));
1810+
patch = xcalloc(1, sizeof(*patch));
18141811
nr = parse_chunk(buffer + offset, size, patch);
18151812
if (nr < 0)
18161813
break;

blob.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@ struct blob *lookup_blob(const unsigned char *sha1)
88
{
99
struct object *obj = lookup_object(sha1);
1010
if (!obj) {
11-
struct blob *ret = xmalloc(sizeof(struct blob));
12-
memset(ret, 0, sizeof(struct blob));
11+
struct blob *ret = xcalloc(1, sizeof(struct blob));
1312
created_object(sha1, &ret->object);
1413
ret->object.type = blob_type;
1514
return ret;

commit.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,7 @@ struct commit *lookup_commit(const unsigned char *sha1)
7373
{
7474
struct object *obj = lookup_object(sha1);
7575
if (!obj) {
76-
struct commit *ret = xmalloc(sizeof(struct commit));
77-
memset(ret, 0, sizeof(struct commit));
76+
struct commit *ret = xcalloc(1, sizeof(struct commit));
7877
created_object(sha1, &ret->object);
7978
ret->object.type = commit_type;
8079
return ret;

convert-objects.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,7 @@ static struct entry * convert_entry(unsigned char *sha1);
2121

2222
static struct entry *insert_new(unsigned char *sha1, int pos)
2323
{
24-
struct entry *new = xmalloc(sizeof(struct entry));
25-
memset(new, 0, sizeof(*new));
24+
struct entry *new = xcalloc(1, sizeof(struct entry));
2625
memcpy(new->old_sha1, sha1, 20);
2726
memmove(convert + pos + 1, convert + pos, (nr_convert - pos) * sizeof(struct entry *));
2827
convert[pos] = new;

http-push.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1008,8 +1008,7 @@ static int fetch_indices(void)
10081008
struct active_request_slot *slot;
10091009
struct slot_results results;
10101010

1011-
data = xmalloc(4096);
1012-
memset(data, 0, 4096);
1011+
data = xcalloc(1, 4096);
10131012
buffer.size = 4096;
10141013
buffer.posn = 0;
10151014
buffer.buffer = data;
@@ -2042,8 +2041,7 @@ static void update_remote_info_refs(struct remote_lock *lock)
20422041
char *if_header;
20432042
struct curl_slist *dav_headers = NULL;
20442043

2045-
buffer.buffer = xmalloc(4096);
2046-
memset(buffer.buffer, 0, 4096);
2044+
buffer.buffer = xcalloc(1, 4096);
20472045
buffer.size = 4096;
20482046
buffer.posn = 0;
20492047
remote_ls("refs/", (PROCESS_FILES | RECURSIVE),

object.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,7 @@ struct object_refs *alloc_object_refs(unsigned count)
8585
struct object_refs *refs;
8686
size_t size = sizeof(*refs) + count*sizeof(struct object *);
8787

88-
refs = xmalloc(size);
89-
memset(refs, 0, size);
88+
refs = xcalloc(1, size);
9089
refs->count = count;
9190
return refs;
9291
}
@@ -178,8 +177,7 @@ struct object *lookup_unknown_object(const unsigned char *sha1)
178177
{
179178
struct object *obj = lookup_object(sha1);
180179
if (!obj) {
181-
union any_object *ret = xmalloc(sizeof(*ret));
182-
memset(ret, 0, sizeof(*ret));
180+
union any_object *ret = xcalloc(1, sizeof(*ret));
183181
created_object(sha1, &ret->object);
184182
ret->object.type = NULL;
185183
return &ret->object;

read-tree.c

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -133,11 +133,9 @@ static int unpack_trees_rec(struct tree_entry_list **posns, int len,
133133
pathlen = strlen(first);
134134
ce_size = cache_entry_size(baselen + pathlen);
135135

136-
src = xmalloc(sizeof(struct cache_entry *) * src_size);
137-
memset(src, 0, sizeof(struct cache_entry *) * src_size);
136+
src = xcalloc(src_size, sizeof(struct cache_entry *));
138137

139-
subposns = xmalloc(sizeof(struct tree_list_entry *) * len);
140-
memset(subposns, 0, sizeof(struct tree_list_entry *) * len);
138+
subposns = xcalloc(len, sizeof(struct tree_list_entry *));
141139

142140
if (cache_name && !strcmp(cache_name, first)) {
143141
any_files = 1;
@@ -177,8 +175,7 @@ static int unpack_trees_rec(struct tree_entry_list **posns, int len,
177175
else
178176
ce_stage = 2;
179177

180-
ce = xmalloc(ce_size);
181-
memset(ce, 0, ce_size);
178+
ce = xcalloc(1, ce_size);
182179
ce->ce_mode = create_ce_mode(posns[i]->mode);
183180
ce->ce_flags = create_ce_flags(baselen + pathlen,
184181
ce_stage);

tag.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@ struct tag *lookup_tag(const unsigned char *sha1)
1919
{
2020
struct object *obj = lookup_object(sha1);
2121
if (!obj) {
22-
struct tag *ret = xmalloc(sizeof(struct tag));
23-
memset(ret, 0, sizeof(struct tag));
22+
struct tag *ret = xcalloc(1, sizeof(struct tag));
2423
created_object(sha1, &ret->object);
2524
ret->object.type = tag_type;
2625
return ret;

tree.c

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,7 @@ static int read_one_entry(unsigned char *sha1, const char *base, int baselen, co
1818

1919
len = strlen(pathname);
2020
size = cache_entry_size(baselen + len);
21-
ce = xmalloc(size);
22-
23-
memset(ce, 0, size);
21+
ce = xcalloc(1, size);
2422

2523
ce->ce_mode = create_ce_mode(mode);
2624
ce->ce_flags = create_ce_flags(baselen + len, stage);
@@ -130,8 +128,7 @@ struct tree *lookup_tree(const unsigned char *sha1)
130128
{
131129
struct object *obj = lookup_object(sha1);
132130
if (!obj) {
133-
struct tree *ret = xmalloc(sizeof(struct tree));
134-
memset(ret, 0, sizeof(struct tree));
131+
struct tree *ret = xcalloc(1, sizeof(struct tree));
135132
created_object(sha1, &ret->object);
136133
ret->object.type = tree_type;
137134
return ret;

update-index.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,7 @@ static int add_file_to_cache(const char *path)
114114

115115
namelen = strlen(path);
116116
size = cache_entry_size(namelen);
117-
ce = xmalloc(size);
118-
memset(ce, 0, size);
117+
ce = xcalloc(1, size);
119118
memcpy(ce->name, path, namelen);
120119
ce->ce_flags = htons(namelen);
121120
fill_stat_cache_info(ce, &st);
@@ -312,8 +311,7 @@ static int add_cacheinfo(unsigned int mode, const unsigned char *sha1,
312311

313312
len = strlen(path);
314313
size = cache_entry_size(len);
315-
ce = xmalloc(size);
316-
memset(ce, 0, size);
314+
ce = xcalloc(1, size);
317315

318316
memcpy(ce->sha1, sha1, 20);
319317
memcpy(ce->name, path, len);

0 commit comments

Comments
 (0)