avahi_unescape_label:
   41|  2.44k|char *avahi_unescape_label(const char **name, char *dest, size_t size) {
   42|  2.44k|    unsigned i = 0;
   43|  2.44k|    char *d;
   44|       |
   45|  2.44k|    assert(dest);
   46|      0|    assert(size > 0);
   47|      0|    assert(name);
   48|       |
   49|      0|    d = dest;
   50|       |
   51|  33.8k|    for (;;) {
   52|  33.8k|        if (i >= size)
  ------------------
  |  Branch (52:13): [True: 0, False: 33.8k]
  ------------------
   53|      0|            return NULL;
   54|       |
   55|  33.8k|        if (**name == '.') {
  ------------------
  |  Branch (55:13): [True: 1.58k, False: 32.2k]
  ------------------
   56|  1.58k|            (*name)++;
   57|  1.58k|            break;
   58|  1.58k|        }
   59|       |
   60|  32.2k|        if (**name == 0)
  ------------------
  |  Branch (60:13): [True: 842, False: 31.3k]
  ------------------
   61|    842|            break;
   62|       |
   63|  31.3k|        if (**name == '\\') {
  ------------------
  |  Branch (63:13): [True: 5.62k, False: 25.7k]
  ------------------
   64|       |            /* Escaped character */
   65|       |
   66|  5.62k|            (*name) ++;
   67|       |
   68|  5.62k|            if (**name == 0)
  ------------------
  |  Branch (68:17): [True: 0, False: 5.62k]
  ------------------
   69|       |                /* Ending NUL */
   70|      0|                return NULL;
   71|       |
   72|  5.62k|            else if (**name == '\\' || **name == '.') {
  ------------------
  |  Branch (72:22): [True: 450, False: 5.17k]
  |  Branch (72:40): [True: 342, False: 4.83k]
  ------------------
   73|       |                /* Escaped backslash or dot */
   74|    792|                *(d++) = *((*name) ++);
   75|    792|                i++;
   76|  4.83k|            } else if (isdigit(**name)) {
   77|  4.83k|                int n;
   78|       |
   79|       |                /* Escaped literal ASCII character */
   80|       |
   81|  4.83k|                if (!isdigit(*(*name+1)) || !isdigit(*(*name+2)))
  ------------------
  |  Branch (81:21): [True: 0, False: 4.83k]
  |  Branch (81:45): [True: 0, False: 4.83k]
  ------------------
   82|      0|                    return NULL;
   83|       |
   84|  4.83k|                n = ((uint8_t) (**name - '0') * 100) + ((uint8_t) (*(*name+1) - '0') * 10) + ((uint8_t) (*(*name +2) - '0'));
   85|       |
   86|  4.83k|                if (n > 255 || n == 0)
  ------------------
  |  Branch (86:21): [True: 0, False: 4.83k]
  |  Branch (86:32): [True: 11, False: 4.82k]
  ------------------
   87|     11|                    return NULL;
   88|       |
   89|  4.82k|                *(d++) = (char) n;
   90|  4.82k|                i++;
   91|       |
   92|  4.82k|                (*name) += 3;
   93|  4.82k|            } else
   94|      0|                return NULL;
   95|       |
   96|  25.7k|        } else {
   97|       |
   98|       |            /* Normal character */
   99|       |
  100|  25.7k|            *(d++) = *((*name) ++);
  101|  25.7k|            i++;
  102|  25.7k|        }
  103|  31.3k|    }
  104|       |
  105|  2.43k|    assert(i < size);
  106|       |
  107|      0|    *d = 0;
  108|       |
  109|  2.43k|    if (!avahi_utf8_valid(dest))
  ------------------
  |  Branch (109:9): [True: 67, False: 2.36k]
  ------------------
  110|     67|        return NULL;
  111|       |
  112|  2.36k|    return dest;
  113|  2.43k|}
avahi_escape_label:
  116|  4.42k|char *avahi_escape_label(const char* src, size_t src_length, char **ret_name, size_t *ret_size) {
  117|  4.42k|    char *r;
  118|       |
  119|  4.42k|    assert(src);
  120|      0|    assert(ret_name);
  121|      0|    assert(*ret_name);
  122|      0|    assert(ret_size);
  123|      0|    assert(*ret_size > 0);
  124|       |
  125|      0|    r = *ret_name;
  126|       |
  127|  41.2k|    while (src_length > 0) {
  ------------------
  |  Branch (127:12): [True: 36.8k, False: 4.40k]
  ------------------
  128|  36.8k|        if (*src == '.' || *src == '\\') {
  ------------------
  |  Branch (128:13): [True: 784, False: 36.0k]
  |  Branch (128:28): [True: 761, False: 35.3k]
  ------------------
  129|       |
  130|       |            /* Dot or backslash */
  131|       |
  132|  1.54k|            if (*ret_size < 3)
  ------------------
  |  Branch (132:17): [True: 2, False: 1.54k]
  ------------------
  133|      2|                return NULL;
  134|       |
  135|  1.54k|            *((*ret_name) ++) = '\\';
  136|  1.54k|            *((*ret_name) ++) = *src;
  137|  1.54k|            (*ret_size) -= 2;
  138|       |
  139|  35.3k|        } else if (
  140|  35.3k|            *src == '_' ||
  ------------------
  |  Branch (140:13): [True: 260, False: 35.0k]
  ------------------
  141|  35.3k|            *src == '-' ||
  ------------------
  |  Branch (141:13): [True: 527, False: 34.5k]
  ------------------
  142|  35.3k|            (*src >= '0' && *src <= '9') ||
  ------------------
  |  Branch (142:14): [True: 28.8k, False: 5.69k]
  |  Branch (142:29): [True: 26.2k, False: 2.62k]
  ------------------
  143|  35.3k|            (*src >= 'a' && *src <= 'z') ||
  ------------------
  |  Branch (143:14): [True: 797, False: 7.52k]
  |  Branch (143:29): [True: 650, False: 147]
  ------------------
  144|  35.3k|            (*src >= 'A' && *src <= 'Z')) {
  ------------------
  |  Branch (144:14): [True: 1.67k, False: 5.99k]
  |  Branch (144:29): [True: 1.44k, False: 229]
  ------------------
  145|       |
  146|       |            /* Proper character */
  147|       |
  148|  29.0k|            if (*ret_size < 2)
  ------------------
  |  Branch (148:17): [True: 1, False: 29.0k]
  ------------------
  149|      1|                return NULL;
  150|       |
  151|  29.0k|            *((*ret_name)++) = *src;
  152|  29.0k|            (*ret_size) --;
  153|       |
  154|  29.0k|        } else {
  155|       |
  156|       |            /* Everything else */
  157|       |
  158|  6.22k|            if (*ret_size < 5)
  ------------------
  |  Branch (158:17): [True: 19, False: 6.20k]
  ------------------
  159|     19|                return NULL;
  160|       |
  161|  6.20k|            *((*ret_name) ++) = '\\';
  162|  6.20k|            *((*ret_name) ++) = '0' + (char)  ((uint8_t) *src / 100);
  163|  6.20k|            *((*ret_name) ++) = '0' + (char) (((uint8_t) *src / 10) % 10);
  164|  6.20k|            *((*ret_name) ++) = '0' + (char)  ((uint8_t) *src % 10);
  165|       |
  166|  6.20k|            (*ret_size) -= 4;
  167|  6.20k|        }
  168|       |
  169|  36.8k|        src_length --;
  170|  36.8k|        src++;
  171|  36.8k|    }
  172|       |
  173|  4.40k|    **ret_name = 0;
  174|       |
  175|  4.40k|    return r;
  176|  4.42k|}
