diff --git a/src/basic/sort-util.c b/src/basic/sort-util.c index 2859f14376..a76a6c85a8 100644 --- a/src/basic/sort-util.c +++ b/src/basic/sort-util.c @@ -65,15 +65,19 @@ void qsort_r_safe(void *base, size_t nmemb, size_t size, comparison_userdata_fn_ } int cmp_int(const int *a, const int *b) { - assert(a); - assert(b); + /* This is called from qsort()s inner loops. Correctly implemented qsort will never pass NULL so we + just suppress the check via POINTER_MAY_BE_NULL instead of assert() to avoid the runtime cost. */ + POINTER_MAY_BE_NULL(a); + POINTER_MAY_BE_NULL(b); return CMP(*a, *b); } int cmp_uint16(const uint16_t *a, const uint16_t *b) { - assert(a); - assert(b); + /* This is called from qsort()s inner loops. Correctly implemented qsort will never pass NULL so we + just suppress the check via POINTER_MAY_BE_NULL instead of assert() to avoid the runtime cost. */ + POINTER_MAY_BE_NULL(a); + POINTER_MAY_BE_NULL(b); return CMP(*a, *b); } diff --git a/src/basic/strv.c b/src/basic/strv.c index 5e4d46bde4..4044a129c6 100644 --- a/src/basic/strv.c +++ b/src/basic/strv.c @@ -844,8 +844,10 @@ bool strv_overlap(char * const *a, char * const *b) { } static int str_compare(char * const *a, char * const *b) { - assert(a); - assert(b); + /* This is called from qsort()s inner loops. Correctly implemented qsort will never pass NULL so we + just suppress the check via POINTER_MAY_BE_NULL instead of assert() to avoid the runtime cost. */ + POINTER_MAY_BE_NULL(a); + POINTER_MAY_BE_NULL(b); return strcmp(*a, *b); } diff --git a/src/core/job.c b/src/core/job.c index 638e6e759e..7dd8a4617d 100644 --- a/src/core/job.c +++ b/src/core/job.c @@ -1525,10 +1525,10 @@ void job_add_to_gc_queue(Job *j) { } static int job_compare_id(Job * const *a, Job * const *b) { - assert(a); - assert(b); - assert(*a); - assert(*b); + /* This is called from qsort()s inner loops. Correctly implemented qsort will never pass NULL so we + just suppress the check via POINTER_MAY_BE_NULL instead of assert() to avoid the runtime cost. */ + POINTER_MAY_BE_NULL(a); + POINTER_MAY_BE_NULL(b); return CMP((*a)->id, (*b)->id); } diff --git a/src/shared/format-table.c b/src/shared/format-table.c index eb1866e8d4..55e19ebd70 100644 --- a/src/shared/format-table.c +++ b/src/shared/format-table.c @@ -1543,8 +1543,10 @@ static int cell_data_compare(TableData *a, size_t index_a, TableData *b, size_t static int table_data_compare(const size_t *a, const size_t *b, Table *t) { int r; - assert(a); - assert(b); + /* This is called from qsort()s inner loops. Correctly implemented qsort will never pass NULL so we + just suppress the check via POINTER_MAY_BE_NULL instead of assert() to avoid the runtime cost. */ + POINTER_MAY_BE_NULL(a); + POINTER_MAY_BE_NULL(b); assert(t); assert(t->sort_map);