Replace xmalloc+memset(0) with xcalloc.
Signed-off-by: Peter Eriksen <s022018@student.dtu.dk> Signed-off-by: Junio C Hamano <junkio@cox.net>
Peter Eriksen committed
Apr 3, 2006 at 19:30 UTC
90321c106ca6e36c0e884ca677c9a52dea47bdde
10 files changed
+18
-37
apply.c
+3
-6
@@ -925,8 +925,7 @@ static int parse_single_patch(char *line, unsigned long size, struct patch *patc
925
struct fragment *fragment;
926
int len;
927
928
- fragment = xmalloc(sizeof(*fragment));
929
- memset(fragment, 0, sizeof(*fragment));
928
+ fragment = xcalloc(1, sizeof(*fragment));
929
len = parse_fragment(line, size, patch, fragment);
930
if (len <= 0)
931
die("corrupt patch at line %d", linenr);
@@ -1652,8 +1651,7 @@ static void add_index_file(const char *path, unsigned mode, void *buf, unsigned
1651
if (!write_index)
1652
return;
1653
1655
- ce = xmalloc(ce_size);
1656
- memset(ce, 0, ce_size);
1654
+ ce = xcalloc(1, ce_size);
1655
memcpy(ce->name, path, namelen);
1656
ce->ce_mode = create_ce_mode(mode);
1657
ce->ce_flags = htons(namelen);
@@ -1809,8 +1807,7 @@ static int apply_patch(int fd, const char *filename)
1807
struct patch *patch;
1808
int nr;
1809
1812
- patch = xmalloc(sizeof(*patch));
1813
- memset(patch, 0, sizeof(*patch));
1810
+ patch = xcalloc(1, sizeof(*patch));
1811
nr = parse_chunk(buffer + offset, size, patch);
1812
if (nr < 0)
1813
break;
blob.c
+1
-2
@@ -8,8 +8,7 @@ struct blob *lookup_blob(const unsigned char *sha1)
8
{
9
struct object *obj = lookup_object(sha1);
10
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));
12
created_object(sha1, &ret->object);
13
ret->object.type = blob_type;
14
return ret;
commit.c
+1
-2
@@ -73,8 +73,7 @@ struct commit *lookup_commit(const unsigned char *sha1)
73
{
74
struct object *obj = lookup_object(sha1);
75
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));
77
created_object(sha1, &ret->object);
78
ret->object.type = commit_type;
79
return ret;
convert-objects.c
+1
-2
@@ -21,8 +21,7 @@ static struct entry * convert_entry(unsigned char *sha1);
21
22
static struct entry *insert_new(unsigned char *sha1, int pos)
23
{
24
- struct entry *new = xmalloc(sizeof(struct entry));
25
- memset(new, 0, sizeof(*new));
24
+ struct entry *new = xcalloc(1, sizeof(struct entry));
25
memcpy(new->old_sha1, sha1, 20);
26
memmove(convert + pos + 1, convert + pos, (nr_convert - pos) * sizeof(struct entry *));
27
convert[pos] = new;
http-push.c
+2
-4
@@ -1008,8 +1008,7 @@ static int fetch_indices(void)
1008
struct active_request_slot *slot;
1009
struct slot_results results;
1010
1011
- data = xmalloc(4096);
1012
- memset(data, 0, 4096);
1011
+ data = xcalloc(1, 4096);
1012
buffer.size = 4096;
1013
buffer.posn = 0;
1014
buffer.buffer = data;
@@ -2042,8 +2041,7 @@ static void update_remote_info_refs(struct remote_lock *lock)
2041
char *if_header;
2042
struct curl_slist *dav_headers = NULL;
2043
2045
- buffer.buffer = xmalloc(4096);
2046
- memset(buffer.buffer, 0, 4096);
2044
+ buffer.buffer = xcalloc(1, 4096);
2045
buffer.size = 4096;
2046
buffer.posn = 0;
2047
remote_ls("refs/", (PROCESS_FILES | RECURSIVE),
object.c
+2
-4
@@ -85,8 +85,7 @@ struct object_refs *alloc_object_refs(unsigned count)
85
struct object_refs *refs;
86
size_t size = sizeof(*refs) + count*sizeof(struct object *);
87
88
- refs = xmalloc(size);
89
- memset(refs, 0, size);
88
+ refs = xcalloc(1, size);
89
refs->count = count;
90
return refs;
91
}
@@ -178,8 +177,7 @@ struct object *lookup_unknown_object(const unsigned char *sha1)
177
{
178
struct object *obj = lookup_object(sha1);
179
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));
181
created_object(sha1, &ret->object);
182
ret->object.type = NULL;
183
return &ret->object;
read-tree.c
+3
-6
@@ -133,11 +133,9 @@ static int unpack_trees_rec(struct tree_entry_list **posns, int len,
133
pathlen = strlen(first);
134
ce_size = cache_entry_size(baselen + pathlen);
135
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 *));
137
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 *));
139
140
if (cache_name && !strcmp(cache_name, first)) {
141
any_files = 1;
@@ -177,8 +175,7 @@ static int unpack_trees_rec(struct tree_entry_list **posns, int len,
175
else
176
ce_stage = 2;
177
180
- ce = xmalloc(ce_size);
181
- memset(ce, 0, ce_size);
178
+ ce = xcalloc(1, ce_size);
179
ce->ce_mode = create_ce_mode(posns[i]->mode);
180
ce->ce_flags = create_ce_flags(baselen + pathlen,
181
ce_stage);
tag.c
+1
-2
@@ -19,8 +19,7 @@ struct tag *lookup_tag(const unsigned char *sha1)
19
{
20
struct object *obj = lookup_object(sha1);
21
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));
23
created_object(sha1, &ret->object);
24
ret->object.type = tag_type;
25
return ret;
tree.c
+2
-5
@@ -18,9 +18,7 @@ static int read_one_entry(unsigned char *sha1, const char *base, int baselen, co
18
19
len = strlen(pathname);
20
size = cache_entry_size(baselen + len);
21
- ce = xmalloc(size);
22
-
23
- memset(ce, 0, size);
21
+ ce = xcalloc(1, size);
22
23
ce->ce_mode = create_ce_mode(mode);
24
ce->ce_flags = create_ce_flags(baselen + len, stage);
@@ -130,8 +128,7 @@ struct tree *lookup_tree(const unsigned char *sha1)
128
{
129
struct object *obj = lookup_object(sha1);
130
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));
132
created_object(sha1, &ret->object);
133
ret->object.type = tree_type;
134
return ret;
update-index.c
+2
-4
@@ -114,8 +114,7 @@ static int add_file_to_cache(const char *path)
114
115
namelen = strlen(path);
116
size = cache_entry_size(namelen);
117
- ce = xmalloc(size);
118
- memset(ce, 0, size);
117
+ ce = xcalloc(1, size);
118
memcpy(ce->name, path, namelen);
119
ce->ce_flags = htons(namelen);
120
fill_stat_cache_info(ce, &st);
@@ -312,8 +311,7 @@ static int add_cacheinfo(unsigned int mode, const unsigned char *sha1,
311
312
len = strlen(path);
313
size = cache_entry_size(len);
315
- ce = xmalloc(size);
316
- memset(ce, 0, size);
314
+ ce = xcalloc(1, size);
315
316
memcpy(ce->sha1, sha1, 20);
317
memcpy(ce->name, path, len);