From 90321c106ca6e36c0e884ca677c9a52dea47bdde Mon Sep 17 00:00:00 2001 From: Peter Eriksen Date: Mon, 3 Apr 2006 19:30:46 +0100 Subject: Replace xmalloc+memset(0) with xcalloc. Signed-off-by: Peter Eriksen Signed-off-by: Junio C Hamano diff --git a/apply.c b/apply.c index cc3f12e..33b4271 100644 --- a/apply.c +++ b/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; diff --git a/blob.c b/blob.c index 84ec121..c1fdd86 100644 --- a/blob.c +++ b/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; diff --git a/commit.c b/commit.c index eb42d51..d4976fb 100644 --- a/commit.c +++ b/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; diff --git a/convert-objects.c b/convert-objects.c index 57de37f..12aacef 100644 --- a/convert-objects.c +++ b/convert-objects.c @@ -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; diff --git a/http-push.c b/http-push.c index ba7d9de..b60fa8d 100644 --- a/http-push.c +++ b/http-push.c @@ -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), diff --git a/object.c b/object.c index b5c0ecf..4d46e0d 100644 --- a/object.c +++ b/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; diff --git a/read-tree.c b/read-tree.c index eaff444..58e5636 100644 --- a/read-tree.c +++ b/read-tree.c @@ -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); diff --git a/tag.c b/tag.c index ac0e573..f390ee7 100644 --- a/tag.c +++ b/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; diff --git a/tree.c b/tree.c index 87e0d74..d599fb5 100644 --- a/tree.c +++ b/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; diff --git a/update-index.c b/update-index.c index 797245a..1efac27 100644 --- a/update-index.c +++ b/update-index.c @@ -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); -- cgit v0.10.2-6-g49f6