avahi_normalize_name:
  178|    355|char *avahi_normalize_name(const char *s, char *ret_s, size_t size) {
  179|    355|    int empty = 1;
  180|    355|    char *r;
  181|       |
  182|    355|    assert(s);
  183|      0|    assert(ret_s);
  184|      0|    assert(size > 0);
  185|       |
  186|      0|    r = ret_s;
  187|    355|    *ret_s = 0;
  188|       |
  189|  1.20k|    while (*s) {
  ------------------
  |  Branch (189:12): [True: 923, False: 277]
  ------------------
  190|    923|        char label[AVAHI_LABEL_MAX];
  191|       |
  192|    923|        if (!(avahi_unescape_label(&s, label, sizeof(label))))
  ------------------
  |  Branch (192:13): [True: 78, False: 845]
  ------------------
  193|     78|            return NULL;
  194|       |
  195|    845|        if (label[0] == 0) {
  ------------------
  |  Branch (195:13): [True: 0, False: 845]
  ------------------
  196|       |
  197|      0|            if (*s == 0 && empty)
  ------------------
  |  Branch (197:17): [True: 0, False: 0]
  |  Branch (197:28): [True: 0, False: 0]
  ------------------
  198|      0|                return ret_s;
  199|       |
  200|      0|            return NULL;
  201|      0|        }
  202|       |
  203|    845|        if (!empty) {
  ------------------
  |  Branch (203:13): [True: 595, False: 250]
  ------------------
  204|    595|            if (size < 1)
  ------------------
  |  Branch (204:17): [True: 0, False: 595]
  ------------------
  205|      0|                return NULL;
  206|       |
  207|    595|            *(r++) = '.';
  208|    595|            size--;
  209|       |
  210|    595|        } else
  211|    250|            empty = 0;
  212|       |
  213|    845|        avahi_escape_label(label, strlen(label), &r, &size);
  214|    845|    }
  215|       |
  216|    277|    return ret_s;
  217|    355|}
avahi_normalize_name_strdup:
  219|    355|char *avahi_normalize_name_strdup(const char *s) {
  220|    355|    char t[AVAHI_DOMAIN_NAME_MAX];
  221|    355|    assert(s);
  222|       |
  223|    355|    if (!(avahi_normalize_name(s, t, sizeof(t))))
  ------------------
  |  Branch (223:9): [True: 78, False: 277]
  ------------------
  224|     78|        return NULL;
  225|       |
  226|    277|    return avahi_strdup(t);
  227|    355|}
avahi_is_valid_domain_name:
  369|    554|int avahi_is_valid_domain_name(const char *t) {
  370|    554|    int is_first = 1;
  371|    554|    assert(t);
  372|       |
  373|    554|    if (strlen(t) >= AVAHI_DOMAIN_NAME_MAX)
  ------------------
  |  |   41|    554|#define AVAHI_DOMAIN_NAME_MAX 1014
  ------------------
  |  Branch (373:9): [True: 0, False: 554]
  ------------------
  374|      0|        return 0;
  375|       |
  376|  1.51k|    do {
  377|  1.51k|        char label[AVAHI_LABEL_MAX];
  378|       |
  379|  1.51k|        if (!(avahi_unescape_label(&t, label, sizeof(label))))
  ------------------
  |  Branch (379:13): [True: 0, False: 1.51k]
  ------------------
  380|      0|            return 0;
  381|       |
  382|       |        /* Explicitly allow the root domain name */
  383|  1.51k|        if (is_first && label[0] == 0 && *t == 0)
  ------------------
  |  Branch (383:13): [True: 554, False: 964]
  |  Branch (383:25): [True: 104, False: 450]
  |  Branch (383:42): [True: 104, False: 0]
  ------------------
  384|    104|            return 1;
  385|       |
  386|  1.41k|        is_first = 0;
  387|       |
  388|  1.41k|        if (label[0] == 0)
  ------------------
  |  Branch (388:13): [True: 0, False: 1.41k]
  ------------------
  389|      0|            return 0;
  390|       |
  391|  1.41k|    } while (*t);
  ------------------
  |  Branch (391:14): [True: 964, False: 450]
  ------------------
  392|       |
  393|    450|    return 1;
  394|    554|}

