diff: 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 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342
diff --git a/src/diff.c b/src/diff.c
index 3e52e3f..4085c5f 100644
--- a/src/diff.c
+++ b/src/diff.c
@@ -77,7 +77,7 @@ void git_diff_addref(git_diff *diff)
size_t git_diff_num_deltas(const git_diff *diff)
{
- assert(diff);
+ GIT_ASSERT_ARG(diff);
return diff->deltas.length;
}
@@ -86,7 +86,7 @@ size_t git_diff_num_deltas_of_type(const git_diff *diff, git_delta_t type)
size_t i, count = 0;
const git_diff_delta *delta;
- assert(diff);
+ GIT_ASSERT_ARG(diff);
git_vector_foreach(&diff->deltas, i, delta) {
count += (delta->status == type);
@@ -97,7 +97,7 @@ size_t git_diff_num_deltas_of_type(const git_diff *diff, git_delta_t type)
const git_diff_delta *git_diff_get_delta(const git_diff *diff, size_t idx)
{
- assert(diff);
+ GIT_ASSERT_ARG_WITH_RETVAL(diff, NULL);
return git_vector_get(&diff->deltas, idx);
}
@@ -108,7 +108,7 @@ int git_diff_is_sorted_icase(const git_diff *diff)
int git_diff_get_perfdata(git_diff_perfdata *out, const git_diff *diff)
{
- assert(out);
+ GIT_ASSERT_ARG(out);
GIT_ERROR_CHECK_VERSION(out, GIT_DIFF_PERFDATA_VERSION, "git_diff_perfdata");
out->stat_calls = diff->perf.stat_calls;
out->oid_calculations = diff->perf.oid_calculations;
@@ -127,7 +127,7 @@ int git_diff_foreach(
git_diff_delta *delta;
size_t idx;
- assert(diff);
+ GIT_ASSERT_ARG(diff);
git_vector_foreach(&diff->deltas, idx, delta) {
git_patch *patch;
@@ -243,8 +243,9 @@ int git_diff_format_email(
size_t allocsize;
int error;
- assert(out && diff && opts);
- assert(opts->summary && opts->id && opts->author);
+ GIT_ASSERT_ARG(out);
+ GIT_ASSERT_ARG(diff);
+ GIT_ASSERT_ARG(opts && opts->summary && opts->id && opts->author);
GIT_ERROR_CHECK_VERSION(opts,
GIT_DIFF_FORMAT_EMAIL_OPTIONS_VERSION,
@@ -326,7 +327,9 @@ int git_diff_commit_as_email(
GIT_DIFF_FORMAT_EMAIL_OPTIONS_INIT;
int error;
- assert (out && repo && commit);
+ GIT_ASSERT_ARG(out);
+ GIT_ASSERT_ARG(repo);
+ GIT_ASSERT_ARG(commit);
opts.flags = flags;
opts.patch_no = patch_no;
diff --git a/src/diff_driver.c b/src/diff_driver.c
index 831d326..606c391 100644
--- a/src/diff_driver.c
+++ b/src/diff_driver.c
@@ -358,7 +358,7 @@ int git_diff_driver_lookup(
int error = 0;
const char *values[1], *attrs[] = { "diff" };
- assert(out);
+ GIT_ASSERT_ARG(out);
*out = NULL;
if (!repo || !path || !strlen(path))
diff --git a/src/diff_generate.c b/src/diff_generate.c
index e7bfd62..f021a26 100644
--- a/src/diff_generate.c
+++ b/src/diff_generate.c
@@ -128,7 +128,7 @@ static int diff_delta__from_one(
git_diff_delta *delta;
const char *matched_pathspec;
- assert((oitem != NULL) ^ (nitem != NULL));
+ GIT_ASSERT_ARG((oitem != NULL) ^ (nitem != NULL));
if (oitem) {
entry = oitem;
@@ -160,7 +160,7 @@ static int diff_delta__from_one(
GIT_ERROR_CHECK_ALLOC(delta);
/* This fn is just for single-sided diffs */
- assert(status != GIT_DELTA_MODIFIED);
+ GIT_ASSERT(status != GIT_DELTA_MODIFIED);
delta->nfiles = 1;
if (has_old) {
@@ -408,7 +408,9 @@ static git_diff_generated *diff_generated_alloc(
git_diff_generated *diff;
git_diff_options dflt = GIT_DIFF_OPTIONS_INIT;
- assert(repo && old_iter && new_iter);
+ GIT_ASSERT_ARG_WITH_RETVAL(repo, NULL);
+ GIT_ASSERT_ARG_WITH_RETVAL(old_iter, NULL);
+ GIT_ASSERT_ARG_WITH_RETVAL(new_iter, NULL);
if ((diff = git__calloc(1, sizeof(git_diff_generated))) == NULL)
return NULL;
@@ -589,7 +591,7 @@ int git_diff__oid_for_entry(
git_filter_list *fl = NULL;
int error = 0;
- assert(d->type == GIT_DIFF_TYPE_GENERATED);
+ GIT_ASSERT(d->type == GIT_DIFF_TYPE_GENERATED);
diff = (git_diff_generated *)d;
memset(out, 0, sizeof(*out));
@@ -1302,7 +1304,8 @@ int git_diff_tree_to_tree(
char *prefix = NULL;
int error = 0;
- assert(out && repo);
+ GIT_ASSERT_ARG(out);
+ GIT_ASSERT_ARG(repo);
*out = NULL;
@@ -1358,7 +1361,8 @@ int git_diff_tree_to_index(
bool index_ignore_case = false;
int error = 0;
- assert(out && repo);
+ GIT_ASSERT_ARG(out);
+ GIT_ASSERT_ARG(repo);
*out = NULL;
@@ -1401,7 +1405,8 @@ int git_diff_index_to_workdir(
char *prefix = NULL;
int error = 0;
- assert(out && repo);
+ GIT_ASSERT_ARG(out);
+ GIT_ASSERT_ARG(repo);
*out = NULL;
@@ -1444,7 +1449,8 @@ int git_diff_tree_to_workdir(
git_index *index;
int error;
- assert(out && repo);
+ GIT_ASSERT_ARG(out);
+ GIT_ASSERT_ARG(repo);
*out = NULL;
@@ -1477,7 +1483,8 @@ int git_diff_tree_to_workdir_with_index(
git_index *index = NULL;
int error = 0;
- assert(out && repo);
+ GIT_ASSERT_ARG(out);
+ GIT_ASSERT_ARG(repo);
*out = NULL;
@@ -1513,7 +1520,9 @@ int git_diff_index_to_index(
char *prefix = NULL;
int error;
- assert(out && old_index && new_index);
+ GIT_ASSERT_ARG(out);
+ GIT_ASSERT_ARG(old_index);
+ GIT_ASSERT_ARG(new_index);
*out = NULL;
diff --git a/src/diff_print.c b/src/diff_print.c
index 0e93fe8..062e267 100644
--- a/src/diff_print.c
+++ b/src/diff_print.c
@@ -95,7 +95,7 @@ static int diff_print_info_init_frompatch(
git_diff_line_cb cb,
void *payload)
{
- assert(patch);
+ GIT_ASSERT_ARG(patch);
memset(pi, 0, sizeof(diff_print_info));
@@ -766,7 +766,9 @@ int git_diff_to_buf(git_buf *out, git_diff *diff, git_diff_format_t format)
{
int error;
- assert(out && diff);
+ GIT_ASSERT_ARG(out);
+ GIT_ASSERT_ARG(diff);
+
if ((error = git_buf_sanitize(out)) < 0)
return error;
@@ -783,7 +785,8 @@ int git_patch_print(
diff_print_info pi;
int error;
- assert(patch && print_cb);
+ GIT_ASSERT_ARG(patch);
+ GIT_ASSERT_ARG(print_cb);
if ((error = diff_print_info_init_frompatch(&pi, &temp, patch,
GIT_DIFF_FORMAT_PATCH, print_cb, payload)) < 0)
@@ -805,7 +808,8 @@ int git_patch_to_buf(git_buf *out, git_patch *patch)
{
int error;
- assert(out && patch);
+ GIT_ASSERT_ARG(out);
+ GIT_ASSERT_ARG(patch);
if ((error = git_buf_sanitize(out)) < 0)
return error;
diff --git a/src/diff_stats.c b/src/diff_stats.c
index f5fda79..41a25bf 100644
--- a/src/diff_stats.c
+++ b/src/diff_stats.c
@@ -183,7 +183,8 @@ int git_diff_get_stats(
git_diff_stats *stats = NULL;
int error = 0;
- assert(out && diff);
+ GIT_ASSERT_ARG(out);
+ GIT_ASSERT_ARG(diff);
stats = git__calloc(1, sizeof(git_diff_stats));
GIT_ERROR_CHECK_ALLOC(stats);
@@ -251,7 +252,7 @@ int git_diff_get_stats(
size_t git_diff_stats_files_changed(
const git_diff_stats *stats)
{
- assert(stats);
+ GIT_ASSERT_ARG(stats);
return stats->files_changed;
}
@@ -259,7 +260,7 @@ size_t git_diff_stats_files_changed(
size_t git_diff_stats_insertions(
const git_diff_stats *stats)
{
- assert(stats);
+ GIT_ASSERT_ARG(stats);
return stats->insertions;
}
@@ -267,7 +268,7 @@ size_t git_diff_stats_insertions(
size_t git_diff_stats_deletions(
const git_diff_stats *stats)
{
- assert(stats);
+ GIT_ASSERT_ARG(stats);
return stats->deletions;
}
@@ -282,7 +283,8 @@ int git_diff_stats_to_buf(
size_t i;
const git_diff_delta *delta;
- assert(out && stats);
+ GIT_ASSERT_ARG(out);
+ GIT_ASSERT_ARG(stats);
if (format & GIT_DIFF_STATS_NUMBER) {
for (i = 0; i < stats->files_changed; ++i) {
diff --git a/src/diff_tform.c b/src/diff_tform.c
index 7de88bd..03fc2b0 100644
--- a/src/diff_tform.c
+++ b/src/diff_tform.c
@@ -87,7 +87,7 @@ git_diff_delta *git_diff__merge_like_cgit(
a->status == GIT_DELTA_UNREADABLE)
return dup;
- assert(b->status != GIT_DELTA_UNMODIFIED);
+ GIT_ASSERT_WITH_RETVAL(b->status != GIT_DELTA_UNMODIFIED, NULL);
/* A cgit exception is that the diff of a file that is only in the
* index (i.e. not in HEAD nor workdir) is given as empty.
@@ -121,7 +121,8 @@ int git_diff__merge(
bool ignore_case, reversed;
unsigned int i, j;
- assert(onto && from);
+ GIT_ASSERT_ARG(onto);
+ GIT_ASSERT_ARG(from);
if (!from->deltas.length)
return 0;
@@ -815,7 +816,7 @@ int git_diff_find_similar(
diff_find_match *best_match;
git_diff_file swap;
- assert(diff);
+ GIT_ASSERT_ARG(diff);
if ((error = normalize_find_opts(diff, &opts, given_opts)) < 0)
return error;
@@ -978,7 +979,7 @@ find_best_matches:
src->flags |= GIT_DIFF_FLAG__TO_DELETE;
num_rewrites++;
} else {
- assert(delta_is_split(tgt));
+ GIT_ASSERT(delta_is_split(tgt));
if (best_match->similarity < opts.rename_from_rewrite_threshold)
continue;
@@ -988,7 +989,7 @@ find_best_matches:
delta_make_rename(tgt, src, best_match->similarity);
num_rewrites--;
- assert(src->status == GIT_DELTA_DELETED);
+ GIT_ASSERT(src->status == GIT_DELTA_DELETED);
memcpy(&src->old_file, &swap, sizeof(src->old_file));
memset(&src->new_file, 0, sizeof(src->new_file));
src->new_file.path = src->old_file.path;
@@ -1024,7 +1025,7 @@ find_best_matches:
num_updates++;
} else {
- assert(delta_is_split(src));
+ GIT_ASSERT(delta_is_split(src));
if (best_match->similarity < opts.rename_from_rewrite_threshold)
continue;