pack: use GIT_ASSERT
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132
diff --git a/src/indexer.c b/src/indexer.c
index b6a2ee4..7b3db31 100644
--- a/src/indexer.c
+++ b/src/indexer.c
@@ -900,8 +900,8 @@ static int inject_object(git_indexer *idx, git_oid *id)
entry->crc = crc32(0L, Z_NULL, 0);
/* Write out the object header */
- hdr_len = git_packfile__object_header(hdr, len, git_odb_object_type(obj));
- if ((error = append_to_pack(idx, hdr, hdr_len)) < 0)
+ if ((error = git_packfile__object_header(&hdr_len, hdr, len, git_odb_object_type(obj))) < 0 ||
+ (error = append_to_pack(idx, hdr, hdr_len)) < 0)
goto cleanup;
idx->pack->mwf.size += hdr_len;
diff --git a/src/pack-objects.c b/src/pack-objects.c
index 9679e8e..abc636b 100644
--- a/src/pack-objects.c
+++ b/src/pack-objects.c
@@ -347,10 +347,9 @@ static int write_object(
}
/* Write header */
- hdr_len = git_packfile__object_header(hdr, data_len, type);
-
- if ((error = write_cb(hdr, hdr_len, cb_data)) < 0 ||
- (error = git_hash_update(&pb->ctx, hdr, hdr_len)) < 0)
+ if ((error = git_packfile__object_header(&hdr_len, hdr, data_len, type)) < 0 ||
+ (error = write_cb(hdr, hdr_len, cb_data)) < 0 ||
+ (error = git_hash_update(&pb->ctx, hdr, hdr_len)) < 0)
goto done;
if (type == GIT_OBJECT_REF_DELTA) {
diff --git a/src/pack.c b/src/pack.c
index 1b5cf67..982ad17 100644
--- a/src/pack.c
+++ b/src/pack.c
@@ -67,7 +67,6 @@ static void free_cache_object(void *o)
git_pack_cache_entry *e = (git_pack_cache_entry *)o;
if (e != NULL) {
- assert(e->refcount.val == 0);
git__free(e->raw.data);
git__free(e);
}
@@ -311,8 +310,9 @@ static int pack_index_open(struct git_pack_file *p)
if (p->index_version > -1)
return 0;
+ /* checked by git_pack_file alloc */
name_len = strlen(p->pack_name);
- assert(name_len > strlen(".pack")); /* checked by git_pack_file alloc */
+ GIT_ASSERT(name_len > strlen(".pack"));
if (git_buf_init(&idx_name, name_len) < 0)
return -1;
@@ -372,12 +372,12 @@ static unsigned char *pack_window_open(
* - each byte afterwards: low seven bits are size continuation,
* with the high bit being "size continues"
*/
-size_t git_packfile__object_header(unsigned char *hdr, size_t size, git_object_t type)
+int git_packfile__object_header(size_t *out, unsigned char *hdr, size_t size, git_object_t type)
{
unsigned char *hdr_base;
unsigned char c;
- assert(type >= GIT_OBJECT_COMMIT && type <= GIT_OBJECT_REF_DELTA);
+ GIT_ASSERT_ARG(type >= GIT_OBJECT_COMMIT && type <= GIT_OBJECT_REF_DELTA);
/* TODO: add support for chunked objects; see git.git 6c0d19b1 */
@@ -392,7 +392,8 @@ size_t git_packfile__object_header(unsigned char *hdr, size_t size, git_object_t
}
*hdr++ = c;
- return (hdr - hdr_base);
+ *out = (hdr - hdr_base);
+ return 0;
}
@@ -899,7 +900,7 @@ int get_delta_base(
off64_t base_offset;
git_oid unused;
- assert(delta_base_out);
+ GIT_ASSERT_ARG(delta_base_out);
base_info = pack_window_open(p, w_curs, *curpos, &left);
/* Assumption: the only reason this would fail is because the file is too small */
@@ -1211,8 +1212,7 @@ int git_pack_foreach_entry(
if ((error = pack_index_open(p)) < 0)
return error;
- assert(p->index_map.data);
-
+ GIT_ASSERT(p->index_map.data);
index = p->index_map.data;
}
@@ -1299,7 +1299,8 @@ static int pack_entry_find_offset(
if ((error = pack_index_open(p)) < 0)
return error;
- assert(p->index_map.data);
+
+ GIT_ASSERT(p->index_map.data);
}
index = p->index_map.data;
@@ -1388,7 +1389,7 @@ int git_pack_entry_find(
git_oid found_oid;
int error;
- assert(p);
+ GIT_ASSERT_ARG(p);
if (len == GIT_OID_HEXSZ && p->num_bad_objects) {
unsigned i;
diff --git a/src/pack.h b/src/pack.h
index cebfcd1..544a5d2 100644
--- a/src/pack.h
+++ b/src/pack.h
@@ -133,7 +133,7 @@ typedef struct git_packfile_stream {
git_mwindow *mw;
} git_packfile_stream;
-size_t git_packfile__object_header(unsigned char *hdr, size_t size, git_object_t type);
+int git_packfile__object_header(size_t *out, unsigned char *hdr, size_t size, git_object_t type);
int git_packfile__name(char **out, const char *path);