summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 276328f)
raw | patch | inline | side by side (parent: 276328f)
author | Brandon Casey <casey@nrlssc.navy.mil> | |
Mon, 6 Oct 2008 23:39:10 +0000 (18:39 -0500) | ||
committer | Shawn O. Pearce <spearce@spearce.org> | |
Wed, 8 Oct 2008 14:30:59 +0000 (07:30 -0700) |
Many call sites immediately initialize allocated memory with zero after
calling xmalloc. A single call to xcalloc can replace this two-call
sequence.
Signed-off-by: Brandon Casey <casey@nrlssc.navy.mil>
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
calling xmalloc. A single call to xcalloc can replace this two-call
sequence.
Signed-off-by: Brandon Casey <casey@nrlssc.navy.mil>
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
diff --git a/builtin-merge.c b/builtin-merge.c
index 5c65a5869900ad1a1014fb3aad88c874a5410bf7..dcf898778202c3e4cfb249c1013a2bb59d8f7645 100644 (file)
--- a/builtin-merge.c
+++ b/builtin-merge.c
exit(1);
}
- ret = xmalloc(sizeof(struct strategy));
- memset(ret, 0, sizeof(struct strategy));
+ ret = xcalloc(1, sizeof(struct strategy));
ret->name = xstrdup(name);
return ret;
}
diff --git a/builtin-pack-objects.c b/builtin-pack-objects.c
index 1158e42cba81e2bdb8640cd6c5a3835453d17e7f..59c30d1caa37416041177ff4aaf01b67f4e8add4 100644 (file)
--- a/builtin-pack-objects.c
+++ b/builtin-pack-objects.c
int window, int depth, unsigned *processed)
{
uint32_t i, idx = 0, count = 0;
- unsigned int array_size = window * sizeof(struct unpacked);
struct unpacked *array;
unsigned long mem_usage = 0;
- array = xmalloc(array_size);
- memset(array, 0, array_size);
+ array = xcalloc(window, sizeof(struct unpacked));
for (;;) {
struct object_entry *entry = *list++;
index d2796b6309d3b13a6c401b502aafd53d684328d8..9f4bdd3296d19b75211ca0f2434d227eafac44b6 100644 (file)
--- a/builtin-unpack-objects.c
+++ b/builtin-unpack-objects.c
if (!quiet)
progress = start_progress("Unpacking objects", nr_objects);
- obj_list = xmalloc(nr_objects * sizeof(*obj_list));
- memset(obj_list, 0, nr_objects * sizeof(*obj_list));
+ obj_list = xcalloc(nr_objects, sizeof(*obj_list));
for (i = 0; i < nr_objects; i++) {
unpack_one(i);
display_progress(progress, i + 1);
diff --git a/merge-tree.c b/merge-tree.c
index 02fc10f7e622ba1c53065e7cf4563ff10af0c41f..2d1413efbbc33c51fd4820933dcb54164e12d706 100644 (file)
--- a/merge-tree.c
+++ b/merge-tree.c
static struct merge_list *create_entry(unsigned stage, unsigned mode, const unsigned char *sha1, const char *path)
{
- struct merge_list *res = xmalloc(sizeof(*res));
+ struct merge_list *res = xcalloc(1, sizeof(*res));
- memset(res, 0, sizeof(*res));
res->stage = stage;
res->path = path;
res->mode = mode;
diff --git a/remote.c b/remote.c
index c45d96e98fffe3411284144b6d836cf499d42ba4..a2d7ab146ed6627cae5c845ef4801963635bf395 100644 (file)
--- a/remote.c
+++ b/remote.c
struct ref *alloc_ref(unsigned namelen)
{
- struct ref *ret = xmalloc(sizeof(struct ref) + namelen);
- memset(ret, 0, sizeof(struct ref) + namelen);
+ struct ref *ret = xcalloc(1, sizeof(struct ref) + namelen);
return ret;
}