{"thread":{"id":"3782","subject":"[PATCH] Replace xmalloc+memset(0) with xcalloc.","startedAt":"2006-04-03T16:35:25Z","lastAt":"2006-04-03T16:35:25Z","messageCount":1,"participants":["Peter Eriksen"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"18293","messageId":"20060403163525.GA23536@bohr.gbar.dtu.dk","threadId":"3782","inReplyTo":null,"subject":"[PATCH] Replace xmalloc+memset(0) with xcalloc.","fromName":"Peter Eriksen","fromEmail":"s022018@student.dtu.dk","sentAt":"2006-04-03T16:35:25Z","receivedAt":"2006-04-03T16:35:25Z","isPatch":true,"sender":{"key":"s022018@student.dtu.dk","avatar":null},"body":"From: Peter Eriksen <s022018@student.dtu.dk>\nDate: Mon Apr 3 19:30:46 2006 +0100\nSubject: [PATCH] Replace xmalloc+memset(0) with xcalloc.\n\nSigned-off-by: Peter Eriksen <s022018@student.dtu.dk>\n\n\n---\n\nIs something like this considered a cleaup?\n\nRegards,\n\nPeter\n\n apply.c           |    9 +++------\n blob.c            |    3 +--\n commit.c          |    3 +--\n convert-objects.c |    3 +--\n http-push.c       |    6 ++----\n object.c          |    6 ++----\n read-tree.c       |    9 +++------\n tag.c             |    3 +--\n tree.c            |    7 ++-----\n update-index.c    |    6 ++----\n 10 files changed, 18 insertions(+), 37 deletions(-)\n\nd5c82aa8a2b9d776bb30efac17d15a8a596b47f4\ndiff --git a/apply.c b/apply.c\nindex c50b3a6..6623ae7 100644\n--- a/apply.c\n+++ b/apply.c\n@@ -924,8 +924,7 @@ static int parse_single_patch(char *line\n \t\tstruct fragment *fragment;\n \t\tint len;\n \n-\t\tfragment = xmalloc(sizeof(*fragment));\n-\t\tmemset(fragment, 0, sizeof(*fragment));\n+\t\tfragment = xcalloc(1, sizeof(*fragment));\n \t\tlen = parse_fragment(line, size, patch, fragment);\n \t\tif (len <= 0)\n \t\t\tdie(\"corrupt patch at line %d\", linenr);\n@@ -1651,8 +1650,7 @@ static void add_index_file(const char *p\n \tif (!write_index)\n \t\treturn;\n \n-\tce = xmalloc(ce_size);\n-\tmemset(ce, 0, ce_size);\n+\tce = xcalloc(1, ce_size);\n \tmemcpy(ce->name, path, namelen);\n \tce->ce_mode = create_ce_mode(mode);\n \tce->ce_flags = htons(namelen);\n@@ -1808,8 +1806,7 @@ static int apply_patch(int fd, const cha\n \t\tstruct patch *patch;\n \t\tint nr;\n \n-\t\tpatch = xmalloc(sizeof(*patch));\n-\t\tmemset(patch, 0, sizeof(*patch));\n+\t\tpatch = xcalloc(1, sizeof(*patch));\n \t\tnr = parse_chunk(buffer + offset, size, patch);\n \t\tif (nr < 0)\n \t\t\tbreak;\ndiff --git a/blob.c b/blob.c\nindex 84ec121..c1fdd86 100644\n--- a/blob.c\n+++ b/blob.c\n@@ -8,8 +8,7 @@ struct blob *lookup_blob(const unsigned \n {\n \tstruct object *obj = lookup_object(sha1);\n \tif (!obj) {\n-\t\tstruct blob *ret = xmalloc(sizeof(struct blob));\n-\t\tmemset(ret, 0, sizeof(struct blob));\n+\t\tstruct blob *ret = xcalloc(1, sizeof(struct blob));\n \t\tcreated_object(sha1, &ret->object);\n \t\tret->object.type = blob_type;\n \t\treturn ret;\ndiff --git a/commit.c b/commit.c\nindex eb42d51..d4976fb 100644\n--- a/commit.c\n+++ b/commit.c\n@@ -73,8 +73,7 @@ struct commit *lookup_commit(const unsig\n {\n \tstruct object *obj = lookup_object(sha1);\n \tif (!obj) {\n-\t\tstruct commit *ret = xmalloc(sizeof(struct commit));\n-\t\tmemset(ret, 0, sizeof(struct commit));\n+\t\tstruct commit *ret = xcalloc(1, sizeof(struct commit));\n \t\tcreated_object(sha1, &ret->object);\n \t\tret->object.type = commit_type;\n \t\treturn ret;\ndiff --git a/convert-objects.c b/convert-objects.c\nindex b49bce2..b2aafbb 100644\n--- a/convert-objects.c\n+++ b/convert-objects.c\n@@ -18,8 +18,7 @@ static struct entry * convert_entry(unsi\n \n static struct entry *insert_new(unsigned char *sha1, int pos)\n {\n-\tstruct entry *new = xmalloc(sizeof(struct entry));\n-\tmemset(new, 0, sizeof(*new));\n+\tstruct entry *new = xcalloc(1, sizeof(struct entry));\n \tmemcpy(new->old_sha1, sha1, 20);\n \tmemmove(convert + pos + 1, convert + pos, (nr_convert - pos) * sizeof(struct entry *));\n \tconvert[pos] = new;\ndiff --git a/http-push.c b/http-push.c\nindex ba7d9de..b60fa8d 100644\n--- a/http-push.c\n+++ b/http-push.c\n@@ -1008,8 +1008,7 @@ static int fetch_indices(void)\n \tstruct active_request_slot *slot;\n \tstruct slot_results results;\n \n-\tdata = xmalloc(4096);\n-\tmemset(data, 0, 4096);\n+\tdata = xcalloc(1, 4096);\n \tbuffer.size = 4096;\n \tbuffer.posn = 0;\n \tbuffer.buffer = data;\n@@ -2042,8 +2041,7 @@ static void update_remote_info_refs(stru\n \tchar *if_header;\n \tstruct curl_slist *dav_headers = NULL;\n \n-\tbuffer.buffer = xmalloc(4096);\n-\tmemset(buffer.buffer, 0, 4096);\n+\tbuffer.buffer = xcalloc(1, 4096);\n \tbuffer.size = 4096;\n \tbuffer.posn = 0;\n \tremote_ls(\"refs/\", (PROCESS_FILES | RECURSIVE),\ndiff --git a/object.c b/object.c\nindex c9ca481..71e15e1 100644\n--- a/object.c\n+++ b/object.c\n@@ -85,8 +85,7 @@ struct object_refs *alloc_object_refs(un\n \tstruct object_refs *refs;\n \tsize_t size = sizeof(*refs) + count*sizeof(struct object *);\n \n-\trefs = xmalloc(size);\n-\tmemset(refs, 0, size);\n+\trefs = xcalloc(1, size);\n \trefs->count = count;\n \treturn refs;\n }\n@@ -178,8 +177,7 @@ struct object *lookup_unknown_object(con\n {\n \tstruct object *obj = lookup_object(sha1);\n \tif (!obj) {\n-\t\tunion any_object *ret = xmalloc(sizeof(*ret));\n-\t\tmemset(ret, 0, sizeof(*ret));\n+\t\tunion any_object *ret = xcalloc(1, sizeof(*ret));\n \t\tcreated_object(sha1, &ret->object);\n \t\tret->object.type = NULL;\n \t\treturn &ret->object;\ndiff --git a/read-tree.c b/read-tree.c\nindex eaff444..58e5636 100644\n--- a/read-tree.c\n+++ b/read-tree.c\n@@ -133,11 +133,9 @@ #endif\n \t\tpathlen = strlen(first);\n \t\tce_size = cache_entry_size(baselen + pathlen);\n \n-\t\tsrc = xmalloc(sizeof(struct cache_entry *) * src_size);\n-\t\tmemset(src, 0, sizeof(struct cache_entry *) * src_size);\n+\t\tsrc = xcalloc(src_size, sizeof(struct cache_entry *));\n \n-\t\tsubposns = xmalloc(sizeof(struct tree_list_entry *) * len);\n-\t\tmemset(subposns, 0, sizeof(struct tree_list_entry *) * len);\n+\t\tsubposns = xcalloc(len, sizeof(struct tree_list_entry *));\n \n \t\tif (cache_name && !strcmp(cache_name, first)) {\n \t\t\tany_files = 1;\n@@ -177,8 +175,7 @@ #endif\n \t\t\telse\n \t\t\t\tce_stage = 2;\n \n-\t\t\tce = xmalloc(ce_size);\n-\t\t\tmemset(ce, 0, ce_size);\n+\t\t\tce = xcalloc(1, ce_size);\n \t\t\tce->ce_mode = create_ce_mode(posns[i]->mode);\n \t\t\tce->ce_flags = create_ce_flags(baselen + pathlen,\n \t\t\t\t\t\t       ce_stage);\ndiff --git a/tag.c b/tag.c\nindex ac0e573..f390ee7 100644\n--- a/tag.c\n+++ b/tag.c\n@@ -19,8 +19,7 @@ struct tag *lookup_tag(const unsigned ch\n {\n         struct object *obj = lookup_object(sha1);\n         if (!obj) {\n-                struct tag *ret = xmalloc(sizeof(struct tag));\n-                memset(ret, 0, sizeof(struct tag));\n+                struct tag *ret = xcalloc(1, sizeof(struct tag));\n                 created_object(sha1, &ret->object);\n                 ret->object.type = tag_type;\n                 return ret;\ndiff --git a/tree.c b/tree.c\nindex 87e0d74..d599fb5 100644\n--- a/tree.c\n+++ b/tree.c\n@@ -18,10 +18,8 @@ static int read_one_entry(unsigned char \n \n \tlen = strlen(pathname);\n \tsize = cache_entry_size(baselen + len);\n-\tce = xmalloc(size);\n+\tce = xcalloc(1, size);\n \n-\tmemset(ce, 0, size);\n-\n \tce->ce_mode = create_ce_mode(mode);\n \tce->ce_flags = create_ce_flags(baselen + len, stage);\n \tmemcpy(ce->name, base, baselen);\n@@ -130,8 +128,7 @@ struct tree *lookup_tree(const unsigned \n {\n \tstruct object *obj = lookup_object(sha1);\n \tif (!obj) {\n-\t\tstruct tree *ret = xmalloc(sizeof(struct tree));\n-\t\tmemset(ret, 0, sizeof(struct tree));\n+\t\tstruct tree *ret = xcalloc(1, sizeof(struct tree));\n \t\tcreated_object(sha1, &ret->object);\n \t\tret->object.type = tree_type;\n \t\treturn ret;\ndiff --git a/update-index.c b/update-index.c\nindex 797245a..1efac27 100644\n--- a/update-index.c\n+++ b/update-index.c\n@@ -114,8 +114,7 @@ static int add_file_to_cache(const char \n \n \tnamelen = strlen(path);\n \tsize = cache_entry_size(namelen);\n-\tce = xmalloc(size);\n-\tmemset(ce, 0, size);\n+\tce = xcalloc(1, size);\n \tmemcpy(ce->name, path, namelen);\n \tce->ce_flags = htons(namelen);\n \tfill_stat_cache_info(ce, &st);\n@@ -312,8 +311,7 @@ static int add_cacheinfo(unsigned int mo\n \n \tlen = strlen(path);\n \tsize = cache_entry_size(len);\n-\tce = xmalloc(size);\n-\tmemset(ce, 0, size);\n+\tce = xcalloc(1, size);\n \n \tmemcpy(ce->sha1, sha1, 20);\n \tmemcpy(ce->name, path, len);\n-- \n1.3.0.rc1.g40e9\n"}]}