odb: 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 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202
diff --git a/src/odb.c b/src/odb.c
index 129a632..1e608f5 100644
--- a/src/odb.c
+++ b/src/odb.c
@@ -114,7 +114,8 @@ int git_odb__hashobj(git_oid *id, git_rawobj *obj)
size_t hdrlen;
int error;
- assert(id && obj);
+ GIT_ASSERT_ARG(id);
+ GIT_ASSERT_ARG(obj);
if (!git_object_typeisloose(obj->type)) {
git_error_set(GIT_ERROR_INVALID, "invalid object type");
@@ -346,7 +347,7 @@ int git_odb_hash(git_oid *id, const void *data, size_t len, git_object_t type)
{
git_rawobj raw;
- assert(id);
+ GIT_ASSERT_ARG(id);
raw.data = (void *)data;
raw.len = len;
@@ -376,7 +377,7 @@ static int fake_wstream__write(git_odb_stream *_stream, const char *data, size_t
{
fake_wstream *stream = (fake_wstream *)_stream;
- assert(stream->written + len <= stream->size);
+ GIT_ASSERT(stream->written + len <= stream->size);
memcpy(stream->buffer + stream->written, data, len);
stream->written += len;
@@ -470,12 +471,13 @@ static int add_backend_internal(
{
backend_internal *internal;
- assert(odb && backend);
+ GIT_ASSERT_ARG(odb);
+ GIT_ASSERT_ARG(backend);
GIT_ERROR_CHECK_VERSION(backend, GIT_ODB_BACKEND_VERSION, "git_odb_backend");
/* Check if the backend is already owned by another ODB */
- assert(!backend->odb || backend->odb == odb);
+ GIT_ASSERT(!backend->odb || backend->odb == odb);
internal = git__malloc(sizeof(backend_internal));
GIT_ERROR_CHECK_ALLOC(internal);
@@ -507,7 +509,7 @@ int git_odb_add_alternate(git_odb *odb, git_odb_backend *backend, int priority)
size_t git_odb_num_backends(git_odb *odb)
{
- assert(odb);
+ GIT_ASSERT_ARG(odb);
return odb->backends.length;
}
@@ -523,7 +525,9 @@ int git_odb_get_backend(git_odb_backend **out, git_odb *odb, size_t pos)
{
backend_internal *internal;
- assert(out && odb);
+ GIT_ASSERT_ARG(out);
+ GIT_ASSERT_ARG(odb);
+
internal = git_vector_get(&odb->backends, pos);
if (internal && internal->backend) {
@@ -645,7 +649,8 @@ int git_odb_open(git_odb **out, const char *objects_dir)
{
git_odb *db;
- assert(out && objects_dir);
+ GIT_ASSERT_ARG(out);
+ GIT_ASSERT_ARG(objects_dir);
*out = NULL;
@@ -755,7 +760,8 @@ static int odb_freshen_1(
int git_odb__freshen(git_odb *db, const git_oid *id)
{
- assert(db && id);
+ GIT_ASSERT_ARG(db);
+ GIT_ASSERT_ARG(id);
if (odb_freshen_1(db, id, false))
return 1;
@@ -771,7 +777,8 @@ int git_odb_exists(git_odb *db, const git_oid *id)
{
git_odb_object *object;
- assert(db && id);
+ GIT_ASSERT_ARG(db);
+ GIT_ASSERT_ARG(id);
if (git_oid_is_zero(id))
return 0;
@@ -839,7 +846,8 @@ int git_odb_exists_prefix(
int error;
git_oid key = {{0}};
- assert(db && short_id);
+ GIT_ASSERT_ARG(db);
+ GIT_ASSERT_ARG(short_id);
if (len < GIT_OID_MINPREFIXLEN)
return git_odb__error_ambiguous("prefix length too short");
@@ -875,7 +883,8 @@ int git_odb_expand_ids(
{
size_t i;
- assert(db && ids);
+ GIT_ASSERT_ARG(db);
+ GIT_ASSERT_ARG(ids);
for (i = 0; i < count; i++) {
git_odb_expand_id *query = &ids[i];
@@ -997,7 +1006,11 @@ int git_odb__read_header_or_object(
int error = GIT_ENOTFOUND;
git_odb_object *object;
- assert(db && id && out && len_p && type_p);
+ GIT_ASSERT_ARG(db);
+ GIT_ASSERT_ARG(id);
+ GIT_ASSERT_ARG(out);
+ GIT_ASSERT_ARG(len_p);
+ GIT_ASSERT_ARG(type_p);
*out = NULL;
@@ -1104,7 +1117,9 @@ int git_odb_read(git_odb_object **out, git_odb *db, const git_oid *id)
{
int error;
- assert(out && db && id);
+ GIT_ASSERT_ARG(out);
+ GIT_ASSERT_ARG(db);
+ GIT_ASSERT_ARG(id);
if (git_oid_is_zero(id))
return error_null_oid(GIT_ENOTFOUND, "cannot read object");
@@ -1237,7 +1252,8 @@ int git_odb_read_prefix(
git_oid key = {{0}};
int error;
- assert(out && db);
+ GIT_ASSERT_ARG(out);
+ GIT_ASSERT_ARG(db);
if (len < GIT_OID_MINPREFIXLEN)
return git_odb__error_ambiguous("prefix length too short");
@@ -1286,7 +1302,8 @@ int git_odb_write(
int error;
git_odb_stream *stream;
- assert(oid && db);
+ GIT_ASSERT_ARG(oid);
+ GIT_ASSERT_ARG(db);
if ((error = git_odb_hash(oid, data, len, type)) < 0)
return error;
@@ -1346,7 +1363,8 @@ int git_odb_open_wstream(
int error = GIT_ERROR;
git_hash_ctx *ctx = NULL;
- assert(stream && db);
+ GIT_ASSERT_ARG(stream);
+ GIT_ASSERT_ARG(db);
for (i = 0; i < db->backends.length && error < 0; ++i) {
backend_internal *internal = git_vector_get(&db->backends, i);
@@ -1456,7 +1474,8 @@ int git_odb_open_rstream(
size_t i, reads = 0;
int error = GIT_ERROR;
- assert(stream && db);
+ GIT_ASSERT_ARG(stream);
+ GIT_ASSERT_ARG(db);
for (i = 0; i < db->backends.length && error < 0; ++i) {
backend_internal *internal = git_vector_get(&db->backends, i);
@@ -1481,7 +1500,8 @@ int git_odb_write_pack(struct git_odb_writepack **out, git_odb *db, git_indexer_
size_t i, writes = 0;
int error = GIT_ERROR;
- assert(out && db);
+ GIT_ASSERT_ARG(out);
+ GIT_ASSERT_ARG(db);
for (i = 0; i < db->backends.length && error < 0; ++i) {
backend_internal *internal = git_vector_get(&db->backends, i);
@@ -1527,7 +1547,8 @@ void git_odb_backend_data_free(git_odb_backend *backend, void *data)
int git_odb_refresh(struct git_odb *db)
{
size_t i;
- assert(db);
+
+ GIT_ASSERT_ARG(db);
for (i = 0; i < db->backends.length; ++i) {
backend_internal *internal = git_vector_get(&db->backends, i);