Skip to content

Commit 16b1a75

Browse files
committed
path: use GIT_ASSERT
1 parent 2cfa31c commit 16b1a75

File tree

1 file changed

+43
-24
lines changed

1 file changed

+43
-24
lines changed

src/path.c

Lines changed: 43 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,9 @@ int git_path_root(const char *path)
307307
static void path_trim_slashes(git_buf *path)
308308
{
309309
int ceiling = git_path_root(path->ptr) + 1;
310-
assert(ceiling >= 0);
310+
311+
if (ceiling < 0)
312+
return;
311313

312314
while (path->size > (size_t)ceiling) {
313315
if (path->ptr[path->size-1] != '/')
@@ -323,7 +325,8 @@ int git_path_join_unrooted(
323325
{
324326
ssize_t root;
325327

326-
assert(path && path_out);
328+
GIT_ASSERT_ARG(path_out);
329+
GIT_ASSERT_ARG(path);
327330

328331
root = (ssize_t)git_path_root(path);
329332

@@ -371,7 +374,8 @@ int git_path_prettify(git_buf *path_out, const char *path, const char *base)
371374
{
372375
char buf[GIT_PATH_MAX];
373376

374-
assert(path && path_out);
377+
GIT_ASSERT_ARG(path_out);
378+
GIT_ASSERT_ARG(path);
375379

376380
/* construct path if needed */
377381
if (base != NULL && git_path_root(path) < 0) {
@@ -422,7 +426,9 @@ void git_path_string_to_dir(char* path, size_t size)
422426
int git__percent_decode(git_buf *decoded_out, const char *input)
423427
{
424428
int len, hi, lo, i;
425-
assert(decoded_out && input);
429+
430+
GIT_ASSERT_ARG(decoded_out);
431+
GIT_ASSERT_ARG(input);
426432

427433
len = (int)strlen(input);
428434
git_buf_clear(decoded_out);
@@ -483,7 +489,8 @@ int git_path_fromurl(git_buf *local_path_out, const char *file_url)
483489
{
484490
int offset;
485491

486-
assert(local_path_out && file_url);
492+
GIT_ASSERT_ARG(local_path_out);
493+
GIT_ASSERT_ARG(file_url);
487494

488495
if ((offset = local_file_url_prefixlen(file_url)) < 0 ||
489496
file_url[offset] == '\0' || file_url[offset] == '/')
@@ -508,7 +515,8 @@ int git_path_walk_up(
508515
ssize_t stop = 0, scan;
509516
char oldc = '\0';
510517

511-
assert(path && cb);
518+
GIT_ASSERT_ARG(path);
519+
GIT_ASSERT_ARG(cb);
512520

513521
if (ceiling != NULL) {
514522
if (git__prefixcmp(path->ptr, ceiling) == 0)
@@ -563,7 +571,7 @@ int git_path_walk_up(
563571

564572
bool git_path_exists(const char *path)
565573
{
566-
assert(path);
574+
GIT_ASSERT_ARG_WITH_RETVAL(path, false);
567575
return p_access(path, F_OK) == 0;
568576
}
569577

@@ -580,7 +588,7 @@ bool git_path_isfile(const char *path)
580588
{
581589
struct stat st;
582590

583-
assert(path);
591+
GIT_ASSERT_ARG_WITH_RETVAL(path, false);
584592
if (p_stat(path, &st) < 0)
585593
return false;
586594

@@ -591,7 +599,7 @@ bool git_path_islink(const char *path)
591599
{
592600
struct stat st;
593601

594-
assert(path);
602+
GIT_ASSERT_ARG_WITH_RETVAL(path, false);
595603
if (p_lstat(path, &st) < 0)
596604
return false;
597605

@@ -1193,7 +1201,8 @@ int git_path_diriter_init(
11931201
if (is_win7_or_later < 0)
11941202
is_win7_or_later = git_has_win32_version(6, 1, 0);
11951203

1196-
assert(diriter && path);
1204+
GIT_ASSERT_ARG(diriter);
1205+
GIT_ASSERT_ARG(path);
11971206

11981207
memset(diriter, 0, sizeof(git_path_diriter));
11991208
diriter->handle = INVALID_HANDLE_VALUE;
@@ -1293,9 +1302,10 @@ int git_path_diriter_filename(
12931302
size_t *out_len,
12941303
git_path_diriter *diriter)
12951304
{
1296-
assert(out && out_len && diriter);
1297-
1298-
assert(diriter->path_utf8.size > diriter->parent_utf8_len);
1305+
GIT_ASSERT_ARG(out);
1306+
GIT_ASSERT_ARG(out_len);
1307+
GIT_ASSERT_ARG(diriter);
1308+
GIT_ASSERT(diriter->path_utf8.size > diriter->parent_utf8_len);
12991309

13001310
*out = &diriter->path_utf8.ptr[diriter->parent_utf8_len+1];
13011311
*out_len = diriter->path_utf8.size - diriter->parent_utf8_len - 1;
@@ -1307,7 +1317,9 @@ int git_path_diriter_fullpath(
13071317
size_t *out_len,
13081318
git_path_diriter *diriter)
13091319
{
1310-
assert(out && out_len && diriter);
1320+
GIT_ASSERT_ARG(out);
1321+
GIT_ASSERT_ARG(out_len);
1322+
GIT_ASSERT_ARG(diriter);
13111323

13121324
*out = diriter->path_utf8.ptr;
13131325
*out_len = diriter->path_utf8.size;
@@ -1316,7 +1328,8 @@ int git_path_diriter_fullpath(
13161328

13171329
int git_path_diriter_stat(struct stat *out, git_path_diriter *diriter)
13181330
{
1319-
assert(out && diriter);
1331+
GIT_ASSERT_ARG(out);
1332+
GIT_ASSERT_ARG(diriter);
13201333

13211334
return git_win32__file_attribute_to_stat(out,
13221335
(WIN32_FILE_ATTRIBUTE_DATA *)&diriter->current,
@@ -1343,7 +1356,8 @@ int git_path_diriter_init(
13431356
const char *path,
13441357
unsigned int flags)
13451358
{
1346-
assert(diriter && path);
1359+
GIT_ASSERT_ARG(diriter);
1360+
GIT_ASSERT_ARG(path);
13471361

13481362
memset(diriter, 0, sizeof(git_path_diriter));
13491363

@@ -1383,7 +1397,7 @@ int git_path_diriter_next(git_path_diriter *diriter)
13831397
bool skip_dot = !(diriter->flags & GIT_PATH_DIR_INCLUDE_DOT_AND_DOTDOT);
13841398
int error = 0;
13851399

1386-
assert(diriter);
1400+
GIT_ASSERT_ARG(diriter);
13871401

13881402
errno = 0;
13891403

@@ -1426,9 +1440,10 @@ int git_path_diriter_filename(
14261440
size_t *out_len,
14271441
git_path_diriter *diriter)
14281442
{
1429-
assert(out && out_len && diriter);
1430-
1431-
assert(diriter->path.size > diriter->parent_len);
1443+
GIT_ASSERT_ARG(out);
1444+
GIT_ASSERT_ARG(out_len);
1445+
GIT_ASSERT_ARG(diriter);
1446+
GIT_ASSERT(diriter->path.size > diriter->parent_len);
14321447

14331448
*out = &diriter->path.ptr[diriter->parent_len+1];
14341449
*out_len = diriter->path.size - diriter->parent_len - 1;
@@ -1440,7 +1455,9 @@ int git_path_diriter_fullpath(
14401455
size_t *out_len,
14411456
git_path_diriter *diriter)
14421457
{
1443-
assert(out && out_len && diriter);
1458+
GIT_ASSERT_ARG(out);
1459+
GIT_ASSERT_ARG(out_len);
1460+
GIT_ASSERT_ARG(diriter);
14441461

14451462
*out = diriter->path.ptr;
14461463
*out_len = diriter->path.size;
@@ -1449,7 +1466,8 @@ int git_path_diriter_fullpath(
14491466

14501467
int git_path_diriter_stat(struct stat *out, git_path_diriter *diriter)
14511468
{
1452-
assert(out && diriter);
1469+
GIT_ASSERT_ARG(out);
1470+
GIT_ASSERT_ARG(diriter);
14531471

14541472
return git_path_lstat(diriter->path.ptr, out);
14551473
}
@@ -1485,7 +1503,8 @@ int git_path_dirload(
14851503
char *dup;
14861504
int error;
14871505

1488-
assert(contents && path);
1506+
GIT_ASSERT_ARG(contents);
1507+
GIT_ASSERT_ARG(path);
14891508

14901509
if ((error = git_path_diriter_init(&iter, path, flags)) < 0)
14911510
return error;
@@ -1494,7 +1513,7 @@ int git_path_dirload(
14941513
if ((error = git_path_diriter_fullpath(&name, &name_len, &iter)) < 0)
14951514
break;
14961515

1497-
assert(name_len > prefix_len);
1516+
GIT_ASSERT(name_len > prefix_len);
14981517

14991518
dup = git__strndup(name + prefix_len, name_len - prefix_len);
15001519
GIT_ERROR_CHECK_ALLOC(dup);

0 commit comments

Comments
 (0)