Commit 419ffdde by Edward Thomson

packbuilder: don't try to malloc(0)

parent 48e6b02b
...@@ -517,13 +517,18 @@ static int cb_tag_foreach(const char *name, git_oid *oid, void *data) ...@@ -517,13 +517,18 @@ static int cb_tag_foreach(const char *name, git_oid *oid, void *data)
return 0; return 0;
} }
static git_pobject **compute_write_order(git_packbuilder *pb) static int compute_write_order(git_pobject ***out, git_packbuilder *pb)
{ {
size_t i, wo_end, last_untagged; size_t i, wo_end, last_untagged;
git_pobject **wo; git_pobject **wo;
*out = NULL;
if (!pb->nr_objects)
return 0;
if ((wo = git__mallocarray(pb->nr_objects, sizeof(*wo))) == NULL) if ((wo = git__mallocarray(pb->nr_objects, sizeof(*wo))) == NULL)
return NULL; return -1;
for (i = 0; i < pb->nr_objects; i++) { for (i = 0; i < pb->nr_objects; i++) {
git_pobject *po = pb->object_list + i; git_pobject *po = pb->object_list + i;
...@@ -552,7 +557,7 @@ static git_pobject **compute_write_order(git_packbuilder *pb) ...@@ -552,7 +557,7 @@ static git_pobject **compute_write_order(git_packbuilder *pb)
*/ */
if (git_tag_foreach(pb->repo, &cb_tag_foreach, pb) < 0) { if (git_tag_foreach(pb->repo, &cb_tag_foreach, pb) < 0) {
git__free(wo); git__free(wo);
return NULL; return -1;
} }
/* /*
...@@ -609,10 +614,11 @@ static git_pobject **compute_write_order(git_packbuilder *pb) ...@@ -609,10 +614,11 @@ static git_pobject **compute_write_order(git_packbuilder *pb)
if (wo_end != pb->nr_objects) { if (wo_end != pb->nr_objects) {
git__free(wo); git__free(wo);
git_error_set(GIT_ERROR_INVALID, "invalid write order"); git_error_set(GIT_ERROR_INVALID, "invalid write order");
return NULL; return -1;
} }
return wo; *out = wo;
return 0;
} }
static int write_pack(git_packbuilder *pb, static int write_pack(git_packbuilder *pb,
...@@ -625,15 +631,15 @@ static int write_pack(git_packbuilder *pb, ...@@ -625,15 +631,15 @@ static int write_pack(git_packbuilder *pb,
struct git_pack_header ph; struct git_pack_header ph;
git_oid entry_oid; git_oid entry_oid;
size_t i = 0; size_t i = 0;
int error = 0; int error;
write_order = compute_write_order(pb); if ((error = compute_write_order(&write_order, pb)) < 0)
if (write_order == NULL) return error;
return -1;
if (!git__is_uint32(pb->nr_objects)) { if (!git__is_uint32(pb->nr_objects)) {
git_error_set(GIT_ERROR_INVALID, "too many objects"); git_error_set(GIT_ERROR_INVALID, "too many objects");
return -1; error = -1;
goto done;
} }
/* Write pack header */ /* Write pack header */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment