summaryrefslogtreecommitdiff
path: root/builtin
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2014-07-21 19:35:39 (GMT)
committerJunio C Hamano <gitster@pobox.com>2014-07-21 19:35:39 (GMT)
commit9ab08822556c49a7856dadd0e9a42f9ec2aaf850 (patch)
treef52f20367d13f2078fe6199e230322c899b9308d /builtin
parent0eff86e4f440fedf26f02f4c3b1a3ead8bfbe6f8 (diff)
parent5c0b13f85ab3a5326508b854768eb70c8829cda4 (diff)
downloadgit-9ab08822556c49a7856dadd0e9a42f9ec2aaf850.zip
git-9ab08822556c49a7856dadd0e9a42f9ec2aaf850.tar.gz
git-9ab08822556c49a7856dadd0e9a42f9ec2aaf850.tar.bz2
Merge branch 'maint'
* maint: use xmemdupz() to allocate copies of strings given by start and length use xcalloc() to allocate zero-initialized memory
Diffstat (limited to 'builtin')
-rw-r--r--builtin/apply.c4
-rw-r--r--builtin/blame.c5
-rw-r--r--builtin/clean.c3
-rw-r--r--builtin/index-pack.c3
4 files changed, 4 insertions, 11 deletions
diff --git a/builtin/apply.c b/builtin/apply.c
index 5fd099e..9f8f5ba 100644
--- a/builtin/apply.c
+++ b/builtin/apply.c
@@ -2867,9 +2867,7 @@ static int apply_binary_fragment(struct image *img, struct patch *patch)
case BINARY_LITERAL_DEFLATED:
clear_image(img);
img->len = fragment->size;
- img->buf = xmalloc(img->len+1);
- memcpy(img->buf, fragment->patch, img->len);
- img->buf[img->len] = '\0';
+ img->buf = xmemdupz(fragment->patch, img->len);
return 0;
}
return -1;
diff --git a/builtin/blame.c b/builtin/blame.c
index c59e702..32ce05f 100644
--- a/builtin/blame.c
+++ b/builtin/blame.c
@@ -2707,11 +2707,8 @@ parse_done:
die("revision walk setup failed");
if (is_null_sha1(sb.final->object.sha1)) {
- char *buf;
o = sb.final->util;
- buf = xmalloc(o->file.size + 1);
- memcpy(buf, o->file.ptr, o->file.size + 1);
- sb.final_buf = buf;
+ sb.final_buf = xmemdupz(o->file.ptr, o->file.size);
sb.final_buf_size = o->file.size;
}
else {
diff --git a/builtin/clean.c b/builtin/clean.c
index 27701d2..1032563 100644
--- a/builtin/clean.c
+++ b/builtin/clean.c
@@ -621,8 +621,7 @@ static int *list_and_choose(struct menu_opts *opts, struct menu_stuff *stuff)
nr += chosen[i];
}
- result = xmalloc(sizeof(int) * (nr + 1));
- memset(result, 0, sizeof(int) * (nr + 1));
+ result = xcalloc(nr + 1, sizeof(int));
for (i = 0; i < stuff->nr && j < nr; i++) {
if (chosen[i])
result[j++] = i;
diff --git a/builtin/index-pack.c b/builtin/index-pack.c
index fc40411..5568a5b 100644
--- a/builtin/index-pack.c
+++ b/builtin/index-pack.c
@@ -362,8 +362,7 @@ static void set_thread_data(struct thread_local *data)
static struct base_data *alloc_base_data(void)
{
- struct base_data *base = xmalloc(sizeof(struct base_data));
- memset(base, 0, sizeof(*base));
+ struct base_data *base = xcalloc(1, sizeof(struct base_data));
base->ref_last = -1;
base->ofs_last = -1;
return base;