avahi_malloc:
  101|  1.61k|void *avahi_malloc(size_t size) {
  102|       |
  103|  1.61k|    if (size <= 0)
  ------------------
  |  Branch (103:9): [True: 0, False: 1.61k]
  ------------------
  104|      0|        return NULL;
  105|       |
  106|  1.61k|    if (!allocator)
  ------------------
  |  Branch (106:9): [True: 1.61k, False: 0]
  ------------------
  107|  1.61k|        return xmalloc(size);
  108|       |
  109|      0|    assert(allocator->malloc);
  110|      0|    return allocator->malloc(size);
  111|  1.61k|}
avahi_free:
  132|  1.61k|void avahi_free(void *p) {
  133|       |
  134|  1.61k|    if (!p)
  ------------------
  |  Branch (134:9): [True: 0, False: 1.61k]
  ------------------
  135|      0|        return;
  136|       |
  137|  1.61k|    if (!allocator) {
  ------------------
  |  Branch (137:9): [True: 1.61k, False: 0]
  ------------------
  138|  1.61k|        free(p);
  139|  1.61k|        return;
  140|  1.61k|    }
  141|       |
  142|      0|    assert(allocator->free);
  143|      0|    allocator->free(p);
  144|      0|}
avahi_realloc:
  146|     73|void *avahi_realloc(void *p, size_t size) {
  147|       |
  148|     73|    if (size == 0) {
  ------------------
  |  Branch (148:9): [True: 0, False: 73]
  ------------------
  149|      0|        avahi_free(p);
  150|      0|        return NULL;
  151|      0|    }
  152|       |
  153|     73|    if (!allocator)
  ------------------
  |  Branch (153:9): [True: 73, False: 0]
  ------------------
  154|     73|        return xrealloc(p, size);
  155|       |
  156|      0|    assert(allocator->realloc);
  157|      0|    return allocator->realloc(p, size);
  158|     73|}
avahi_strdup:
  160|    277|char *avahi_strdup(const char *s) {
  161|    277|    char *r;
  162|    277|    size_t size;
  163|       |
  164|    277|    if (!s)
  ------------------
  |  Branch (164:9): [True: 0, False: 277]
  ------------------
  165|      0|        return NULL;
  166|       |
  167|    277|    size = strlen(s);
  168|    277|    if (!(r = avahi_malloc(size+1)))
  ------------------
  |  Branch (168:9): [True: 0, False: 277]
  ------------------
  169|      0|        return NULL;
  170|       |
  171|    277|    memcpy(r, s, size+1);
  172|    277|    return r;
  173|    277|}
avahi_strdup_vprintf:
  200|    277|char *avahi_strdup_vprintf(const char *fmt, va_list ap) {
  201|    277|    size_t len = 80;
  202|    277|    char *buf;
  203|       |
  204|    277|    assert(fmt);
  205|       |
  206|    277|    if (!(buf = avahi_malloc(len)))
  ------------------
  |  Branch (206:9): [True: 0, False: 277]
  ------------------
  207|      0|        return NULL;
  208|       |
  209|    350|    for (;;) {
  210|    350|        int n;
  211|    350|        char *nbuf;
  212|    350|        va_list ap2;
  213|       |
  214|    350|        va_copy (ap2, ap);
  215|    350|        n = vsnprintf(buf, len, fmt, ap2);
  216|    350|        va_end (ap2);
  217|       |
  218|    350|        if (n >= 0 && n < (int) len)
  ------------------
  |  Branch (218:13): [True: 350, False: 0]
  |  Branch (218:23): [True: 277, False: 73]
  ------------------
  219|    277|            return buf;
  220|       |
  221|     73|        if (n >= 0)
  ------------------
  |  Branch (221:13): [True: 73, False: 0]
  ------------------
  222|     73|            len = n+1;
  223|      0|        else
  224|      0|            len *= 2;
  225|       |
  226|     73|        if (!(nbuf = avahi_realloc(buf, len))) {
  ------------------
  |  Branch (226:13): [True: 0, False: 73]
  ------------------
  227|      0|            avahi_free(buf);
  228|      0|            return NULL;
  229|      0|        }
  230|       |
  231|     73|        buf = nbuf;
  232|     73|    }
  233|    277|}
avahi_strdup_printf:
  235|    277|char *avahi_strdup_printf(const char *fmt, ... ) {
  236|    277|    char *s;
  237|    277|    va_list ap;
  238|       |
  239|    277|    assert(fmt);
  240|       |
  241|      0|    va_start(ap, fmt);
  242|    277|    s = avahi_strdup_vprintf(fmt, ap);
  243|    277|    va_end(ap);
  244|       |
  245|    277|    return s;
  246|    277|}
malloc.c:xmalloc:
   62|  1.61k|static void* xmalloc(size_t size) {
   63|  1.61k|    void *p;
   64|       |
   65|  1.61k|    if (size == 0)
  ------------------
  |  Branch (65:9): [True: 0, False: 1.61k]
  ------------------
   66|      0|        return NULL;
   67|       |
   68|  1.61k|    if (!(p = malloc(size)))
  ------------------
  |  Branch (68:9): [True: 0, False: 1.61k]
  ------------------
   69|      0|        oom();
   70|       |
   71|  1.61k|    return p;
   72|  1.61k|}
malloc.c:xrealloc:
   75|     73|static void *xrealloc(void *p, size_t size) {
   76|       |
   77|     73|    if (size == 0) {
  ------------------
  |  Branch (77:9): [True: 0, False: 73]
  ------------------
   78|      0|        free(p);
   79|      0|        return NULL;
   80|      0|    }
   81|       |
   82|     73|    if (!(p = realloc(p, size)))
  ------------------
  |  Branch (82:9): [True: 0, False: 73]
  ------------------
   83|      0|        oom();
   84|       |
   85|     73|    return p;
   86|     73|}

