LCOV - code coverage report
Current view: top level - basic - sort-util.c (source / functions) Hit Total Coverage
Test: systemd_full.info Lines: 14 14 100.0 %
Date: 2019-08-23 13:36:53 Functions: 1 1 100.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 7 8 87.5 %

           Branch data     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                 :       4952 : 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         [ -  + ]:       4952 :         assert(!size_multiply_overflow(nmemb, size));
      12                 :            : 
      13                 :       4952 :         l = 0;
      14                 :       4952 :         u = nmemb;
      15         [ +  + ]:      16024 :         while (l < u) {
      16                 :      11080 :                 idx = (l + u) / 2;
      17                 :      11080 :                 p = (const uint8_t*) base + idx * size;
      18                 :      11080 :                 comparison = compar(key, p, arg);
      19         [ +  + ]:      11080 :                 if (comparison < 0)
      20                 :       2476 :                         u = idx;
      21         [ +  + ]:       8604 :                 else if (comparison > 0)
      22                 :       8596 :                         l = idx + 1;
      23                 :            :                 else
      24                 :          8 :                         return (void *)p;
      25                 :            :         }
      26                 :       4944 :         return NULL;
      27                 :            : }

Generated by: LCOV version 1.14