diff options
author | Thomas Haller <thaller@redhat.com> | 2022-10-07 11:17:49 +0200 |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2022-10-07 11:49:41 +0200 |
commit | 1c76fe418b08e19718ca288a99db55605e5853e2 (patch) | |
tree | 01fe081f7d59fe081f797fb147872deaa00269c2 | |
parent | 1656d82045343b5af5b86cf129d4f2b12540b277 (diff) | |
download | NetworkManager-1c76fe418b08e19718ca288a99db55605e5853e2.tar.gz |
glib-aux: use nm_assert() in nm_{ptr,}array_find_bsearch()
These checks don't seem very useful, to have them enabled
in production code.
What is actually the real danger of messing up with binary search,
is that the input array is not properly sorted. Asserting for that
would be way more useful, but also likely too expensive to be worth
it.
Checking that the input arguments are not NULL/zero, is not that useful,
because we "usually" won't make such mistakes.
While at it, declare each local variable on a separate line.
-rw-r--r-- | src/libnm-glib-aux/nm-shared-utils.c | 29 |
1 files changed, 19 insertions, 10 deletions
diff --git a/src/libnm-glib-aux/nm-shared-utils.c b/src/libnm-glib-aux/nm-shared-utils.c index 58c424fd34..f60ae1f2d6 100644 --- a/src/libnm-glib-aux/nm-shared-utils.c +++ b/src/libnm-glib-aux/nm-shared-utils.c @@ -3793,11 +3793,13 @@ nm_ptrarray_find_bsearch(gconstpointer *list, GCompareDataFunc cmpfcn, gpointer user_data) { - gssize imin, imax, imid; + gssize imax; + gssize imid; + gssize imin; int cmp; - g_return_val_if_fail(list || !len, ~((gssize) 0)); - g_return_val_if_fail(cmpfcn, ~((gssize) 0)); + nm_assert(list || len == 0); + nm_assert(cmpfcn); imin = 0; if (len > 0) { @@ -3832,11 +3834,16 @@ nm_ptrarray_find_bsearch_range(gconstpointer *list, gssize *out_idx_first, gssize *out_idx_last) { - gssize imin, imax, imid, i2min, i2max, i2mid; + gssize imax; + gssize imid; + gssize imin; + gssize i2max; + gssize i2mid; + gssize i2min; int cmp; - g_return_val_if_fail(list || !len, ~((gssize) 0)); - g_return_val_if_fail(cmpfcn, ~((gssize) 0)); + nm_assert(list || len == 0); + nm_assert(cmpfcn); imin = 0; if (len > 0) { @@ -3936,12 +3943,14 @@ nm_array_find_bsearch(gconstpointer list, GCompareDataFunc cmpfcn, gpointer user_data) { - gssize imin, imax, imid; + gssize imax; + gssize imid; + gssize imin; int cmp; - g_return_val_if_fail(list || !len, ~((gssize) 0)); - g_return_val_if_fail(cmpfcn, ~((gssize) 0)); - g_return_val_if_fail(elem_size > 0, ~((gssize) 0)); + nm_assert(list || len == 0); + nm_assert(cmpfcn); + nm_assert(elem_size > 0); imin = 0; if (len == 0) |