avahi_utf8_valid:
   52|  2.43k|{
   53|  2.43k|  unsigned val = 0;
   54|  2.43k|  unsigned min = 0;
   55|  2.43k|  const char *p;
   56|       |
   57|  32.3k|  for (p = str; *p; p++)
  ------------------
  |  Branch (57:17): [True: 30.0k, False: 2.36k]
  ------------------
   58|  30.0k|    {
   59|  30.0k|      if (*(const unsigned char *)p < 128)
  ------------------
  |  Branch (59:11): [True: 29.3k, False: 627]
  ------------------
   60|  29.3k|	/* done */;
   61|    627|      else
   62|    627|	{
   63|    627|	  if ((*(const unsigned char *)p & 0xe0) == 0xc0) /* 110xxxxx */
  ------------------
  |  Branch (63:8): [True: 128, False: 499]
  ------------------
   64|    128|	    {
   65|    128|	      if ( ((*(const unsigned char *)p & 0x1e) == 0))
  ------------------
  |  Branch (65:13): [True: 20, False: 108]
  ------------------
   66|     20|		goto error;
   67|    108|	      p++;
   68|    108|	      if ( ((*(const unsigned char *)p & 0xc0) != 0x80)) /* 10xxxxxx */
  ------------------
  |  Branch (68:13): [True: 6, False: 102]
  ------------------
   69|      6|		goto error;
   70|    108|	    }
   71|    499|	  else
   72|    499|	    {
   73|    499|	      if ((*(const unsigned char *)p & 0xf0) == 0xe0) /* 1110xxxx */
  ------------------
  |  Branch (73:12): [True: 296, False: 203]
  ------------------
   74|    296|		{
   75|    296|		  min = (1 << 11);
   76|    296|		  val = *(const unsigned char *)p & 0x0f;
   77|    296|		  goto TWO_REMAINING;
   78|    296|		}
   79|    203|	      else if ((*(const unsigned char *)p & 0xf8) == 0xf0) /* 11110xxx */
  ------------------
  |  Branch (79:17): [True: 190, False: 13]
  ------------------
   80|    190|		{
   81|    190|		  min = (1 << 16);
   82|    190|		  val = *(const unsigned char *)p & 0x07;
   83|    190|		}
   84|     13|	      else
   85|     13|		goto error;
   86|       |
   87|    190|	      p++;
   88|    190|	      CONTINUATION_CHAR;
  ------------------
  |  |   41|    190| do {                                     \
  |  |   42|    190|  if ((*(const unsigned char *)p & 0xc0) != 0x80) /* 10xxxxxx */ \
  |  |  ------------------
  |  |  |  Branch (42:7): [True: 5, False: 185]
  |  |  ------------------
  |  |   43|    190|    goto error;                                     \
  |  |   44|    190|  val <<= 6;                                        \
  |  |   45|    185|  val |= (*(const unsigned char *)p) & 0x3f;                     \
  |  |   46|    185| } while(0)
  |  |  ------------------
  |  |  |  Branch (46:10): [Folded - Ignored]
  |  |  ------------------
  ------------------
   89|    481|	    TWO_REMAINING:
   90|    481|	      p++;
   91|    481|	      CONTINUATION_CHAR;
  ------------------
  |  |   41|    481| do {                                     \
  |  |   42|    481|  if ((*(const unsigned char *)p & 0xc0) != 0x80) /* 10xxxxxx */ \
  |  |  ------------------
  |  |  |  Branch (42:7): [True: 5, False: 476]
  |  |  ------------------
  |  |   43|    481|    goto error;                                     \
  |  |   44|    481|  val <<= 6;                                        \
  |  |   45|    476|  val |= (*(const unsigned char *)p) & 0x3f;                     \
  |  |   46|    476| } while(0)
  |  |  ------------------
  |  |  |  Branch (46:10): [Folded - Ignored]
  |  |  ------------------
  ------------------
   92|    476|	      p++;
   93|    476|	      CONTINUATION_CHAR;
  ------------------
  |  |   41|    476| do {                                     \
  |  |   42|    476|  if ((*(const unsigned char *)p & 0xc0) != 0x80) /* 10xxxxxx */ \
  |  |  ------------------
  |  |  |  Branch (42:7): [True: 3, False: 473]
  |  |  ------------------
  |  |   43|    476|    goto error;                                     \
  |  |   44|    476|  val <<= 6;                                        \
  |  |   45|    473|  val |= (*(const unsigned char *)p) & 0x3f;                     \
  |  |   46|    473| } while(0)
  |  |  ------------------
  |  |  |  Branch (46:10): [Folded - Ignored]
  |  |  ------------------
  ------------------
   94|       |
   95|    473|	      if ( (val < min))
  ------------------
  |  Branch (95:13): [True: 2, False: 471]
  ------------------
   96|      2|		goto error;
   97|       |
   98|    471|	      if ( (!UNICODE_VALID(val)))
  ------------------
  |  |   34|    471|    ((Char) < 0x110000 &&                     \
  |  |  ------------------
  |  |  |  Branch (34:6): [True: 467, False: 4]
  |  |  ------------------
  |  |   35|    471|     (((Char) & 0xFFFFF800) != 0xD800) &&     \
  |  |  ------------------
  |  |  |  Branch (35:6): [True: 466, False: 1]
  |  |  ------------------
  |  |   36|    471|     ((Char) < 0xFDD0 || (Char) > 0xFDEF) &&  \
  |  |  ------------------
  |  |  |  Branch (36:7): [True: 241, False: 225]
  |  |  |  Branch (36:26): [True: 222, False: 3]
  |  |  ------------------
  |  |   37|    471|     ((Char) & 0xFFFE) != 0xFFFE)
  |  |  ------------------
  |  |  |  Branch (37:6): [True: 458, False: 5]
  |  |  ------------------
  ------------------
   99|     13|		goto error;
  100|    471|	    }
  101|       |
  102|    560|	  continue;
  103|       |
  104|    560|	error:
  105|     67|	  return NULL;
  106|    627|	}
  107|  30.0k|    }
  108|       |
  109|  2.36k|  return str;
  110|  2.43k|}

