aboutsummaryrefslogtreecommitdiff
path: root/sha1_file.c
diff options
context:
space:
mode:
authorPierre Habouzit <madcoder@debian.org>2007-09-16 00:32:36 +0200
committerJunio C Hamano <gitster@pobox.com>2007-09-18 17:42:17 -0700
commit182af8343c307436bb5364309aa6d4d46fa5911d (patch)
tree154c50047e12595027a0d61f54bfdd6ecd2305a5 /sha1_file.c
parent39bd2eb56af89d43a08ba54699d9a1849ab57b39 (diff)
downloadgit-182af8343c307436bb5364309aa6d4d46fa5911d.tar.gz
git-182af8343c307436bb5364309aa6d4d46fa5911d.tar.xz
Use xmemdupz() in many places.
Signed-off-by: Pierre Habouzit <madcoder@debian.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'sha1_file.c')
-rw-r--r--sha1_file.c12
1 files changed, 3 insertions, 9 deletions
diff --git a/sha1_file.c b/sha1_file.c
index 59325d46b..385c5d891 100644
--- a/sha1_file.c
+++ b/sha1_file.c
@@ -1491,11 +1491,8 @@ found_cache_entry:
ent->lru.next->prev = ent->lru.prev;
ent->lru.prev->next = ent->lru.next;
delta_base_cached -= ent->size;
- }
- else {
- ret = xmalloc(ent->size + 1);
- memcpy(ret, ent->data, ent->size);
- ((char *)ret)[ent->size] = 0;
+ } else {
+ ret = xmemdupz(ent->data, ent->size);
}
*type = ent->type;
*base_size = ent->size;
@@ -1872,12 +1869,9 @@ void *read_sha1_file(const unsigned char *sha1, enum object_type *type,
co = find_cached_object(sha1);
if (co) {
- buf = xmalloc(co->size + 1);
- memcpy(buf, co->buf, co->size);
- ((char*)buf)[co->size] = 0;
*type = co->type;
*size = co->size;
- return buf;
+ return xmemdupz(co->buf, co->size);
}
buf = read_packed_sha1(sha1, type, size);