LCOV - code coverage report
Current view: top level - basic - sort-util.c (source / functions) Hit Total Coverage
Test: main_coverage.info Lines: 14 14 100.0 %
Date: 2019-08-22 15:41:25 Functions: 1 1 100.0 %

          Line data    Source code
       1             : #include "sort-util.h"
       2             : #include "alloc-util.h"
       3             : 
       4             : /* hey glibc, APIs with callbacks without a user pointer are so useless */
       5        1238 : void *xbsearch_r(const void *key, const void *base, size_t nmemb, size_t size,
       6             :                  __compar_d_fn_t compar, void *arg) {
       7             :         size_t l, u, idx;
       8             :         const void *p;
       9             :         int comparison;
      10             : 
      11        1238 :         assert(!size_multiply_overflow(nmemb, size));
      12             : 
      13        1238 :         l = 0;
      14        1238 :         u = nmemb;
      15        4006 :         while (l < u) {
      16        2770 :                 idx = (l + u) / 2;
      17        2770 :                 p = (const uint8_t*) base + idx * size;
      18        2770 :                 comparison = compar(key, p, arg);
      19        2770 :                 if (comparison < 0)
      20         619 :                         u = idx;
      21        2151 :                 else if (comparison > 0)
      22        2149 :                         l = idx + 1;
      23             :                 else
      24           2 :                         return (void *)p;
      25             :         }
      26        1236 :         return NULL;
      27             : }

Generated by: LCOV version 1.14