rr.c:avahi_new_internal:
   48|    355|static inline void* AVAHI_GCC_ALLOC_SIZE2(1,2) avahi_new_internal(unsigned n, size_t k) {
   49|    355|    assert(n < INT_MAX/k);
   50|      0|    return avahi_malloc(n*k);
   51|    355|}

avahi_dns_packet_new:
   39|    703|AvahiDnsPacket* avahi_dns_packet_new(unsigned mtu) {
   40|    703|    AvahiDnsPacket *p;
   41|    703|    size_t max_size;
   42|       |
   43|    703|    if (mtu <= 0)
  ------------------
  |  Branch (43:9): [True: 0, False: 703]
  ------------------
   44|      0|        max_size = AVAHI_DNS_PACKET_SIZE_MAX;
  ------------------
  |  |   30|      0|#define AVAHI_DNS_PACKET_SIZE_MAX (AVAHI_DNS_PACKET_HEADER_SIZE + 256 + 2 + 2 + 4 + 2 + AVAHI_DNS_RDATA_MAX)
  |  |  ------------------
  |  |  |  |   26|      0|#define AVAHI_DNS_PACKET_HEADER_SIZE 12
  |  |  ------------------
  |  |               #define AVAHI_DNS_PACKET_SIZE_MAX (AVAHI_DNS_PACKET_HEADER_SIZE + 256 + 2 + 2 + 4 + 2 + AVAHI_DNS_RDATA_MAX)
  |  |  ------------------
  |  |  |  |   29|      0|#define AVAHI_DNS_RDATA_MAX 0xFFFF
  |  |  ------------------
  ------------------
   45|    703|    else if (mtu >= AVAHI_DNS_PACKET_EXTRA_SIZE)
  ------------------
  |  |   27|    703|#define AVAHI_DNS_PACKET_EXTRA_SIZE 48
  ------------------
  |  Branch (45:14): [True: 703, False: 0]
  ------------------
   46|    703|        max_size = mtu - AVAHI_DNS_PACKET_EXTRA_SIZE;
  ------------------
  |  |   27|    703|#define AVAHI_DNS_PACKET_EXTRA_SIZE 48
  ------------------
   47|      0|    else
   48|      0|        max_size = 0;
   49|       |
   50|    703|    if (max_size < AVAHI_DNS_PACKET_HEADER_SIZE)
  ------------------
  |  |   26|    703|#define AVAHI_DNS_PACKET_HEADER_SIZE 12
  ------------------
  |  Branch (50:9): [True: 8, False: 695]
  ------------------
   51|      8|        max_size = AVAHI_DNS_PACKET_HEADER_SIZE;
  ------------------
  |  |   26|      8|#define AVAHI_DNS_PACKET_HEADER_SIZE 12
  ------------------
   52|       |
   53|    703|    if (!(p = avahi_malloc(sizeof(AvahiDnsPacket) + max_size)))
  ------------------
  |  Branch (53:9): [True: 0, False: 703]
  ------------------
   54|      0|        return p;
   55|       |
   56|    703|    p->size = p->rindex = AVAHI_DNS_PACKET_HEADER_SIZE;
  ------------------
  |  |   26|    703|#define AVAHI_DNS_PACKET_HEADER_SIZE 12
  ------------------
   57|    703|    p->max_size = max_size;
   58|    703|    p->res_size = 0;
   59|    703|    p->name_table = NULL;
   60|    703|    p->data = NULL;
   61|       |
   62|    703|    memset(AVAHI_DNS_PACKET_DATA(p), 0, p->size);
  ------------------
  |  |   38|    703|#define AVAHI_DNS_PACKET_DATA(p) ((p)->data ? (p)->data : ((uint8_t*) p) + sizeof(AvahiDnsPacket))
  |  |  ------------------
  |  |  |  Branch (38:35): [True: 0, False: 703]
  |  |  ------------------
  ------------------
   63|    703|    return p;
   64|    703|}
avahi_dns_packet_free:
  125|    703|void avahi_dns_packet_free(AvahiDnsPacket *p) {
  126|    703|    assert(p);
  127|       |
  128|    703|    if (p->name_table)
  ------------------
  |  Branch (128:9): [True: 0, False: 703]
  ------------------
  129|      0|        avahi_hashmap_free(p->name_table);
  130|       |
  131|    703|    avahi_free(p);
  132|    703|}
avahi_dns_packet_consume_name:
  422|    703|int avahi_dns_packet_consume_name(AvahiDnsPacket *p, char *ret_name, size_t l) {
  423|    703|    int r;
  424|       |
  425|    703|    if ((r = consume_labels(p, p->rindex, ret_name, l)) < 0)
  ------------------
  |  Branch (425:9): [True: 325, False: 378]
  ------------------
  426|    325|        return -1;
  427|       |
  428|    378|    p->rindex += r;
  429|    378|    return 0;
  430|    703|}
avahi_dns_packet_consume_uint16:
  432|    743|int avahi_dns_packet_consume_uint16(AvahiDnsPacket *p, uint16_t *ret_v) {
  433|    743|    uint8_t *d;
  434|       |
  435|    743|    assert(p);
  436|      0|    assert(ret_v);
  437|       |
  438|    743|    if (p->rindex + sizeof(uint16_t) > p->size)
  ------------------
  |  Branch (438:9): [True: 23, False: 720]
  ------------------
  439|     23|        return -1;
  440|       |
  441|    720|    d = (uint8_t*) (AVAHI_DNS_PACKET_DATA(p) + p->rindex);
  ------------------
  |  |   38|    720|#define AVAHI_DNS_PACKET_DATA(p) ((p)->data ? (p)->data : ((uint8_t*) p) + sizeof(AvahiDnsPacket))
  |  |  ------------------
  |  |  |  Branch (38:35): [True: 0, False: 720]
  |  |  ------------------
  ------------------
  442|    720|    *ret_v = (d[0] << 8) | d[1];
  443|    720|    p->rindex += sizeof(uint16_t);
  444|       |
  445|    720|    return 0;
  446|    743|}
avahi_dns_packet_consume_key:
  661|    703|AvahiKey* avahi_dns_packet_consume_key(AvahiDnsPacket *p, int *ret_unicast_response) {
  662|    703|    char name[256];
  663|    703|    uint16_t type, class;
  664|    703|    AvahiKey *k;
  665|       |
  666|    703|    assert(p);
  667|       |
  668|    703|    if (avahi_dns_packet_consume_name(p, name, sizeof(name)) < 0 ||
  ------------------
  |  Branch (668:9): [True: 325, False: 378]
  ------------------
  669|    703|        avahi_dns_packet_consume_uint16(p, &type) < 0 ||
  ------------------
  |  Branch (669:9): [True: 13, False: 365]
  ------------------
  670|    703|        avahi_dns_packet_consume_uint16(p, &class) < 0)
  ------------------
  |  Branch (670:9): [True: 10, False: 355]
  ------------------
  671|    348|        return NULL;
  672|       |
  673|    355|    if (ret_unicast_response)
  ------------------
  |  Branch (673:9): [True: 0, False: 355]
  ------------------
  674|      0|        *ret_unicast_response = !!(class & AVAHI_DNS_UNICAST_RESPONSE);
  675|       |
  676|    355|    class &= ~AVAHI_DNS_UNICAST_RESPONSE;
  677|       |
  678|    355|    if (!(k = avahi_key_new(name, class, type)))
  ------------------
  |  Branch (678:9): [True: 78, False: 277]
  ------------------
  679|     78|        return NULL;
  680|       |
  681|    277|    if (!avahi_key_is_valid(k)) {
  ------------------
  |  Branch (681:9): [True: 0, False: 277]
  ------------------
  682|      0|        avahi_key_unref(k);
  683|      0|        return NULL;
  684|      0|    }
  685|       |
  686|    277|    return k;
  687|    277|}
dns.c:consume_labels:
  346|    703|static int consume_labels(AvahiDnsPacket *p, unsigned idx, char *ret_name, size_t l) {
  347|    703|    int ret = 0;
  348|    703|    int compressed = 0;
  349|    703|    int first_label = 1;
  350|    703|    unsigned label_ptr;
  351|    703|    int i;
  352|    703|    assert(p && ret_name && l);
  353|       |
  354|  6.00k|    for (i = 0; i < AVAHI_DNS_LABELS_MAX; i++) {
  ------------------
  |  |   28|  6.00k|#define AVAHI_DNS_LABELS_MAX 127
  ------------------
  |  Branch (354:17): [True: 5.98k, False: 16]
  ------------------
  355|  5.98k|        uint8_t n;
  356|       |
  357|  5.98k|        if (idx+1 > p->size)
  ------------------
  |  Branch (357:13): [True: 115, False: 5.87k]
  ------------------
  358|    115|            return -1;
  359|       |
  360|  5.87k|        n = AVAHI_DNS_PACKET_DATA(p)[idx];
  ------------------
  |  |   38|  5.87k|#define AVAHI_DNS_PACKET_DATA(p) ((p)->data ? (p)->data : ((uint8_t*) p) + sizeof(AvahiDnsPacket))
  |  |  ------------------
  |  |  |  Branch (38:35): [True: 0, False: 5.87k]
  |  |  ------------------
  ------------------
  361|       |
  362|  5.87k|        if (!n) {
  ------------------
  |  Branch (362:13): [True: 378, False: 5.49k]
  ------------------
  363|    378|            idx++;
  364|    378|            if (!compressed)
  ------------------
  |  Branch (364:17): [True: 353, False: 25]
  ------------------
  365|    353|                ret++;
  366|       |
  367|    378|            if (l < 1)
  ------------------
  |  Branch (367:17): [True: 0, False: 378]
  ------------------
  368|      0|                return -1;
  369|    378|            *ret_name = 0;
  370|       |
  371|    378|            return ret;
  372|       |
  373|  5.49k|        } else if (n <= 63) {
  ------------------
  |  Branch (373:20): [True: 3.63k, False: 1.86k]
  ------------------
  374|       |            /* Uncompressed label */
  375|  3.63k|            idx++;
  376|  3.63k|            if (!compressed)
  ------------------
  |  Branch (376:17): [True: 1.81k, False: 1.81k]
  ------------------
  377|  1.81k|                ret++;
  378|       |
  379|  3.63k|            if (idx + n > p->size)
  ------------------
  |  Branch (379:17): [True: 27, False: 3.60k]
  ------------------
  380|     27|                return -1;
  381|       |
  382|  3.60k|            if ((size_t) n + 1 > l)
  ------------------
  |  Branch (382:17): [True: 25, False: 3.57k]
  ------------------
  383|     25|                return -1;
  384|       |
  385|  3.57k|            if (!first_label) {
  ------------------
  |  Branch (385:17): [True: 3.02k, False: 557]
  ------------------
  386|  3.02k|                *(ret_name++) = '.';
  387|  3.02k|                l--;
  388|  3.02k|            } else
  389|    557|                first_label = 0;
  390|       |
  391|  3.57k|            if (!(avahi_escape_label((char*) AVAHI_DNS_PACKET_DATA(p) + idx, n, &ret_name, &l)))
  ------------------
  |  |   38|  3.57k|#define AVAHI_DNS_PACKET_DATA(p) ((p)->data ? (p)->data : ((uint8_t*) p) + sizeof(AvahiDnsPacket))
  |  |  ------------------
  |  |  |  Branch (38:35): [True: 0, False: 3.57k]
  |  |  ------------------
  ------------------
  |  Branch (391:17): [True: 22, False: 3.55k]
  ------------------
  392|     22|                return -1;
  393|       |
  394|  3.55k|            idx += n;
  395|       |
  396|  3.55k|            if (!compressed)
  ------------------
  |  Branch (396:17): [True: 1.77k, False: 1.78k]
  ------------------
  397|  1.77k|                ret += n;
  398|  3.55k|        } else if ((n & 0xC0) == 0xC0) {
  ------------------
  |  Branch (398:20): [True: 1.83k, False: 26]
  ------------------
  399|       |            /* Compressed label */
  400|       |
  401|  1.83k|            if (idx+2 > p->size)
  ------------------
  |  Branch (401:17): [True: 9, False: 1.82k]
  ------------------
  402|      9|                return -1;
  403|       |
  404|  1.82k|            label_ptr = ((unsigned) (AVAHI_DNS_PACKET_DATA(p)[idx] & ~0xC0)) << 8 | AVAHI_DNS_PACKET_DATA(p)[idx+1];
  ------------------
  |  |   38|  1.82k|#define AVAHI_DNS_PACKET_DATA(p) ((p)->data ? (p)->data : ((uint8_t*) p) + sizeof(AvahiDnsPacket))
  |  |  ------------------
  |  |  |  Branch (38:35): [True: 0, False: 1.82k]
  |  |  ------------------
  ------------------
                          label_ptr = ((unsigned) (AVAHI_DNS_PACKET_DATA(p)[idx] & ~0xC0)) << 8 | AVAHI_DNS_PACKET_DATA(p)[idx+1];
  ------------------
  |  |   38|  1.82k|#define AVAHI_DNS_PACKET_DATA(p) ((p)->data ? (p)->data : ((uint8_t*) p) + sizeof(AvahiDnsPacket))
  |  |  ------------------
  |  |  |  Branch (38:35): [True: 0, False: 1.82k]
  |  |  ------------------
  ------------------
  405|       |
  406|  1.82k|            if ((label_ptr < AVAHI_DNS_PACKET_HEADER_SIZE) || (label_ptr >= idx))
  ------------------
  |  |   26|  1.82k|#define AVAHI_DNS_PACKET_HEADER_SIZE 12
  ------------------
  |  Branch (406:17): [True: 5, False: 1.82k]
  |  Branch (406:63): [True: 80, False: 1.74k]
  ------------------
  407|     85|                return -1;
  408|       |
  409|  1.74k|            idx = label_ptr;
  410|       |
  411|  1.74k|            if (!compressed)
  ------------------
  |  Branch (411:17): [True: 83, False: 1.65k]
  ------------------
  412|     83|                ret += 2;
  413|       |
  414|  1.74k|            compressed = 1;
  415|  1.74k|        } else
  416|     26|            return -1;
  417|  5.87k|    }
  418|       |
  419|     16|    return -1;
  420|    703|}

avahi_set_log_function:
   31|    703|void avahi_set_log_function(AvahiLogFunction function) {
   32|    703|    log_function = function;
   33|    703|}
avahi_log_ap:
   35|     78|void avahi_log_ap(AvahiLogLevel level, const char*format, va_list ap) {
   36|     78|    char txt[256];
   37|       |
   38|     78|    vsnprintf(txt, sizeof(txt), format, ap);
   39|       |
   40|     78|    if (log_function)
  ------------------
  |  Branch (40:9): [True: 78, False: 0]
  ------------------
   41|     78|        log_function(level, txt);
   42|      0|    else
   43|      0|        fprintf(stderr, "%s\n", txt);
   44|     78|}
avahi_log_error:
   53|     78|void avahi_log_error(const char*format, ...) {
   54|     78|    va_list ap;
   55|     78|    va_start(ap, format);
   56|     78|    avahi_log_ap(AVAHI_LOG_ERROR, format, ap);
   57|     78|    va_end(ap);
   58|     78|}

avahi_key_new:
   43|    355|AvahiKey *avahi_key_new(const char *name, uint16_t class, uint16_t type) {
   44|    355|    AvahiKey *k;
   45|    355|    assert(name);
   46|       |
   47|    355|    if (!(k = avahi_new(AvahiKey, 1))) {
  ------------------
  |  |   54|    355|#define avahi_new(type, n) ((type*) avahi_new_internal((n), sizeof(type)))
  ------------------
  |  Branch (47:9): [True: 0, False: 355]
  ------------------
   48|      0|        avahi_log_error("avahi_new() failed.");
   49|      0|        return NULL;
   50|      0|    }
   51|       |
   52|    355|    if (!(k->name = avahi_normalize_name_strdup(name))) {
  ------------------
  |  Branch (52:9): [True: 78, False: 277]
  ------------------
   53|     78|        avahi_log_error("avahi_normalize_name() failed.");
   54|     78|        avahi_free(k);
   55|     78|        return NULL;
   56|     78|    }
   57|       |
   58|    277|    k->ref = 1;
   59|    277|    k->clazz = class;
   60|    277|    k->type = type;
   61|       |
   62|    277|    return k;
   63|    355|}
avahi_key_unref:
   86|    277|void avahi_key_unref(AvahiKey *k) {
   87|    277|    assert(k);
   88|      0|    assert(k->ref >= 1);
   89|       |
   90|    277|    if ((--k->ref) <= 0) {
  ------------------
  |  Branch (90:9): [True: 277, False: 0]
  ------------------
   91|    277|        avahi_free(k->name);
   92|    277|        avahi_free(k);
   93|    277|    }
   94|    277|}
avahi_dns_class_to_string:
  185|    277|const char *avahi_dns_class_to_string(uint16_t class) {
  186|    277|    if (class & AVAHI_DNS_CACHE_FLUSH)
  ------------------
  |  Branch (186:9): [True: 0, False: 277]
  ------------------
  187|      0|        return "FLUSH";
  188|       |
  189|    277|    switch (class) {
  190|      5|        case AVAHI_DNS_CLASS_IN:
  ------------------
  |  Branch (190:9): [True: 5, False: 272]
  ------------------
  191|      5|            return "IN";
  192|      3|        case AVAHI_DNS_CLASS_ANY:
  ------------------
  |  Branch (192:9): [True: 3, False: 274]
  ------------------
  193|      3|            return "ANY";
  194|    269|        default:
  ------------------
  |  Branch (194:9): [True: 269, False: 8]
  ------------------
  195|    269|            return NULL;
  196|    277|    }
  197|    277|}
avahi_dns_type_to_string:
  199|    277|const char *avahi_dns_type_to_string(uint16_t type) {
  200|    277|    switch (type) {
  201|      3|        case AVAHI_DNS_TYPE_CNAME:
  ------------------
  |  Branch (201:9): [True: 3, False: 274]
  ------------------
  202|      3|            return "CNAME";
  203|      7|        case AVAHI_DNS_TYPE_A:
  ------------------
  |  Branch (203:9): [True: 7, False: 270]
  ------------------
  204|      7|            return "A";
  205|      1|        case AVAHI_DNS_TYPE_AAAA:
  ------------------
  |  Branch (205:9): [True: 1, False: 276]
  ------------------
  206|      1|            return "AAAA";
  207|      1|        case AVAHI_DNS_TYPE_PTR:
  ------------------
  |  Branch (207:9): [True: 1, False: 276]
  ------------------
  208|      1|            return "PTR";
  209|      6|        case AVAHI_DNS_TYPE_HINFO:
  ------------------
  |  Branch (209:9): [True: 6, False: 271]
  ------------------
  210|      6|            return "HINFO";
  211|      3|        case AVAHI_DNS_TYPE_TXT:
  ------------------
  |  Branch (211:9): [True: 3, False: 274]
  ------------------
  212|      3|            return "TXT";
  213|      2|        case AVAHI_DNS_TYPE_SRV:
  ------------------
  |  Branch (213:9): [True: 2, False: 275]
  ------------------
  214|      2|            return "SRV";
  215|      4|        case AVAHI_DNS_TYPE_ANY:
  ------------------
  |  Branch (215:9): [True: 4, False: 273]
  ------------------
  216|      4|            return "ANY";
  217|      2|        case AVAHI_DNS_TYPE_SOA:
  ------------------
  |  Branch (217:9): [True: 2, False: 275]
  ------------------
  218|      2|            return "SOA";
  219|      1|        case AVAHI_DNS_TYPE_NS:
  ------------------
  |  Branch (219:9): [True: 1, False: 276]
  ------------------
  220|      1|            return "NS";
  221|    247|        default:
  ------------------
  |  Branch (221:9): [True: 247, False: 30]
  ------------------
  222|    247|            return NULL;
  223|    277|    }
  224|    277|}
avahi_key_to_string:
  226|    277|char *avahi_key_to_string(const AvahiKey *k) {
  227|    277|    char class[16], type[16];
  228|    277|    const char *c, *t;
  229|       |
  230|    277|    assert(k);
  231|      0|    assert(k->ref >= 1);
  232|       |
  233|       |    /* According to RFC3597 */
  234|       |
  235|    277|    if (!(c = avahi_dns_class_to_string(k->clazz))) {
  ------------------
  |  Branch (235:9): [True: 269, False: 8]
  ------------------
  236|    269|        snprintf(class, sizeof(class), "CLASS%u", k->clazz);
  237|    269|        c = class;
  238|    269|    }
  239|       |
  240|    277|    if (!(t = avahi_dns_type_to_string(k->type))) {
  ------------------
  |  Branch (240:9): [True: 247, False: 30]
  ------------------
  241|    247|        snprintf(type, sizeof(type), "TYPE%u", k->type);
  242|    247|        t = type;
  243|    247|    }
  244|       |
  245|    277|    return avahi_strdup_printf("%s\t%s\t%s", k->name, c, t);
  246|    277|}
avahi_key_is_valid:
  658|    554|int avahi_key_is_valid(AvahiKey *k) {
  659|    554|    assert(k);
  660|       |
  661|    554|    if (!avahi_is_valid_domain_name(k->name))
  ------------------
  |  Branch (661:9): [True: 0, False: 554]
  ------------------
  662|      0|        return 0;
  663|       |
  664|    554|    return 1;
  665|    554|}

log_function:
   27|     78|void log_function(AvahiLogLevel level, const char *txt) {}
LLVMFuzzerTestOneInput:
   29|    703|int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
   30|    703|    avahi_set_log_function(log_function);
   31|    703|    AvahiDnsPacket* packet = avahi_dns_packet_new(size + AVAHI_DNS_PACKET_EXTRA_SIZE);
  ------------------
  |  |   27|    703|#define AVAHI_DNS_PACKET_EXTRA_SIZE 48
  ------------------
   32|    703|    memcpy(AVAHI_DNS_PACKET_DATA(packet), data, size);
  ------------------
  |  |   38|    703|#define AVAHI_DNS_PACKET_DATA(p) ((p)->data ? (p)->data : ((uint8_t*) p) + sizeof(AvahiDnsPacket))
  |  |  ------------------
  |  |  |  Branch (38:35): [True: 0, False: 703]
  |  |  ------------------
  ------------------
   33|    703|    packet->size = size;
   34|    703|    AvahiKey* key = avahi_dns_packet_consume_key(packet, NULL);
   35|    703|    if (key) {
  ------------------
  |  Branch (35:9): [True: 277, False: 426]
  ------------------
   36|    277|        avahi_key_is_valid(key);
   37|    277|        char *s = avahi_key_to_string(key);
   38|    277|        avahi_free(s);
   39|    277|        avahi_key_unref(key);
   40|    277|    }
   41|    703|    avahi_dns_packet_free(packet);
   42|       |
   43|    703|    return 0;
   44|    703|}

