LLVMFuzzerTestOneInput:
   30|  4.59k|int LLVMFuzzerTestOneInput(const uint8_t *buf, size_t nr) {
   31|  4.59k|  log_init("/tmp/foo", 0, NULL);
   32|  4.59k|  struct regional* reg;
   33|       |
   34|  4.59k|  struct sldns_buffer *pkt = sldns_buffer_new(1);
   35|  4.59k|  sldns_buffer_new_frm_data(pkt, buf, nr);
   36|       |
   37|  4.59k|  reg = regional_create();
   38|       |
   39|  4.59k|  struct msg_parse msg;
   40|  4.59k|  struct edns_data edns;
   41|  4.59k|  memset(&msg, 0, sizeof(struct msg_parse));
   42|  4.59k|  memset(&edns, 0, sizeof(edns));
   43|       |
   44|  4.59k|  struct query_info qinfo_out;
   45|  4.59k|  memset(&qinfo_out, 0, sizeof(struct query_info));
   46|  4.59k|  qinfo_out.qname = (unsigned char *) "\03nic\02de";
   47|  4.59k|  uint8_t *peter = (unsigned char *) "\02de";   // zonename  
   48|  4.59k|  struct module_env env;
   49|  4.59k|  memset(&env, 0, sizeof(struct module_env));
   50|  4.59k|  struct config_file cfg;
   51|  4.59k|  memset(&cfg, 0, sizeof(struct config_file));
   52|       |
   53|  4.59k|  cfg.harden_glue = 0;    // crashes now, want to remove that later
   54|  4.59k|  env.cfg = &cfg;
   55|  4.59k|  cfg.rrset_cache_slabs = HASH_DEFAULT_SLABS;
  ------------------
  |  |   49|  4.59k|#define HASH_DEFAULT_SLABS 4
  ------------------
   56|  4.59k|  cfg.rrset_cache_size = HASH_DEFAULT_MAXMEM;
  ------------------
  |  |  116|  4.59k|#define HASH_DEFAULT_MAXMEM		4*1024*1024 /* bytes */
  ------------------
   57|       |
   58|  4.59k|  struct comm_base* base = comm_base_create(0);
   59|  4.59k|  comm_base_timept(base, &env.now, &env.now_tv);
   60|       |
   61|  4.59k|  env.alloc = malloc(sizeof(struct alloc_cache));
   62|  4.59k|  alloc_init(env.alloc, NULL, 0);
   63|       |
   64|  4.59k|  env.rrset_cache = rrset_cache_create(env.cfg, env.alloc);
   65|       |  
   66|       |
   67|  4.59k|  struct iter_env ie;
   68|  4.59k|  memset(&ie, 0, sizeof(struct iter_env));
   69|       |
   70|  4.59k|  struct iter_priv priv;
   71|  4.59k|  memset(&priv, 0, sizeof(struct iter_priv));
   72|  4.59k|  ie.priv = &priv;
   73|       |
   74|       |
   75|  4.59k|  if (parse_packet(pkt, &msg, reg) != LDNS_RCODE_NOERROR) {    
  ------------------
  |  Branch (75:7): [True: 2.57k, False: 2.02k]
  ------------------
   76|  2.57k|    goto out;
   77|  2.57k|  }
   78|  2.02k|  if (parse_extract_edns_from_response_msg(&msg, &edns, reg) != LDNS_RCODE_NOERROR) {
  ------------------
  |  Branch (78:7): [True: 4, False: 2.01k]
  ------------------
   79|      4|    goto out;
   80|      4|  }
   81|       |
   82|       |
   83|  2.01k|  scrub_message(pkt, &msg, &qinfo_out, peter, reg, &env, &ie);   
   84|       |
   85|  4.59k|out:
   86|  4.59k|  rrset_cache_delete(env.rrset_cache);
   87|  4.59k|  alloc_clear(env.alloc);
   88|  4.59k|  free(env.alloc);
   89|  4.59k|  comm_base_delete(base);
   90|  4.59k|  regional_destroy(reg);
   91|  4.59k|  sldns_buffer_free(pkt);
   92|  4.59k|  return 0;
   93|  2.01k|}

priv_rrset_bad:
  234|  12.9k|{
  235|  12.9k|	if(priv->a.count == 0) 
  ------------------
  |  Branch (235:5): [True: 12.9k, False: 0]
  ------------------
  236|  12.9k|		return 0; /* there are no blocked addresses */
  237|       |
  238|       |	/* see if it is a private name, that is allowed to have any */
  239|      0|	if(priv_lookup_name(priv, pkt, rrset->dname, rrset->dname_len,
  ------------------
  |  Branch (239:5): [True: 0, False: 0]
  ------------------
  240|      0|		ntohs(rrset->rrset_class))) {
  241|      0|		return 0;
  242|      0|	} else {
  243|       |		/* so its a public name, check the address */
  244|      0|		socklen_t len;
  245|      0|		struct rr_parse* rr, *prev = NULL;
  246|      0|		if(rrset->type == LDNS_RR_TYPE_A) {
  ------------------
  |  Branch (246:6): [True: 0, False: 0]
  ------------------
  247|      0|			struct sockaddr_storage addr;
  248|      0|			struct sockaddr_in sa;
  249|       |
  250|      0|			len = (socklen_t)sizeof(sa);
  251|      0|			memset(&sa, 0, len);
  252|      0|			sa.sin_family = AF_INET;
  253|      0|			sa.sin_port = (in_port_t)htons(UNBOUND_DNS_PORT);
  254|      0|			for(rr = rrset->rr_first; rr; rr = rr->next) {
  ------------------
  |  Branch (254:30): [True: 0, False: 0]
  ------------------
  255|      0|				if(sldns_read_uint16(rr->ttl_data+4) 
  ------------------
  |  Branch (255:8): [True: 0, False: 0]
  ------------------
  256|      0|					!= INET_SIZE) {
  ------------------
  |  |   87|      0|#define INET_SIZE 4
  ------------------
  257|      0|					prev = rr;
  258|      0|					continue;
  259|      0|				}
  260|      0|				memmove(&sa.sin_addr, rr->ttl_data+4+2, 
  261|      0|					INET_SIZE);
  ------------------
  |  |   87|      0|#define INET_SIZE 4
  ------------------
  262|      0|				memmove(&addr, &sa, len);
  263|      0|				if(priv_lookup_addr(priv, &addr, len)) {
  ------------------
  |  Branch (263:8): [True: 0, False: 0]
  ------------------
  264|      0|					if(remove_rr("sanitize: removing public name with private address", pkt, rrset, prev, &rr, &addr, len))
  ------------------
  |  Branch (264:9): [True: 0, False: 0]
  ------------------
  265|      0|						return 1;
  266|      0|					continue;
  267|      0|				}
  268|      0|				prev = rr;
  269|      0|			}
  270|      0|		} else if(rrset->type == LDNS_RR_TYPE_AAAA) {
  ------------------
  |  Branch (270:13): [True: 0, False: 0]
  ------------------
  271|      0|			struct sockaddr_storage addr;
  272|      0|			struct sockaddr_in6 sa;
  273|      0|			len = (socklen_t)sizeof(sa);
  274|      0|			memset(&sa, 0, len);
  275|      0|			sa.sin6_family = AF_INET6;
  276|      0|			sa.sin6_port = (in_port_t)htons(UNBOUND_DNS_PORT);
  277|      0|			for(rr = rrset->rr_first; rr; rr = rr->next) {
  ------------------
  |  Branch (277:30): [True: 0, False: 0]
  ------------------
  278|      0|				if(sldns_read_uint16(rr->ttl_data+4) 
  ------------------
  |  Branch (278:8): [True: 0, False: 0]
  ------------------
  279|      0|					!= INET6_SIZE) {
  ------------------
  |  |   89|      0|#define INET6_SIZE 16
  ------------------
  280|      0|					prev = rr;
  281|      0|					continue;
  282|      0|				}
  283|      0|				memmove(&sa.sin6_addr, rr->ttl_data+4+2, 
  284|      0|					INET6_SIZE);
  ------------------
  |  |   89|      0|#define INET6_SIZE 16
  ------------------
  285|      0|				memmove(&addr, &sa, len);
  286|      0|				if(priv_lookup_addr(priv, &addr, len)) {
  ------------------
  |  Branch (286:8): [True: 0, False: 0]
  ------------------
  287|      0|					if(remove_rr("sanitize: removing public name with private address", pkt, rrset, prev, &rr, &addr, len))
  ------------------
  |  Branch (287:9): [True: 0, False: 0]
  ------------------
  288|      0|						return 1;
  289|      0|					continue;
  290|      0|				}
  291|      0|				prev = rr;
  292|      0|			}
  293|      0|		} 
  294|      0|	}
  295|      0|	return 0;
  296|      0|}

scrub_message:
  858|  2.01k|{
  859|       |	/* basic sanity checks */
  860|  2.01k|	log_nametypeclass(VERB_ALGO, "scrub for", zonename, LDNS_RR_TYPE_NS, 
  861|  2.01k|		qinfo->qclass);
  862|  2.01k|	if(msg->qdcount > 1)
  ------------------
  |  Branch (862:5): [True: 0, False: 2.01k]
  ------------------
  863|      0|		return 0;
  864|  2.01k|	if( !(msg->flags&BIT_QR) )
  ------------------
  |  |   72|  2.01k|#define BIT_QR 0x8000
  ------------------
  |  Branch (864:6): [True: 81, False: 1.93k]
  ------------------
  865|     81|		return 0;
  866|  1.93k|	msg->flags &= ~(BIT_AD|BIT_Z); /* force off bit AD and Z */
  ------------------
  |  |   60|  1.93k|#define BIT_AD 0x0020
  ------------------
              	msg->flags &= ~(BIT_AD|BIT_Z); /* force off bit AD and Z */
  ------------------
  |  |   62|  1.93k|#define BIT_Z  0x0040
  ------------------
  867|       |	
  868|       |	/* make sure that a query is echoed back when NOERROR or NXDOMAIN */
  869|       |	/* this is not required for basic operation but is a forgery 
  870|       |	 * resistance (security) feature */
  871|  1.93k|	if((FLAGS_GET_RCODE(msg->flags) == LDNS_RCODE_NOERROR ||
  ------------------
  |  |   74|  1.93k|#define FLAGS_GET_RCODE(f) ((f) & 0xf)
  ------------------
  |  Branch (871:6): [True: 794, False: 1.14k]
  ------------------
  872|  1.93k|		FLAGS_GET_RCODE(msg->flags) == LDNS_RCODE_NXDOMAIN) &&
  ------------------
  |  |   74|  1.14k|#define FLAGS_GET_RCODE(f) ((f) & 0xf)
  ------------------
  |  Branch (872:3): [True: 166, False: 975]
  ------------------
  873|  1.93k|		msg->qdcount == 0)
  ------------------
  |  Branch (873:3): [True: 13, False: 947]
  ------------------
  874|     13|		return 0;
  875|       |
  876|       |	/* if a query is echoed back, make sure it is correct. Otherwise,
  877|       |	 * this may be not a reply to our query. */
  878|  1.92k|	if(msg->qdcount == 1) {
  ------------------
  |  Branch (878:5): [True: 1.01k, False: 904]
  ------------------
  879|  1.01k|		if(dname_pkt_compare(pkt, msg->qname, qinfo->qname) != 0)
  ------------------
  |  Branch (879:6): [True: 31, False: 987]
  ------------------
  880|     31|			return 0;
  881|    987|		if(msg->qtype != qinfo->qtype || msg->qclass != qinfo->qclass)
  ------------------
  |  Branch (881:6): [True: 28, False: 959]
  |  Branch (881:36): [True: 27, False: 932]
  ------------------
  882|     55|			return 0;
  883|    987|	}
  884|       |
  885|       |	/* normalize the response, this cleans up the additional.  */
  886|  1.83k|	if(!scrub_normalize(pkt, msg, qinfo, region, env))
  ------------------
  |  Branch (886:5): [True: 119, False: 1.71k]
  ------------------
  887|    119|		return 0;
  888|       |	/* delete all out-of-zone information */
  889|  1.71k|	if(!scrub_sanitize(pkt, msg, qinfo, zonename, env, ie))
  ------------------
  |  Branch (889:5): [True: 0, False: 1.71k]
  ------------------
  890|      0|		return 0;
  891|  1.71k|	return 1;
  892|  1.71k|}
iter_scrub.c:scrub_normalize:
  385|  1.83k|{
  386|  1.83k|	uint8_t* sname = qinfo->qname;
  387|  1.83k|	size_t snamelen = qinfo->qname_len;
  388|  1.83k|	struct rrset_parse* rrset, *prev, *nsset=NULL;
  389|       |
  390|  1.83k|	if(FLAGS_GET_RCODE(msg->flags) != LDNS_RCODE_NOERROR &&
  ------------------
  |  |   74|  1.83k|#define FLAGS_GET_RCODE(f) ((f) & 0xf)
  ------------------
  |  Branch (390:5): [True: 1.10k, False: 734]
  ------------------
  391|  1.83k|		FLAGS_GET_RCODE(msg->flags) != LDNS_RCODE_NXDOMAIN)
  ------------------
  |  |   74|  1.10k|#define FLAGS_GET_RCODE(f) ((f) & 0xf)
  ------------------
  |  Branch (391:3): [True: 947, False: 155]
  ------------------
  392|    947|		return 1;
  393|       |
  394|       |	/* For the ANSWER section, remove all "irrelevant" records and add
  395|       |	 * synthesized CNAMEs from DNAMEs
  396|       |	 * This will strip out-of-order CNAMEs as well. */
  397|       |
  398|       |	/* walk through the parse packet rrset list, keep track of previous
  399|       |	 * for insert and delete ease, and examine every RRset */
  400|    889|	prev = NULL;
  401|    889|	rrset = msg->rrset_first;
  402|  4.48k|	while(rrset && rrset->section == LDNS_SECTION_ANSWER) {
  ------------------
  |  Branch (402:8): [True: 4.24k, False: 232]
  |  Branch (402:17): [True: 3.71k, False: 538]
  ------------------
  403|  3.71k|		if(rrset->type == LDNS_RR_TYPE_DNAME && 
  ------------------
  |  Branch (403:6): [True: 1.03k, False: 2.67k]
  ------------------
  404|  3.71k|			pkt_strict_sub(pkt, sname, rrset->dname)) {
  ------------------
  |  Branch (404:4): [True: 676, False: 357]
  ------------------
  405|       |			/* check if next rrset is correct CNAME. else,
  406|       |			 * synthesize a CNAME */
  407|    676|			struct rrset_parse* nx = rrset->rrset_all_next;
  408|    676|			uint8_t alias[LDNS_MAX_DOMAINLEN+1];
  409|    676|			size_t aliaslen = 0;
  410|    676|			if(rrset->rr_count != 1) {
  ------------------
  |  Branch (410:7): [True: 7, False: 669]
  ------------------
  411|      7|				verbose(VERB_ALGO, "Found DNAME rrset with "
  412|      7|					"size > 1: %u", 
  413|      7|					(unsigned)rrset->rr_count);
  414|      7|				return 0;
  415|      7|			}
  416|    669|			if(!synth_cname(sname, snamelen, rrset, alias, 
  ------------------
  |  Branch (416:7): [True: 41, False: 628]
  ------------------
  417|    669|				&aliaslen, pkt)) {
  418|     41|				verbose(VERB_ALGO, "synthesized CNAME "
  419|     41|					"too long");
  420|     41|				return 0;
  421|     41|			}
  422|    628|			if(nx && nx->type == LDNS_RR_TYPE_CNAME && 
  ------------------
  |  Branch (422:7): [True: 583, False: 45]
  |  Branch (422:13): [True: 63, False: 520]
  ------------------
  423|    628|			   dname_pkt_compare(pkt, sname, nx->dname) == 0) {
  ------------------
  |  Branch (423:7): [True: 39, False: 24]
  ------------------
  424|       |				/* check next cname */
  425|     39|				uint8_t* t = NULL;
  426|     39|				size_t tlen = 0;
  427|     39|				if(!parse_get_cname_target(nx, &t, &tlen, pkt))
  ------------------
  |  Branch (427:8): [True: 3, False: 36]
  ------------------
  428|      3|					return 0;
  429|     36|				if(dname_pkt_compare(pkt, alias, t) == 0) {
  ------------------
  |  Branch (429:8): [True: 9, False: 27]
  ------------------
  430|       |					/* it's OK and better capitalized */
  431|      9|					prev = rrset;
  432|      9|					rrset = nx;
  433|      9|					continue;
  434|      9|				}
  435|       |				/* synth ourselves */
  436|     36|			}
  437|       |			/* synth a CNAME rrset */
  438|    616|			prev = synth_cname_rrset(&sname, &snamelen, alias, 
  439|    616|				aliaslen, region, msg, rrset, rrset, nx, pkt);
  440|    616|			if(!prev) {
  ------------------
  |  Branch (440:7): [True: 0, False: 616]
  ------------------
  441|      0|				log_err("out of memory synthesizing CNAME");
  442|      0|				return 0;
  443|      0|			}
  444|       |			/* FIXME: resolve the conflict between synthesized 
  445|       |			 * CNAME ttls and the cache. */
  446|    616|			rrset = nx;
  447|    616|			continue;
  448|       |
  449|    616|		}
  450|       |
  451|       |		/* The only records in the ANSWER section not allowed to */
  452|  3.03k|		if(dname_pkt_compare(pkt, sname, rrset->dname) != 0) {
  ------------------
  |  Branch (452:6): [True: 1.82k, False: 1.21k]
  ------------------
  453|  1.82k|			remove_rrset("normalize: removing irrelevant RRset:", 
  454|  1.82k|				pkt, msg, prev, &rrset);
  455|  1.82k|			continue;
  456|  1.82k|		}
  457|       |
  458|       |		/* Follow the CNAME chain. */
  459|  1.21k|		if(rrset->type == LDNS_RR_TYPE_CNAME) {
  ------------------
  |  Branch (459:6): [True: 508, False: 705]
  ------------------
  460|    508|			struct rrset_parse* nx = rrset->rrset_all_next;
  461|    508|			uint8_t* oldsname = sname;
  462|       |			/* see if the next one is a DNAME, if so, swap them */
  463|    508|			if(nx && nx->section == LDNS_SECTION_ANSWER &&
  ------------------
  |  Branch (463:7): [True: 479, False: 29]
  |  Branch (463:13): [True: 473, False: 6]
  ------------------
  464|    508|				nx->type == LDNS_RR_TYPE_DNAME &&
  ------------------
  |  Branch (464:5): [True: 272, False: 201]
  ------------------
  465|    508|				nx->rr_count == 1 &&
  ------------------
  |  Branch (465:5): [True: 258, False: 14]
  ------------------
  466|    508|				pkt_strict_sub(pkt, sname, nx->dname)) {
  ------------------
  |  Branch (466:5): [True: 195, False: 63]
  ------------------
  467|       |				/* there is a DNAME after this CNAME, it 
  468|       |				 * is in the ANSWER section, and the DNAME
  469|       |				 * applies to the name we cover */
  470|       |				/* check if the alias of the DNAME equals
  471|       |				 * this CNAME */
  472|    195|				uint8_t alias[LDNS_MAX_DOMAINLEN+1];
  473|    195|				size_t aliaslen = 0;
  474|    195|				uint8_t* t = NULL;
  475|    195|				size_t tlen = 0;
  476|    195|				if(synth_cname(sname, snamelen, nx, alias,
  ------------------
  |  Branch (476:8): [True: 65, False: 130]
  ------------------
  477|    195|					&aliaslen, pkt) &&
  478|    195|					parse_get_cname_target(rrset, &t, &tlen, pkt) &&
  ------------------
  |  Branch (478:6): [True: 55, False: 10]
  ------------------
  479|    195|			   		dname_pkt_compare(pkt, alias, t) == 0) {
  ------------------
  |  Branch (479:9): [True: 15, False: 40]
  ------------------
  480|       |					/* the synthesized CNAME equals the
  481|       |					 * current CNAME.  This CNAME is the
  482|       |					 * one that the DNAME creates, and this
  483|       |					 * CNAME is better capitalised */
  484|     15|					verbose(VERB_ALGO, "normalize: re-order of DNAME and its CNAME");
  485|     15|					if(prev) prev->rrset_all_next = nx;
  ------------------
  |  Branch (485:9): [True: 15, False: 0]
  ------------------
  486|      0|					else msg->rrset_first = nx;
  487|     15|					if(nx->rrset_all_next == NULL)
  ------------------
  |  Branch (487:9): [True: 3, False: 12]
  ------------------
  488|      3|						msg->rrset_last = rrset;
  489|     15|					rrset->rrset_all_next =
  490|     15|						nx->rrset_all_next;
  491|     15|					nx->rrset_all_next = rrset;
  492|       |					/* prev = nx; unused, enable if there
  493|       |					 * is other rrset removal code after
  494|       |					 * this */
  495|     15|				}
  496|    195|			}
  497|       |
  498|       |			/* move to next name in CNAME chain */
  499|    508|			if(!parse_get_cname_target(rrset, &sname, &snamelen, pkt))
  ------------------
  |  Branch (499:7): [True: 68, False: 440]
  ------------------
  500|     68|				return 0;
  501|    440|			prev = rrset;
  502|    440|			rrset = rrset->rrset_all_next;
  503|       |			/* in CNAME ANY response, can have data after CNAME */
  504|    440|			if(qinfo->qtype == LDNS_RR_TYPE_ANY) {
  ------------------
  |  Branch (504:7): [True: 0, False: 440]
  ------------------
  505|      0|				while(rrset && rrset->section ==
  ------------------
  |  Branch (505:11): [True: 0, False: 0]
  |  Branch (505:20): [True: 0, False: 0]
  ------------------
  506|      0|					LDNS_SECTION_ANSWER &&
  507|      0|					dname_pkt_compare(pkt, oldsname,
  ------------------
  |  Branch (507:6): [True: 0, False: 0]
  ------------------
  508|      0|					rrset->dname) == 0) {
  509|      0|					prev = rrset;
  510|      0|					rrset = rrset->rrset_all_next;
  511|      0|				}
  512|      0|			}
  513|    440|			continue;
  514|    508|		}
  515|       |
  516|       |		/* Otherwise, make sure that the RRset matches the qtype. */
  517|    705|		if(qinfo->qtype != LDNS_RR_TYPE_ANY && 
  ------------------
  |  Branch (517:6): [True: 705, False: 0]
  ------------------
  518|    705|			qinfo->qtype != rrset->type) {
  ------------------
  |  Branch (518:4): [True: 533, False: 172]
  ------------------
  519|    533|			remove_rrset("normalize: removing irrelevant RRset:", 
  520|    533|				pkt, msg, prev, &rrset);
  521|    533|			continue;
  522|    533|		}
  523|       |
  524|       |		/* Mark the additional names from relevant rrset as OK. */
  525|       |		/* only for RRsets that match the query name, other ones
  526|       |		 * will be removed by sanitize, so no additional for them */
  527|    172|		if(dname_pkt_compare(pkt, qinfo->qname, rrset->dname) == 0)
  ------------------
  |  Branch (527:6): [True: 31, False: 141]
  ------------------
  528|     31|			mark_additional_rrset(pkt, msg, rrset);
  529|       |		
  530|    172|		prev = rrset;
  531|    172|		rrset = rrset->rrset_all_next;
  532|    172|	}
  533|       |
  534|       |	/* Mark additional names from AUTHORITY */
  535|  11.7k|	while(rrset && rrset->section == LDNS_SECTION_AUTHORITY) {
  ------------------
  |  Branch (535:8): [True: 11.1k, False: 609]
  |  Branch (535:17): [True: 11.0k, False: 161]
  ------------------
  536|       |		/* protect internals of recursor by making sure to del these */
  537|  11.0k|		if(rrset->type==LDNS_RR_TYPE_DNAME ||
  ------------------
  |  Branch (537:6): [True: 123, False: 10.9k]
  ------------------
  538|  11.0k|			rrset->type==LDNS_RR_TYPE_CNAME ||
  ------------------
  |  Branch (538:4): [True: 168, False: 10.7k]
  ------------------
  539|  11.0k|			rrset->type==LDNS_RR_TYPE_A ||
  ------------------
  |  Branch (539:4): [True: 700, False: 10.0k]
  ------------------
  540|  11.0k|			rrset->type==LDNS_RR_TYPE_AAAA) {
  ------------------
  |  Branch (540:4): [True: 152, False: 9.88k]
  ------------------
  541|  1.14k|			remove_rrset("normalize: removing irrelevant "
  542|  1.14k|				"RRset:", pkt, msg, prev, &rrset);
  543|  1.14k|			continue;
  544|  1.14k|		}
  545|       |		/* Allowed list of types in the authority section */
  546|  9.88k|		if(env->cfg->harden_unknown_additional &&
  ------------------
  |  Branch (546:6): [True: 0, False: 9.88k]
  ------------------
  547|  9.88k|			!type_allowed_in_authority_section(rrset->type)) {
  ------------------
  |  Branch (547:4): [True: 0, False: 0]
  ------------------
  548|      0|			remove_rrset("normalize: removing irrelevant "
  549|      0|				"RRset:", pkt, msg, prev, &rrset);
  550|      0|			continue;
  551|      0|		}
  552|       |		/* only one NS set allowed in authority section */
  553|  9.88k|		if(rrset->type==LDNS_RR_TYPE_NS) {
  ------------------
  |  Branch (553:6): [True: 1.65k, False: 8.23k]
  ------------------
  554|       |			/* NS set must be pertinent to the query */
  555|  1.65k|			if(!sub_of_pkt(pkt, qinfo->qname, rrset->dname)) {
  ------------------
  |  Branch (555:7): [True: 210, False: 1.44k]
  ------------------
  556|    210|				remove_rrset("normalize: removing irrelevant "
  557|    210|					"RRset:", pkt, msg, prev, &rrset);
  558|    210|				continue;
  559|    210|			}
  560|       |			/* we don't want NS sets for NXDOMAIN answers,
  561|       |			 * because they could contain poisonous contents,
  562|       |			 * from. eg. fragmentation attacks, inserted after
  563|       |			 * long RRSIGs in the packet get to the packet
  564|       |			 * border and such */
  565|       |			/* also for NODATA answers */
  566|  1.44k|			if(FLAGS_GET_RCODE(msg->flags) == LDNS_RCODE_NXDOMAIN ||
  ------------------
  |  |   74|  1.44k|#define FLAGS_GET_RCODE(f) ((f) & 0xf)
  ------------------
  |  Branch (566:7): [True: 298, False: 1.14k]
  ------------------
  567|  1.44k|			   (FLAGS_GET_RCODE(msg->flags) == LDNS_RCODE_NOERROR
  ------------------
  |  |   74|  1.14k|#define FLAGS_GET_RCODE(f) ((f) & 0xf)
  ------------------
  |  Branch (567:8): [True: 1.14k, False: 0]
  ------------------
  568|  1.14k|			    && soa_in_auth(msg) && msg->an_rrsets == 0)) {
  ------------------
  |  Branch (568:11): [True: 669, False: 475]
  |  Branch (568:31): [True: 327, False: 342]
  ------------------
  569|    625|				remove_rrset("normalize: removing irrelevant "
  570|    625|					"RRset:", pkt, msg, prev, &rrset);
  571|    625|				continue;
  572|    625|			}
  573|    817|			if(nsset == NULL) {
  ------------------
  |  Branch (573:7): [True: 151, False: 666]
  ------------------
  574|    151|				nsset = rrset;
  575|    666|			} else {
  576|    666|				remove_rrset("normalize: removing irrelevant "
  577|    666|					"RRset:", pkt, msg, prev, &rrset);
  578|    666|				continue;
  579|    666|			}
  580|    817|		}
  581|       |		/* if this is type DS and we query for type DS we just got
  582|       |		 * a referral answer for our type DS query, fix packet */
  583|  8.38k|		if(rrset->type==LDNS_RR_TYPE_DS &&
  ------------------
  |  Branch (583:6): [True: 81, False: 8.30k]
  ------------------
  584|  8.38k|			qinfo->qtype == LDNS_RR_TYPE_DS &&
  ------------------
  |  Branch (584:4): [True: 0, False: 81]
  ------------------
  585|  8.38k|			dname_pkt_compare(pkt, qinfo->qname, rrset->dname) == 0) {
  ------------------
  |  Branch (585:4): [True: 0, False: 0]
  ------------------
  586|      0|			rrset->section = LDNS_SECTION_ANSWER;
  587|      0|			msg->ancount = rrset->rr_count + rrset->rrsig_count;
  588|      0|			msg->nscount = 0;
  589|      0|			msg->arcount = 0;
  590|      0|			msg->an_rrsets = 1;
  591|      0|			msg->ns_rrsets = 0;
  592|      0|			msg->ar_rrsets = 0;
  593|      0|			msg->rrset_count = 1;
  594|      0|			msg->rrset_first = rrset;
  595|      0|			msg->rrset_last = rrset;
  596|      0|			rrset->rrset_all_next = NULL;
  597|      0|			return 1;
  598|      0|		}
  599|  8.38k|		mark_additional_rrset(pkt, msg, rrset);
  600|  8.38k|		prev = rrset;
  601|  8.38k|		rrset = rrset->rrset_all_next;
  602|  8.38k|	}
  603|       |
  604|       |	/* For each record in the additional section, remove it if it is an
  605|       |	 * address record and not in the collection of additional names 
  606|       |	 * found in ANSWER and AUTHORITY. */
  607|       |	/* These records have not been marked OK previously */
  608|  3.57k|	while(rrset && rrset->section == LDNS_SECTION_ADDITIONAL) {
  ------------------
  |  Branch (608:8): [True: 2.80k, False: 770]
  |  Branch (608:17): [True: 2.80k, False: 0]
  ------------------
  609|  2.80k|		if(rrset->type==LDNS_RR_TYPE_A || 
  ------------------
  |  Branch (609:6): [True: 532, False: 2.27k]
  ------------------
  610|  2.80k|			rrset->type==LDNS_RR_TYPE_AAAA) 
  ------------------
  |  Branch (610:4): [True: 160, False: 2.11k]
  ------------------
  611|    692|		{
  612|    692|			if((rrset->flags & RRSET_SCRUB_OK)) {
  ------------------
  |  |   59|    692|#define RRSET_SCRUB_OK	0x80
  ------------------
  |  Branch (612:7): [True: 75, False: 617]
  ------------------
  613|       |				/* remove flag to clean up flags variable */
  614|     75|				rrset->flags &= ~RRSET_SCRUB_OK;
  ------------------
  |  |   59|     75|#define RRSET_SCRUB_OK	0x80
  ------------------
  615|    617|			} else {
  616|    617|				remove_rrset("normalize: removing irrelevant "
  617|    617|					"RRset:", pkt, msg, prev, &rrset);
  618|    617|				continue;
  619|    617|			}
  620|    692|		}
  621|       |		/* protect internals of recursor by making sure to del these */
  622|  2.18k|		if(rrset->type==LDNS_RR_TYPE_DNAME || 
  ------------------
  |  Branch (622:6): [True: 93, False: 2.09k]
  ------------------
  623|  2.18k|			rrset->type==LDNS_RR_TYPE_CNAME ||
  ------------------
  |  Branch (623:4): [True: 87, False: 2.00k]
  ------------------
  624|  2.18k|			rrset->type==LDNS_RR_TYPE_NS) {
  ------------------
  |  Branch (624:4): [True: 216, False: 1.79k]
  ------------------
  625|    396|			remove_rrset("normalize: removing irrelevant "
  626|    396|				"RRset:", pkt, msg, prev, &rrset);
  627|    396|			continue;
  628|    396|		}
  629|       |		/* Allowed list of types in the additional section */
  630|  1.79k|		if(env->cfg->harden_unknown_additional &&
  ------------------
  |  Branch (630:6): [True: 0, False: 1.79k]
  ------------------
  631|  1.79k|			!type_allowed_in_additional_section(rrset->type)) {
  ------------------
  |  Branch (631:4): [True: 0, False: 0]
  ------------------
  632|      0|			remove_rrset("normalize: removing irrelevant "
  633|      0|				"RRset:", pkt, msg, prev, &rrset);
  634|      0|			continue;
  635|      0|		}
  636|  1.79k|		prev = rrset;
  637|  1.79k|		rrset = rrset->rrset_all_next;
  638|  1.79k|	}
  639|       |	
  640|    770|	return 1;
  641|    770|}
iter_scrub.c:pkt_strict_sub:
  310|  1.33k|{
  311|  1.33k|	uint8_t buf1[LDNS_MAX_DOMAINLEN+1];
  312|  1.33k|	uint8_t buf2[LDNS_MAX_DOMAINLEN+1];
  313|       |	/* decompress names */
  314|  1.33k|	dname_pkt_copy(pkt, buf1, sname);
  315|  1.33k|	dname_pkt_copy(pkt, buf2, dr);
  316|  1.33k|	return dname_strict_subdomain_c(buf1, buf2);
  317|  1.33k|}
iter_scrub.c:synth_cname:
  228|    864|{
  229|       |	/* we already know that sname is a strict subdomain of DNAME owner */
  230|    864|	uint8_t* dtarg = NULL;
  231|    864|	size_t dtarglen;
  232|    864|	if(!parse_get_cname_target(dname_rrset, &dtarg, &dtarglen, pkt))
  ------------------
  |  Branch (232:5): [True: 53, False: 811]
  ------------------
  233|     53|		return 0; 
  234|    811|	if(qnamelen <= dname_rrset->dname_len)
  ------------------
  |  Branch (234:5): [True: 105, False: 706]
  ------------------
  235|    105|		return 0;
  236|    706|	if(qnamelen == 0)
  ------------------
  |  Branch (236:5): [True: 0, False: 706]
  ------------------
  237|      0|		return 0;
  238|    706|	log_assert(qnamelen > dname_rrset->dname_len);
  239|       |	/* DNAME from com. to net. with qname example.com. -> example.net. */
  240|       |	/* so: \3com\0 to \3net\0 and qname \7example\3com\0 */
  241|    706|	*aliaslen = qnamelen + dtarglen - dname_rrset->dname_len;
  242|    706|	if(*aliaslen > LDNS_MAX_DOMAINLEN)
  ------------------
  |  |   29|    706|#define LDNS_MAX_DOMAINLEN    255
  ------------------
  |  Branch (242:5): [True: 13, False: 693]
  ------------------
  243|     13|		return 0; /* should have been RCODE YXDOMAIN */
  244|       |	/* decompress dnames into buffer, we know it fits */
  245|    693|	dname_pkt_copy(pkt, alias, qname);
  246|    693|	dname_pkt_copy(pkt, alias+(qnamelen-dname_rrset->dname_len), dtarg);
  247|    693|	return 1;
  248|    706|}
iter_scrub.c:parse_get_cname_target:
  189|  1.47k|{
  190|  1.47k|	size_t oldpos, dlen;
  191|  1.47k|	if(rrset->rr_count != 1) {
  ------------------
  |  Branch (191:5): [True: 71, False: 1.40k]
  ------------------
  192|     71|		struct rr_parse* sig;
  193|     71|		verbose(VERB_ALGO, "Found CNAME rrset with "
  194|     71|			"size > 1: %u", (unsigned)rrset->rr_count);
  195|       |		/* use the first CNAME! */
  196|     71|		rrset->rr_count = 1;
  197|     71|		rrset->size = rrset->rr_first->size;
  198|    346|		for(sig=rrset->rrsig_first; sig; sig=sig->next)
  ------------------
  |  Branch (198:31): [True: 275, False: 71]
  ------------------
  199|    275|			rrset->size += sig->size;
  200|     71|		rrset->rr_last = rrset->rr_first;
  201|     71|		rrset->rr_first->next = NULL;
  202|     71|	}
  203|  1.47k|	if(rrset->rr_first->size < sizeof(uint16_t)+1)
  ------------------
  |  Branch (203:5): [True: 134, False: 1.34k]
  ------------------
  204|    134|		return 0; /* CNAME rdata too small */
  205|  1.34k|	*sname = rrset->rr_first->ttl_data + sizeof(uint32_t)
  206|  1.34k|		+ sizeof(uint16_t); /* skip ttl, rdatalen */
  207|  1.34k|	*snamelen = rrset->rr_first->size - sizeof(uint16_t);
  208|       |
  209|  1.34k|	if(rrset->rr_first->outside_packet) {
  ------------------
  |  Branch (209:5): [True: 0, False: 1.34k]
  ------------------
  210|      0|		if(!dname_valid(*sname, *snamelen))
  ------------------
  |  Branch (210:6): [True: 0, False: 0]
  ------------------
  211|      0|			return 0;
  212|      0|		return 1;
  213|      0|	}
  214|  1.34k|	oldpos = sldns_buffer_position(pkt);
  215|  1.34k|	sldns_buffer_set_position(pkt, (size_t)(*sname - sldns_buffer_begin(pkt)));
  216|  1.34k|	dlen = pkt_dname_len(pkt);
  217|  1.34k|	sldns_buffer_set_position(pkt, oldpos);
  218|  1.34k|	if(dlen == 0)
  ------------------
  |  Branch (218:5): [True: 0, False: 1.34k]
  ------------------
  219|      0|		return 0; /* parse fail on the rdata name */
  220|  1.34k|	*snamelen = dlen;
  221|  1.34k|	return 1;
  222|  1.34k|}
iter_scrub.c:synth_cname_rrset:
  256|    616|{
  257|    616|	struct rrset_parse* cn = (struct rrset_parse*)regional_alloc(region,
  258|    616|		sizeof(struct rrset_parse));
  259|    616|	if(!cn)
  ------------------
  |  Branch (259:5): [True: 0, False: 616]
  ------------------
  260|      0|		return NULL;
  261|    616|	memset(cn, 0, sizeof(*cn));
  262|    616|	cn->rr_first = (struct rr_parse*)regional_alloc(region, 
  263|    616|		sizeof(struct rr_parse));
  264|    616|	if(!cn->rr_first)
  ------------------
  |  Branch (264:5): [True: 0, False: 616]
  ------------------
  265|      0|		return NULL;
  266|    616|	cn->rr_last = cn->rr_first;
  267|       |	/* CNAME from sname to alias */
  268|    616|	cn->dname = (uint8_t*)regional_alloc(region, *snamelen);
  269|    616|	if(!cn->dname)
  ------------------
  |  Branch (269:5): [True: 0, False: 616]
  ------------------
  270|      0|		return NULL;
  271|    616|	dname_pkt_copy(pkt, cn->dname, *sname);
  272|    616|	cn->dname_len = *snamelen;
  273|    616|	cn->type = LDNS_RR_TYPE_CNAME;
  274|    616|	cn->section = rrset->section;
  275|    616|	cn->rrset_class = rrset->rrset_class;
  276|    616|	cn->rr_count = 1;
  277|    616|	cn->size = sizeof(uint16_t) + aliaslen;
  278|    616|	cn->hash=pkt_hash_rrset(pkt, cn->dname, cn->type, cn->rrset_class, 0);
  279|       |	/* allocate TTL + rdatalen + uncompressed dname */
  280|    616|	memset(cn->rr_first, 0, sizeof(struct rr_parse));
  281|    616|	cn->rr_first->outside_packet = 1;
  282|    616|	cn->rr_first->ttl_data = (uint8_t*)regional_alloc(region, 
  283|    616|		sizeof(uint32_t)+sizeof(uint16_t)+aliaslen);
  284|    616|	if(!cn->rr_first->ttl_data)
  ------------------
  |  Branch (284:5): [True: 0, False: 616]
  ------------------
  285|      0|		return NULL;
  286|    616|	sldns_write_uint32(cn->rr_first->ttl_data, 0); /* TTL = 0 */
  287|    616|	sldns_write_uint16(cn->rr_first->ttl_data+4, aliaslen);
  288|    616|	memmove(cn->rr_first->ttl_data+6, alias, aliaslen);
  289|    616|	cn->rr_first->size = sizeof(uint16_t)+aliaslen;
  290|       |
  291|       |	/* link it in */
  292|    616|	cn->rrset_all_next = nx;
  293|    616|	if(prev)
  ------------------
  |  Branch (293:5): [True: 616, False: 0]
  ------------------
  294|    616|		prev->rrset_all_next = cn;
  295|      0|	else	msg->rrset_first = cn;
  296|    616|	if(nx == NULL)
  ------------------
  |  Branch (296:5): [True: 45, False: 571]
  ------------------
  297|     45|		msg->rrset_last = cn;
  298|    616|	msg->rrset_count ++;
  299|    616|	msg->an_rrsets++;
  300|       |	/* it is not inserted in the msg hashtable. */
  301|       |
  302|    616|	*sname = cn->rr_first->ttl_data + sizeof(uint32_t)+sizeof(uint16_t);
  303|    616|	*snamelen = aliaslen;
  304|    616|	return cn;
  305|    616|}
iter_scrub.c:remove_rrset:
   65|  51.0k|{
   66|  51.0k|	if(verbosity >= VERB_QUERY && str
  ------------------
  |  Branch (66:5): [True: 0, False: 51.0k]
  |  Branch (66:32): [True: 0, False: 0]
  ------------------
   67|  51.0k|		&& (*rrset)->dname_len <= LDNS_MAX_DOMAINLEN) {
  ------------------
  |  |   29|      0|#define LDNS_MAX_DOMAINLEN    255
  ------------------
  |  Branch (67:6): [True: 0, False: 0]
  ------------------
   68|      0|		uint8_t buf[LDNS_MAX_DOMAINLEN+1];
   69|      0|		dname_pkt_copy(pkt, buf, (*rrset)->dname);
   70|      0|		log_nametypeclass(VERB_QUERY, str, buf, 
   71|      0|			(*rrset)->type, ntohs((*rrset)->rrset_class));
   72|      0|	}
   73|  51.0k|	if(prev)
  ------------------
  |  Branch (73:5): [True: 16.8k, False: 34.2k]
  ------------------
   74|  16.8k|		prev->rrset_all_next = (*rrset)->rrset_all_next;
   75|  34.2k|	else	msg->rrset_first = (*rrset)->rrset_all_next;
   76|  51.0k|	if(msg->rrset_last == *rrset)
  ------------------
  |  Branch (76:5): [True: 1.64k, False: 49.4k]
  ------------------
   77|  1.64k|		msg->rrset_last = prev;
   78|  51.0k|	msg->rrset_count --;
   79|  51.0k|	switch((*rrset)->section) {
   80|  5.96k|		case LDNS_SECTION_ANSWER: msg->an_rrsets--; break;
  ------------------
  |  Branch (80:3): [True: 5.96k, False: 45.1k]
  ------------------
   81|  21.5k|		case LDNS_SECTION_AUTHORITY: msg->ns_rrsets--; break;
  ------------------
  |  Branch (81:3): [True: 21.5k, False: 29.5k]
  ------------------
   82|  23.5k|		case LDNS_SECTION_ADDITIONAL: msg->ar_rrsets--; break;
  ------------------
  |  Branch (82:3): [True: 23.5k, False: 27.4k]
  ------------------
   83|      0|		default: log_assert(0);
  ------------------
  |  Branch (83:3): [True: 0, False: 51.0k]
  ------------------
   84|  51.0k|	}
   85|  51.0k|	msgparse_bucket_remove(msg, *rrset);
   86|  51.0k|	*rrset = (*rrset)->rrset_all_next;
   87|  51.0k|}
iter_scrub.c:mark_additional_rrset:
  153|  8.41k|{
  154|       |	/* Mark A and AAAA for NS as appropriate additional section info. */
  155|  8.41k|	uint8_t* nm = NULL;
  156|  8.41k|	size_t nmlen = 0;
  157|  8.41k|	struct rr_parse* rr;
  158|       |
  159|  8.41k|	if(!has_additional(rrset->type))
  ------------------
  |  Branch (159:5): [True: 6.43k, False: 1.97k]
  ------------------
  160|  6.43k|		return;
  161|  8.86k|	for(rr = rrset->rr_first; rr; rr = rr->next) {
  ------------------
  |  Branch (161:28): [True: 6.88k, False: 1.97k]
  ------------------
  162|  6.88k|		if(get_additional_name(rrset, rr, &nm, &nmlen, pkt)) {
  ------------------
  |  Branch (162:6): [True: 2.39k, False: 4.49k]
  ------------------
  163|       |			/* mark A */
  164|  2.39k|			hashvalue_type h = pkt_hash_rrset(pkt, nm,
  165|  2.39k|				LDNS_RR_TYPE_A, rrset->rrset_class, 0);
  166|  2.39k|			struct rrset_parse* r = msgparse_hashtable_lookup(
  167|  2.39k|				msg, pkt, h, 0, nm, nmlen, 
  168|  2.39k|				LDNS_RR_TYPE_A, rrset->rrset_class);
  169|  2.39k|			if(r && r->section == LDNS_SECTION_ADDITIONAL) {
  ------------------
  |  Branch (169:7): [True: 767, False: 1.62k]
  |  Branch (169:12): [True: 43, False: 724]
  ------------------
  170|     43|				r->flags |= RRSET_SCRUB_OK;
  ------------------
  |  |   59|     43|#define RRSET_SCRUB_OK	0x80
  ------------------
  171|     43|			}
  172|       |			
  173|       |			/* mark AAAA */
  174|  2.39k|			h = pkt_hash_rrset(pkt, nm, LDNS_RR_TYPE_AAAA, 
  175|  2.39k|				rrset->rrset_class, 0);
  176|  2.39k|			r = msgparse_hashtable_lookup(msg, pkt, h, 0, nm, 
  177|  2.39k|				nmlen, LDNS_RR_TYPE_AAAA, rrset->rrset_class);
  178|  2.39k|			if(r && r->section == LDNS_SECTION_ADDITIONAL) {
  ------------------
  |  Branch (178:7): [True: 335, False: 2.05k]
  |  Branch (178:12): [True: 32, False: 303]
  ------------------
  179|     32|				r->flags |= RRSET_SCRUB_OK;
  ------------------
  |  |   59|     32|#define RRSET_SCRUB_OK	0x80
  ------------------
  180|     32|			}
  181|  2.39k|		}
  182|  6.88k|	}
  183|  1.97k|}
iter_scrub.c:has_additional:
   92|  39.8k|{
   93|  39.8k|	switch(t) {
  ------------------
  |  Branch (93:9): [True: 33.4k, False: 6.44k]
  ------------------
   94|  1.31k|		case LDNS_RR_TYPE_MB:
  ------------------
  |  Branch (94:3): [True: 1.31k, False: 38.5k]
  ------------------
   95|  1.94k|		case LDNS_RR_TYPE_MD:
  ------------------
  |  Branch (95:3): [True: 630, False: 39.2k]
  ------------------
   96|  2.97k|		case LDNS_RR_TYPE_MF:
  ------------------
  |  Branch (96:3): [True: 1.02k, False: 38.8k]
  ------------------
   97|  4.39k|		case LDNS_RR_TYPE_NS:
  ------------------
  |  Branch (97:3): [True: 1.42k, False: 38.4k]
  ------------------
   98|  4.74k|		case LDNS_RR_TYPE_MX:
  ------------------
  |  Branch (98:3): [True: 349, False: 39.5k]
  ------------------
   99|  5.11k|		case LDNS_RR_TYPE_KX:
  ------------------
  |  Branch (99:3): [True: 371, False: 39.4k]
  ------------------
  100|  6.21k|		case LDNS_RR_TYPE_SRV:
  ------------------
  |  Branch (100:3): [True: 1.09k, False: 38.7k]
  ------------------
  101|  6.21k|			return 1;
  102|    231|		case LDNS_RR_TYPE_NAPTR:
  ------------------
  |  Branch (102:3): [True: 231, False: 39.6k]
  ------------------
  103|       |			/* TODO: NAPTR not supported, glue stripped off */
  104|    231|			return 0;
  105|  39.8k|	}
  106|  33.4k|	return 0;
  107|  39.8k|}
iter_scrub.c:get_additional_name:
  113|  6.88k|{
  114|  6.88k|	size_t offset = 0;
  115|  6.88k|	size_t len, oldpos;
  116|  6.88k|	switch(rrset->type) {
  117|  2.63k|		case LDNS_RR_TYPE_MB:
  ------------------
  |  Branch (117:3): [True: 2.63k, False: 4.25k]
  ------------------
  118|  3.13k|		case LDNS_RR_TYPE_MD:
  ------------------
  |  Branch (118:3): [True: 501, False: 6.38k]
  ------------------
  119|  4.58k|		case LDNS_RR_TYPE_MF:
  ------------------
  |  Branch (119:3): [True: 1.45k, False: 5.43k]
  ------------------
  120|  5.15k|		case LDNS_RR_TYPE_NS:
  ------------------
  |  Branch (120:3): [True: 562, False: 6.32k]
  ------------------
  121|  5.15k|			offset = 0;
  122|  5.15k|			break;
  123|    412|		case LDNS_RR_TYPE_MX:
  ------------------
  |  Branch (123:3): [True: 412, False: 6.47k]
  ------------------
  124|    759|		case LDNS_RR_TYPE_KX:
  ------------------
  |  Branch (124:3): [True: 347, False: 6.54k]
  ------------------
  125|    759|			offset = 2;
  126|    759|			break;
  127|    980|		case LDNS_RR_TYPE_SRV:
  ------------------
  |  Branch (127:3): [True: 980, False: 5.90k]
  ------------------
  128|    980|			offset = 6;
  129|    980|			break;
  130|      0|		case LDNS_RR_TYPE_NAPTR:
  ------------------
  |  Branch (130:3): [True: 0, False: 6.88k]
  ------------------
  131|       |			/* TODO: NAPTR not supported, glue stripped off */
  132|      0|			return 0;
  133|      0|		default:
  ------------------
  |  Branch (133:3): [True: 0, False: 6.88k]
  ------------------
  134|      0|			return 0;
  135|  6.88k|	}
  136|  6.88k|	len = sldns_read_uint16(rr->ttl_data+sizeof(uint32_t));
  137|  6.88k|	if(len < offset+1)
  ------------------
  |  Branch (137:5): [True: 4.49k, False: 2.39k]
  ------------------
  138|  4.49k|		return 0; /* rdata field too small */
  139|  2.39k|	*nm = rr->ttl_data+sizeof(uint32_t)+sizeof(uint16_t)+offset;
  140|  2.39k|	oldpos = sldns_buffer_position(pkt);
  141|  2.39k|	sldns_buffer_set_position(pkt, (size_t)(*nm - sldns_buffer_begin(pkt)));
  142|  2.39k|	*nmlen = pkt_dname_len(pkt);
  143|  2.39k|	sldns_buffer_set_position(pkt, oldpos);
  144|  2.39k|	if(*nmlen == 0)
  ------------------
  |  Branch (144:5): [True: 0, False: 2.39k]
  ------------------
  145|      0|		return 0;
  146|  2.39k|	return 1;
  147|  2.39k|}
iter_scrub.c:sub_of_pkt:
  331|  1.78k|{
  332|  1.78k|	uint8_t buf[LDNS_MAX_DOMAINLEN+1];
  333|  1.78k|	dname_pkt_copy(pkt, buf, comprname);
  334|  1.78k|	return dname_subdomain_c(zone, buf);
  335|  1.78k|}
iter_scrub.c:soa_in_auth:
  340|  1.27k|{
  341|  1.27k|	struct rrset_parse* rrset;
  342|   120k|	for(rrset = msg->rrset_first; rrset; rrset = rrset->rrset_all_next)
  ------------------
  |  Branch (342:32): [True: 120k, False: 608]
  ------------------
  343|   120k|		if(rrset->type == LDNS_RR_TYPE_SOA &&
  ------------------
  |  Branch (343:6): [True: 969, False: 119k]
  ------------------
  344|   120k|			rrset->section == LDNS_SECTION_AUTHORITY) 
  ------------------
  |  Branch (344:4): [True: 669, False: 300]
  ------------------
  345|    669|			return 1;
  346|    608|	return 0;
  347|  1.27k|}
iter_scrub.c:scrub_sanitize:
  737|  1.71k|{
  738|  1.71k|	int del_addi = 0; /* if additional-holding rrsets are deleted, we
  739|       |		do not trust the normalized additional-A-AAAA any more */
  740|  1.71k|	struct rrset_parse* rrset, *prev;
  741|  1.71k|	prev = NULL;
  742|  1.71k|	rrset = msg->rrset_first;
  743|       |
  744|       |	/* the first DNAME is allowed to stay. It needs checking before
  745|       |	 * it can be used from the cache. After normalization, an initial 
  746|       |	 * DNAME will have a correctly synthesized CNAME after it. */
  747|  1.71k|	if(rrset && rrset->type == LDNS_RR_TYPE_DNAME && 
  ------------------
  |  Branch (747:5): [True: 1.49k, False: 219]
  |  Branch (747:14): [True: 56, False: 1.44k]
  ------------------
  748|  1.71k|		rrset->section == LDNS_SECTION_ANSWER &&
  ------------------
  |  Branch (748:3): [True: 41, False: 15]
  ------------------
  749|  1.71k|		pkt_strict_sub(pkt, qinfo->qname, rrset->dname) &&
  ------------------
  |  Branch (749:3): [True: 21, False: 20]
  ------------------
  750|  1.71k|		pkt_sub(pkt, rrset->dname, zonename)) {
  ------------------
  |  Branch (750:3): [True: 14, False: 7]
  ------------------
  751|     14|		prev = rrset; /* DNAME allowed to stay in answer section */
  752|     14|		rrset = rrset->rrset_all_next;
  753|     14|	}
  754|       |	
  755|       |	/* remove all records from the answer section that are 
  756|       |	 * not the same domain name as the query domain name.
  757|       |	 * The answer section should contain rrsets with the same name
  758|       |	 * as the question. For DNAMEs a CNAME has been synthesized.
  759|       |	 * Wildcards have the query name in answer section.
  760|       |	 * ANY queries get query name in answer section.
  761|       |	 * Remainders of CNAME chains are cut off and resolved by iterator. */
  762|  5.78k|	while(rrset && rrset->section == LDNS_SECTION_ANSWER) {
  ------------------
  |  Branch (762:8): [True: 5.28k, False: 498]
  |  Branch (762:17): [True: 4.06k, False: 1.21k]
  ------------------
  763|  4.06k|		if(dname_pkt_compare(pkt, qinfo->qname, rrset->dname) != 0) {
  ------------------
  |  Branch (763:6): [True: 3.58k, False: 480]
  ------------------
  764|  3.58k|			if(has_additional(rrset->type)) del_addi = 1;
  ------------------
  |  Branch (764:7): [True: 368, False: 3.22k]
  ------------------
  765|  3.58k|			remove_rrset("sanitize: removing extraneous answer "
  766|  3.58k|				"RRset:", pkt, msg, prev, &rrset);
  767|  3.58k|			continue;
  768|  3.58k|		}
  769|    480|		prev = rrset;
  770|    480|		rrset = rrset->rrset_all_next;
  771|    480|	}
  772|       |
  773|       |	/* At this point, we brutally remove ALL rrsets that aren't 
  774|       |	 * children of the originating zone. The idea here is that, 
  775|       |	 * as far as we know, the server that we contacted is ONLY 
  776|       |	 * authoritative for the originating zone. It, of course, MAY 
  777|       |	 * be authoritative for any other zones, and of course, MAY 
  778|       |	 * NOT be authoritative for some subdomains of the originating 
  779|       |	 * zone. */
  780|  1.71k|	prev = NULL;
  781|  1.71k|	rrset = msg->rrset_first;
  782|  45.0k|	while(rrset) {
  ------------------
  |  Branch (782:8): [True: 43.3k, False: 1.71k]
  ------------------
  783|       |
  784|       |		/* remove private addresses */
  785|  43.3k|		if( (rrset->type == LDNS_RR_TYPE_A || 
  ------------------
  |  Branch (785:8): [True: 11.3k, False: 32.0k]
  ------------------
  786|  43.3k|			rrset->type == LDNS_RR_TYPE_AAAA)) {
  ------------------
  |  Branch (786:4): [True: 1.66k, False: 30.3k]
  ------------------
  787|       |
  788|       |			/* do not set servfail since this leads to too
  789|       |			 * many drops of other people using rfc1918 space */
  790|       |			/* also do not remove entire rrset, unless all records
  791|       |			 * in it are bad */
  792|  12.9k|			if(priv_rrset_bad(ie->priv, pkt, rrset)) {
  ------------------
  |  Branch (792:7): [True: 0, False: 12.9k]
  ------------------
  793|      0|				remove_rrset(NULL, pkt, msg, prev, &rrset);
  794|      0|				continue;
  795|      0|			}
  796|  12.9k|		}
  797|       |		
  798|       |		/* skip DNAME records -- they will always be followed by a 
  799|       |		 * synthesized CNAME, which will be relevant.
  800|       |		 * FIXME: should this do something differently with DNAME 
  801|       |		 * rrsets NOT in Section.ANSWER? */
  802|       |		/* But since DNAME records are also subdomains of the zone,
  803|       |		 * same check can be used */
  804|       |
  805|  43.3k|		if(!pkt_sub(pkt, rrset->dname, zonename)) {
  ------------------
  |  Branch (805:6): [True: 40.9k, False: 2.38k]
  ------------------
  806|  40.9k|			if(msg->an_rrsets == 0 && 
  ------------------
  |  Branch (806:7): [True: 38.2k, False: 2.66k]
  ------------------
  807|  40.9k|				rrset->type == LDNS_RR_TYPE_NS && 
  ------------------
  |  Branch (807:5): [True: 1.16k, False: 37.1k]
  ------------------
  808|  40.9k|				rrset->section == LDNS_SECTION_AUTHORITY &&
  ------------------
  |  Branch (808:5): [True: 485, False: 683]
  ------------------
  809|  40.9k|				FLAGS_GET_RCODE(msg->flags) == 
  ------------------
  |  |   74|    485|#define FLAGS_GET_RCODE(f) ((f) & 0xf)
  ------------------
  |  Branch (809:5): [True: 133, False: 352]
  ------------------
  810|    485|				LDNS_RCODE_NOERROR && !soa_in_auth(msg) &&
  ------------------
  |  Branch (810:27): [True: 133, False: 0]
  ------------------
  811|  40.9k|				sub_of_pkt(pkt, zonename, rrset->dname)) {
  ------------------
  |  Branch (811:5): [True: 133, False: 0]
  ------------------
  812|       |				/* noerror, nodata and this NS rrset is above
  813|       |				 * the zone. This is LAME! 
  814|       |				 * Leave in the NS for lame classification. */
  815|       |				/* remove everything from the additional
  816|       |				 * (we dont want its glue that was approved
  817|       |				 * during the normalize action) */
  818|    133|				del_addi = 1;
  819|  40.8k|			} else if(!env->cfg->harden_glue && (
  ------------------
  |  Branch (819:14): [True: 40.8k, False: 0]
  ------------------
  820|  40.8k|				rrset->type == LDNS_RR_TYPE_A ||
  ------------------
  |  Branch (820:5): [True: 11.3k, False: 29.5k]
  ------------------
  821|  40.8k|				rrset->type == LDNS_RR_TYPE_AAAA)) {
  ------------------
  |  Branch (821:5): [True: 1.66k, False: 27.8k]
  ------------------
  822|       |				/* store in cache! Since it is relevant
  823|       |				 * (from normalize) it will be picked up 
  824|       |				 * from the cache to be used later */
  825|  12.9k|				store_rrset(pkt, msg, env, rrset);
  826|  12.9k|				remove_rrset("sanitize: storing potential "
  827|  12.9k|				"poison RRset:", pkt, msg, prev, &rrset);
  828|  12.9k|				continue;
  829|  27.8k|			} else {
  830|  27.8k|				if(has_additional(rrset->type)) del_addi = 1;
  ------------------
  |  Branch (830:8): [True: 3.86k, False: 23.9k]
  ------------------
  831|  27.8k|				remove_rrset("sanitize: removing potential "
  832|  27.8k|				"poison RRset:", pkt, msg, prev, &rrset);
  833|  27.8k|				continue;
  834|  27.8k|			}
  835|  40.9k|		}
  836|  2.52k|		if(del_addi && rrset->section == LDNS_SECTION_ADDITIONAL) {
  ------------------
  |  Branch (836:6): [True: 1.23k, False: 1.28k]
  |  Branch (836:18): [True: 258, False: 977]
  ------------------
  837|    258|			remove_rrset("sanitize: removing potential "
  838|    258|			"poison reference RRset:", pkt, msg, prev, &rrset);
  839|    258|			continue;
  840|    258|		}
  841|       |		/* check if right hand side of NSEC is within zone */
  842|  2.26k|		if(rrset->type == LDNS_RR_TYPE_NSEC &&
  ------------------
  |  Branch (842:6): [True: 804, False: 1.45k]
  ------------------
  843|  2.26k|			sanitize_nsec_is_overreach(pkt, rrset, zonename)) {
  ------------------
  |  Branch (843:4): [True: 387, False: 417]
  ------------------
  844|    387|			remove_rrset("sanitize: removing overreaching NSEC "
  845|    387|				"RRset:", pkt, msg, prev, &rrset);
  846|    387|			continue;
  847|    387|		}
  848|  1.87k|		prev = rrset;
  849|  1.87k|		rrset = rrset->rrset_all_next;
  850|  1.87k|	}
  851|  1.71k|	return 1;
  852|  1.71k|}
iter_scrub.c:pkt_sub:
  322|  44.7k|{
  323|  44.7k|	uint8_t buf[LDNS_MAX_DOMAINLEN+1];
  324|  44.7k|	dname_pkt_copy(pkt, buf, comprname);
  325|  44.7k|	return dname_subdomain_c(buf, zone);
  326|  44.7k|}
iter_scrub.c:store_rrset:
  656|  12.9k|{
  657|  12.9k|	struct ub_packed_rrset_key* k;
  658|  12.9k|	struct packed_rrset_data* d;
  659|  12.9k|	struct rrset_ref ref;
  660|  12.9k|	time_t now = *env->now;
  661|       |
  662|  12.9k|	k = alloc_special_obtain(env->alloc);
  663|  12.9k|	if(!k)
  ------------------
  |  Branch (663:5): [True: 0, False: 12.9k]
  ------------------
  664|      0|		return;
  665|  12.9k|	k->entry.data = NULL;
  666|  12.9k|	if(!parse_copy_decompress_rrset(pkt, msg, rrset, NULL, k)) {
  ------------------
  |  Branch (666:5): [True: 0, False: 12.9k]
  ------------------
  667|      0|		alloc_special_release(env->alloc, k);
  668|      0|		return;
  669|      0|	}
  670|  12.9k|	d = (struct packed_rrset_data*)k->entry.data;
  671|  12.9k|	packed_rrset_ttl_add(d, now);
  672|  12.9k|	ref.key = k;
  673|  12.9k|	ref.id = k->id;
  674|       |	/*ignore ret: it was in the cache, ref updated */
  675|  12.9k|	(void)rrset_cache_update(env->rrset_cache, &ref, env->alloc, now);
  676|  12.9k|}
iter_scrub.c:sanitize_nsec_is_overreach:
  687|    804|{
  688|    804|	struct rr_parse* rr;
  689|    804|	uint8_t* rhs;
  690|    804|	size_t len;
  691|    804|	log_assert(rrset->type == LDNS_RR_TYPE_NSEC);
  692|  1.96k|	for(rr = rrset->rr_first; rr; rr = rr->next) {
  ------------------
  |  Branch (692:28): [True: 1.54k, False: 417]
  ------------------
  693|  1.54k|		size_t pos = sldns_buffer_position(pkt);
  694|  1.54k|		size_t rhspos;
  695|  1.54k|		rhs = rr->ttl_data+4+2;
  696|  1.54k|		len = sldns_read_uint16(rr->ttl_data+4);
  697|  1.54k|		rhspos = rhs-sldns_buffer_begin(pkt);
  698|  1.54k|		sldns_buffer_set_position(pkt, rhspos);
  699|  1.54k|		if(pkt_dname_len(pkt) == 0) {
  ------------------
  |  Branch (699:6): [True: 12, False: 1.53k]
  ------------------
  700|       |			/* malformed */
  701|     12|			sldns_buffer_set_position(pkt, pos);
  702|     12|			return 1;
  703|     12|		}
  704|  1.53k|		if(sldns_buffer_position(pkt)-rhspos > len) {
  ------------------
  |  Branch (704:6): [True: 188, False: 1.34k]
  ------------------
  705|       |			/* outside of rdata boundaries */
  706|    188|			sldns_buffer_set_position(pkt, pos);
  707|    188|			return 1;
  708|    188|		}
  709|  1.34k|		sldns_buffer_set_position(pkt, pos);
  710|  1.34k|		if(!pkt_sub(pkt, rhs, zonename)) {
  ------------------
  |  Branch (710:6): [True: 187, False: 1.16k]
  ------------------
  711|       |			/* overreaching */
  712|    187|			return 1;
  713|    187|		}
  714|  1.34k|	}
  715|       |	/* all NSEC RRs OK */
  716|    417|	return 0;
  717|    804|}

rrset_markdel:
   55|    304|{
   56|    304|	struct ub_packed_rrset_key* r = (struct ub_packed_rrset_key*)key;
   57|    304|	r->id = 0;
   58|    304|}
rrset_cache_create:
   62|  4.59k|{
   63|  4.59k|	size_t slabs = (cfg?cfg->rrset_cache_slabs:HASH_DEFAULT_SLABS);
  ------------------
  |  |   49|      0|#define HASH_DEFAULT_SLABS 4
  ------------------
  |  Branch (63:18): [True: 4.59k, False: 0]
  ------------------
   64|  4.59k|	size_t startarray = HASH_DEFAULT_STARTARRAY;
  ------------------
  |  |  114|  4.59k|#define HASH_DEFAULT_STARTARRAY		1024 /* entries in array */
  ------------------
   65|  4.59k|	size_t maxmem = (cfg?cfg->rrset_cache_size:HASH_DEFAULT_MAXMEM);
  ------------------
  |  |  116|      0|#define HASH_DEFAULT_MAXMEM		4*1024*1024 /* bytes */
  ------------------
  |  Branch (65:19): [True: 4.59k, False: 0]
  ------------------
   66|       |
   67|  4.59k|	struct rrset_cache *r = (struct rrset_cache*)slabhash_create(slabs,
   68|  4.59k|		startarray, maxmem, ub_rrset_sizefunc, ub_rrset_compare,
   69|  4.59k|		ub_rrset_key_delete, rrset_data_delete, alloc);
   70|  4.59k|	slabhash_setmarkdel(&r->table, &rrset_markdel);
   71|  4.59k|	return r;
   72|  4.59k|}
rrset_cache_delete:
   75|  4.59k|{
   76|  4.59k|	if(!r) 
  ------------------
  |  Branch (76:5): [True: 0, False: 4.59k]
  ------------------
   77|      0|		return;
   78|  4.59k|	slabhash_delete(&r->table);
   79|       |	/* slabhash delete also does free(r), since table is first in struct*/
   80|  4.59k|}
rrset_cache_update:
  188|  12.9k|{
  189|  12.9k|	struct lruhash_entry* e;
  190|  12.9k|	struct ub_packed_rrset_key* k = ref->key;
  191|  12.9k|	hashvalue_type h = k->entry.hash;
  192|  12.9k|	uint16_t rrset_type = ntohs(k->rk.type);
  193|  12.9k|	int equal = 0;
  194|  12.9k|	log_assert(ref->id != 0 && k->id != 0);
  195|  12.9k|	log_assert(k->rk.dname != NULL);
  196|       |	/* looks up item with a readlock - no editing! */
  197|  12.9k|	if((e=slabhash_lookup(&r->table, h, k, 0)) != 0) {
  ------------------
  |  Branch (197:5): [True: 0, False: 12.9k]
  ------------------
  198|       |		/* return id and key as they will be used in the cache
  199|       |		 * since the lruhash_insert, if item already exists, deallocs
  200|       |		 * the passed key in favor of the already stored key.
  201|       |		 * because of the small gap (see below) this key ptr and id
  202|       |		 * may prove later to be already deleted, which is no problem
  203|       |		 * as it only makes a cache miss. 
  204|       |		 */
  205|      0|		ref->key = (struct ub_packed_rrset_key*)e->key;
  206|      0|		ref->id = ref->key->id;
  207|      0|		equal = rrsetdata_equal((struct packed_rrset_data*)k->entry.
  208|      0|			data, (struct packed_rrset_data*)e->data);
  209|      0|		if(!need_to_update_rrset(k->entry.data, e->data, timenow,
  ------------------
  |  Branch (209:6): [True: 0, False: 0]
  ------------------
  210|      0|			equal, (rrset_type==LDNS_RR_TYPE_NS))) {
  211|       |			/* cache is superior, return that value */
  212|      0|			lock_rw_unlock(&e->lock);
  ------------------
  |  |  121|      0|#define lock_rw_unlock(lock) LOCKRET(pthread_rwlock_unlock(lock))
  |  |  ------------------
  |  |  |  |   67|      0|#define LOCKRET(func) do {\
  |  |  |  |   68|      0|	int lockret_err;		\
  |  |  |  |   69|      0|	if( (lockret_err=(func)) != 0)		\
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (69:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |   70|      0|		log_err("%s at %d could not " #func ": %s", \
  |  |  |  |   71|      0|		__FILE__, __LINE__, strerror(lockret_err));	\
  |  |  |  |   72|      0| 	} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (72:11): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  213|      0|			ub_packed_rrset_parsedelete(k, alloc);
  214|      0|			if(equal) return 2;
  ------------------
  |  Branch (214:7): [True: 0, False: 0]
  ------------------
  215|      0|			return 1;
  216|      0|		}
  217|      0|		lock_rw_unlock(&e->lock);
  ------------------
  |  |  121|      0|#define lock_rw_unlock(lock) LOCKRET(pthread_rwlock_unlock(lock))
  |  |  ------------------
  |  |  |  |   67|      0|#define LOCKRET(func) do {\
  |  |  |  |   68|      0|	int lockret_err;		\
  |  |  |  |   69|      0|	if( (lockret_err=(func)) != 0)		\
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (69:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |   70|      0|		log_err("%s at %d could not " #func ": %s", \
  |  |  |  |   71|      0|		__FILE__, __LINE__, strerror(lockret_err));	\
  |  |  |  |   72|      0| 	} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (72:11): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  218|       |		/* Go on and insert the passed item.
  219|       |		 * small gap here, where entry is not locked.
  220|       |		 * possibly entry is updated with something else.
  221|       |		 * we then overwrite that with our data.
  222|       |		 * this is just too bad, its cache anyway. */
  223|       |		/* use insert to update entry to manage lruhash
  224|       |		 * cache size values nicely. */
  225|      0|	}
  226|  12.9k|	log_assert(ref->key->id != 0);
  227|  12.9k|	slabhash_insert(&r->table, h, &k->entry, k->entry.data, alloc);
  228|  12.9k|	if(e) {
  ------------------
  |  Branch (228:5): [True: 0, False: 12.9k]
  ------------------
  229|       |		/* For NSEC, NSEC3, DNAME, when rdata is updated, update 
  230|       |		 * the ID number so that proofs in message cache are 
  231|       |		 * invalidated */
  232|      0|		if((rrset_type == LDNS_RR_TYPE_NSEC 
  ------------------
  |  Branch (232:7): [True: 0, False: 0]
  ------------------
  233|      0|			|| rrset_type == LDNS_RR_TYPE_NSEC3
  ------------------
  |  Branch (233:7): [True: 0, False: 0]
  ------------------
  234|      0|			|| rrset_type == LDNS_RR_TYPE_DNAME) && !equal) {
  ------------------
  |  Branch (234:7): [True: 0, False: 0]
  |  Branch (234:44): [True: 0, False: 0]
  ------------------
  235|      0|			rrset_update_id(ref, alloc);
  236|      0|		}
  237|      0|		return 1;
  238|      0|	}
  239|  12.9k|	return 0;
  240|  12.9k|}

sldns_rr_descript:
  641|  5.13M|{
  642|  5.13M|	size_t i;
  643|  5.13M|	if (type < LDNS_RDATA_FIELD_DESCRIPTORS_COMMON) {
  ------------------
  |  |   41|  5.13M|#define LDNS_RDATA_FIELD_DESCRIPTORS_COMMON 259
  ------------------
  |  Branch (643:6): [True: 5.09M, False: 43.3k]
  ------------------
  644|  5.09M|		return &rdata_field_descriptors[type];
  645|  5.09M|	} else {
  646|       |		/* because not all array index equals type code */
  647|  43.3k|		for (i = LDNS_RDATA_FIELD_DESCRIPTORS_COMMON;
  ------------------
  |  |   41|  43.3k|#define LDNS_RDATA_FIELD_DESCRIPTORS_COMMON 259
  ------------------
  648|   128k|		     i < LDNS_RDATA_FIELD_DESCRIPTORS_COUNT;
  ------------------
  |  |  637|   128k|	(sizeof(rdata_field_descriptors)/sizeof(rdata_field_descriptors[0]))
  ------------------
  |  Branch (648:8): [True: 86.6k, False: 42.0k]
  ------------------
  649|  86.6k|		     i++) {
  650|  86.6k|		        if (rdata_field_descriptors[i]._type == type) {
  ------------------
  |  Branch (650:15): [True: 1.32k, False: 85.3k]
  ------------------
  651|  1.32k|		     		return &rdata_field_descriptors[i];
  652|  1.32k|			}
  653|  86.6k|		}
  654|  42.0k|                return &rdata_field_descriptors[0];
  655|  43.3k|	}
  656|  5.13M|}

sldns_buffer_new:
   20|  4.59k|{
   21|  4.59k|	sldns_buffer *buffer = (sldns_buffer*)malloc(sizeof(sldns_buffer));
   22|       |
   23|  4.59k|	if (!buffer) {
  ------------------
  |  Branch (23:6): [True: 0, False: 4.59k]
  ------------------
   24|      0|		return NULL;
   25|      0|	}
   26|       |	
   27|  4.59k|	buffer->_data = (uint8_t *) malloc(capacity);
   28|  4.59k|	if (!buffer->_data) {
  ------------------
  |  Branch (28:6): [True: 0, False: 4.59k]
  ------------------
   29|      0|		free(buffer);
   30|      0|		return NULL;
   31|      0|	}
   32|       |	
   33|  4.59k|	buffer->_position = 0;
   34|  4.59k|	buffer->_limit = buffer->_capacity = capacity;
   35|  4.59k|	buffer->_fixed = 0;
   36|  4.59k|	buffer->_status_err = 0;
   37|       |	
   38|  4.59k|	sldns_buffer_invariant(buffer);
   39|       |	
   40|  4.59k|	return buffer;
   41|  4.59k|}
sldns_buffer_new_frm_data:
   45|  4.59k|{
   46|  4.59k|	assert(data != NULL);
   47|       |
   48|  4.59k|	buffer->_position = 0; 
   49|  4.59k|	buffer->_limit = buffer->_capacity = size;
   50|  4.59k|	buffer->_fixed = 0;
   51|  4.59k|	if (!buffer->_fixed && buffer->_data)
  ------------------
  |  Branch (51:6): [True: 4.59k, False: 0]
  |  Branch (51:25): [True: 4.59k, False: 0]
  ------------------
   52|  4.59k|		free(buffer->_data);
   53|  4.59k|	buffer->_data = malloc(size);
   54|  4.59k|	if(!buffer->_data) {
  ------------------
  |  Branch (54:5): [True: 0, False: 4.59k]
  ------------------
   55|      0|		buffer->_status_err = 1;
   56|      0|		return;
   57|      0|	}
   58|  4.59k|	memcpy(buffer->_data, data, size);
   59|  4.59k|	buffer->_status_err = 0;
   60|       |	
   61|  4.59k|	sldns_buffer_invariant(buffer);
   62|  4.59k|}
sldns_buffer_free:
  139|  4.59k|{
  140|  4.59k|	if (!buffer) {
  ------------------
  |  Branch (140:6): [True: 0, False: 4.59k]
  ------------------
  141|      0|		return;
  142|      0|	}
  143|       |
  144|  4.59k|	if (!buffer->_fixed)
  ------------------
  |  Branch (144:6): [True: 4.59k, False: 0]
  ------------------
  145|  4.59k|		free(buffer->_data);
  146|       |
  147|  4.59k|	free(buffer);
  148|  4.59k|}

dname.c:sldns_buffer_remaining:
  394|  3.81M|{
  395|  3.81M|	return sldns_buffer_remaining_at(buffer, buffer->_position);
  396|  3.81M|}
dname.c:sldns_buffer_remaining_at:
  380|  3.81M|{
  381|  3.81M|	sldns_buffer_invariant(buffer);
  382|  3.81M|	assert(at <= buffer->_limit);
  383|  3.81M|	return at < buffer->_limit ? buffer->_limit - at : 0;
  ------------------
  |  Branch (383:9): [True: 3.81M, False: 1.40k]
  ------------------
  384|  3.81M|}
dname.c:sldns_buffer_invariant:
  143|  3.81M|{
  144|  3.81M|}
dname.c:sldns_buffer_read_u8:
  638|  3.69M|{
  639|  3.69M|	uint8_t result = sldns_buffer_read_u8_at(buffer, buffer->_position);
  640|  3.69M|	buffer->_position += sizeof(uint8_t);
  641|  3.69M|	return result;
  642|  3.69M|}
dname.c:sldns_buffer_read_u8_at:
  626|  3.69M|{
  627|  3.69M|	assert(sldns_buffer_available_at(buffer, at, sizeof(uint8_t)));
  628|  3.69M|	return buffer->_data[at];
  629|  3.69M|}
dname.c:sldns_buffer_skip:
  259|   120k|{
  260|   120k|	assert(buffer->_position + count <= buffer->_limit);
  261|   120k|	buffer->_position += count;
  262|   120k|}
dname.c:sldns_buffer_limit:
  271|   264k|{
  272|   264k|	return buffer->_limit;
  273|   264k|}
dname.c:sldns_buffer_at:
  331|   141k|{
  332|   141k|	assert(at <= buffer->_limit);
  333|   141k|	return buffer->_data + at;
  334|   141k|}
dname.c:sldns_buffer_position:
  233|  47.4k|{
  234|  47.4k|	return buffer->_position;
  235|  47.4k|}
dname.c:sldns_buffer_set_position:
  245|   168k|{
  246|   168k|	assert(mark <= buffer->_limit);
  247|   168k|	buffer->_position = mark;
  248|   168k|}
msgparse.c:sldns_buffer_remaining:
  394|  9.22M|{
  395|  9.22M|	return sldns_buffer_remaining_at(buffer, buffer->_position);
  396|  9.22M|}
msgparse.c:sldns_buffer_remaining_at:
  380|  9.22M|{
  381|  9.22M|	sldns_buffer_invariant(buffer);
  382|  9.22M|	assert(at <= buffer->_limit);
  383|  9.22M|	return at < buffer->_limit ? buffer->_limit - at : 0;
  ------------------
  |  Branch (383:9): [True: 9.21M, False: 3.47k]
  ------------------
  384|  9.22M|}
msgparse.c:sldns_buffer_invariant:
  143|  9.22M|{
  144|  9.22M|}
msgparse.c:sldns_buffer_read:
  613|  3.26M|{
  614|  3.26M|	sldns_buffer_read_at(buffer, buffer->_position, data, count);
  615|  3.26M|	buffer->_position += count;
  616|  3.26M|}
msgparse.c:sldns_buffer_read_at:
  600|  3.26M|{
  601|  3.26M|	assert(sldns_buffer_available_at(buffer, at, count));
  602|  3.26M|	memcpy(data, buffer->_data + at, count);
  603|  3.26M|}
msgparse.c:sldns_buffer_read_u16:
  664|  9.28M|{
  665|  9.28M|	uint16_t result = sldns_buffer_read_u16_at(buffer, buffer->_position);
  666|  9.28M|	buffer->_position += sizeof(uint16_t);
  667|  9.28M|	return result;
  668|  9.28M|}
msgparse.c:sldns_buffer_read_u16_at:
  652|  9.28M|{
  653|  9.28M|	assert(sldns_buffer_available_at(buffer, at, sizeof(uint16_t)));
  654|  9.28M|	return sldns_read_uint16(buffer->_data + at);
  655|  9.28M|}
msgparse.c:sldns_buffer_limit:
  271|  6.74k|{
  272|  6.74k|	return buffer->_limit;
  273|  6.74k|}
msgparse.c:sldns_buffer_at:
  331|  8.41M|{
  332|  8.41M|	assert(at <= buffer->_limit);
  333|  8.41M|	return buffer->_data + at;
  334|  8.41M|}
msgparse.c:sldns_buffer_position:
  233|  2.24M|{
  234|  2.24M|	return buffer->_position;
  235|  2.24M|}
msgparse.c:sldns_buffer_skip:
  259|  8.78M|{
  260|  8.78M|	assert(buffer->_position + count <= buffer->_limit);
  261|  8.78M|	buffer->_position += count;
  262|  8.78M|}
msgparse.c:sldns_buffer_set_position:
  245|  3.89M|{
  246|  3.89M|	assert(mark <= buffer->_limit);
  247|  3.89M|	buffer->_position = mark;
  248|  3.89M|}
msgparse.c:sldns_read_uint16:
   36|  9.31M|{
   37|       |#ifdef ALLOW_UNALIGNED_ACCESSES
   38|       |        return ntohs(*(const uint16_t *) src);
   39|       |#else
   40|  9.31M|        const uint8_t *p = (const uint8_t *) src;
   41|  9.31M|        return ((uint16_t) p[0] << 8) | (uint16_t) p[1];
   42|  9.31M|#endif
   43|  9.31M|}
msgparse.c:sldns_buffer_begin:
  344|  1.78M|{
  345|  1.78M|	return sldns_buffer_at(buffer, 0);
  346|  1.78M|}
msgparse.c:sldns_buffer_read_u8:
  638|  6.99k|{
  639|  6.99k|	uint8_t result = sldns_buffer_read_u8_at(buffer, buffer->_position);
  640|  6.99k|	buffer->_position += sizeof(uint8_t);
  641|  6.99k|	return result;
  642|  6.99k|}
msgparse.c:sldns_buffer_read_u8_at:
  626|  6.99k|{
  627|  6.99k|	assert(sldns_buffer_available_at(buffer, at, sizeof(uint8_t)));
  628|  6.99k|	return buffer->_data[at];
  629|  6.99k|}
msgparse.c:sldns_buffer_current:
  367|  6.62M|{
  368|  6.62M|	return sldns_buffer_at(buffer, buffer->_position);
  369|  6.62M|}
msgreply.c:sldns_read_uint32:
   47|  2.13M|{
   48|       |#ifdef ALLOW_UNALIGNED_ACCESSES
   49|       |        return ntohl(*(const uint32_t *) src);
   50|       |#else
   51|  2.13M|        const uint8_t *p = (const uint8_t *) src;
   52|  2.13M|        return (  ((uint32_t) p[0] << 24)
   53|  2.13M|                | ((uint32_t) p[1] << 16)
   54|  2.13M|                | ((uint32_t) p[2] << 8)
   55|  2.13M|                |  (uint32_t) p[3]);
   56|  2.13M|#endif
   57|  2.13M|}
msgreply.c:sldns_buffer_set_position:
  245|  2.13M|{
  246|  2.13M|	assert(mark <= buffer->_limit);
  247|  2.13M|	buffer->_position = mark;
  248|  2.13M|}
msgreply.c:sldns_buffer_begin:
  344|  2.13M|{
  345|  2.13M|	return sldns_buffer_at(buffer, 0);
  346|  2.13M|}
msgreply.c:sldns_buffer_at:
  331|  2.20M|{
  332|  2.20M|	assert(at <= buffer->_limit);
  333|  2.20M|	return buffer->_data + at;
  334|  2.20M|}
msgreply.c:sldns_read_uint16:
   36|  2.13M|{
   37|       |#ifdef ALLOW_UNALIGNED_ACCESSES
   38|       |        return ntohs(*(const uint16_t *) src);
   39|       |#else
   40|  2.13M|        const uint8_t *p = (const uint8_t *) src;
   41|  2.13M|        return ((uint16_t) p[0] << 8) | (uint16_t) p[1];
   42|  2.13M|#endif
   43|  2.13M|}
msgreply.c:sldns_buffer_position:
  233|  16.7k|{
  234|  16.7k|	return buffer->_position;
  235|  16.7k|}
msgreply.c:sldns_buffer_skip:
  259|  58.6k|{
  260|  58.6k|	assert(buffer->_position + count <= buffer->_limit);
  261|  58.6k|	buffer->_position += count;
  262|  58.6k|}
msgreply.c:sldns_buffer_current:
  367|  72.3k|{
  368|  72.3k|	return sldns_buffer_at(buffer, buffer->_position);
  369|  72.3k|}
msgreply.c:sldns_buffer_remaining:
  394|  2.13M|{
  395|  2.13M|	return sldns_buffer_remaining_at(buffer, buffer->_position);
  396|  2.13M|}
msgreply.c:sldns_buffer_remaining_at:
  380|  2.13M|{
  381|  2.13M|	sldns_buffer_invariant(buffer);
  382|  2.13M|	assert(at <= buffer->_limit);
  383|  2.13M|	return at < buffer->_limit ? buffer->_limit - at : 0;
  ------------------
  |  Branch (383:9): [True: 2.13M, False: 252]
  ------------------
  384|  2.13M|}
msgreply.c:sldns_buffer_invariant:
  143|  2.13M|{
  144|  2.13M|}
msgreply.c:sldns_buffer_read_u16:
  664|  2.13M|{
  665|  2.13M|	uint16_t result = sldns_buffer_read_u16_at(buffer, buffer->_position);
  666|  2.13M|	buffer->_position += sizeof(uint16_t);
  667|  2.13M|	return result;
  668|  2.13M|}
msgreply.c:sldns_buffer_read_u16_at:
  652|  2.13M|{
  653|  2.13M|	assert(sldns_buffer_available_at(buffer, at, sizeof(uint16_t)));
  654|  2.13M|	return sldns_read_uint16(buffer->_data + at);
  655|  2.13M|}
iter_scrub.c:sldns_buffer_position:
  233|  6.81k|{
  234|  6.81k|	return buffer->_position;
  235|  6.81k|}
iter_scrub.c:sldns_buffer_set_position:
  245|  10.5k|{
  246|  10.5k|	assert(mark <= buffer->_limit);
  247|  10.5k|	buffer->_position = mark;
  248|  10.5k|}
iter_scrub.c:sldns_buffer_begin:
  344|  5.28k|{
  345|  5.28k|	return sldns_buffer_at(buffer, 0);
  346|  5.28k|}
iter_scrub.c:sldns_buffer_at:
  331|  5.28k|{
  332|  5.28k|	assert(at <= buffer->_limit);
  333|  5.28k|	return buffer->_data + at;
  334|  5.28k|}
iter_scrub.c:sldns_write_uint32:
   77|    616|{
   78|       |#ifdef ALLOW_UNALIGNED_ACCESSES
   79|       |        * (uint32_t *) dst = htonl(data);
   80|       |#else
   81|    616|        uint8_t *p = (uint8_t *) dst;
   82|    616|        p[0] = (uint8_t) ((data >> 24) & 0xff);
   83|    616|        p[1] = (uint8_t) ((data >> 16) & 0xff);
   84|    616|        p[2] = (uint8_t) ((data >> 8) & 0xff);
   85|    616|        p[3] = (uint8_t) (data & 0xff);
   86|    616|#endif
   87|    616|}
iter_scrub.c:sldns_write_uint16:
   65|    616|{
   66|       |#ifdef ALLOW_UNALIGNED_ACCESSES
   67|       |        * (uint16_t *) dst = htons(data);
   68|       |#else
   69|    616|        uint8_t *p = (uint8_t *) dst;
   70|    616|        p[0] = (uint8_t) ((data >> 8) & 0xff);
   71|    616|        p[1] = (uint8_t) (data & 0xff);
   72|    616|#endif
   73|    616|}
iter_scrub.c:sldns_read_uint16:
   36|  8.43k|{
   37|       |#ifdef ALLOW_UNALIGNED_ACCESSES
   38|       |        return ntohs(*(const uint16_t *) src);
   39|       |#else
   40|  8.43k|        const uint8_t *p = (const uint8_t *) src;
   41|  8.43k|        return ((uint16_t) p[0] << 8) | (uint16_t) p[1];
   42|  8.43k|#endif
   43|  8.43k|}
sbuffer.c:sldns_buffer_invariant:
  143|  9.18k|{
  144|  9.18k|}

alloc_init:
  105|  4.59k|{
  106|  4.59k|	memset(alloc, 0, sizeof(*alloc));
  107|  4.59k|	alloc->super = super;
  108|  4.59k|	alloc->thread_num = thread_num;
  109|  4.59k|	alloc->next_id = (uint64_t)thread_num; 	/* in steps, so that type */
  110|  4.59k|	alloc->next_id <<= THRNUM_SHIFT; 	/* of *_id is used. */
  ------------------
  |  |   51|  4.59k|#define THRNUM_SHIFT	48	/* for 65k threads, 2^48 rrsets per thr. */
  ------------------
  111|  4.59k|	alloc->last_id = 1; 			/* so no 64bit constants, */
  112|  4.59k|	alloc->last_id <<= THRNUM_SHIFT; 	/* or implicit 'int' ops. */
  ------------------
  |  |   51|  4.59k|#define THRNUM_SHIFT	48	/* for 65k threads, 2^48 rrsets per thr. */
  ------------------
  113|  4.59k|	alloc->last_id -= 1; 			/* for compiler portability. */
  114|  4.59k|	alloc->last_id |= alloc->next_id;
  115|  4.59k|	alloc->next_id += 1;			/* because id=0 is special. */
  116|  4.59k|	alloc->max_reg_blocks = 100;
  117|  4.59k|	alloc->num_reg_blocks = 0;
  118|  4.59k|	alloc->reg_list = NULL;
  119|  4.59k|	alloc->cleanup = NULL;
  120|  4.59k|	alloc->cleanup_arg = NULL;
  121|  4.59k|	if(alloc->super)
  ------------------
  |  Branch (121:5): [True: 0, False: 4.59k]
  ------------------
  122|      0|		prealloc_blocks(alloc, alloc->max_reg_blocks);
  123|  4.59k|	if(!alloc->super) {
  ------------------
  |  Branch (123:5): [True: 4.59k, False: 0]
  ------------------
  124|  4.59k|		lock_quick_init(&alloc->lock);
  ------------------
  |  |  143|  4.59k|#define lock_quick_init(lock) LOCKRET(pthread_spin_init(lock, PTHREAD_PROCESS_PRIVATE))
  |  |  ------------------
  |  |  |  |   67|  4.59k|#define LOCKRET(func) do {\
  |  |  |  |   68|  4.59k|	int lockret_err;		\
  |  |  |  |   69|  4.59k|	if( (lockret_err=(func)) != 0)		\
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (69:6): [True: 0, False: 4.59k]
  |  |  |  |  ------------------
  |  |  |  |   70|  4.59k|		log_err("%s at %d could not " #func ": %s", \
  |  |  |  |   71|      0|		__FILE__, __LINE__, strerror(lockret_err));	\
  |  |  |  |   72|  4.59k| 	} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (72:11): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  125|  4.59k|		lock_protect(&alloc->lock, alloc, sizeof(*alloc));
  126|  4.59k|	}
  127|  4.59k|}
alloc_clear:
  161|  4.59k|{
  162|  4.59k|	alloc_special_type* p;
  163|  4.59k|	struct regional* r, *nr;
  164|  4.59k|	if(!alloc)
  ------------------
  |  Branch (164:5): [True: 0, False: 4.59k]
  ------------------
  165|      0|		return;
  166|  4.59k|	if(!alloc->super) {
  ------------------
  |  Branch (166:5): [True: 4.59k, False: 0]
  ------------------
  167|  4.59k|		lock_quick_destroy(&alloc->lock);
  ------------------
  |  |  144|  4.59k|#define lock_quick_destroy(lock) LOCKRET(pthread_spin_destroy(lock))
  |  |  ------------------
  |  |  |  |   67|  4.59k|#define LOCKRET(func) do {\
  |  |  |  |   68|  4.59k|	int lockret_err;		\
  |  |  |  |   69|  4.59k|	if( (lockret_err=(func)) != 0)		\
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (69:6): [True: 0, False: 4.59k]
  |  |  |  |  ------------------
  |  |  |  |   70|  4.59k|		log_err("%s at %d could not " #func ": %s", \
  |  |  |  |   71|      0|		__FILE__, __LINE__, strerror(lockret_err));	\
  |  |  |  |   72|  4.59k| 	} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (72:11): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  168|  4.59k|	}
  169|  4.59k|	if(alloc->super && alloc->quar) {
  ------------------
  |  Branch (169:5): [True: 0, False: 4.59k]
  |  Branch (169:21): [True: 0, False: 0]
  ------------------
  170|       |		/* push entire list into super */
  171|      0|		p = alloc->quar;
  172|      0|		while(alloc_special_next(p)) /* find last */
  ------------------
  |  |   60|      0|#define alloc_special_next(x) ((alloc_special_type*)((x)->entry.overflow_next))
  |  |  ------------------
  |  |  |  Branch (60:31): [True: 0, False: 0]
  |  |  ------------------
  ------------------
  173|      0|			p = alloc_special_next(p);
  ------------------
  |  |   60|      0|#define alloc_special_next(x) ((alloc_special_type*)((x)->entry.overflow_next))
  ------------------
  174|      0|		lock_quick_lock(&alloc->super->lock);
  ------------------
  |  |  145|      0|#define lock_quick_lock(lock) LOCKRET(pthread_spin_lock(lock))
  |  |  ------------------
  |  |  |  |   67|      0|#define LOCKRET(func) do {\
  |  |  |  |   68|      0|	int lockret_err;		\
  |  |  |  |   69|      0|	if( (lockret_err=(func)) != 0)		\
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (69:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |   70|      0|		log_err("%s at %d could not " #func ": %s", \
  |  |  |  |   71|      0|		__FILE__, __LINE__, strerror(lockret_err));	\
  |  |  |  |   72|      0| 	} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (72:11): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  175|      0|		alloc_set_special_next(p, alloc->super->quar);
  ------------------
  |  |   63|      0|	((x)->entry.overflow_next) = (struct lruhash_entry*)(y);
  ------------------
  176|      0|		alloc->super->quar = alloc->quar;
  177|      0|		alloc->super->num_quar += alloc->num_quar;
  178|      0|		lock_quick_unlock(&alloc->super->lock);
  ------------------
  |  |  146|      0|#define lock_quick_unlock(lock) LOCKRET(pthread_spin_unlock(lock))
  |  |  ------------------
  |  |  |  |   67|      0|#define LOCKRET(func) do {\
  |  |  |  |   68|      0|	int lockret_err;		\
  |  |  |  |   69|      0|	if( (lockret_err=(func)) != 0)		\
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (69:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |   70|      0|		log_err("%s at %d could not " #func ": %s", \
  |  |  |  |   71|      0|		__FILE__, __LINE__, strerror(lockret_err));	\
  |  |  |  |   72|      0| 	} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (72:11): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  179|  4.59k|	} else {
  180|  4.59k|		alloc_clear_special_list(alloc);
  181|  4.59k|	}
  182|  4.59k|	alloc->quar = 0;
  183|  4.59k|	alloc->num_quar = 0;
  184|  4.59k|	r = alloc->reg_list;
  185|  4.59k|	while(r) {
  ------------------
  |  Branch (185:8): [True: 0, False: 4.59k]
  ------------------
  186|      0|		nr = (struct regional*)r->next;
  187|      0|		free(r);
  188|      0|		r = nr;
  189|      0|	}
  190|  4.59k|	alloc->reg_list = NULL;
  191|  4.59k|	alloc->num_reg_blocks = 0;
  192|  4.59k|}
alloc_get_id:
  196|  12.9k|{
  197|  12.9k|	uint64_t id = alloc->next_id++;
  198|  12.9k|	if(id == alloc->last_id) {
  ------------------
  |  Branch (198:5): [True: 0, False: 12.9k]
  ------------------
  199|      0|		log_warn("rrset alloc: out of 64bit ids. Clearing cache.");
  200|      0|		fptr_ok(fptr_whitelist_alloc_cleanup(alloc->cleanup));
  ------------------
  |  |   71|      0|	do { if(!(x)) \
  |  |  ------------------
  |  |  |  Branch (71:10): [True: 0, False: 0]
  |  |  ------------------
  |  |   72|      0|		fatal_exit("%s:%d: %s: pointer whitelist %s failed", \
  |  |   73|      0|		__FILE__, __LINE__, __func__, #x); \
  |  |   74|      0|	} while(0);
  |  |  ------------------
  |  |  |  Branch (74:10): [Folded - Ignored]
  |  |  ------------------
  ------------------
  201|      0|		(*alloc->cleanup)(alloc->cleanup_arg);
  202|       |
  203|       |		/* start back at first number */   	/* like in alloc_init*/
  204|      0|		alloc->next_id = (uint64_t)alloc->thread_num; 	
  205|      0|		alloc->next_id <<= THRNUM_SHIFT; 	/* in steps for comp. */
  ------------------
  |  |   51|      0|#define THRNUM_SHIFT	48	/* for 65k threads, 2^48 rrsets per thr. */
  ------------------
  206|      0|		alloc->next_id += 1;			/* portability. */
  207|       |		/* and generate new and safe id */
  208|      0|		id = alloc->next_id++;
  209|      0|	}
  210|  12.9k|	return id;
  211|  12.9k|}
alloc_special_obtain:
  215|  12.9k|{
  216|  12.9k|	alloc_special_type* p;
  217|  12.9k|	log_assert(alloc);
  218|       |	/* see if in local cache */
  219|  12.9k|	if(alloc->quar) {
  ------------------
  |  Branch (219:5): [True: 11.4k, False: 1.53k]
  ------------------
  220|  11.4k|		p = alloc->quar;
  221|  11.4k|		alloc->quar = alloc_special_next(p);
  ------------------
  |  |   60|  11.4k|#define alloc_special_next(x) ((alloc_special_type*)((x)->entry.overflow_next))
  ------------------
  222|  11.4k|		alloc->num_quar--;
  223|  11.4k|		p->id = alloc_get_id(alloc);
  224|  11.4k|		return p;
  225|  11.4k|	}
  226|       |	/* see if in global cache */
  227|  1.53k|	if(alloc->super) {
  ------------------
  |  Branch (227:5): [True: 0, False: 1.53k]
  ------------------
  228|       |		/* could maybe grab alloc_max/2 entries in one go,
  229|       |		 * but really, isn't that just as fast as this code? */
  230|      0|		lock_quick_lock(&alloc->super->lock);
  ------------------
  |  |  145|      0|#define lock_quick_lock(lock) LOCKRET(pthread_spin_lock(lock))
  |  |  ------------------
  |  |  |  |   67|      0|#define LOCKRET(func) do {\
  |  |  |  |   68|      0|	int lockret_err;		\
  |  |  |  |   69|      0|	if( (lockret_err=(func)) != 0)		\
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (69:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |   70|      0|		log_err("%s at %d could not " #func ": %s", \
  |  |  |  |   71|      0|		__FILE__, __LINE__, strerror(lockret_err));	\
  |  |  |  |   72|      0| 	} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (72:11): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  231|      0|		if((p = alloc->super->quar)) {
  ------------------
  |  Branch (231:6): [True: 0, False: 0]
  ------------------
  232|      0|			alloc->super->quar = alloc_special_next(p);
  ------------------
  |  |   60|      0|#define alloc_special_next(x) ((alloc_special_type*)((x)->entry.overflow_next))
  ------------------
  233|      0|			alloc->super->num_quar--;
  234|      0|		}
  235|      0|		lock_quick_unlock(&alloc->super->lock);
  ------------------
  |  |  146|      0|#define lock_quick_unlock(lock) LOCKRET(pthread_spin_unlock(lock))
  |  |  ------------------
  |  |  |  |   67|      0|#define LOCKRET(func) do {\
  |  |  |  |   68|      0|	int lockret_err;		\
  |  |  |  |   69|      0|	if( (lockret_err=(func)) != 0)		\
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (69:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |   70|      0|		log_err("%s at %d could not " #func ": %s", \
  |  |  |  |   71|      0|		__FILE__, __LINE__, strerror(lockret_err));	\
  |  |  |  |   72|      0| 	} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (72:11): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  236|      0|		if(p) {
  ------------------
  |  Branch (236:6): [True: 0, False: 0]
  ------------------
  237|      0|			p->id = alloc_get_id(alloc);
  238|      0|			return p;
  239|      0|		}
  240|      0|	}
  241|       |	/* allocate new */
  242|  1.53k|	prealloc_setup(alloc);
  243|  1.53k|	if(!(p = (alloc_special_type*)malloc(sizeof(alloc_special_type)))) {
  ------------------
  |  Branch (243:5): [True: 0, False: 1.53k]
  ------------------
  244|      0|		log_err("alloc_special_obtain: out of memory");
  245|      0|		return NULL;
  246|      0|	}
  247|  1.53k|	alloc_setup_special(p);
  248|  1.53k|	p->id = alloc_get_id(alloc);
  249|  1.53k|	return p;
  250|  1.53k|}
alloc_special_release:
  280|  12.9k|{
  281|  12.9k|	log_assert(alloc);
  282|  12.9k|	if(!mem)
  ------------------
  |  Branch (282:5): [True: 0, False: 12.9k]
  ------------------
  283|      0|		return;
  284|  12.9k|	if(!alloc->super) { 
  ------------------
  |  Branch (284:5): [True: 12.9k, False: 0]
  ------------------
  285|  12.9k|		lock_quick_lock(&alloc->lock); /* superalloc needs locking */
  ------------------
  |  |  145|  12.9k|#define lock_quick_lock(lock) LOCKRET(pthread_spin_lock(lock))
  |  |  ------------------
  |  |  |  |   67|  12.9k|#define LOCKRET(func) do {\
  |  |  |  |   68|  12.9k|	int lockret_err;		\
  |  |  |  |   69|  12.9k|	if( (lockret_err=(func)) != 0)		\
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (69:6): [True: 0, False: 12.9k]
  |  |  |  |  ------------------
  |  |  |  |   70|  12.9k|		log_err("%s at %d could not " #func ": %s", \
  |  |  |  |   71|      0|		__FILE__, __LINE__, strerror(lockret_err));	\
  |  |  |  |   72|  12.9k| 	} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (72:11): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  286|  12.9k|	}
  287|       |
  288|  12.9k|	alloc_special_clean(mem);
  ------------------
  |  |   58|  12.9k|#define alloc_special_clean(x) (x)->id = 0;
  ------------------
  289|  12.9k|	if(alloc->super && alloc->num_quar >= ALLOC_SPECIAL_MAX) {
  ------------------
  |  |   66|      0|#define ALLOC_SPECIAL_MAX 10
  ------------------
  |  Branch (289:5): [True: 0, False: 12.9k]
  |  Branch (289:21): [True: 0, False: 0]
  ------------------
  290|       |		/* push it to the super structure */
  291|      0|		pushintosuper(alloc, mem);
  292|      0|		return;
  293|      0|	}
  294|       |
  295|  12.9k|	alloc_set_special_next(mem, alloc->quar);
  ------------------
  |  |   63|  12.9k|	((x)->entry.overflow_next) = (struct lruhash_entry*)(y);
  ------------------
  296|  12.9k|	alloc->quar = mem;
  297|  12.9k|	alloc->num_quar++;
  298|  12.9k|	if(!alloc->super) {
  ------------------
  |  Branch (298:5): [True: 12.9k, False: 0]
  ------------------
  299|  12.9k|		lock_quick_unlock(&alloc->lock);
  ------------------
  |  |  146|  12.9k|#define lock_quick_unlock(lock) LOCKRET(pthread_spin_unlock(lock))
  |  |  ------------------
  |  |  |  |   67|  12.9k|#define LOCKRET(func) do {\
  |  |  |  |   68|  12.9k|	int lockret_err;		\
  |  |  |  |   69|  12.9k|	if( (lockret_err=(func)) != 0)		\
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (69:6): [True: 0, False: 12.9k]
  |  |  |  |  ------------------
  |  |  |  |   70|  12.9k|		log_err("%s at %d could not " #func ": %s", \
  |  |  |  |   71|      0|		__FILE__, __LINE__, strerror(lockret_err));	\
  |  |  |  |   72|  12.9k| 	} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (72:11): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  300|  12.9k|	}
  301|  12.9k|}
alloc.c:alloc_clear_special_list:
  132|  4.59k|{
  133|  4.59k|	alloc_special_type* p, *np;
  134|       |	/* free */
  135|  4.59k|	p = alloc->quar;
  136|  21.4k|	while(p) {
  ------------------
  |  Branch (136:8): [True: 16.9k, False: 4.59k]
  ------------------
  137|  16.9k|		np = alloc_special_next(p);
  ------------------
  |  |   60|  16.9k|#define alloc_special_next(x) ((alloc_special_type*)((x)->entry.overflow_next))
  ------------------
  138|       |		/* deinit special type */
  139|  16.9k|		lock_rw_destroy(&p->entry.lock);
  ------------------
  |  |  118|  16.9k|#define lock_rw_destroy(lock) LOCKRET(pthread_rwlock_destroy(lock))
  |  |  ------------------
  |  |  |  |   67|  16.9k|#define LOCKRET(func) do {\
  |  |  |  |   68|  16.9k|	int lockret_err;		\
  |  |  |  |   69|  16.9k|	if( (lockret_err=(func)) != 0)		\
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (69:6): [True: 0, False: 16.9k]
  |  |  |  |  ------------------
  |  |  |  |   70|  16.9k|		log_err("%s at %d could not " #func ": %s", \
  |  |  |  |   71|      0|		__FILE__, __LINE__, strerror(lockret_err));	\
  |  |  |  |   72|  16.9k| 	} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (72:11): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  140|  16.9k|		free(p);
  141|  16.9k|		p = np;
  142|  16.9k|	}
  143|  4.59k|}
alloc.c:prealloc_setup:
   68|  1.53k|{
   69|  1.53k|	alloc_special_type* p;
   70|  1.53k|	int i;
   71|  16.9k|	for(i=0; i<ALLOC_SPECIAL_MAX; i++) {
  ------------------
  |  |   66|  16.9k|#define ALLOC_SPECIAL_MAX 10
  ------------------
  |  Branch (71:11): [True: 15.3k, False: 1.53k]
  ------------------
   72|  15.3k|		if(!(p = (alloc_special_type*)malloc(
  ------------------
  |  Branch (72:6): [True: 0, False: 15.3k]
  ------------------
   73|  15.3k|			sizeof(alloc_special_type)))) {
   74|      0|			log_err("prealloc: out of memory");
   75|      0|			return;
   76|      0|		}
   77|  15.3k|		alloc_setup_special(p);
   78|  15.3k|		alloc_set_special_next(p, alloc->quar);
  ------------------
  |  |   63|  15.3k|	((x)->entry.overflow_next) = (struct lruhash_entry*)(y);
  ------------------
   79|  15.3k|		alloc->quar = p;
   80|  15.3k|		alloc->num_quar++;
   81|  15.3k|	}
   82|  1.53k|}
alloc.c:alloc_setup_special:
   56|  16.9k|{
   57|  16.9k|	memset(t, 0, sizeof(*t));
   58|  16.9k|	lock_rw_init(&t->entry.lock);
  ------------------
  |  |  117|  16.9k|#define lock_rw_init(lock) LOCKRET(pthread_rwlock_init(lock, NULL))
  |  |  ------------------
  |  |  |  |   67|  16.9k|#define LOCKRET(func) do {\
  |  |  |  |   68|  16.9k|	int lockret_err;		\
  |  |  |  |   69|  16.9k|	if( (lockret_err=(func)) != 0)		\
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (69:6): [True: 0, False: 16.9k]
  |  |  |  |  ------------------
  |  |  |  |   70|  16.9k|		log_err("%s at %d could not " #func ": %s", \
  |  |  |  |   71|      0|		__FILE__, __LINE__, strerror(lockret_err));	\
  |  |  |  |   72|  16.9k| 	} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (72:11): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
   59|  16.9k|	t->entry.key = t;
   60|  16.9k|}

query_dname_compare:
  101|     62|{
  102|     62|	register uint8_t lab1, lab2;
  103|     62|	log_assert(d1 && d2);
  104|     62|	lab1 = *d1++;
  105|     62|	lab2 = *d2++;
  106|    366|	while( lab1 != 0 || lab2 != 0 ) {
  ------------------
  |  Branch (106:9): [True: 324, False: 42]
  |  Branch (106:22): [True: 0, False: 42]
  ------------------
  107|       |		/* compare label length */
  108|       |		/* if one dname ends, it has labellength 0 */
  109|    324|		if(lab1 != lab2) {
  ------------------
  |  Branch (109:6): [True: 0, False: 324]
  ------------------
  110|      0|			if(lab1 < lab2)
  ------------------
  |  Branch (110:7): [True: 0, False: 0]
  ------------------
  111|      0|				return -1;
  112|      0|			return 1;
  113|      0|		}
  114|    324|		log_assert(lab1 == lab2 && lab1 != 0);
  115|       |		/* compare lowercased labels. */
  116|  6.30k|		while(lab1--) {
  ------------------
  |  Branch (116:9): [True: 6.00k, False: 304]
  ------------------
  117|       |			/* compare bytes first for speed */
  118|  6.00k|			if(*d1 != *d2 && 
  ------------------
  |  Branch (118:7): [True: 28, False: 5.97k]
  ------------------
  119|  6.00k|				tolower((unsigned char)*d1) != tolower((unsigned char)*d2)) {
  ------------------
  |  Branch (119:5): [True: 20, False: 8]
  ------------------
  120|     20|				if(tolower((unsigned char)*d1) < tolower((unsigned char)*d2))
  ------------------
  |  Branch (120:8): [True: 12, False: 8]
  ------------------
  121|     12|					return -1;
  122|      8|				return 1;
  123|     20|			}
  124|  5.98k|			d1++;
  125|  5.98k|			d2++;
  126|  5.98k|		}
  127|       |		/* next pair of labels. */
  128|    304|		lab1 = *d1++;
  129|    304|		lab2 = *d2++;
  130|    304|	}
  131|     42|	return 0;
  132|     62|}
pkt_dname_len:
  184|  3.32M|{
  185|  3.32M|	size_t len = 0;
  186|  3.32M|	int ptrcount = 0;
  187|  3.32M|	uint8_t labellen;
  188|  3.32M|	size_t endpos = 0;
  189|       |
  190|       |	/* read dname and determine length */
  191|       |	/* check compression pointers, loops, out of bounds */
  192|  3.57M|	while(1) {
  ------------------
  |  Branch (192:8): [Folded - Ignored]
  ------------------
  193|       |		/* read next label */
  194|  3.57M|		if(sldns_buffer_remaining(pkt) < 1)
  ------------------
  |  Branch (194:6): [True: 864, False: 3.57M]
  ------------------
  195|    864|			return 0;
  196|  3.57M|		labellen = sldns_buffer_read_u8(pkt);
  197|  3.57M|		if(LABEL_IS_PTR(labellen)) {
  ------------------
  |  |  202|  3.57M|#define LABEL_IS_PTR(x) ( ((x)&0xc0) == 0xc0 )
  |  |  ------------------
  |  |  |  Branch (202:25): [True: 123k, False: 3.44M]
  |  |  ------------------
  ------------------
  198|       |			/* compression ptr */
  199|   123k|			uint16_t ptr;
  200|   123k|			if(sldns_buffer_remaining(pkt) < 1)
  ------------------
  |  Branch (200:7): [True: 246, False: 122k]
  ------------------
  201|    246|				return 0;
  202|   122k|			ptr = PTR_OFFSET(labellen, sldns_buffer_read_u8(pkt));
  ------------------
  |  |  205|   122k|#define PTR_OFFSET(x, y) ( ((x)&0x3f)<<8 | (y) )
  ------------------
  203|   122k|			if(ptrcount++ > MAX_COMPRESS_PTRS)
  ------------------
  |  |   51|   122k|#define MAX_COMPRESS_PTRS 256
  ------------------
  |  Branch (203:7): [True: 196, False: 122k]
  ------------------
  204|    196|				return 0; /* loop! */
  205|   122k|			if(sldns_buffer_limit(pkt) <= ptr)
  ------------------
  |  Branch (205:7): [True: 305, False: 122k]
  ------------------
  206|    305|				return 0; /* out of bounds! */
  207|   122k|			if(!endpos)
  ------------------
  |  Branch (207:7): [True: 47.4k, False: 74.8k]
  ------------------
  208|  47.4k|				endpos = sldns_buffer_position(pkt);
  209|   122k|			sldns_buffer_set_position(pkt, ptr);
  210|  3.44M|		} else {
  211|       |			/* label contents */
  212|  3.44M|			if(labellen > 0x3f)
  ------------------
  |  Branch (212:7): [True: 427, False: 3.44M]
  ------------------
  213|    427|				return 0; /* label too long */
  214|  3.44M|			len += 1 + labellen;
  215|  3.44M|			if(len > LDNS_MAX_DOMAINLEN)
  ------------------
  |  |   29|  3.44M|#define LDNS_MAX_DOMAINLEN    255
  ------------------
  |  Branch (215:7): [True: 233, False: 3.44M]
  ------------------
  216|    233|				return 0;
  217|  3.44M|			if(labellen == 0) {
  ------------------
  |  Branch (217:7): [True: 3.32M, False: 121k]
  ------------------
  218|       |				/* end of dname */
  219|  3.32M|				break;
  220|  3.32M|			}
  221|   121k|			if(sldns_buffer_remaining(pkt) < labellen)
  ------------------
  |  Branch (221:7): [True: 482, False: 120k]
  ------------------
  222|    482|				return 0;
  223|   120k|			sldns_buffer_skip(pkt, (ssize_t)labellen);
  224|   120k|		}
  225|  3.57M|	}
  226|  3.32M|	if(endpos)
  ------------------
  |  Branch (226:5): [True: 46.3k, False: 3.28M]
  ------------------
  227|  46.3k|		sldns_buffer_set_position(pkt, endpos);
  228|       |
  229|  3.32M|	return len;
  230|  3.32M|}
dname_pkt_compare:
  234|  3.25M|{
  235|  3.25M|	uint8_t len1, len2;
  236|  3.25M|	int count1 = 0, count2 = 0;
  237|  3.25M|	log_assert(pkt && d1 && d2);
  238|  3.25M|	len1 = *d1++;
  239|  3.25M|	len2 = *d2++;
  240|  3.39M|	while( len1 != 0 || len2 != 0 ) {
  ------------------
  |  Branch (240:9): [True: 123k, False: 3.26M]
  |  Branch (240:22): [True: 23.3k, False: 3.24M]
  ------------------
  241|       |		/* resolve ptrs */
  242|   147k|		if(LABEL_IS_PTR(len1)) {
  ------------------
  |  |  202|   147k|#define LABEL_IS_PTR(x) ( ((x)&0xc0) == 0xc0 )
  |  |  ------------------
  |  |  |  Branch (202:25): [True: 39.1k, False: 108k]
  |  |  ------------------
  ------------------
  243|  39.1k|			if((size_t)PTR_OFFSET(len1, *d1)
  ------------------
  |  |  205|  39.1k|#define PTR_OFFSET(x, y) ( ((x)&0x3f)<<8 | (y) )
  ------------------
  |  Branch (243:7): [True: 0, False: 39.1k]
  ------------------
  244|  39.1k|				>= sldns_buffer_limit(pkt))
  245|      0|				return -1;
  246|  39.1k|			if(count1++ > MAX_COMPRESS_PTRS)
  ------------------
  |  |   51|  39.1k|#define MAX_COMPRESS_PTRS 256
  ------------------
  |  Branch (246:7): [True: 0, False: 39.1k]
  ------------------
  247|      0|				return -1;
  248|  39.1k|			d1 = sldns_buffer_at(pkt, PTR_OFFSET(len1, *d1));
  ------------------
  |  |  205|  39.1k|#define PTR_OFFSET(x, y) ( ((x)&0x3f)<<8 | (y) )
  ------------------
  249|  39.1k|			len1 = *d1++;
  250|  39.1k|			continue;
  251|  39.1k|		}
  252|   108k|		if(LABEL_IS_PTR(len2)) {
  ------------------
  |  |  202|   108k|#define LABEL_IS_PTR(x) ( ((x)&0xc0) == 0xc0 )
  |  |  ------------------
  |  |  |  Branch (202:25): [True: 42.7k, False: 65.4k]
  |  |  ------------------
  ------------------
  253|  42.7k|			if((size_t)PTR_OFFSET(len2, *d2)
  ------------------
  |  |  205|  42.7k|#define PTR_OFFSET(x, y) ( ((x)&0x3f)<<8 | (y) )
  ------------------
  |  Branch (253:7): [True: 0, False: 42.7k]
  ------------------
  254|  42.7k|				>= sldns_buffer_limit(pkt))
  255|      0|				return 1;
  256|  42.7k|			if(count2++ > MAX_COMPRESS_PTRS)
  ------------------
  |  |   51|  42.7k|#define MAX_COMPRESS_PTRS 256
  ------------------
  |  Branch (256:7): [True: 0, False: 42.7k]
  ------------------
  257|      0|				return 1;
  258|  42.7k|			d2 = sldns_buffer_at(pkt, PTR_OFFSET(len2, *d2));
  ------------------
  |  |  205|  42.7k|#define PTR_OFFSET(x, y) ( ((x)&0x3f)<<8 | (y) )
  ------------------
  259|  42.7k|			len2 = *d2++;
  260|  42.7k|			continue;
  261|  42.7k|		}
  262|       |		/* check label length */
  263|  65.4k|		log_assert(len1 <= LDNS_MAX_LABELLEN);
  264|  65.4k|		log_assert(len2 <= LDNS_MAX_LABELLEN);
  265|  65.4k|		if(len1 != len2) {
  ------------------
  |  Branch (265:6): [True: 7.33k, False: 58.1k]
  ------------------
  266|  7.33k|			if(len1 < len2) return -1;
  ------------------
  |  Branch (266:7): [True: 1.66k, False: 5.66k]
  ------------------
  267|  5.66k|			return 1;
  268|  7.33k|		}
  269|  58.1k|		log_assert(len1 == len2 && len1 != 0);
  270|       |		/* compare labels */
  271|   688k|		while(len1--) {
  ------------------
  |  Branch (271:9): [True: 632k, False: 56.1k]
  ------------------
  272|   632k|			if(tolower((unsigned char)*d1) != tolower((unsigned char)*d2)) {
  ------------------
  |  Branch (272:7): [True: 2.01k, False: 630k]
  ------------------
  273|  2.01k|				if(tolower((unsigned char)*d1) < tolower((unsigned char)*d2))
  ------------------
  |  Branch (273:8): [True: 1.16k, False: 843]
  ------------------
  274|  1.16k|					return -1;
  275|    843|				return 1;
  276|  2.01k|			}
  277|   630k|			d1++;
  278|   630k|			d2++;
  279|   630k|		}
  280|  56.1k|		len1 = *d1++;
  281|  56.1k|		len2 = *d2++;
  282|  56.1k|	}
  283|  3.24M|	return 0;
  284|  3.25M|}
dname_pkt_hash:
  312|  3.26M|{
  313|  3.26M|	uint8_t labuf[LDNS_MAX_LABELLEN+1];
  314|  3.26M|	uint8_t lablen;
  315|  3.26M|	int i;
  316|  3.26M|	int count = 0;
  317|       |
  318|       |	/* preserve case of query, make hash label by label */
  319|  3.26M|	lablen = *dname++;
  320|  3.40M|	while(lablen) {
  ------------------
  |  Branch (320:8): [True: 139k, False: 3.26M]
  ------------------
  321|   139k|		if(LABEL_IS_PTR(lablen)) {
  ------------------
  |  |  202|   139k|#define LABEL_IS_PTR(x) ( ((x)&0xc0) == 0xc0 )
  |  |  ------------------
  |  |  |  Branch (202:25): [True: 49.7k, False: 89.3k]
  |  |  ------------------
  ------------------
  322|       |			/* follow pointer */
  323|  49.7k|			if((size_t)PTR_OFFSET(lablen, *dname)
  ------------------
  |  |  205|  49.7k|#define PTR_OFFSET(x, y) ( ((x)&0x3f)<<8 | (y) )
  ------------------
  |  Branch (323:7): [True: 0, False: 49.7k]
  ------------------
  324|  49.7k|				>= sldns_buffer_limit(pkt))
  325|      0|				return h;
  326|  49.7k|			if(count++ > MAX_COMPRESS_PTRS)
  ------------------
  |  |   51|  49.7k|#define MAX_COMPRESS_PTRS 256
  ------------------
  |  Branch (326:7): [True: 0, False: 49.7k]
  ------------------
  327|      0|				return h;
  328|  49.7k|			dname = sldns_buffer_at(pkt, PTR_OFFSET(lablen, *dname));
  ------------------
  |  |  205|  49.7k|#define PTR_OFFSET(x, y) ( ((x)&0x3f)<<8 | (y) )
  ------------------
  329|  49.7k|			lablen = *dname++;
  330|  49.7k|			continue;
  331|  49.7k|		}
  332|  89.3k|		log_assert(lablen <= LDNS_MAX_LABELLEN);
  333|  89.3k|		labuf[0] = lablen;
  334|  89.3k|		i=0;
  335|  1.11M|		while(lablen--) {
  ------------------
  |  Branch (335:9): [True: 1.02M, False: 89.3k]
  ------------------
  336|  1.02M|			labuf[++i] = (uint8_t)tolower((unsigned char)*dname);
  337|  1.02M|			dname++;
  338|  1.02M|		}
  339|  89.3k|		h = hashlittle(labuf, labuf[0] + 1, h);
  340|  89.3k|		lablen = *dname++;
  341|  89.3k|	}
  342|       |
  343|  3.26M|	return h;
  344|  3.26M|}
dname_pkt_copy:
  347|  72.4k|{
  348|       |	/* copy over the dname and decompress it at the same time */
  349|  72.4k|	size_t comprcount = 0;
  350|  72.4k|	size_t len = 0;
  351|  72.4k|	uint8_t lablen;
  352|  72.4k|	lablen = *dname++;
  353|   117k|	while(lablen) {
  ------------------
  |  Branch (353:8): [True: 45.1k, False: 72.4k]
  ------------------
  354|  45.1k|		if(LABEL_IS_PTR(lablen)) {
  ------------------
  |  |  202|  45.1k|#define LABEL_IS_PTR(x) ( ((x)&0xc0) == 0xc0 )
  |  |  ------------------
  |  |  |  Branch (202:25): [True: 10.2k, False: 34.8k]
  |  |  ------------------
  ------------------
  355|  10.2k|			if(comprcount++ > MAX_COMPRESS_PTRS) {
  ------------------
  |  |   51|  10.2k|#define MAX_COMPRESS_PTRS 256
  ------------------
  |  Branch (355:7): [True: 0, False: 10.2k]
  ------------------
  356|       |				/* too many compression pointers */
  357|      0|				*to = 0; /* end the result prematurely */
  358|      0|				return;
  359|      0|			}
  360|       |			/* follow pointer */
  361|  10.2k|			if((size_t)PTR_OFFSET(lablen, *dname)
  ------------------
  |  |  205|  10.2k|#define PTR_OFFSET(x, y) ( ((x)&0x3f)<<8 | (y) )
  ------------------
  |  Branch (361:7): [True: 0, False: 10.2k]
  ------------------
  362|  10.2k|				>= sldns_buffer_limit(pkt))
  363|      0|				return;
  364|  10.2k|			dname = sldns_buffer_at(pkt, PTR_OFFSET(lablen, *dname));
  ------------------
  |  |  205|  10.2k|#define PTR_OFFSET(x, y) ( ((x)&0x3f)<<8 | (y) )
  ------------------
  365|  10.2k|			lablen = *dname++;
  366|  10.2k|			continue;
  367|  10.2k|		}
  368|  34.8k|		if(lablen > LDNS_MAX_LABELLEN) {
  ------------------
  |  |   27|  34.8k|#define LDNS_MAX_LABELLEN     63
  ------------------
  |  Branch (368:6): [True: 0, False: 34.8k]
  ------------------
  369|      0|			*to = 0; /* end the result prematurely */
  370|      0|			return;
  371|      0|		}
  372|  34.8k|		log_assert(lablen <= LDNS_MAX_LABELLEN);
  373|  34.8k|		len += (size_t)lablen+1;
  374|  34.8k|		if(len >= LDNS_MAX_DOMAINLEN) {
  ------------------
  |  |   29|  34.8k|#define LDNS_MAX_DOMAINLEN    255
  ------------------
  |  Branch (374:6): [True: 0, False: 34.8k]
  ------------------
  375|      0|			*to = 0; /* end the result prematurely */
  376|      0|			log_err("bad dname in dname_pkt_copy");
  377|      0|			return;
  378|      0|		}
  379|  34.8k|		*to++ = lablen;
  380|  34.8k|		memmove(to, dname, lablen);
  381|  34.8k|		dname += lablen;
  382|  34.8k|		to += lablen;
  383|  34.8k|		lablen = *dname++;
  384|  34.8k|	}
  385|       |	/* copy last \0 */
  386|  72.4k|	*to = 0;
  387|  72.4k|}
dname_count_labels:
  432|  95.6k|{
  433|  95.6k|	uint8_t lablen;
  434|  95.6k|	int labs = 1;
  435|       |
  436|  95.6k|	lablen = *dname++;
  437|   166k|	while(lablen) {
  ------------------
  |  Branch (437:8): [True: 71.3k, False: 95.6k]
  ------------------
  438|  71.3k|		labs++;
  439|  71.3k|		dname += lablen;
  440|  71.3k|		lablen = *dname++;
  441|  71.3k|	}
  442|  95.6k|	return labs;
  443|  95.6k|}
dname_lab_cmp:
  487|  10.9k|{
  488|  10.9k|	uint8_t len1, len2;
  489|  10.9k|	int atlabel = labs1;
  490|  10.9k|	int lastmlabs;
  491|  10.9k|	int lastdiff = 0;
  492|       |	/* first skip so that we compare same label. */
  493|  10.9k|	if(labs1 > labs2) {
  ------------------
  |  Branch (493:5): [True: 5.99k, False: 4.99k]
  ------------------
  494|  19.5k|		while(atlabel > labs2) {
  ------------------
  |  Branch (494:9): [True: 13.5k, False: 5.99k]
  ------------------
  495|  13.5k|			len1 = *d1++;
  496|  13.5k|			d1 += len1;
  497|  13.5k|			atlabel--;
  498|  13.5k|		}
  499|  5.99k|		log_assert(atlabel == labs2);
  500|  5.99k|	} else if(labs1 < labs2) {
  ------------------
  |  Branch (500:12): [True: 0, False: 4.99k]
  ------------------
  501|      0|		atlabel = labs2;
  502|      0|		while(atlabel > labs1) {
  ------------------
  |  Branch (502:9): [True: 0, False: 0]
  ------------------
  503|      0|			len2 = *d2++;
  504|      0|			d2 += len2;
  505|      0|			atlabel--;
  506|      0|		}
  507|      0|		log_assert(atlabel == labs1);
  508|      0|	}
  509|  10.9k|	lastmlabs = atlabel+1;
  510|       |	/* now at same label in d1 and d2, atlabel */
  511|       |	/* www.example.com.                  */
  512|       |	/* 4   3       2  1   atlabel number */
  513|       |	/* repeat until at root label (which is always the same) */
  514|  20.7k|	while(atlabel > 1) {
  ------------------
  |  Branch (514:8): [True: 9.73k, False: 10.9k]
  ------------------
  515|  9.73k|		len1 = *d1++;
  516|  9.73k|		len2 = *d2++;
  517|  9.73k|		if(len1 != len2) {
  ------------------
  |  Branch (517:6): [True: 4.60k, False: 5.13k]
  ------------------
  518|  4.60k|			log_assert(len1 != 0 && len2 != 0);
  519|  4.60k|			if(len1<len2)
  ------------------
  |  Branch (519:7): [True: 2.12k, False: 2.48k]
  ------------------
  520|  2.12k|				lastdiff = -1;
  521|  2.48k|			else	lastdiff = 1;
  522|  4.60k|			lastmlabs = atlabel;
  523|  4.60k|			d1 += len1;
  524|  4.60k|			d2 += len2;
  525|  5.13k|		} else {
  526|       |			/* memlowercmp is inlined here; or just like
  527|       |			 * if((c=memlowercmp(d1, d2, len1)) != 0) { 
  528|       |			 *	lastdiff = c;
  529|       |			 *	lastmlabs = atlabel; } apart from d1++,d2++ */
  530|  14.0k|			while(len1) {
  ------------------
  |  Branch (530:10): [True: 10.0k, False: 4.06k]
  ------------------
  531|  10.0k|				if(*d1 != *d2 && tolower((unsigned char)*d1) 
  ------------------
  |  Branch (531:8): [True: 3.82k, False: 6.21k]
  |  Branch (531:22): [True: 1.06k, False: 2.75k]
  ------------------
  532|  3.82k|					!= tolower((unsigned char)*d2)) {
  533|  1.06k|					if(tolower((unsigned char)*d1) < 
  ------------------
  |  Branch (533:9): [True: 672, False: 397]
  ------------------
  534|  1.06k|						tolower((unsigned char)*d2)) {
  535|    672|						lastdiff = -1;
  536|    672|						lastmlabs = atlabel;
  537|    672|						d1 += len1;
  538|    672|						d2 += len1;
  539|    672|						break;
  540|    672|					}
  541|    397|					lastdiff = 1;
  542|    397|					lastmlabs = atlabel;
  543|    397|					d1 += len1;
  544|    397|					d2 += len1;
  545|    397|					break; /* out of memlowercmp */
  546|  1.06k|				}
  547|  8.96k|				d1++;
  548|  8.96k|				d2++;
  549|  8.96k|				len1--;
  550|  8.96k|			}
  551|  5.13k|		}
  552|  9.73k|		atlabel--;
  553|  9.73k|	}
  554|       |	/* last difference atlabel number, so number of labels matching,
  555|       |	 * at the right side, is one less. */
  556|  10.9k|	*mlabs = lastmlabs-1;
  557|  10.9k|	if(lastdiff == 0) {
  ------------------
  |  Branch (557:5): [True: 6.02k, False: 4.96k]
  ------------------
  558|       |		/* all labels compared were equal, check if one has more
  559|       |		 * labels, so that example.com. > com. */
  560|  6.02k|		if(labs1 > labs2)
  ------------------
  |  Branch (560:6): [True: 4.02k, False: 2.00k]
  ------------------
  561|  4.02k|			return 1;
  562|  2.00k|		else if(labs1 < labs2)
  ------------------
  |  Branch (562:11): [True: 0, False: 2.00k]
  ------------------
  563|      0|			return -1;
  564|  6.02k|	}
  565|  6.96k|	return lastdiff;
  566|  10.9k|}
dname_strict_subdomain:
  680|  1.33k|{
  681|  1.33k|	int m;
  682|       |	/* check subdomain: d1: www.example.com. and d2: example.com. */
  683|  1.33k|	if(labs2 >= labs1) 
  ------------------
  |  Branch (683:5): [True: 194, False: 1.13k]
  ------------------
  684|    194|		return 0;
  685|  1.13k|	if(dname_lab_cmp(d1, labs1, d2, labs2, &m) > 0) {
  ------------------
  |  Branch (685:5): [True: 967, False: 171]
  ------------------
  686|       |		/* subdomain if all labels match */
  687|    967|		return (m == labs2);
  688|    967|	}
  689|    171|	return 0;
  690|  1.13k|}
dname_strict_subdomain_c:
  694|  1.33k|{
  695|  1.33k|	return dname_strict_subdomain(d1, dname_count_labels(d1), d2,
  696|  1.33k|		dname_count_labels(d2));
  697|  1.33k|}
dname_subdomain_c:
  701|  46.4k|{
  702|  46.4k|	int m;
  703|       |	/* check subdomain: d1: www.example.com. and d2: example.com. */
  704|       |	/*  	or 	    d1: example.com. and d2: example.com. */
  705|  46.4k|	int labs1 = dname_count_labels(d1);
  706|  46.4k|	int labs2 = dname_count_labels(d2);
  707|  46.4k|	if(labs2 > labs1) 
  ------------------
  |  Branch (707:5): [True: 36.6k, False: 9.85k]
  ------------------
  708|  36.6k|		return 0;
  709|  9.85k|	if(dname_lab_cmp(d1, labs1, d2, labs2, &m) < 0) {
  ------------------
  |  Branch (709:5): [True: 2.26k, False: 7.58k]
  ------------------
  710|       |		/* must have been example.com , www.example.com - wrong */
  711|       |		/* or otherwise different dnames */
  712|  2.26k|		return 0;
  713|  2.26k|	}
  714|  7.58k|	return (m == labs2);
  715|  9.85k|}

pkt_hash_rrset:
  171|  10.2k|{
  172|       |	/* note this MUST be identical to rrset_key_hash in packed_rrset.c */
  173|       |	/* this routine handles compressed names */
  174|  10.2k|	hashvalue_type h = 0xab;
  175|  10.2k|	h = dname_pkt_hash(pkt, dname, h);
  176|  10.2k|	h = hashlittle(&type, sizeof(type), h);		/* host order */
  177|  10.2k|	h = hashlittle(&dclass, sizeof(dclass), h);	/* netw order */
  178|  10.2k|	h = hashlittle(&rrset_flags, sizeof(uint32_t), h);
  179|  10.2k|	return h;
  180|  10.2k|}
msgparse_hashtable_lookup:
  226|  1.07M|{
  227|  1.07M|	struct rrset_parse* p = msg->hashtable[h & (PARSE_TABLE_SIZE-1)];
  ------------------
  |  |   77|  1.07M|#define PARSE_TABLE_SIZE 32
  ------------------
  228|  4.34M|	while(p) {
  ------------------
  |  Branch (228:8): [True: 3.79M, False: 553k]
  ------------------
  229|  3.79M|		if(rrset_parse_equals(p, pkt, h, rrset_flags, dname, dnamelen,
  ------------------
  |  Branch (229:6): [True: 523k, False: 3.27M]
  ------------------
  230|  3.79M|			type, dclass))
  231|   523k|			return p;
  232|  3.27M|		p = p->rrset_bucket_next;
  233|  3.27M|	}
  234|   553k|	return NULL;
  235|  1.07M|}
msgparse_bucket_remove:
  268|  51.5k|{
  269|  51.5k|	struct rrset_parse** p;
  270|  51.5k|	p = &msg->hashtable[ rrset->hash & (PARSE_TABLE_SIZE-1) ];
  ------------------
  |  |   77|  51.5k|#define PARSE_TABLE_SIZE 32
  ------------------
  271|   296k|	while(*p) {
  ------------------
  |  Branch (271:8): [True: 296k, False: 549]
  ------------------
  272|   296k|		if(*p == rrset) {
  ------------------
  |  Branch (272:6): [True: 51.0k, False: 244k]
  ------------------
  273|  51.0k|			*p = rrset->rrset_bucket_next;
  274|  51.0k|			return;
  275|  51.0k|		}
  276|   244k|		p = &( (*p)->rrset_bucket_next );
  277|   244k|	}
  278|  51.5k|}
get_rdf_size:
  602|   226k|{
  603|   226k|	switch(rdf) {
  604|      0|		case LDNS_RDF_TYPE_CLASS:
  ------------------
  |  Branch (604:3): [True: 0, False: 226k]
  ------------------
  605|  32.5k|		case LDNS_RDF_TYPE_ALG:
  ------------------
  |  Branch (605:3): [True: 32.5k, False: 194k]
  ------------------
  606|  64.9k|		case LDNS_RDF_TYPE_INT8:
  ------------------
  |  Branch (606:3): [True: 32.4k, False: 194k]
  ------------------
  607|  64.9k|			return 1;
  608|      0|			break;
  609|  32.7k|		case LDNS_RDF_TYPE_INT16:
  ------------------
  |  Branch (609:3): [True: 32.7k, False: 193k]
  ------------------
  610|  65.5k|		case LDNS_RDF_TYPE_TYPE:
  ------------------
  |  Branch (610:3): [True: 32.8k, False: 193k]
  ------------------
  611|  65.5k|		case LDNS_RDF_TYPE_CERT_ALG:
  ------------------
  |  Branch (611:3): [True: 0, False: 226k]
  ------------------
  612|  65.5k|			return 2;
  613|      0|			break;
  614|  32.1k|		case LDNS_RDF_TYPE_INT32:
  ------------------
  |  Branch (614:3): [True: 32.1k, False: 194k]
  ------------------
  615|  96.1k|		case LDNS_RDF_TYPE_TIME:
  ------------------
  |  Branch (615:3): [True: 63.9k, False: 162k]
  ------------------
  616|  96.1k|		case LDNS_RDF_TYPE_A:
  ------------------
  |  Branch (616:3): [True: 0, False: 226k]
  ------------------
  617|  96.1k|		case LDNS_RDF_TYPE_PERIOD:
  ------------------
  |  Branch (617:3): [True: 0, False: 226k]
  ------------------
  618|  96.1k|			return 4;
  619|      0|			break;
  620|      0|		case LDNS_RDF_TYPE_TSIGTIME:
  ------------------
  |  Branch (620:3): [True: 0, False: 226k]
  ------------------
  621|      0|			return 6;
  622|      0|			break;
  623|      0|		case LDNS_RDF_TYPE_AAAA:
  ------------------
  |  Branch (623:3): [True: 0, False: 226k]
  ------------------
  624|      0|			return 16;
  625|      0|			break;
  626|      0|		default:
  ------------------
  |  Branch (626:3): [True: 0, False: 226k]
  ------------------
  627|      0|			log_assert(0); /* add type above */
  628|       |			/* only types that appear before a domain  *
  629|       |			 * name are needed. rest is simply copied. */
  630|   226k|	}
  631|      0|	return 0;
  632|   226k|}
parse_packet:
  909|  4.59k|{
  910|  4.59k|	int ret;
  911|  4.59k|	if(sldns_buffer_remaining(pkt) < LDNS_HEADER_SIZE)
  ------------------
  |  |   26|  4.59k|#define	LDNS_HEADER_SIZE	12
  ------------------
  |  Branch (911:5): [True: 10, False: 4.58k]
  ------------------
  912|     10|		return LDNS_RCODE_FORMERR;
  913|       |	/* read the header */
  914|  4.58k|	sldns_buffer_read(pkt, &msg->id, sizeof(uint16_t));
  915|  4.58k|	msg->flags = sldns_buffer_read_u16(pkt);
  916|  4.58k|	msg->qdcount = sldns_buffer_read_u16(pkt);
  917|  4.58k|	msg->ancount = sldns_buffer_read_u16(pkt);
  918|  4.58k|	msg->nscount = sldns_buffer_read_u16(pkt);
  919|  4.58k|	msg->arcount = sldns_buffer_read_u16(pkt);
  920|  4.58k|	if(msg->qdcount > 1)
  ------------------
  |  Branch (920:5): [True: 15, False: 4.56k]
  ------------------
  921|     15|		return LDNS_RCODE_FORMERR;
  922|  4.56k|	if((ret = parse_query_section(pkt, msg)) != 0)
  ------------------
  |  Branch (922:5): [True: 29, False: 4.53k]
  ------------------
  923|     29|		return ret;
  924|  4.53k|	if((ret = parse_section(pkt, msg, region, LDNS_SECTION_ANSWER,
  ------------------
  |  Branch (924:5): [True: 1.42k, False: 3.11k]
  ------------------
  925|  4.53k|		msg->ancount, &msg->an_rrsets)) != 0)
  926|  1.42k|		return ret;
  927|  3.11k|	if((ret = parse_section(pkt, msg, region, LDNS_SECTION_AUTHORITY,
  ------------------
  |  Branch (927:5): [True: 700, False: 2.41k]
  ------------------
  928|  3.11k|		msg->nscount, &msg->ns_rrsets)) != 0)
  929|    700|		return ret;
  930|  2.41k|	if(sldns_buffer_remaining(pkt) == 0 && msg->arcount == 1) {
  ------------------
  |  Branch (930:5): [True: 1.11k, False: 1.29k]
  |  Branch (930:41): [True: 292, False: 824]
  ------------------
  931|       |		/* BIND accepts leniently that an EDNS record is missing.
  932|       |		 * so, we do too. */
  933|  2.12k|	} else if((ret = parse_section(pkt, msg, region,
  ------------------
  |  Branch (933:12): [True: 393, False: 1.72k]
  ------------------
  934|  2.12k|		LDNS_SECTION_ADDITIONAL, msg->arcount, &msg->ar_rrsets)) != 0)
  935|    393|		return ret;
  936|       |	/* if(sldns_buffer_remaining(pkt) > 0) { */
  937|       |		/* there is spurious data at end of packet. ignore */
  938|       |	/* } */
  939|  2.02k|	msg->rrset_count = msg->an_rrsets + msg->ns_rrsets + msg->ar_rrsets;
  940|  2.02k|	return 0;
  941|  2.41k|}
parse_extract_edns_from_response_msg:
 1061|  2.02k|{
 1062|  2.02k|	struct rrset_parse* rrset = msg->rrset_first;
 1063|  2.02k|	struct rrset_parse* prev = 0;
 1064|  2.02k|	struct rrset_parse* found = 0;
 1065|  2.02k|	struct rrset_parse* found_prev = 0;
 1066|  2.02k|	size_t rdata_len;
 1067|  2.02k|	uint8_t* rdata_ptr;
 1068|       |	/* since the class encodes the UDP size, we cannot use hash table to
 1069|       |	 * find the EDNS OPT record. Scan the packet. */
 1070|  56.0k|	while(rrset) {
  ------------------
  |  Branch (1070:8): [True: 54.0k, False: 2.01k]
  ------------------
 1071|  54.0k|		if(rrset->type == LDNS_RR_TYPE_OPT) {
  ------------------
  |  Branch (1071:6): [True: 177, False: 53.8k]
  ------------------
 1072|       |			/* only one OPT RR allowed. */
 1073|    177|			if(found) return LDNS_RCODE_FORMERR;
  ------------------
  |  Branch (1073:7): [True: 2, False: 175]
  ------------------
 1074|       |			/* found it! */
 1075|    175|			found_prev = prev;
 1076|    175|			found = rrset;
 1077|    175|		}
 1078|  54.0k|		prev = rrset;
 1079|  54.0k|		rrset = rrset->rrset_all_next;
 1080|  54.0k|	}
 1081|  2.01k|	if(!found) {
  ------------------
  |  Branch (1081:5): [True: 1.84k, False: 173]
  ------------------
 1082|  1.84k|		memset(edns, 0, sizeof(*edns));
 1083|  1.84k|		edns->udp_size = 512;
 1084|  1.84k|		return 0;
 1085|  1.84k|	}
 1086|       |	/* check the found RRset */
 1087|       |	/* most lenient check possible. ignore dname, use last opt */
 1088|    173|	if(found->section != LDNS_SECTION_ADDITIONAL)
  ------------------
  |  Branch (1088:5): [True: 1, False: 172]
  ------------------
 1089|      1|		return LDNS_RCODE_FORMERR; 
 1090|    172|	if(found->rr_count == 0)
  ------------------
  |  Branch (1090:5): [True: 1, False: 171]
  ------------------
 1091|      1|		return LDNS_RCODE_FORMERR;
 1092|    171|	if(0) { /* strict checking of dname and RRcount */
  ------------------
  |  Branch (1092:5): [Folded - Ignored]
  ------------------
 1093|      0|		if(found->dname_len != 1 || !found->dname 
  ------------------
  |  Branch (1093:6): [True: 0, False: 0]
  |  Branch (1093:31): [True: 0, False: 0]
  ------------------
 1094|      0|			|| found->dname[0] != 0) return LDNS_RCODE_FORMERR; 
  ------------------
  |  Branch (1094:7): [True: 0, False: 0]
  ------------------
 1095|      0|		if(found->rr_count != 1) return LDNS_RCODE_FORMERR; 
  ------------------
  |  Branch (1095:6): [True: 0, False: 0]
  ------------------
 1096|      0|	}
 1097|    171|	log_assert(found->rr_first && found->rr_last);
 1098|       |
 1099|       |	/* remove from packet */
 1100|    171|	if(found_prev)	found_prev->rrset_all_next = found->rrset_all_next;
  ------------------
  |  Branch (1100:5): [True: 37, False: 134]
  ------------------
 1101|    134|	else	msg->rrset_first = found->rrset_all_next;
 1102|    171|	if(found == msg->rrset_last)
  ------------------
  |  Branch (1102:5): [True: 132, False: 39]
  ------------------
 1103|    132|		msg->rrset_last = found_prev;
 1104|    171|	msg->arcount --;
 1105|    171|	msg->ar_rrsets --;
 1106|    171|	msg->rrset_count --;
 1107|       |	
 1108|       |	/* take the data ! */
 1109|    171|	edns->edns_present = 1;
 1110|    171|	edns->ext_rcode = found->rr_last->ttl_data[0];
 1111|    171|	edns->edns_version = found->rr_last->ttl_data[1];
 1112|    171|	edns->bits = sldns_read_uint16(&found->rr_last->ttl_data[2]);
 1113|    171|	edns->udp_size = ntohs(found->rrset_class);
 1114|    171|	edns->opt_list_in = NULL;
 1115|    171|	edns->opt_list_out = NULL;
 1116|    171|	edns->opt_list_inplace_cb_out = NULL;
 1117|    171|	edns->padding_block_size = 0;
 1118|       |
 1119|       |	/* take the options */
 1120|    171|	rdata_len = found->rr_first->size-2;
 1121|    171|	rdata_ptr = found->rr_first->ttl_data+6;
 1122|       |
 1123|       |	/* while still more options, and have code+len to read */
 1124|       |	/* ignores partial content (i.e. rdata len 3) */
 1125|  18.0k|	while(rdata_len >= 4) {
  ------------------
  |  Branch (1125:8): [True: 17.9k, False: 93]
  ------------------
 1126|  17.9k|		uint16_t opt_code = sldns_read_uint16(rdata_ptr);
 1127|  17.9k|		uint16_t opt_len = sldns_read_uint16(rdata_ptr+2);
 1128|  17.9k|		rdata_ptr += 4;
 1129|  17.9k|		rdata_len -= 4;
 1130|  17.9k|		if(opt_len > rdata_len)
  ------------------
  |  Branch (1130:6): [True: 78, False: 17.9k]
  ------------------
 1131|     78|			break; /* option code partial */
 1132|       |
 1133|  17.9k|		if(!edns_opt_list_append(&edns->opt_list_in,
  ------------------
  |  Branch (1133:6): [True: 0, False: 17.9k]
  ------------------
 1134|  17.9k|				opt_code, opt_len, rdata_ptr, region)) {
 1135|      0|			log_err("out of memory");
 1136|      0|			break;
 1137|      0|		}
 1138|  17.9k|		rdata_ptr += opt_len;
 1139|  17.9k|		rdata_len -= opt_len;
 1140|  17.9k|	}
 1141|       |	/* ignore rrsigs */
 1142|    171|	return LDNS_RCODE_NOERROR;
 1143|    171|}
msgparse.c:rrset_parse_equals:
  213|  3.79M|{
  214|  3.79M|	if(p->hash == h && p->dname_len == dnamelen && p->type == type &&
  ------------------
  |  Branch (214:5): [True: 527k, False: 3.26M]
  |  Branch (214:21): [True: 525k, False: 1.76k]
  |  Branch (214:49): [True: 524k, False: 1.00k]
  ------------------
  215|  3.79M|		p->rrset_class == dclass && p->flags == rrset_flags &&
  ------------------
  |  Branch (215:3): [True: 524k, False: 486]
  |  Branch (215:31): [True: 524k, False: 281]
  ------------------
  216|  3.79M|		dname_pkt_compare(pkt, dname, p->dname) == 0)
  ------------------
  |  Branch (216:3): [True: 523k, False: 606]
  ------------------
  217|   523k|		return 1;
  218|  3.27M|	return 0;
  219|  3.79M|}
msgparse.c:parse_query_section:
  582|  4.56k|{
  583|  4.56k|	if(msg->qdcount == 0)
  ------------------
  |  Branch (583:5): [True: 2.81k, False: 1.75k]
  ------------------
  584|  2.81k|		return 0;
  585|  1.75k|	if(msg->qdcount > 1)
  ------------------
  |  Branch (585:5): [True: 0, False: 1.75k]
  ------------------
  586|      0|		return LDNS_RCODE_FORMERR;
  587|  1.75k|	log_assert(msg->qdcount == 1);
  588|  1.75k|	if(sldns_buffer_remaining(pkt) <= 0)
  ------------------
  |  Branch (588:5): [True: 1, False: 1.75k]
  ------------------
  589|      1|		return LDNS_RCODE_FORMERR;
  590|  1.75k|	msg->qname = sldns_buffer_current(pkt);
  591|  1.75k|	if((msg->qname_len = pkt_dname_len(pkt)) == 0)
  ------------------
  |  Branch (591:5): [True: 13, False: 1.74k]
  ------------------
  592|     13|		return LDNS_RCODE_FORMERR;
  593|  1.74k|	if(sldns_buffer_remaining(pkt) < sizeof(uint16_t)*2)
  ------------------
  |  Branch (593:5): [True: 15, False: 1.72k]
  ------------------
  594|     15|		return LDNS_RCODE_FORMERR;
  595|  1.72k|	msg->qtype = sldns_buffer_read_u16(pkt);
  596|  1.72k|	msg->qclass = sldns_buffer_read_u16(pkt);
  597|  1.72k|	return 0;
  598|  1.74k|}
msgparse.c:parse_section:
  826|  9.77k|{
  827|  9.77k|	uint16_t i;
  828|  9.77k|	uint8_t* dname, *prev_dname_f = NULL, *prev_dname_l = NULL;
  829|  9.77k|	size_t dnamelen, prev_dnamelen = 0;
  830|  9.77k|	uint16_t type, prev_type = 0;
  831|  9.77k|	uint16_t dclass, prev_dclass = 0;
  832|  9.77k|	uint32_t rrset_flags = 0;
  833|  9.77k|	hashvalue_type hash = 0;
  834|  9.77k|	struct rrset_parse* rrset = NULL;
  835|  9.77k|	int r;
  836|       |
  837|  9.77k|	if(num_rrs == 0)
  ------------------
  |  Branch (837:5): [True: 4.11k, False: 5.65k]
  ------------------
  838|  4.11k|		return 0;
  839|  5.65k|	if(sldns_buffer_remaining(pkt) <= 0)
  ------------------
  |  Branch (839:5): [True: 43, False: 5.61k]
  ------------------
  840|     43|		return LDNS_RCODE_FORMERR;
  841|  3.26M|	for(i=0; i<num_rrs; i++) {
  ------------------
  |  Branch (841:11): [True: 3.25M, False: 3.13k]
  ------------------
  842|       |		/* parse this RR. */
  843|  3.25M|		dname = sldns_buffer_current(pkt);
  844|  3.25M|		if((dnamelen = pkt_dname_len(pkt)) == 0)
  ------------------
  |  Branch (844:6): [True: 894, False: 3.25M]
  ------------------
  845|    894|			return LDNS_RCODE_FORMERR;
  846|  3.25M|		if(sldns_buffer_remaining(pkt) < 10) /* type, class, ttl, len */
  ------------------
  |  Branch (846:6): [True: 232, False: 3.25M]
  ------------------
  847|    232|			return LDNS_RCODE_FORMERR;
  848|  3.25M|		type = sldns_buffer_read_u16(pkt);
  849|  3.25M|		sldns_buffer_read(pkt, &dclass, sizeof(dclass));
  850|       |
  851|  3.25M|		if(0) { /* debug show what is being parsed. */
  ------------------
  |  Branch (851:6): [Folded - Ignored]
  ------------------
  852|      0|			if(type == LDNS_RR_TYPE_RRSIG) {
  ------------------
  |  Branch (852:7): [True: 0, False: 0]
  ------------------
  853|      0|				uint16_t t;
  854|      0|				if(pkt_rrsig_covered(pkt, 
  ------------------
  |  Branch (854:8): [True: 0, False: 0]
  ------------------
  855|      0|					sldns_buffer_current(pkt), &t))
  856|      0|					fprintf(stderr, "parse of %s(%d) [%s(%d)]",
  857|      0|					sldns_rr_descript(type)?
  ------------------
  |  Branch (857:6): [True: 0, False: 0]
  ------------------
  858|      0|					sldns_rr_descript(type)->_name: "??",
  859|      0|					(int)type,
  860|      0|					sldns_rr_descript(t)?
  ------------------
  |  Branch (860:6): [True: 0, False: 0]
  ------------------
  861|      0|					sldns_rr_descript(t)->_name: "??",
  862|      0|					(int)t);
  863|      0|			} else
  864|      0|			  fprintf(stderr, "parse of %s(%d)",
  865|      0|				sldns_rr_descript(type)?
  ------------------
  |  Branch (865:5): [True: 0, False: 0]
  ------------------
  866|      0|				sldns_rr_descript(type)->_name: "??",
  867|      0|				(int)type);
  868|      0|			fprintf(stderr, " %s(%d) ",
  869|      0|				sldns_lookup_by_id(sldns_rr_classes, 
  ------------------
  |  Branch (869:5): [True: 0, False: 0]
  ------------------
  870|      0|				(int)ntohs(dclass))?sldns_lookup_by_id(
  871|      0|				sldns_rr_classes, (int)ntohs(dclass))->name: 
  872|      0|				"??", (int)ntohs(dclass));
  873|      0|			dname_print(stderr, pkt, dname);
  874|      0|			fprintf(stderr, "\n");
  875|      0|		}
  876|       |
  877|       |		/* see if it is part of an existing RR set */
  878|  3.25M|		if(!find_rrset(msg, pkt, dname, dnamelen, type, dclass, &hash, 
  ------------------
  |  Branch (878:6): [True: 0, False: 3.25M]
  ------------------
  879|  3.25M|			&rrset_flags, &prev_dname_f, &prev_dname_l, 
  880|  3.25M|			&prev_dnamelen, &prev_type, &prev_dclass, &rrset, 
  881|  3.25M|			section, region))
  882|      0|			return LDNS_RCODE_SERVFAIL;
  883|  3.25M|		if(!rrset) {
  ------------------
  |  Branch (883:6): [True: 84.0k, False: 3.17M]
  ------------------
  884|       |			/* it is a new RR set. hash&flags already calculated.*/
  885|  84.0k|			(*num_rrsets)++;
  886|  84.0k|			rrset = new_rrset(msg, dname, dnamelen, type, dclass,
  887|  84.0k|				hash, rrset_flags, section, region);
  888|  84.0k|			if(!rrset) 
  ------------------
  |  Branch (888:7): [True: 0, False: 84.0k]
  ------------------
  889|      0|				return LDNS_RCODE_SERVFAIL;
  890|  84.0k|		}
  891|  3.17M|		else if(0)	{ 
  ------------------
  |  Branch (891:11): [Folded - Ignored]
  ------------------
  892|      0|			fprintf(stderr, "is part of existing: ");
  893|      0|			dname_print(stderr, pkt, rrset->dname);
  894|      0|			fprintf(stderr, " type %s(%d)\n",
  895|      0|				sldns_rr_descript(rrset->type)?
  ------------------
  |  Branch (895:5): [True: 0, False: 0]
  ------------------
  896|      0|				sldns_rr_descript(rrset->type)->_name: "??",
  897|      0|				(int)rrset->type);
  898|      0|		}
  899|       |		/* add to rrset. */
  900|  3.25M|		if((r=add_rr_to_rrset(rrset, pkt, msg, region, section, 
  ------------------
  |  Branch (900:6): [True: 1.34k, False: 3.25M]
  ------------------
  901|  3.25M|			type)) != 0)
  902|  1.34k|			return r;
  903|  3.25M|	}
  904|  3.13k|	return 0;
  905|  5.61k|}
msgparse.c:find_rrset:
  470|  3.25M|{
  471|  3.25M|	hashvalue_type dname_h = pkt_hash_rrset_first(pkt, dname);
  472|  3.25M|	uint16_t covtype;
  473|  3.25M|	if(*rrset_prev) {
  ------------------
  |  Branch (473:5): [True: 3.25M, False: 5.52k]
  ------------------
  474|       |		/* check if equal to previous item */
  475|  3.25M|		if(type == *prev_type && dclass == *prev_dclass &&
  ------------------
  |  Branch (475:6): [True: 3.05M, False: 195k]
  |  Branch (475:28): [True: 2.72M, False: 333k]
  ------------------
  476|  3.25M|			dnamelen == *prev_dnamelen &&
  ------------------
  |  Branch (476:4): [True: 2.71M, False: 10.7k]
  ------------------
  477|  3.25M|			smart_compare(pkt, dname, *prev_dname_first, 
  ------------------
  |  Branch (477:4): [True: 2.71M, False: 1.42k]
  ------------------
  478|  2.71M|				*prev_dname_last) == 0 &&
  479|  3.25M|			type != LDNS_RR_TYPE_RRSIG) {
  ------------------
  |  Branch (479:4): [True: 2.70M, False: 8.28k]
  ------------------
  480|       |			/* same as previous */
  481|  2.70M|			*prev_dname_last = dname;
  482|  2.70M|			return 1;
  483|  2.70M|		}
  484|       |		/* check if rrsig over previous item */
  485|   548k|		if(type == LDNS_RR_TYPE_RRSIG && dclass == *prev_dclass &&
  ------------------
  |  Branch (485:6): [True: 32.3k, False: 516k]
  |  Branch (485:36): [True: 26.6k, False: 5.70k]
  ------------------
  486|   548k|			pkt_rrsig_covered_equals(pkt, sldns_buffer_current(pkt),
  ------------------
  |  Branch (486:4): [True: 10.6k, False: 15.9k]
  ------------------
  487|  26.6k|				*prev_type) &&
  488|   548k|			smart_compare(pkt, dname, *prev_dname_first,
  ------------------
  |  Branch (488:4): [True: 9.04k, False: 1.64k]
  ------------------
  489|  10.6k|				*prev_dname_last) == 0) {
  490|       |			/* covers previous */
  491|  9.04k|			*prev_dname_last = dname;
  492|  9.04k|			return 1;
  493|  9.04k|		}
  494|   548k|	}
  495|       |	/* find by hashing and lookup in hashtable */
  496|   545k|	*rrset_flags = pkt_rrset_flags(pkt, type, section);
  497|       |	
  498|       |	/* if rrsig - try to lookup matching data set first */
  499|   545k|	if(type == LDNS_RR_TYPE_RRSIG && pkt_rrsig_covered(pkt, 
  ------------------
  |  Branch (499:5): [True: 24.5k, False: 520k]
  |  Branch (499:35): [True: 16.9k, False: 7.53k]
  ------------------
  500|  24.5k|		sldns_buffer_current(pkt), &covtype)) {
  501|  16.9k|		*hash = pkt_hash_rrset_rest(dname_h, covtype, dclass, 
  502|  16.9k|			*rrset_flags);
  503|  16.9k|		*rrset_prev = msgparse_hashtable_lookup(msg, pkt, *hash, 
  504|  16.9k|			*rrset_flags, dname, dnamelen, covtype, dclass);
  505|  16.9k|		if(!*rrset_prev && covtype == LDNS_RR_TYPE_NSEC) {
  ------------------
  |  Branch (505:6): [True: 9.28k, False: 7.71k]
  |  Branch (505:22): [True: 1.00k, False: 8.27k]
  ------------------
  506|       |			/* if NSEC try with NSEC apex bit twiddled */
  507|  1.00k|			*rrset_flags ^= PACKED_RRSET_NSEC_AT_APEX;
  ------------------
  |  |   53|  1.00k|#define PACKED_RRSET_NSEC_AT_APEX 0x1
  ------------------
  508|  1.00k|			*hash = pkt_hash_rrset_rest(dname_h, covtype, dclass, 
  509|  1.00k|				*rrset_flags);
  510|  1.00k|			*rrset_prev = msgparse_hashtable_lookup(msg, pkt, 
  511|  1.00k|				*hash, *rrset_flags, dname, dnamelen, covtype, 
  512|  1.00k|				dclass);
  513|  1.00k|			if(!*rrset_prev) /* untwiddle if not found */
  ------------------
  |  Branch (513:7): [True: 782, False: 224]
  ------------------
  514|    782|				*rrset_flags ^= PACKED_RRSET_NSEC_AT_APEX;
  ------------------
  |  |   53|    782|#define PACKED_RRSET_NSEC_AT_APEX 0x1
  ------------------
  515|  1.00k|		}
  516|  16.9k|		if(!*rrset_prev && covtype == LDNS_RR_TYPE_SOA) {
  ------------------
  |  Branch (516:6): [True: 9.05k, False: 7.94k]
  |  Branch (516:22): [True: 1.29k, False: 7.75k]
  ------------------
  517|       |			/* if SOA try with SOA neg flag twiddled */
  518|  1.29k|			*rrset_flags ^= PACKED_RRSET_SOA_NEG;
  ------------------
  |  |   59|  1.29k|#define PACKED_RRSET_SOA_NEG 0x4
  ------------------
  519|  1.29k|			*hash = pkt_hash_rrset_rest(dname_h, covtype, dclass, 
  520|  1.29k|				*rrset_flags);
  521|  1.29k|			*rrset_prev = msgparse_hashtable_lookup(msg, pkt, 
  522|  1.29k|				*hash, *rrset_flags, dname, dnamelen, covtype, 
  523|  1.29k|				dclass);
  524|  1.29k|			if(!*rrset_prev) /* untwiddle if not found */
  ------------------
  |  Branch (524:7): [True: 850, False: 449]
  ------------------
  525|    850|				*rrset_flags ^= PACKED_RRSET_SOA_NEG;
  ------------------
  |  |   59|    850|#define PACKED_RRSET_SOA_NEG 0x4
  ------------------
  526|  1.29k|		}
  527|  16.9k|		if(*rrset_prev) {
  ------------------
  |  Branch (527:6): [True: 8.39k, False: 8.60k]
  ------------------
  528|  8.39k|			*prev_dname_first = (*rrset_prev)->dname;
  529|  8.39k|			*prev_dname_last = dname;
  530|  8.39k|			*prev_dnamelen = dnamelen;
  531|  8.39k|			*prev_type = covtype;
  532|  8.39k|			*prev_dclass = dclass;
  533|  8.39k|			return 1;
  534|  8.39k|		}
  535|  16.9k|	}
  536|   536k|	if(type != LDNS_RR_TYPE_RRSIG) {
  ------------------
  |  Branch (536:5): [True: 520k, False: 16.1k]
  ------------------
  537|   520k|		int hasother = 0;
  538|       |		/* find matching rrsig */
  539|   520k|		*hash = pkt_hash_rrset_rest(dname_h, LDNS_RR_TYPE_RRSIG, 
  540|   520k|			dclass, 0);
  541|   520k|		*rrset_prev = msgparse_hashtable_lookup(msg, pkt, *hash, 
  542|   520k|			0, dname, dnamelen, LDNS_RR_TYPE_RRSIG, 
  543|   520k|			dclass);
  544|   520k|		if(*rrset_prev && rrset_has_sigover(pkt, *rrset_prev, type,
  ------------------
  |  Branch (544:6): [True: 66.1k, False: 454k]
  |  Branch (544:21): [True: 4.89k, False: 61.2k]
  ------------------
  545|  66.1k|			&hasother)) {
  546|       |			/* yes! */
  547|  4.89k|			*prev_dname_first = (*rrset_prev)->dname;
  548|  4.89k|			*prev_dname_last = dname;
  549|  4.89k|			*prev_dnamelen = dnamelen;
  550|  4.89k|			*prev_type = type;
  551|  4.89k|			*prev_dclass = dclass;
  552|  4.89k|			*rrset_prev = change_rrsig_rrset(*rrset_prev, msg, 
  553|  4.89k|				pkt, type, *rrset_flags, hasother, section, 
  554|  4.89k|				region);
  555|  4.89k|			if(!*rrset_prev) return 0;
  ------------------
  |  Branch (555:7): [True: 0, False: 4.89k]
  ------------------
  556|  4.89k|			return 1;
  557|  4.89k|		}
  558|   520k|	}
  559|       |
  560|   531k|	*hash = pkt_hash_rrset_rest(dname_h, type, dclass, *rrset_flags);
  561|   531k|	*rrset_prev = msgparse_hashtable_lookup(msg, pkt, *hash, *rrset_flags, 
  562|   531k|		dname, dnamelen, type, dclass);
  563|   531k|	if(*rrset_prev)
  ------------------
  |  Branch (563:5): [True: 447k, False: 84.0k]
  ------------------
  564|   447k|		*prev_dname_first = (*rrset_prev)->dname;
  565|  84.0k|	else 	*prev_dname_first = dname;
  566|   531k|	*prev_dname_last = dname;
  567|   531k|	*prev_dnamelen = dnamelen;
  568|   531k|	*prev_type = type;
  569|   531k|	*prev_dclass = dclass;
  570|   531k|	return 1;
  571|   536k|}
msgparse.c:pkt_hash_rrset_first:
  185|  3.25M|{
  186|       |	/* works together with pkt_hash_rrset_rest */
  187|       |	/* note this MUST be identical to rrset_key_hash in packed_rrset.c */
  188|       |	/* this routine handles compressed names */
  189|  3.25M|	hashvalue_type h = 0xab;
  190|  3.25M|	h = dname_pkt_hash(pkt, dname, h);
  191|  3.25M|	return h;
  192|  3.25M|}
msgparse.c:smart_compare:
   57|  2.72M|{
   58|  2.72M|	if(LABEL_IS_PTR(*dnow)) {
  ------------------
  |  |  202|  2.72M|#define LABEL_IS_PTR(x) ( ((x)&0xc0) == 0xc0 )
  |  |  ------------------
  |  |  |  Branch (202:25): [True: 6.74k, False: 2.71M]
  |  |  ------------------
  ------------------
   59|       |		/* ptr points to a previous dname */
   60|  6.74k|		uint8_t* p;
   61|  6.74k|		if((size_t)PTR_OFFSET(dnow[0], dnow[1])
  ------------------
  |  |  205|  6.74k|#define PTR_OFFSET(x, y) ( ((x)&0x3f)<<8 | (y) )
  ------------------
  |  Branch (61:6): [True: 0, False: 6.74k]
  ------------------
   62|  6.74k|			>= sldns_buffer_limit(pkt))
   63|      0|			return -1;
   64|  6.74k|		p = sldns_buffer_at(pkt, PTR_OFFSET(dnow[0], dnow[1]));
  ------------------
  |  |  205|  6.74k|#define PTR_OFFSET(x, y) ( ((x)&0x3f)<<8 | (y) )
  ------------------
   65|  6.74k|		if( p == dprfirst || p == dprlast )
  ------------------
  |  Branch (65:7): [True: 452, False: 6.29k]
  |  Branch (65:24): [True: 25, False: 6.27k]
  ------------------
   66|    477|			return 0;
   67|       |		/* prev dname is also a ptr, both ptrs are the same. */
   68|  6.27k|		if(LABEL_IS_PTR(*dprlast) &&
  ------------------
  |  |  202|  12.5k|#define LABEL_IS_PTR(x) ( ((x)&0xc0) == 0xc0 )
  |  |  ------------------
  |  |  |  Branch (202:25): [True: 4.71k, False: 1.55k]
  |  |  ------------------
  ------------------
   69|  6.27k|			dprlast[0] == dnow[0] && dprlast[1] == dnow[1])
  ------------------
  |  Branch (69:4): [True: 2.89k, False: 1.81k]
  |  Branch (69:29): [True: 1.22k, False: 1.67k]
  ------------------
   70|  1.22k|			return 0;
   71|  6.27k|	}
   72|  2.72M|	return dname_pkt_compare(pkt, dnow, dprlast);
   73|  2.72M|}
msgparse.c:pkt_rrsig_covered_equals:
  259|  1.75M|{
  260|  1.75M|	uint16_t t;
  261|  1.75M|	if(pkt_rrsig_covered(pkt, here, &t) && t == type)
  ------------------
  |  Branch (261:5): [True: 616k, False: 1.14M]
  |  Branch (261:41): [True: 215k, False: 401k]
  ------------------
  262|   215k|		return 1;
  263|  1.54M|	return 0;
  264|  1.75M|}
msgparse.c:pkt_rrset_flags:
  158|   545k|{
  159|   545k|	uint32_t f = 0;
  160|   545k|	if(type == LDNS_RR_TYPE_NSEC && nsec_at_apex(pkt)) {
  ------------------
  |  Branch (160:5): [True: 15.5k, False: 529k]
  |  Branch (160:34): [True: 826, False: 14.7k]
  ------------------
  161|    826|		f |= PACKED_RRSET_NSEC_AT_APEX;
  ------------------
  |  |   53|    826|#define PACKED_RRSET_NSEC_AT_APEX 0x1
  ------------------
  162|   544k|	} else if(type == LDNS_RR_TYPE_SOA && sec == LDNS_SECTION_AUTHORITY) {
  ------------------
  |  Branch (162:12): [True: 1.98k, False: 542k]
  |  Branch (162:40): [True: 835, False: 1.14k]
  ------------------
  163|    835|		f |= PACKED_RRSET_SOA_NEG;
  ------------------
  |  |   59|    835|#define PACKED_RRSET_SOA_NEG 0x4
  ------------------
  164|    835|	}
  165|   545k|	return f;
  166|   545k|}
msgparse.c:nsec_at_apex:
  113|  15.5k|{
  114|       |	/* we are at ttl position in packet. */
  115|  15.5k|	size_t pos = sldns_buffer_position(pkt);
  116|  15.5k|	uint16_t rdatalen;
  117|  15.5k|	if(sldns_buffer_remaining(pkt) < 7) /* ttl+len+root */
  ------------------
  |  Branch (117:5): [True: 77, False: 15.4k]
  ------------------
  118|     77|		return 0; /* eek! */
  119|  15.4k|	sldns_buffer_skip(pkt, 4); /* ttl */;
  120|  15.4k|	rdatalen = sldns_buffer_read_u16(pkt);
  121|  15.4k|	if(sldns_buffer_remaining(pkt) < rdatalen) {
  ------------------
  |  Branch (121:5): [True: 58, False: 15.4k]
  ------------------
  122|     58|		sldns_buffer_set_position(pkt, pos);
  123|     58|		return 0; /* parse error happens later */
  124|     58|	}
  125|       |	/* must validate the nsec next domain name format */
  126|  15.4k|	if(pkt_dname_len(pkt) == 0) {
  ------------------
  |  Branch (126:5): [True: 1.64k, False: 13.7k]
  ------------------
  127|  1.64k|		sldns_buffer_set_position(pkt, pos);
  128|  1.64k|		return 0; /* parse error */
  129|  1.64k|	}
  130|       |
  131|       |	/* see if SOA bit is set. */
  132|  13.7k|	if(sldns_buffer_position(pkt) < pos+4+rdatalen) {
  ------------------
  |  Branch (132:5): [True: 2.89k, False: 10.8k]
  ------------------
  133|       |		/* nsec type bitmap contains items */
  134|  2.89k|		uint8_t win, blen, bits;
  135|       |		/* need: windownum, bitmap len, firstbyte */
  136|  2.89k|		if(sldns_buffer_position(pkt)+3 > pos+4+rdatalen) {
  ------------------
  |  Branch (136:6): [True: 559, False: 2.33k]
  ------------------
  137|    559|			sldns_buffer_set_position(pkt, pos);
  138|    559|			return 0; /* malformed nsec */
  139|    559|		}
  140|  2.33k|		win = sldns_buffer_read_u8(pkt);
  141|  2.33k|		blen = sldns_buffer_read_u8(pkt);
  142|  2.33k|		bits = sldns_buffer_read_u8(pkt);
  143|       |		/* 0window always first window. bitlen >=1 or parse
  144|       |		   error really. bit 0x2 is SOA. */
  145|  2.33k|		if(win == 0 && blen >= 1 && (bits & 0x02)) {
  ------------------
  |  Branch (145:6): [True: 1.82k, False: 505]
  |  Branch (145:18): [True: 1.37k, False: 457]
  |  Branch (145:31): [True: 826, False: 544]
  ------------------
  146|    826|			sldns_buffer_set_position(pkt, pos);
  147|    826|			return 1;
  148|    826|		}
  149|  2.33k|	}
  150|       |
  151|  12.3k|	sldns_buffer_set_position(pkt, pos);
  152|  12.3k|	return 0;
  153|  13.7k|}
msgparse.c:pkt_rrsig_covered:
  240|  1.78M|{
  241|  1.78M|	size_t pos = sldns_buffer_position(pkt);
  242|  1.78M|	sldns_buffer_set_position(pkt, (size_t)(here-sldns_buffer_begin(pkt)));
  243|       |	/* ttl + len + size of small rrsig(rootlabel, no signature) */
  244|  1.78M|	if(sldns_buffer_remaining(pkt) < 4+2+19)
  ------------------
  |  Branch (244:5): [True: 1.47k, False: 1.78M]
  ------------------
  245|  1.47k|		return 0;
  246|  1.78M|	sldns_buffer_skip(pkt, 4); /* ttl */
  247|  1.78M|	if(sldns_buffer_read_u16(pkt) < 19) /* too short */ {
  ------------------
  |  Branch (247:5): [True: 1.14M, False: 633k]
  ------------------
  248|  1.14M|		sldns_buffer_set_position(pkt, pos);
  249|  1.14M|		return 0;
  250|  1.14M|	}
  251|   633k|	*type = sldns_buffer_read_u16(pkt);
  252|   633k|	sldns_buffer_set_position(pkt, pos);
  253|   633k|	return 1;
  254|  1.78M|}
msgparse.c:pkt_hash_rrset_rest:
  198|  1.07M|{
  199|       |	/* works together with pkt_hash_rrset_first */
  200|       |	/* note this MUST be identical to rrset_key_hash in packed_rrset.c */
  201|  1.07M|	hashvalue_type h;
  202|  1.07M|	h = hashlittle(&type, sizeof(type), dname_h);	/* host order */
  203|  1.07M|	h = hashlittle(&dclass, sizeof(dclass), h);	/* netw order */
  204|  1.07M|	h = hashlittle(&rrset_flags, sizeof(uint32_t), h);
  205|  1.07M|	return h;
  206|  1.07M|}
msgparse.c:rrset_has_sigover:
  328|  66.1k|{
  329|  66.1k|	int res = 0;
  330|  66.1k|	struct rr_parse* rr = rrset->rr_first;
  331|  66.1k|	log_assert( rrset->type == LDNS_RR_TYPE_RRSIG );
  332|  1.65M|	while(rr) {
  ------------------
  |  Branch (332:8): [True: 1.58M, False: 66.1k]
  ------------------
  333|  1.58M|		if(pkt_rrsig_covered_equals(pkt, rr->ttl_data, type))
  ------------------
  |  Branch (333:6): [True: 102k, False: 1.48M]
  ------------------
  334|   102k|			res = 1;
  335|  1.48M|		else	*hasother = 1;
  336|  1.58M|		rr = rr->next;
  337|  1.58M|	}
  338|  66.1k|	return res;
  339|  66.1k|}
msgparse.c:change_rrsig_rrset:
  395|  4.89k|{
  396|  4.89k|	struct rrset_parse* dataset = sigset;
  397|  4.89k|	hashvalue_type hash = pkt_hash_rrset(pkt, sigset->dname, datatype, 
  398|  4.89k|		sigset->rrset_class, rrset_flags);
  399|  4.89k|	log_assert( sigset->type == LDNS_RR_TYPE_RRSIG );
  400|  4.89k|	log_assert( datatype != LDNS_RR_TYPE_RRSIG );
  401|  4.89k|	if(hasother) {
  ------------------
  |  Branch (401:5): [True: 4.38k, False: 516]
  ------------------
  402|       |		/* need to make new rrset to hold data type */
  403|  4.38k|		dataset = new_rrset(msg, sigset->dname, sigset->dname_len, 
  404|  4.38k|			datatype, sigset->rrset_class, hash, rrset_flags, 
  405|  4.38k|			section, region);
  406|  4.38k|		if(!dataset) 
  ------------------
  |  Branch (406:6): [True: 0, False: 4.38k]
  ------------------
  407|      0|			return NULL;
  408|  4.38k|		switch(section) {
  409|  2.32k|			case LDNS_SECTION_ANSWER: msg->an_rrsets++; break;
  ------------------
  |  Branch (409:4): [True: 2.32k, False: 2.06k]
  ------------------
  410|  1.37k|			case LDNS_SECTION_AUTHORITY: msg->ns_rrsets++; break;
  ------------------
  |  Branch (410:4): [True: 1.37k, False: 3.00k]
  ------------------
  411|    687|			case LDNS_SECTION_ADDITIONAL: msg->ar_rrsets++; break;
  ------------------
  |  Branch (411:4): [True: 687, False: 3.69k]
  ------------------
  412|      0|			default: log_assert(0);
  ------------------
  |  Branch (412:4): [True: 0, False: 4.38k]
  ------------------
  413|  4.38k|		}
  414|  4.38k|		if(!moveover_rrsigs(pkt, region, sigset, dataset, 
  ------------------
  |  Branch (414:6): [True: 0, False: 4.38k]
  ------------------
  415|  4.38k|			msg->qtype == LDNS_RR_TYPE_RRSIG ||
  ------------------
  |  Branch (415:4): [True: 3.08k, False: 1.30k]
  ------------------
  416|  4.38k|			(msg->qtype == LDNS_RR_TYPE_ANY &&
  ------------------
  |  Branch (416:5): [True: 1.13k, False: 170]
  ------------------
  417|  1.30k|			section != LDNS_SECTION_ANSWER) ))
  ------------------
  |  Branch (417:4): [True: 1.13k, False: 2]
  ------------------
  418|      0|			return NULL;
  419|  4.38k|		return dataset;
  420|  4.38k|	}
  421|       |	/* changeover the type of the rrset to data set */
  422|    516|	msgparse_bucket_remove(msg, dataset);
  423|       |	/* insert into new hash bucket */
  424|    516|	dataset->rrset_bucket_next = msg->hashtable[hash&(PARSE_TABLE_SIZE-1)];
  ------------------
  |  |   77|    516|#define PARSE_TABLE_SIZE 32
  ------------------
  425|    516|	msg->hashtable[hash&(PARSE_TABLE_SIZE-1)] = dataset;
  ------------------
  |  |   77|    516|#define PARSE_TABLE_SIZE 32
  ------------------
  426|    516|	dataset->hash = hash;
  427|       |	/* use section of data item for result */
  428|    516|	change_section(msg, dataset, section);
  429|    516|	dataset->type = datatype;
  430|    516|	dataset->flags = rrset_flags;
  431|    516|	dataset->rrsig_count += dataset->rr_count;
  432|    516|	dataset->rr_count = 0;
  433|       |	/* move sigs to end of siglist */
  434|    516|	if(dataset->rrsig_last)
  ------------------
  |  Branch (434:5): [True: 0, False: 516]
  ------------------
  435|      0|		dataset->rrsig_last->next = dataset->rr_first;
  436|    516|	else	dataset->rrsig_first = dataset->rr_first;
  437|    516|	dataset->rrsig_last = dataset->rr_last;
  438|    516|	dataset->rr_first = 0;
  439|    516|	dataset->rr_last = 0;
  440|    516|	return dataset;
  441|  4.89k|}
msgparse.c:moveover_rrsigs:
  345|  4.38k|{
  346|  4.38k|	struct rr_parse* sig = sigset->rr_first;
  347|  4.38k|	struct rr_parse* prev = NULL;
  348|  4.38k|	struct rr_parse* insert;
  349|  4.38k|	struct rr_parse* nextsig;
  350|   146k|	while(sig) {
  ------------------
  |  Branch (350:8): [True: 142k, False: 4.38k]
  ------------------
  351|   142k|		nextsig = sig->next;
  352|   142k|		if(pkt_rrsig_covered_equals(pkt, sig->ttl_data, 
  ------------------
  |  Branch (352:6): [True: 101k, False: 40.6k]
  ------------------
  353|   142k|			dataset->type)) {
  354|   101k|			if(duplicate) {
  ------------------
  |  Branch (354:7): [True: 100k, False: 1.71k]
  ------------------
  355|       |				/* new */
  356|   100k|				insert = (struct rr_parse*)regional_alloc(
  357|   100k|					region, sizeof(struct rr_parse));
  358|   100k|				if(!insert) return 0;
  ------------------
  |  Branch (358:8): [True: 0, False: 100k]
  ------------------
  359|   100k|				insert->outside_packet = 0;
  360|   100k|				insert->ttl_data = sig->ttl_data;
  361|   100k|				insert->size = sig->size;
  362|       |				/* prev not used */
  363|   100k|			} else {
  364|       |				/* remove from sigset */
  365|  1.71k|				if(prev) prev->next = sig->next;
  ------------------
  |  Branch (365:8): [True: 1.31k, False: 406]
  ------------------
  366|    406|				else	sigset->rr_first = sig->next;
  367|  1.71k|				if(sigset->rr_last == sig)
  ------------------
  |  Branch (367:8): [True: 93, False: 1.62k]
  ------------------
  368|     93|					sigset->rr_last = prev;
  369|  1.71k|				sigset->rr_count--;
  370|  1.71k|				sigset->size -= sig->size;
  371|  1.71k|				insert = sig;
  372|       |				/* prev not changed */
  373|  1.71k|			}
  374|       |			/* add to dataset */
  375|   101k|			dataset->rrsig_count++;
  376|   101k|			insert->next = 0;
  377|   101k|			if(dataset->rrsig_last) 
  ------------------
  |  Branch (377:7): [True: 97.5k, False: 4.38k]
  ------------------
  378|  97.5k|				dataset->rrsig_last->next = insert;
  379|  4.38k|			else	dataset->rrsig_first = insert;
  380|   101k|			dataset->rrsig_last = insert;
  381|   101k|			dataset->size += insert->size;
  382|   101k|		} else  {
  383|  40.6k|			prev = sig;
  384|  40.6k|		}
  385|   142k|		sig = nextsig;
  386|   142k|	}
  387|  4.38k|	return 1;
  388|  4.38k|}
msgparse.c:change_section:
  284|    516|{
  285|    516|	struct rrset_parse *p, *prev;
  286|       |	/* remove from list */
  287|    516|	if(section == rrset->section)
  ------------------
  |  Branch (287:5): [True: 404, False: 112]
  ------------------
  288|    404|		return;
  289|    112|	p = msg->rrset_first;
  290|    112|	prev = 0;
  291|    536|	while(p) {
  ------------------
  |  Branch (291:8): [True: 536, False: 0]
  ------------------
  292|    536|		if(p == rrset) {
  ------------------
  |  Branch (292:6): [True: 112, False: 424]
  ------------------
  293|    112|			if(prev) prev->rrset_all_next = p->rrset_all_next;
  ------------------
  |  Branch (293:7): [True: 60, False: 52]
  ------------------
  294|     52|			else	msg->rrset_first = p->rrset_all_next;
  295|    112|			if(msg->rrset_last == rrset)
  ------------------
  |  Branch (295:7): [True: 19, False: 93]
  ------------------
  296|     19|				msg->rrset_last = prev;
  297|    112|			break;
  298|    112|		}
  299|    424|		prev = p;
  300|    424|		p = p->rrset_all_next;
  301|    424|	}
  302|       |	/* remove from count */
  303|    112|	switch(rrset->section) {
  304|     73|		case LDNS_SECTION_ANSWER: msg->an_rrsets--; break;
  ------------------
  |  Branch (304:3): [True: 73, False: 39]
  ------------------
  305|     39|		case LDNS_SECTION_AUTHORITY: msg->ns_rrsets--; break;
  ------------------
  |  Branch (305:3): [True: 39, False: 73]
  ------------------
  306|      0|		case LDNS_SECTION_ADDITIONAL: msg->ar_rrsets--; break;
  ------------------
  |  Branch (306:3): [True: 0, False: 112]
  ------------------
  307|      0|		default: log_assert(0);
  ------------------
  |  Branch (307:3): [True: 0, False: 112]
  ------------------
  308|    112|	}
  309|       |	/* insert at end of list */
  310|    112|	rrset->rrset_all_next = 0;
  311|    112|	if(msg->rrset_last)
  ------------------
  |  Branch (311:5): [True: 106, False: 6]
  ------------------
  312|    106|		msg->rrset_last->rrset_all_next = rrset;
  313|      6|	else	msg->rrset_first = rrset;
  314|    112|	msg->rrset_last = rrset;
  315|       |	/* up count of new section */
  316|    112|	switch(section) {
  317|     52|		case LDNS_SECTION_AUTHORITY: msg->ns_rrsets++; break;
  ------------------
  |  Branch (317:3): [True: 52, False: 60]
  ------------------
  318|     60|		case LDNS_SECTION_ADDITIONAL: msg->ar_rrsets++; break;
  ------------------
  |  Branch (318:3): [True: 60, False: 52]
  ------------------
  319|      0|		default: log_assert(0);
  ------------------
  |  Branch (319:3): [True: 0, False: 112]
  ------------------
  320|    112|	}
  321|    112|	rrset->section = section;
  322|    112|}
msgparse.c:new_rrset:
   83|  88.4k|{
   84|  88.4k|	struct rrset_parse* p = regional_alloc(region, sizeof(*p));
   85|  88.4k|	if(!p) return NULL;
  ------------------
  |  Branch (85:5): [True: 0, False: 88.4k]
  ------------------
   86|  88.4k|	p->rrset_bucket_next = msg->hashtable[hash & (PARSE_TABLE_SIZE-1)];
  ------------------
  |  |   77|  88.4k|#define PARSE_TABLE_SIZE 32
  ------------------
   87|  88.4k|	msg->hashtable[hash & (PARSE_TABLE_SIZE-1)] = p;
  ------------------
  |  |   77|  88.4k|#define PARSE_TABLE_SIZE 32
  ------------------
   88|  88.4k|	p->rrset_all_next = 0;
   89|  88.4k|	if(msg->rrset_last)
  ------------------
  |  Branch (89:5): [True: 84.0k, False: 4.33k]
  ------------------
   90|  84.0k|		msg->rrset_last->rrset_all_next = p;
   91|  4.33k|	else 	msg->rrset_first = p;
   92|  88.4k|	msg->rrset_last = p;
   93|  88.4k|	p->hash = hash;
   94|  88.4k|	p->section = section;
   95|  88.4k|	p->dname = dname;
   96|  88.4k|	p->dname_len = dnamelen;
   97|  88.4k|	p->type = type;
   98|  88.4k|	p->rrset_class = dclass;
   99|  88.4k|	p->flags = rrset_flags;
  100|  88.4k|	p->rr_count = 0;
  101|  88.4k|	p->size = 0;
  102|  88.4k|	p->rr_first = 0;
  103|  88.4k|	p->rr_last = 0;
  104|  88.4k|	p->rrsig_count = 0;
  105|  88.4k|	p->rrsig_first = 0;
  106|  88.4k|	p->rrsig_last = 0;
  107|  88.4k|	return p;
  108|  88.4k|}
msgparse.c:add_rr_to_rrset:
  754|  3.25M|{
  755|  3.25M|	struct rr_parse* rr;
  756|       |	/* check section of rrset. */
  757|  3.25M|	if(rrset->section != section && type != LDNS_RR_TYPE_RRSIG &&
  ------------------
  |  Branch (757:5): [True: 256k, False: 2.99M]
  |  Branch (757:34): [True: 252k, False: 4.58k]
  ------------------
  758|  3.25M|		rrset->type != LDNS_RR_TYPE_RRSIG) {
  ------------------
  |  Branch (758:3): [True: 252k, False: 0]
  ------------------
  759|       |		/* silently drop it - we drop the last part, since
  760|       |		 * trust in rr data depends on the section it is in. 
  761|       |		 * the less trustworthy part is discarded. 
  762|       |		 * also the last part is more likely to be incomplete.
  763|       |		 * RFC 2181: must put RRset only once in response. */
  764|       |		/*
  765|       |		verbose(VERB_QUERY, "Packet contains rrset data in "
  766|       |			"multiple sections, dropped last part.");
  767|       |		log_buf(VERB_QUERY, "packet was", pkt);
  768|       |		*/
  769|       |		/* forwards */
  770|   252k|		if(!skip_ttl_rdata(pkt))
  ------------------
  |  Branch (770:6): [True: 130, False: 252k]
  ------------------
  771|    130|			return LDNS_RCODE_FORMERR;
  772|   252k|		return 0;
  773|   252k|	} 
  774|       |
  775|  3.00M|	if( (msg->qtype == LDNS_RR_TYPE_RRSIG ||
  ------------------
  |  Branch (775:7): [True: 103k, False: 2.90M]
  ------------------
  776|  3.00M|	     msg->qtype == LDNS_RR_TYPE_ANY) 
  ------------------
  |  Branch (776:7): [True: 207k, False: 2.69M]
  ------------------
  777|  3.00M|	    && sig_is_double(pkt, rrset, sldns_buffer_current(pkt))) {
  ------------------
  |  Branch (777:9): [True: 2.48k, False: 308k]
  ------------------
  778|  2.48k|		if(!skip_ttl_rdata(pkt))
  ------------------
  |  Branch (778:6): [True: 0, False: 2.48k]
  ------------------
  779|      0|			return LDNS_RCODE_FORMERR;
  780|  2.48k|		return 0;
  781|  2.48k|	}
  782|       |	
  783|       |	/* create rr */
  784|  3.00M|	if(!(rr = (struct rr_parse*)regional_alloc(region, sizeof(*rr))))
  ------------------
  |  Branch (784:5): [True: 0, False: 3.00M]
  ------------------
  785|      0|		return LDNS_RCODE_SERVFAIL;
  786|  3.00M|	rr->outside_packet = 0;
  787|  3.00M|	rr->ttl_data = sldns_buffer_current(pkt);
  788|  3.00M|	rr->next = 0;
  789|  3.00M|	if(type == LDNS_RR_TYPE_RRSIG && rrset->type != LDNS_RR_TYPE_RRSIG) {
  ------------------
  |  Branch (789:5): [True: 31.3k, False: 2.97M]
  |  Branch (789:35): [True: 14.2k, False: 17.0k]
  ------------------
  790|  14.2k|		if(rrset->rrsig_last) 
  ------------------
  |  Branch (790:6): [True: 13.8k, False: 422]
  ------------------
  791|  13.8k|			rrset->rrsig_last->next = rr;
  792|    422|		else	rrset->rrsig_first = rr;
  793|  14.2k|		rrset->rrsig_last = rr;
  794|  14.2k|		rrset->rrsig_count++;
  795|  2.98M|	} else {
  796|  2.98M|		if(rrset->rr_last)
  ------------------
  |  Branch (796:6): [True: 2.89M, False: 88.8k]
  ------------------
  797|  2.89M|			rrset->rr_last->next = rr;
  798|  88.8k|		else	rrset->rr_first = rr;
  799|  2.98M|		rrset->rr_last = rr;
  800|  2.98M|		rrset->rr_count++;
  801|  2.98M|	}
  802|       |
  803|       |	/* calc decompressed size */
  804|  3.00M|	if(!calc_size(pkt, type, rr))
  ------------------
  |  Branch (804:5): [True: 1.21k, False: 3.00M]
  ------------------
  805|  1.21k|		return LDNS_RCODE_FORMERR;
  806|  3.00M|	rrset->size += rr->size;
  807|       |
  808|  3.00M|	return 0;
  809|  3.00M|}
msgparse.c:skip_ttl_rdata:
  695|   254k|{
  696|   254k|	uint16_t rdatalen;
  697|   254k|	if(sldns_buffer_remaining(pkt) < 6) /* ttl + rdatalen */
  ------------------
  |  Branch (697:5): [True: 0, False: 254k]
  ------------------
  698|      0|		return 0;
  699|   254k|	sldns_buffer_skip(pkt, 4); /* ttl */
  700|   254k|	rdatalen = sldns_buffer_read_u16(pkt);
  701|   254k|	if(sldns_buffer_remaining(pkt) < rdatalen)
  ------------------
  |  Branch (701:5): [True: 130, False: 254k]
  ------------------
  702|    130|		return 0;
  703|   254k|	sldns_buffer_skip(pkt, (ssize_t)rdatalen);
  704|   254k|	return 1;
  705|   254k|}
msgparse.c:sig_is_double:
  710|   310k|{
  711|   310k|	uint16_t rlen, siglen;
  712|   310k|	size_t pos = sldns_buffer_position(pkt);
  713|   310k|	struct rr_parse* sig;
  714|   310k|	if(sldns_buffer_remaining(pkt) < 6) 
  ------------------
  |  Branch (714:5): [True: 0, False: 310k]
  ------------------
  715|      0|		return 0;
  716|   310k|	sldns_buffer_skip(pkt, 4); /* ttl */
  717|   310k|	rlen = sldns_buffer_read_u16(pkt);
  718|   310k|	if(sldns_buffer_remaining(pkt) < rlen) {
  ------------------
  |  Branch (718:5): [True: 213, False: 310k]
  ------------------
  719|    213|		sldns_buffer_set_position(pkt, pos);
  720|    213|		return 0;
  721|    213|	}
  722|   310k|	sldns_buffer_set_position(pkt, pos);
  723|       |
  724|   310k|	sig = rrset->rrsig_first;
  725|  1.00M|	while(sig) {
  ------------------
  |  Branch (725:8): [True: 692k, False: 308k]
  ------------------
  726|       |		/* check if rdatalen is same */
  727|   692k|		memmove(&siglen, sig->ttl_data+4, sizeof(siglen));
  728|   692k|		siglen = ntohs(siglen);
  729|       |		/* checks if data in packet is exactly the same, this means
  730|       |		 * also dname in rdata is the same, but rrsig is not allowed
  731|       |		 * to have compressed dnames anyway. If it is compressed anyway
  732|       |		 * it will lead to duplicate rrs for qtype=RRSIG. (or ANY).
  733|       |		 *
  734|       |		 * Cannot use sig->size because size of the other one is not 
  735|       |		 * calculated yet.
  736|       |		 */
  737|   692k|		if(siglen == rlen) {
  ------------------
  |  Branch (737:6): [True: 26.8k, False: 665k]
  ------------------
  738|  26.8k|			if(siglen>0 && memcmp(sig->ttl_data+6, ttldata+6, 
  ------------------
  |  Branch (738:7): [True: 26.8k, False: 0]
  |  Branch (738:19): [True: 2.48k, False: 24.3k]
  ------------------
  739|  26.8k|				siglen) == 0) {
  740|       |				/* same! */
  741|  2.48k|				return 1;
  742|  2.48k|			}
  743|  26.8k|		}
  744|   689k|		sig = sig->next;
  745|   689k|	}
  746|   308k|	return 0;
  747|   310k|}
msgparse.c:calc_size:
  637|  3.00M|{
  638|  3.00M|	const sldns_rr_descriptor* desc;
  639|  3.00M|	uint16_t pkt_len; /* length of rr inside the packet */
  640|  3.00M|	rr->size = sizeof(uint16_t); /* the rdatalen */
  641|  3.00M|	sldns_buffer_skip(pkt, 4); /* skip ttl */
  642|  3.00M|	pkt_len = sldns_buffer_read_u16(pkt);
  643|  3.00M|	if(sldns_buffer_remaining(pkt) < pkt_len)
  ------------------
  |  Branch (643:5): [True: 954, False: 3.00M]
  ------------------
  644|    954|		return 0;
  645|  3.00M|	desc = sldns_rr_descript(type);
  646|  3.00M|	if(pkt_len > 0 && desc && desc->_dname_count > 0) {
  ------------------
  |  Branch (646:5): [True: 70.5k, False: 2.93M]
  |  Branch (646:20): [True: 70.5k, False: 0]
  |  Branch (646:28): [True: 41.5k, False: 29.0k]
  ------------------
  647|  41.5k|		int count = (int)desc->_dname_count;
  648|  41.5k|		int rdf = 0;
  649|  41.5k|		size_t len;
  650|  41.5k|		size_t oldpos;
  651|       |		/* skip first part. */
  652|   250k|		while(pkt_len > 0 && count) {
  ------------------
  |  Branch (652:9): [True: 220k, False: 30.5k]
  |  Branch (652:24): [True: 209k, False: 10.7k]
  ------------------
  653|   209k|			switch(desc->_wireformat[rdf]) {
  654|  40.7k|			case LDNS_RDF_TYPE_DNAME:
  ------------------
  |  Branch (654:4): [True: 40.7k, False: 168k]
  ------------------
  655|       |				/* decompress every domain name */
  656|  40.7k|				oldpos = sldns_buffer_position(pkt);
  657|  40.7k|				if((len = pkt_dname_len(pkt)) == 0)
  ------------------
  |  Branch (657:8): [True: 189, False: 40.5k]
  ------------------
  658|    189|					return 0; /* malformed dname */
  659|  40.5k|				if(sldns_buffer_position(pkt)-oldpos > pkt_len)
  ------------------
  |  Branch (659:8): [True: 27, False: 40.5k]
  ------------------
  660|     27|					return 0; /* dname exceeds rdata */
  661|  40.5k|				pkt_len -= sldns_buffer_position(pkt)-oldpos;
  662|  40.5k|				rr->size += len;
  663|  40.5k|				count--;
  664|  40.5k|				len = 0;
  665|  40.5k|				break;
  666|    591|			case LDNS_RDF_TYPE_STR:
  ------------------
  |  Branch (666:4): [True: 591, False: 208k]
  ------------------
  667|    591|				if(pkt_len < 1) {
  ------------------
  |  Branch (667:8): [True: 0, False: 591]
  ------------------
  668|       |					/* NOTREACHED, due to 'while(>0)' */
  669|      0|					return 0; /* len byte exceeds rdata */
  670|      0|				}
  671|    591|				len = sldns_buffer_current(pkt)[0] + 1;
  672|    591|				break;
  673|   167k|			default:
  ------------------
  |  Branch (673:4): [True: 167k, False: 41.3k]
  ------------------
  674|   167k|				len = get_rdf_size(desc->_wireformat[rdf]);
  675|   209k|			}
  676|   209k|			if(len) {
  ------------------
  |  Branch (676:7): [True: 168k, False: 40.5k]
  ------------------
  677|   168k|				if(pkt_len < len)
  ------------------
  |  Branch (677:8): [True: 49, False: 168k]
  ------------------
  678|     49|					return 0; /* exceeds rdata */
  679|   168k|				pkt_len -= len;
  680|   168k|				sldns_buffer_skip(pkt, (ssize_t)len);
  681|   168k|				rr->size += len;
  682|   168k|			}
  683|   209k|			rdf++;
  684|   209k|		}
  685|  41.5k|	}
  686|       |	/* remaining rdata */
  687|  3.00M|	rr->size += pkt_len;
  688|  3.00M|	sldns_buffer_skip(pkt, (ssize_t)pkt_len);
  689|  3.00M|	return 1;
  690|  3.00M|}

parse_copy_decompress_rrset:
  414|  12.9k|{
  415|  12.9k|	struct packed_rrset_data* data;
  416|  12.9k|	pk->rk.flags = pset->flags;
  417|  12.9k|	pk->rk.dname_len = pset->dname_len;
  418|  12.9k|	if(region)
  ------------------
  |  Branch (418:5): [True: 0, False: 12.9k]
  ------------------
  419|      0|		pk->rk.dname = (uint8_t*)regional_alloc(
  420|      0|			region, pset->dname_len);
  421|  12.9k|	else	pk->rk.dname = 
  422|  12.9k|			(uint8_t*)malloc(pset->dname_len);
  423|  12.9k|	if(!pk->rk.dname)
  ------------------
  |  Branch (423:5): [True: 0, False: 12.9k]
  ------------------
  424|      0|		return 0;
  425|       |	/** copy & decompress dname */
  426|  12.9k|	dname_pkt_copy(pkt, pk->rk.dname, pset->dname);
  427|       |	/** copy over type and class */
  428|  12.9k|	pk->rk.type = htons(pset->type);
  429|  12.9k|	pk->rk.rrset_class = pset->rrset_class;
  430|       |	/** read data part. */
  431|  12.9k|	if(!parse_create_rrset(pkt, pset, &data, region)) {
  ------------------
  |  Branch (431:5): [True: 0, False: 12.9k]
  ------------------
  432|      0|		if(!region) {
  ------------------
  |  Branch (432:6): [True: 0, False: 0]
  ------------------
  433|      0|			free(pk->rk.dname);
  434|      0|			pk->rk.dname = NULL;
  435|      0|		}
  436|      0|		return 0;
  437|      0|	}
  438|  12.9k|	pk->entry.data = (void*)data;
  439|  12.9k|	pk->entry.key = (void*)pk;
  440|  12.9k|	pk->entry.hash = pset->hash;
  441|  12.9k|	data->trust = get_rrset_trust(msg, pset);
  442|  12.9k|	return 1;
  443|  12.9k|}
edns_opt_list_append:
 1025|  17.9k|{
 1026|  17.9k|	struct edns_option** prevp;
 1027|  17.9k|	struct edns_option* opt;
 1028|       |
 1029|       |	/* allocate new element */
 1030|  17.9k|	opt = (struct edns_option*)regional_alloc(region, sizeof(*opt));
 1031|  17.9k|	if(!opt)
  ------------------
  |  Branch (1031:5): [True: 0, False: 17.9k]
  ------------------
 1032|      0|		return 0;
 1033|  17.9k|	opt->next = NULL;
 1034|  17.9k|	opt->opt_code = code;
 1035|  17.9k|	opt->opt_len = len;
 1036|  17.9k|	opt->opt_data = NULL;
 1037|  17.9k|	if(len > 0) {
  ------------------
  |  Branch (1037:5): [True: 1.44k, False: 16.4k]
  ------------------
 1038|  1.44k|		opt->opt_data = regional_alloc_init(region, data, len);
 1039|  1.44k|		if(!opt->opt_data)
  ------------------
  |  Branch (1039:6): [True: 0, False: 1.44k]
  ------------------
 1040|      0|			return 0;
 1041|  1.44k|	}
 1042|       |
 1043|       |	/* append at end of list */
 1044|  17.9k|	prevp = list;
 1045|  23.7M|	while(*prevp != NULL) {
  ------------------
  |  Branch (1045:8): [True: 23.7M, False: 17.9k]
  ------------------
 1046|  23.7M|		prevp = &((*prevp)->next);
 1047|  23.7M|	}
 1048|  17.9k|	*prevp = opt;
 1049|  17.9k|	return 1;
 1050|  17.9k|}
msgreply.c:parse_create_rrset:
  346|  12.9k|{
  347|       |	/* allocate */
  348|  12.9k|	size_t s;
  349|  12.9k|	if(pset->rr_count > RR_COUNT_MAX || pset->rrsig_count > RR_COUNT_MAX ||
  ------------------
  |  |   76|  25.9k|#define RR_COUNT_MAX 0xffffff
  ------------------
              	if(pset->rr_count > RR_COUNT_MAX || pset->rrsig_count > RR_COUNT_MAX ||
  ------------------
  |  |   76|  25.9k|#define RR_COUNT_MAX 0xffffff
  ------------------
  |  Branch (349:5): [True: 0, False: 12.9k]
  |  Branch (349:38): [True: 0, False: 12.9k]
  ------------------
  350|  12.9k|		pset->size > RR_COUNT_MAX)
  ------------------
  |  |   76|  12.9k|#define RR_COUNT_MAX 0xffffff
  ------------------
  |  Branch (350:3): [True: 0, False: 12.9k]
  ------------------
  351|      0|		return 0; /* protect against integer overflow */
  352|  12.9k|	s = sizeof(struct packed_rrset_data) + 
  353|  12.9k|		(pset->rr_count + pset->rrsig_count) * 
  354|  12.9k|		(sizeof(size_t)+sizeof(uint8_t*)+sizeof(time_t)) + 
  355|  12.9k|		pset->size;
  356|  12.9k|	if(region)
  ------------------
  |  Branch (356:5): [True: 0, False: 12.9k]
  ------------------
  357|      0|		*data = regional_alloc_zero(region, s);
  358|  12.9k|	else	*data = calloc(1, s);
  359|  12.9k|	if(!*data)
  ------------------
  |  Branch (359:5): [True: 0, False: 12.9k]
  ------------------
  360|      0|		return 0;
  361|       |	/* copy & decompress */
  362|  12.9k|	if(!parse_rr_copy(pkt, pset, *data)) {
  ------------------
  |  Branch (362:5): [True: 0, False: 12.9k]
  ------------------
  363|      0|		if(!region) {
  ------------------
  |  Branch (363:6): [True: 0, False: 0]
  ------------------
  364|      0|			free(*data);
  365|      0|			*data = NULL;
  366|      0|		}
  367|      0|		return 0;
  368|      0|	}
  369|  12.9k|	return 1;
  370|  12.9k|}
msgreply.c:parse_rr_copy:
  303|  12.9k|{
  304|  12.9k|	size_t i;
  305|  12.9k|	struct rr_parse* rr = pset->rr_first;
  306|  12.9k|	uint8_t* nextrdata;
  307|  12.9k|	size_t total = pset->rr_count + pset->rrsig_count;
  308|  12.9k|	data->ttl = MAX_TTL;
  309|  12.9k|	data->count = pset->rr_count;
  310|  12.9k|	data->rrsig_count = pset->rrsig_count;
  311|  12.9k|	data->trust = rrset_trust_none;
  312|  12.9k|	data->security = sec_status_unchecked;
  313|       |	/* layout: struct - rr_len - rr_data - rr_ttl - rdata - rrsig */
  314|  12.9k|	data->rr_len = (size_t*)((uint8_t*)data + 
  315|  12.9k|		sizeof(struct packed_rrset_data));
  316|  12.9k|	data->rr_data = (uint8_t**)&(data->rr_len[total]);
  317|  12.9k|	data->rr_ttl = (time_t*)&(data->rr_data[total]);
  318|  12.9k|	nextrdata = (uint8_t*)&(data->rr_ttl[total]);
  319|  2.13M|	for(i=0; i<data->count; i++) {
  ------------------
  |  Branch (319:11): [True: 2.12M, False: 12.9k]
  ------------------
  320|  2.12M|		data->rr_len[i] = rr->size;
  321|  2.12M|		data->rr_data[i] = nextrdata;
  322|  2.12M|		nextrdata += rr->size;
  323|  2.12M|		if(!rdata_copy(pkt, data, data->rr_data[i], rr, 
  ------------------
  |  Branch (323:6): [True: 0, False: 2.12M]
  ------------------
  324|  2.12M|			&data->rr_ttl[i], pset->type, pset->section))
  325|      0|			return 0;
  326|  2.12M|		rr = rr->next;
  327|  2.12M|	}
  328|       |	/* if rrsig, its rdata is at nextrdata */
  329|  12.9k|	rr = pset->rrsig_first;
  330|  21.3k|	for(i=data->count; i<total; i++) {
  ------------------
  |  Branch (330:21): [True: 8.37k, False: 12.9k]
  ------------------
  331|  8.37k|		data->rr_len[i] = rr->size;
  332|  8.37k|		data->rr_data[i] = nextrdata;
  333|  8.37k|		nextrdata += rr->size;
  334|  8.37k|		if(!rdata_copy(pkt, data, data->rr_data[i], rr, 
  ------------------
  |  Branch (334:6): [True: 0, False: 8.37k]
  ------------------
  335|  8.37k|			&data->rr_ttl[i], LDNS_RR_TYPE_RRSIG, pset->section))
  336|      0|			return 0;
  337|  8.37k|		rr = rr->next;
  338|  8.37k|	}
  339|  12.9k|	return 1;
  340|  12.9k|}
msgreply.c:rdata_copy:
  213|  2.13M|{
  214|  2.13M|	uint16_t pkt_len;
  215|  2.13M|	const sldns_rr_descriptor* desc;
  216|       |
  217|  2.13M|	*rr_ttl = sldns_read_uint32(rr->ttl_data);
  218|       |	/* RFC 2181 Section 8. if msb of ttl is set treat as if zero. */
  219|  2.13M|	if(*rr_ttl & 0x80000000U)
  ------------------
  |  Branch (219:5): [True: 8.10k, False: 2.12M]
  ------------------
  220|  8.10k|		*rr_ttl = 0;
  221|  2.13M|	if(type == LDNS_RR_TYPE_SOA && section == LDNS_SECTION_AUTHORITY) {
  ------------------
  |  Branch (221:5): [True: 0, False: 2.13M]
  |  Branch (221:33): [True: 0, False: 0]
  ------------------
  222|       |		/* negative response. see if TTL of SOA record larger than the
  223|       |		 * minimum-ttl in the rdata of the SOA record */
  224|      0|		if(*rr_ttl > soa_find_minttl(rr))
  ------------------
  |  Branch (224:6): [True: 0, False: 0]
  ------------------
  225|      0|			*rr_ttl = soa_find_minttl(rr);
  226|      0|	}
  227|  2.13M|	if(!SERVE_ORIGINAL_TTL && (*rr_ttl < MIN_TTL))
  ------------------
  |  Branch (227:5): [True: 2.13M, False: 0]
  |  Branch (227:28): [True: 0, False: 2.13M]
  ------------------
  228|      0|		*rr_ttl = MIN_TTL;
  229|  2.13M|	if(!SERVE_ORIGINAL_TTL && (*rr_ttl > MAX_TTL))
  ------------------
  |  Branch (229:5): [True: 2.13M, False: 0]
  |  Branch (229:28): [True: 227k, False: 1.90M]
  ------------------
  230|   227k|		*rr_ttl = MAX_TTL;
  231|  2.13M|	if(type == LDNS_RR_TYPE_SOA && section == LDNS_SECTION_AUTHORITY) {
  ------------------
  |  Branch (231:5): [True: 0, False: 2.13M]
  |  Branch (231:33): [True: 0, False: 0]
  ------------------
  232|       |		/* max neg ttl overrides the min and max ttl of everything
  233|       |		 * else, it is for a more specific record */
  234|      0|		if(*rr_ttl > MAX_NEG_TTL)
  ------------------
  |  Branch (234:6): [True: 0, False: 0]
  ------------------
  235|      0|			*rr_ttl = MAX_NEG_TTL;
  236|      0|	}
  237|  2.13M|	if(*rr_ttl < data->ttl)
  ------------------
  |  Branch (237:5): [True: 9.34k, False: 2.12M]
  ------------------
  238|  9.34k|		data->ttl = *rr_ttl;
  239|       |
  240|  2.13M|	if(rr->outside_packet) {
  ------------------
  |  Branch (240:5): [True: 0, False: 2.13M]
  ------------------
  241|       |		/* uncompressed already, only needs copy */
  242|      0|		memmove(to, rr->ttl_data+sizeof(uint32_t), rr->size);
  243|      0|		return 1;
  244|      0|	}
  245|       |
  246|  2.13M|	sldns_buffer_set_position(pkt, (size_t)
  247|  2.13M|		(rr->ttl_data - sldns_buffer_begin(pkt) + sizeof(uint32_t)));
  248|       |	/* insert decompressed size into rdata len stored in memory */
  249|       |	/* -2 because rdatalen bytes are not included. */
  250|  2.13M|	pkt_len = htons(rr->size - 2);
  251|  2.13M|	memmove(to, &pkt_len, sizeof(uint16_t));
  252|  2.13M|	to += 2;
  253|       |	/* read packet rdata len */
  254|  2.13M|	pkt_len = sldns_buffer_read_u16(pkt);
  255|  2.13M|	if(sldns_buffer_remaining(pkt) < pkt_len)
  ------------------
  |  Branch (255:5): [True: 0, False: 2.13M]
  ------------------
  256|      0|		return 0;
  257|  2.13M|	desc = sldns_rr_descript(type);
  258|  2.13M|	if(pkt_len > 0 && desc && desc->_dname_count > 0) {
  ------------------
  |  Branch (258:5): [True: 11.4k, False: 2.12M]
  |  Branch (258:20): [True: 11.4k, False: 0]
  |  Branch (258:28): [True: 8.37k, False: 3.10k]
  ------------------
  259|  8.37k|		int count = (int)desc->_dname_count;
  260|  8.37k|		int rdf = 0;
  261|  8.37k|		size_t len;
  262|  8.37k|		size_t oldpos;
  263|       |		/* decompress dnames. */
  264|  75.3k|		while(pkt_len > 0 && count) {
  ------------------
  |  Branch (264:9): [True: 69.2k, False: 6.13k]
  |  Branch (264:24): [True: 67.0k, False: 2.23k]
  ------------------
  265|  67.0k|			switch(desc->_wireformat[rdf]) {
  266|  8.37k|			case LDNS_RDF_TYPE_DNAME:
  ------------------
  |  Branch (266:4): [True: 8.37k, False: 58.6k]
  ------------------
  267|  8.37k|				oldpos = sldns_buffer_position(pkt);
  268|  8.37k|				dname_pkt_copy(pkt, to, 
  269|  8.37k|					sldns_buffer_current(pkt));
  270|  8.37k|				to += pkt_dname_len(pkt);
  271|  8.37k|				pkt_len -= sldns_buffer_position(pkt)-oldpos;
  272|  8.37k|				count--;
  273|  8.37k|				len = 0;
  274|  8.37k|				break;
  275|      0|			case LDNS_RDF_TYPE_STR:
  ------------------
  |  Branch (275:4): [True: 0, False: 67.0k]
  ------------------
  276|      0|				len = sldns_buffer_current(pkt)[0] + 1;
  277|      0|				break;
  278|  58.6k|			default:
  ------------------
  |  Branch (278:4): [True: 58.6k, False: 8.37k]
  ------------------
  279|  58.6k|				len = get_rdf_size(desc->_wireformat[rdf]);
  280|  58.6k|				break;
  281|  67.0k|			}
  282|  67.0k|			if(len) {
  ------------------
  |  Branch (282:7): [True: 58.6k, False: 8.37k]
  ------------------
  283|  58.6k|				log_assert(len <= pkt_len);
  284|  58.6k|				memmove(to, sldns_buffer_current(pkt), len);
  285|  58.6k|				to += len;
  286|  58.6k|				sldns_buffer_skip(pkt, (ssize_t)len);
  287|  58.6k|				pkt_len -= len;
  288|  58.6k|			}
  289|  67.0k|			rdf++;
  290|  67.0k|		}
  291|  8.37k|	}
  292|       |	/* copy remaining rdata */
  293|  2.13M|	if(pkt_len >  0)
  ------------------
  |  Branch (293:5): [True: 5.34k, False: 2.12M]
  ------------------
  294|  5.34k|		memmove(to, sldns_buffer_current(pkt), pkt_len);
  295|       |	
  296|  2.13M|	return 1;
  297|  2.13M|}
msgreply.c:get_rrset_trust:
  375|  12.9k|{
  376|  12.9k|	uint16_t AA = msg->flags & BIT_AA;
  ------------------
  |  |   70|  12.9k|#define BIT_AA 0x0400
  ------------------
  377|  12.9k|	if(rrset->section == LDNS_SECTION_ANSWER) {
  ------------------
  |  Branch (377:5): [True: 0, False: 12.9k]
  ------------------
  378|      0|		if(AA) {
  ------------------
  |  Branch (378:6): [True: 0, False: 0]
  ------------------
  379|       |			/* RFC2181 says remainder of CNAME chain is nonauth*/
  380|      0|			if(msg->rrset_first && 
  ------------------
  |  Branch (380:7): [True: 0, False: 0]
  ------------------
  381|      0|				msg->rrset_first->section==LDNS_SECTION_ANSWER
  ------------------
  |  Branch (381:5): [True: 0, False: 0]
  ------------------
  382|      0|				&& msg->rrset_first->type==LDNS_RR_TYPE_CNAME){
  ------------------
  |  Branch (382:8): [True: 0, False: 0]
  ------------------
  383|      0|				if(rrset == msg->rrset_first)
  ------------------
  |  Branch (383:8): [True: 0, False: 0]
  ------------------
  384|      0|					return rrset_trust_ans_AA;
  385|      0|				else 	return rrset_trust_ans_noAA;
  386|      0|			}
  387|      0|			if(msg->rrset_first && 
  ------------------
  |  Branch (387:7): [True: 0, False: 0]
  ------------------
  388|      0|				msg->rrset_first->section==LDNS_SECTION_ANSWER
  ------------------
  |  Branch (388:5): [True: 0, False: 0]
  ------------------
  389|      0|				&& msg->rrset_first->type==LDNS_RR_TYPE_DNAME){
  ------------------
  |  Branch (389:8): [True: 0, False: 0]
  ------------------
  390|      0|				if(rrset == msg->rrset_first ||
  ------------------
  |  Branch (390:8): [True: 0, False: 0]
  ------------------
  391|      0|				   rrset == msg->rrset_first->rrset_all_next)
  ------------------
  |  Branch (391:8): [True: 0, False: 0]
  ------------------
  392|      0|					return rrset_trust_ans_AA;
  393|      0|				else 	return rrset_trust_ans_noAA;
  394|      0|			}
  395|      0|			return rrset_trust_ans_AA;
  396|      0|		}
  397|      0|		else	return rrset_trust_ans_noAA;
  398|  12.9k|	} else if(rrset->section == LDNS_SECTION_AUTHORITY) {
  ------------------
  |  Branch (398:12): [True: 4.67k, False: 8.28k]
  ------------------
  399|  4.67k|		if(AA)	return rrset_trust_auth_AA;
  ------------------
  |  Branch (399:6): [True: 2.93k, False: 1.74k]
  ------------------
  400|  1.74k|		else	return rrset_trust_auth_noAA;
  401|  8.28k|	} else {
  402|       |		/* addit section */
  403|  8.28k|		if(AA)	return rrset_trust_add_AA;
  ------------------
  |  Branch (403:6): [True: 5.21k, False: 3.07k]
  ------------------
  404|  3.07k|		else	return rrset_trust_add_noAA;
  405|  8.28k|	}
  406|       |	/* NOTREACHED */
  407|      0|	return rrset_trust_none;
  408|  12.9k|}

ub_rrset_sizefunc:
   71|  13.2k|{
   72|  13.2k|	struct ub_packed_rrset_key* k = (struct ub_packed_rrset_key*)key;
   73|  13.2k|	struct packed_rrset_data* d = (struct packed_rrset_data*)data;
   74|  13.2k|	size_t s = sizeof(struct ub_packed_rrset_key) + k->rk.dname_len;
   75|  13.2k|	s += packed_rrset_sizeof(d) + lock_get_mem(&k->entry.lock);
  ------------------
  |  |   88|  13.2k|#define lock_get_mem(lock) (0) /* nothing */
  ------------------
   76|  13.2k|	return s;
   77|  13.2k|}
packed_rrset_sizeof:
   81|  13.2k|{
   82|  13.2k|	size_t s;
   83|  13.2k|	if(d->rrsig_count > 0) {
  ------------------
  |  Branch (83:5): [True: 112, False: 13.1k]
  ------------------
   84|    112|		s = ((uint8_t*)d->rr_data[d->count+d->rrsig_count-1] - 
   85|    112|			(uint8_t*)d) + d->rr_len[d->count+d->rrsig_count-1];
   86|  13.1k|	} else {
   87|  13.1k|		log_assert(d->count > 0);
   88|  13.1k|		s = ((uint8_t*)d->rr_data[d->count-1] - (uint8_t*)d) + 
   89|  13.1k|			d->rr_len[d->count-1];
   90|  13.1k|	}
   91|  13.2k|	return s;
   92|  13.2k|}
ub_rrset_compare:
   96|    542|{
   97|    542|	struct ub_packed_rrset_key* key1 = (struct ub_packed_rrset_key*)k1;
   98|    542|	struct ub_packed_rrset_key* key2 = (struct ub_packed_rrset_key*)k2;
   99|    542|	int c;
  100|    542|	if(key1 == key2)
  ------------------
  |  Branch (100:5): [True: 0, False: 542]
  ------------------
  101|      0|		return 0;
  102|    542|	if(key1->rk.type != key2->rk.type) {
  ------------------
  |  Branch (102:5): [True: 4, False: 538]
  ------------------
  103|      4|		if(key1->rk.type < key2->rk.type)
  ------------------
  |  Branch (103:6): [True: 2, False: 2]
  ------------------
  104|      2|			return -1;
  105|      2|		return 1;
  106|      4|	}
  107|    538|	if(key1->rk.dname_len != key2->rk.dname_len) {
  ------------------
  |  Branch (107:5): [True: 476, False: 62]
  ------------------
  108|    476|		if(key1->rk.dname_len < key2->rk.dname_len)
  ------------------
  |  Branch (108:6): [True: 292, False: 184]
  ------------------
  109|    292|			return -1;
  110|    184|		return 1;
  111|    476|	}
  112|     62|	if((c=query_dname_compare(key1->rk.dname, key2->rk.dname)) != 0)
  ------------------
  |  Branch (112:5): [True: 20, False: 42]
  ------------------
  113|     20|		return c;
  114|     42|	if(key1->rk.rrset_class != key2->rk.rrset_class) {
  ------------------
  |  Branch (114:5): [True: 42, False: 0]
  ------------------
  115|     42|		if(key1->rk.rrset_class < key2->rk.rrset_class)
  ------------------
  |  Branch (115:6): [True: 20, False: 22]
  ------------------
  116|     20|			return -1;
  117|     22|		return 1;
  118|     42|	}
  119|      0|	if(key1->rk.flags != key2->rk.flags) {
  ------------------
  |  Branch (119:5): [True: 0, False: 0]
  ------------------
  120|      0|		if(key1->rk.flags < key2->rk.flags)
  ------------------
  |  Branch (120:6): [True: 0, False: 0]
  ------------------
  121|      0|			return -1;
  122|      0|		return 1;
  123|      0|	}
  124|      0|	return 0;
  125|      0|}
ub_rrset_key_delete:
  129|  12.9k|{
  130|  12.9k|	struct ub_packed_rrset_key* k = (struct ub_packed_rrset_key*)key;
  131|  12.9k|	struct alloc_cache* a = (struct alloc_cache*)userdata;
  132|  12.9k|	k->id = 0;
  133|  12.9k|	free(k->rk.dname);
  134|  12.9k|	k->rk.dname = NULL;
  135|  12.9k|	alloc_special_release(a, k);
  136|  12.9k|}
rrset_data_delete:
  140|  12.9k|{
  141|  12.9k|	struct packed_rrset_data* d = (struct packed_rrset_data*)data;
  142|  12.9k|	free(d);
  143|  12.9k|}
packed_rrset_ttl_add:
  220|  12.9k|{
  221|  12.9k|	size_t i;
  222|  12.9k|	size_t total = data->count + data->rrsig_count;
  223|  12.9k|	data->ttl_add = add;
  224|  12.9k|	data->ttl += add;
  225|  2.14M|	for(i=0; i<total; i++)
  ------------------
  |  Branch (225:11): [True: 2.13M, False: 12.9k]
  ------------------
  226|  2.13M|		data->rr_ttl[i] += add;
  227|  12.9k|}

fptr_whitelist_hash_sizefunc:
  253|  12.9k|{
  254|  12.9k|	if(fptr == &msgreply_sizefunc) return 1;
  ------------------
  |  Branch (254:5): [True: 0, False: 12.9k]
  ------------------
  255|  12.9k|	else if(fptr == &ub_rrset_sizefunc) return 1;
  ------------------
  |  Branch (255:10): [True: 12.9k, False: 0]
  ------------------
  256|      0|	else if(fptr == &infra_sizefunc) return 1;
  ------------------
  |  Branch (256:10): [True: 0, False: 0]
  ------------------
  257|      0|	else if(fptr == &key_entry_sizefunc) return 1;
  ------------------
  |  Branch (257:10): [True: 0, False: 0]
  ------------------
  258|      0|	else if(fptr == &rate_sizefunc) return 1;
  ------------------
  |  Branch (258:10): [True: 0, False: 0]
  ------------------
  259|      0|	else if(fptr == &ip_rate_sizefunc) return 1;
  ------------------
  |  Branch (259:10): [True: 0, False: 0]
  ------------------
  260|      0|	else if(fptr == &test_slabhash_sizefunc) return 1;
  ------------------
  |  Branch (260:10): [True: 0, False: 0]
  ------------------
  261|       |#ifdef CLIENT_SUBNET
  262|       |	else if(fptr == &msg_cache_sizefunc) return 1;
  263|       |#endif
  264|       |#ifdef USE_DNSCRYPT
  265|       |	else if(fptr == &dnsc_shared_secrets_sizefunc) return 1;
  266|       |	else if(fptr == &dnsc_nonces_sizefunc) return 1;
  267|       |#endif
  268|      0|	return 0;
  269|  12.9k|}
fptr_whitelist_hash_compfunc:
  273|  25.9k|{
  274|  25.9k|	if(fptr == &query_info_compare) return 1;
  ------------------
  |  Branch (274:5): [True: 0, False: 25.9k]
  ------------------
  275|  25.9k|	else if(fptr == &ub_rrset_compare) return 1;
  ------------------
  |  Branch (275:10): [True: 25.9k, False: 0]
  ------------------
  276|      0|	else if(fptr == &infra_compfunc) return 1;
  ------------------
  |  Branch (276:10): [True: 0, False: 0]
  ------------------
  277|      0|	else if(fptr == &key_entry_compfunc) return 1;
  ------------------
  |  Branch (277:10): [True: 0, False: 0]
  ------------------
  278|      0|	else if(fptr == &rate_compfunc) return 1;
  ------------------
  |  Branch (278:10): [True: 0, False: 0]
  ------------------
  279|      0|	else if(fptr == &ip_rate_compfunc) return 1;
  ------------------
  |  Branch (279:10): [True: 0, False: 0]
  ------------------
  280|      0|	else if(fptr == &test_slabhash_compfunc) return 1;
  ------------------
  |  Branch (280:10): [True: 0, False: 0]
  ------------------
  281|       |#ifdef USE_DNSCRYPT
  282|       |	else if(fptr == &dnsc_shared_secrets_compfunc) return 1;
  283|       |	else if(fptr == &dnsc_nonces_compfunc) return 1;
  284|       |#endif
  285|      0|	return 0;
  286|  25.9k|}
fptr_whitelist_hash_delkeyfunc:
  290|  12.9k|{
  291|  12.9k|	if(fptr == &query_entry_delete) return 1;
  ------------------
  |  Branch (291:5): [True: 0, False: 12.9k]
  ------------------
  292|  12.9k|	else if(fptr == &ub_rrset_key_delete) return 1;
  ------------------
  |  Branch (292:10): [True: 12.9k, False: 0]
  ------------------
  293|      0|	else if(fptr == &infra_delkeyfunc) return 1;
  ------------------
  |  Branch (293:10): [True: 0, False: 0]
  ------------------
  294|      0|	else if(fptr == &key_entry_delkeyfunc) return 1;
  ------------------
  |  Branch (294:10): [True: 0, False: 0]
  ------------------
  295|      0|	else if(fptr == &rate_delkeyfunc) return 1;
  ------------------
  |  Branch (295:10): [True: 0, False: 0]
  ------------------
  296|      0|	else if(fptr == &ip_rate_delkeyfunc) return 1;
  ------------------
  |  Branch (296:10): [True: 0, False: 0]
  ------------------
  297|      0|	else if(fptr == &test_slabhash_delkey) return 1;
  ------------------
  |  Branch (297:10): [True: 0, False: 0]
  ------------------
  298|       |#ifdef USE_DNSCRYPT
  299|       |	else if(fptr == &dnsc_shared_secrets_delkeyfunc) return 1;
  300|       |	else if(fptr == &dnsc_nonces_delkeyfunc) return 1;
  301|       |#endif
  302|      0|	return 0;
  303|  12.9k|}
fptr_whitelist_hash_deldatafunc:
  307|  12.9k|{
  308|  12.9k|	if(fptr == &reply_info_delete) return 1;
  ------------------
  |  Branch (308:5): [True: 0, False: 12.9k]
  ------------------
  309|  12.9k|	else if(fptr == &rrset_data_delete) return 1;
  ------------------
  |  Branch (309:10): [True: 12.9k, False: 0]
  ------------------
  310|      0|	else if(fptr == &infra_deldatafunc) return 1;
  ------------------
  |  Branch (310:10): [True: 0, False: 0]
  ------------------
  311|      0|	else if(fptr == &key_entry_deldatafunc) return 1;
  ------------------
  |  Branch (311:10): [True: 0, False: 0]
  ------------------
  312|      0|	else if(fptr == &rate_deldatafunc) return 1;
  ------------------
  |  Branch (312:10): [True: 0, False: 0]
  ------------------
  313|      0|	else if(fptr == &test_slabhash_deldata) return 1;
  ------------------
  |  Branch (313:10): [True: 0, False: 0]
  ------------------
  314|       |#ifdef CLIENT_SUBNET
  315|       |	else if(fptr == &subnet_data_delete) return 1;
  316|       |#endif
  317|       |#ifdef USE_DNSCRYPT
  318|       |	else if(fptr == &dnsc_shared_secrets_deldatafunc) return 1;
  319|       |	else if(fptr == &dnsc_nonces_deldatafunc) return 1;
  320|       |#endif
  321|      0|	return 0;
  322|  12.9k|}
fptr_whitelist_hash_markdelfunc:
  326|  12.9k|{
  327|  12.9k|	if(fptr == NULL) return 1;
  ------------------
  |  Branch (327:5): [True: 0, False: 12.9k]
  ------------------
  328|  12.9k|	else if(fptr == &rrset_markdel) return 1;
  ------------------
  |  Branch (328:10): [True: 12.9k, False: 0]
  ------------------
  329|       |#ifdef CLIENT_SUBNET
  330|       |	else if(fptr == &subnet_markdel) return 1;
  331|       |#endif
  332|      0|	return 0;
  333|  12.9k|}

log_init:
   87|  4.59k|{
   88|  4.59k|	FILE *f;
   89|  4.59k|	if(!key_created) {
  ------------------
  |  Branch (89:5): [True: 1, False: 4.59k]
  ------------------
   90|      1|		key_created = 1;
   91|      1|		ub_thread_key_create(&logkey, NULL);
  ------------------
  |  |  176|      1|#define ub_thread_key_create(key, f) LOCKRET(pthread_key_create(key, f))
  |  |  ------------------
  |  |  |  |   67|      1|#define LOCKRET(func) do {\
  |  |  |  |   68|      1|	int lockret_err;		\
  |  |  |  |   69|      1|	if( (lockret_err=(func)) != 0)		\
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (69:6): [True: 0, False: 1]
  |  |  |  |  ------------------
  |  |  |  |   70|      1|		log_err("%s at %d could not " #func ": %s", \
  |  |  |  |   71|      0|		__FILE__, __LINE__, strerror(lockret_err));	\
  |  |  |  |   72|      1| 	} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (72:11): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
   92|      1|		lock_basic_init(&log_lock);
  ------------------
  |  |  100|      1|#define lock_basic_init(lock) LOCKRET(pthread_mutex_init(lock, NULL))
  |  |  ------------------
  |  |  |  |   67|      1|#define LOCKRET(func) do {\
  |  |  |  |   68|      1|	int lockret_err;		\
  |  |  |  |   69|      1|	if( (lockret_err=(func)) != 0)		\
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (69:6): [True: 0, False: 1]
  |  |  |  |  ------------------
  |  |  |  |   70|      1|		log_err("%s at %d could not " #func ": %s", \
  |  |  |  |   71|      0|		__FILE__, __LINE__, strerror(lockret_err));	\
  |  |  |  |   72|      1| 	} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (72:11): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
   93|      1|	}
   94|  4.59k|	lock_basic_lock(&log_lock);
  ------------------
  |  |  102|  4.59k|#define lock_basic_lock(lock) LOCKRET(pthread_mutex_lock(lock))
  |  |  ------------------
  |  |  |  |   67|  4.59k|#define LOCKRET(func) do {\
  |  |  |  |   68|  4.59k|	int lockret_err;		\
  |  |  |  |   69|  4.59k|	if( (lockret_err=(func)) != 0)		\
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (69:6): [True: 0, False: 4.59k]
  |  |  |  |  ------------------
  |  |  |  |   70|  4.59k|		log_err("%s at %d could not " #func ": %s", \
  |  |  |  |   71|      0|		__FILE__, __LINE__, strerror(lockret_err));	\
  |  |  |  |   72|  4.59k| 	} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (72:11): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
   95|  4.59k|	if(logfile 
  ------------------
  |  Branch (95:5): [True: 4.59k, False: 1]
  ------------------
   96|  4.59k|#if defined(HAVE_SYSLOG_H) || defined(UB_ON_WINDOWS)
   97|  4.59k|	|| logging_to_syslog
  ------------------
  |  Branch (97:5): [True: 0, False: 1]
  ------------------
   98|  4.59k|#endif
   99|  4.59k|	) {
  100|  4.59k|		lock_basic_unlock(&log_lock); /* verbose() needs the lock */
  ------------------
  |  |  103|  4.59k|#define lock_basic_unlock(lock) LOCKRET(pthread_mutex_unlock(lock))
  |  |  ------------------
  |  |  |  |   67|  4.59k|#define LOCKRET(func) do {\
  |  |  |  |   68|  4.59k|	int lockret_err;		\
  |  |  |  |   69|  4.59k|	if( (lockret_err=(func)) != 0)		\
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (69:6): [True: 0, False: 4.59k]
  |  |  |  |  ------------------
  |  |  |  |   70|  4.59k|		log_err("%s at %d could not " #func ": %s", \
  |  |  |  |   71|      0|		__FILE__, __LINE__, strerror(lockret_err));	\
  |  |  |  |   72|  4.59k| 	} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (72:11): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  101|  4.59k|		verbose(VERB_QUERY, "switching log to %s", 
  102|  4.59k|			use_syslog?"syslog":(filename&&filename[0]?filename:"stderr"));
  ------------------
  |  Branch (102:4): [True: 0, False: 4.59k]
  |  Branch (102:25): [True: 4.59k, False: 0]
  |  Branch (102:35): [True: 4.59k, False: 0]
  ------------------
  103|  4.59k|		lock_basic_lock(&log_lock);
  ------------------
  |  |  102|  4.59k|#define lock_basic_lock(lock) LOCKRET(pthread_mutex_lock(lock))
  |  |  ------------------
  |  |  |  |   67|  4.59k|#define LOCKRET(func) do {\
  |  |  |  |   68|  4.59k|	int lockret_err;		\
  |  |  |  |   69|  4.59k|	if( (lockret_err=(func)) != 0)		\
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (69:6): [True: 0, False: 4.59k]
  |  |  |  |  ------------------
  |  |  |  |   70|  4.59k|		log_err("%s at %d could not " #func ": %s", \
  |  |  |  |   71|      0|		__FILE__, __LINE__, strerror(lockret_err));	\
  |  |  |  |   72|  4.59k| 	} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (72:11): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  104|  4.59k|	}
  105|  4.59k|	if(logfile && logfile != stderr) {
  ------------------
  |  Branch (105:5): [True: 4.59k, False: 1]
  |  Branch (105:16): [True: 4.59k, False: 0]
  ------------------
  106|  4.59k|		FILE* cl = logfile;
  107|  4.59k|		logfile = NULL; /* set to NULL before it is closed, so that
  108|       |			other threads have a valid logfile or NULL */
  109|  4.59k|		fclose(cl);
  110|  4.59k|	}
  111|  4.59k|#ifdef HAVE_SYSLOG_H
  112|  4.59k|	if(logging_to_syslog) {
  ------------------
  |  Branch (112:5): [True: 0, False: 4.59k]
  ------------------
  113|      0|		closelog();
  114|      0|		logging_to_syslog = 0;
  115|      0|	}
  116|  4.59k|	if(use_syslog) {
  ------------------
  |  Branch (116:5): [True: 0, False: 4.59k]
  ------------------
  117|       |		/* do not delay opening until first write, because we may
  118|       |		 * chroot and no longer be able to access dev/log and so on */
  119|       |		/* the facility is LOG_DAEMON by default, but
  120|       |		 * --with-syslog-facility=LOCAL[0-7] can override it */
  121|      0|		openlog(ident, LOG_NDELAY, UB_SYSLOG_FACILITY);
  ------------------
  |  |  841|      0|#define UB_SYSLOG_FACILITY LOG_DAEMON
  ------------------
  122|      0|		logging_to_syslog = 1;
  123|      0|		lock_basic_unlock(&log_lock);
  ------------------
  |  |  103|      0|#define lock_basic_unlock(lock) LOCKRET(pthread_mutex_unlock(lock))
  |  |  ------------------
  |  |  |  |   67|      0|#define LOCKRET(func) do {\
  |  |  |  |   68|      0|	int lockret_err;		\
  |  |  |  |   69|      0|	if( (lockret_err=(func)) != 0)		\
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (69:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |   70|      0|		log_err("%s at %d could not " #func ": %s", \
  |  |  |  |   71|      0|		__FILE__, __LINE__, strerror(lockret_err));	\
  |  |  |  |   72|      0| 	} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (72:11): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  124|      0|		return;
  125|      0|	}
  126|       |#elif defined(UB_ON_WINDOWS)
  127|       |	if(logging_to_syslog) {
  128|       |		logging_to_syslog = 0;
  129|       |	}
  130|       |	if(use_syslog) {
  131|       |		logging_to_syslog = 1;
  132|       |		lock_basic_unlock(&log_lock);
  133|       |		return;
  134|       |	}
  135|       |#endif /* HAVE_SYSLOG_H */
  136|  4.59k|	if(!filename || !filename[0]) {
  ------------------
  |  Branch (136:5): [True: 0, False: 4.59k]
  |  Branch (136:18): [True: 0, False: 4.59k]
  ------------------
  137|      0|		logfile = stderr;
  138|      0|		lock_basic_unlock(&log_lock);
  ------------------
  |  |  103|      0|#define lock_basic_unlock(lock) LOCKRET(pthread_mutex_unlock(lock))
  |  |  ------------------
  |  |  |  |   67|      0|#define LOCKRET(func) do {\
  |  |  |  |   68|      0|	int lockret_err;		\
  |  |  |  |   69|      0|	if( (lockret_err=(func)) != 0)		\
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (69:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |   70|      0|		log_err("%s at %d could not " #func ": %s", \
  |  |  |  |   71|      0|		__FILE__, __LINE__, strerror(lockret_err));	\
  |  |  |  |   72|      0| 	} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (72:11): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  139|      0|		return;
  140|      0|	}
  141|       |	/* open the file for logging */
  142|  4.59k|	if(chrootdir && chrootdir[0] && strncmp(filename, chrootdir,
  ------------------
  |  Branch (142:5): [True: 0, False: 4.59k]
  |  Branch (142:18): [True: 0, False: 0]
  |  Branch (142:34): [True: 0, False: 0]
  ------------------
  143|      0|		strlen(chrootdir)) == 0) 
  144|      0|		filename += strlen(chrootdir);
  145|  4.59k|	f = fopen(filename, "a");
  146|  4.59k|	if(!f) {
  ------------------
  |  Branch (146:5): [True: 0, False: 4.59k]
  ------------------
  147|      0|		lock_basic_unlock(&log_lock);
  ------------------
  |  |  103|      0|#define lock_basic_unlock(lock) LOCKRET(pthread_mutex_unlock(lock))
  |  |  ------------------
  |  |  |  |   67|      0|#define LOCKRET(func) do {\
  |  |  |  |   68|      0|	int lockret_err;		\
  |  |  |  |   69|      0|	if( (lockret_err=(func)) != 0)		\
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (69:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |   70|      0|		log_err("%s at %d could not " #func ": %s", \
  |  |  |  |   71|      0|		__FILE__, __LINE__, strerror(lockret_err));	\
  |  |  |  |   72|      0| 	} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (72:11): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  148|      0|		log_err("Could not open logfile %s: %s", filename, 
  149|      0|			strerror(errno));
  150|      0|		return;
  151|      0|	}
  152|  4.59k|#ifndef UB_ON_WINDOWS
  153|       |	/* line buffering does not work on windows */
  154|  4.59k|	setvbuf(f, NULL, (int)_IOLBF, 0);
  155|  4.59k|#endif
  156|  4.59k|	logfile = f;
  157|  4.59k|	lock_basic_unlock(&log_lock);
  ------------------
  |  |  103|  4.59k|#define lock_basic_unlock(lock) LOCKRET(pthread_mutex_unlock(lock))
  |  |  ------------------
  |  |  |  |   67|  4.59k|#define LOCKRET(func) do {\
  |  |  |  |   68|  4.59k|	int lockret_err;		\
  |  |  |  |   69|  4.59k|	if( (lockret_err=(func)) != 0)		\
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (69:6): [True: 0, False: 4.59k]
  |  |  |  |  ------------------
  |  |  |  |   70|  4.59k|		log_err("%s at %d could not " #func ": %s", \
  |  |  |  |   71|      0|		__FILE__, __LINE__, strerror(lockret_err));	\
  |  |  |  |   72|  4.59k| 	} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (72:11): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  158|  4.59k|}
verbose:
  357|  9.31k|{
  358|  9.31k|        va_list args;
  359|  9.31k|	va_start(args, format);
  360|  9.31k|	if(verbosity >= level) {
  ------------------
  |  Branch (360:5): [True: 0, False: 9.31k]
  ------------------
  361|      0|		if(level == VERB_OPS)
  ------------------
  |  Branch (361:6): [True: 0, False: 0]
  ------------------
  362|      0|			log_vmsg(LOG_NOTICE, "notice", format, args);
  363|      0|		else if(level == VERB_DETAIL)
  ------------------
  |  Branch (363:11): [True: 0, False: 0]
  ------------------
  364|      0|			log_vmsg(LOG_INFO, "info", format, args);
  365|      0|		else	log_vmsg(LOG_DEBUG, "debug", format, args);
  366|      0|	}
  367|  9.31k|	va_end(args);
  368|  9.31k|}

minievent_init:
   89|  4.59k|{
   90|  4.59k|	struct event_base* base = (struct event_base*)malloc(
   91|  4.59k|		sizeof(struct event_base));
   92|  4.59k|	if(!base)
  ------------------
  |  Branch (92:5): [True: 0, False: 4.59k]
  ------------------
   93|      0|		return NULL;
   94|  4.59k|	memset(base, 0, sizeof(*base));
   95|  4.59k|	base->time_secs = time_secs;
   96|  4.59k|	base->time_tv = time_tv;
   97|  4.59k|	if(settime(base) < 0) {
  ------------------
  |  Branch (97:5): [True: 0, False: 4.59k]
  ------------------
   98|      0|		event_base_free(base);
  ------------------
  |  |   74|      0|#define event_base_free minievent_base_free
  ------------------
   99|      0|		return NULL;
  100|      0|	}
  101|  4.59k|	base->times = rbtree_create(mini_ev_cmp);
  102|  4.59k|	if(!base->times) {
  ------------------
  |  Branch (102:5): [True: 0, False: 4.59k]
  ------------------
  103|      0|		event_base_free(base);
  ------------------
  |  |   74|      0|#define event_base_free minievent_base_free
  ------------------
  104|      0|		return NULL;
  105|      0|	}
  106|  4.59k|	base->capfd = MAX_FDS;
  ------------------
  |  |   97|  4.59k|#define MAX_FDS 1024
  ------------------
  107|  4.59k|#ifdef FD_SETSIZE
  108|  4.59k|	if((int)FD_SETSIZE < base->capfd)
  ------------------
  |  Branch (108:5): [True: 0, False: 4.59k]
  ------------------
  109|      0|		base->capfd = (int)FD_SETSIZE;
  110|  4.59k|#endif
  111|  4.59k|	base->fds = (struct event**)calloc((size_t)base->capfd, 
  112|  4.59k|		sizeof(struct event*));
  113|  4.59k|	if(!base->fds) {
  ------------------
  |  Branch (113:5): [True: 0, False: 4.59k]
  ------------------
  114|      0|		event_base_free(base);
  ------------------
  |  |   74|      0|#define event_base_free minievent_base_free
  ------------------
  115|      0|		return NULL;
  116|      0|	}
  117|  4.59k|	base->signals = (struct event**)calloc(MAX_SIG, sizeof(struct event*));
  ------------------
  |  |   99|  4.59k|#define MAX_SIG 32
  ------------------
  118|  4.59k|	if(!base->signals) {
  ------------------
  |  Branch (118:5): [True: 0, False: 4.59k]
  ------------------
  119|      0|		event_base_free(base);
  ------------------
  |  |   74|      0|#define event_base_free minievent_base_free
  ------------------
  120|      0|		return NULL;
  121|      0|	}
  122|  4.59k|#ifndef S_SPLINT_S
  123|  4.59k|	FD_ZERO(&base->reads);
  124|  4.59k|	FD_ZERO(&base->writes);
  125|  4.59k|#endif
  126|  4.59k|	return base;
  127|  4.59k|}
minievent_base_free:
  261|  4.59k|{
  262|  4.59k|	if(!base)
  ------------------
  |  Branch (262:5): [True: 0, False: 4.59k]
  ------------------
  263|      0|		return;
  264|  4.59k|	free(base->times);
  265|  4.59k|	free(base->fds);
  266|  4.59k|	free(base->signals);
  267|  4.59k|	free(base);
  268|  4.59k|}
mini_event.c:settime:
   77|  4.59k|{
   78|  4.59k|	if(gettimeofday(base->time_tv, NULL) < 0) {
  ------------------
  |  Branch (78:5): [True: 0, False: 4.59k]
  ------------------
   79|      0|		return -1;
   80|      0|	}
   81|  4.59k|#ifndef S_SPLINT_S
   82|  4.59k|	*base->time_secs = (time_t)base->time_tv->tv_sec;
   83|  4.59k|#endif
   84|  4.59k|	return 0;
   85|  4.59k|}

log_nametypeclass:
  533|  2.01k|{
  534|  2.01k|	char buf[LDNS_MAX_DOMAINLEN+1];
  535|  2.01k|	char t[12], c[12];
  536|  2.01k|	const char *ts, *cs; 
  537|  2.01k|	if(verbosity < v)
  ------------------
  |  Branch (537:5): [True: 2.01k, False: 0]
  ------------------
  538|  2.01k|		return;
  539|      0|	dname_str(name, buf);
  540|      0|	if(type == LDNS_RR_TYPE_TSIG) ts = "TSIG";
  ------------------
  |  Branch (540:5): [True: 0, False: 0]
  ------------------
  541|      0|	else if(type == LDNS_RR_TYPE_IXFR) ts = "IXFR";
  ------------------
  |  Branch (541:10): [True: 0, False: 0]
  ------------------
  542|      0|	else if(type == LDNS_RR_TYPE_AXFR) ts = "AXFR";
  ------------------
  |  Branch (542:10): [True: 0, False: 0]
  ------------------
  543|      0|	else if(type == LDNS_RR_TYPE_MAILB) ts = "MAILB";
  ------------------
  |  Branch (543:10): [True: 0, False: 0]
  ------------------
  544|      0|	else if(type == LDNS_RR_TYPE_MAILA) ts = "MAILA";
  ------------------
  |  Branch (544:10): [True: 0, False: 0]
  ------------------
  545|      0|	else if(type == LDNS_RR_TYPE_ANY) ts = "ANY";
  ------------------
  |  Branch (545:10): [True: 0, False: 0]
  ------------------
  546|      0|	else if(sldns_rr_descript(type) && sldns_rr_descript(type)->_name)
  ------------------
  |  Branch (546:10): [True: 0, False: 0]
  |  Branch (546:37): [True: 0, False: 0]
  ------------------
  547|      0|		ts = sldns_rr_descript(type)->_name;
  548|      0|	else {
  549|      0|		snprintf(t, sizeof(t), "TYPE%d", (int)type);
  550|      0|		ts = t;
  551|      0|	}
  552|      0|	if(sldns_lookup_by_id(sldns_rr_classes, (int)dclass) &&
  ------------------
  |  Branch (552:5): [True: 0, False: 0]
  ------------------
  553|      0|		sldns_lookup_by_id(sldns_rr_classes, (int)dclass)->name)
  ------------------
  |  Branch (553:3): [True: 0, False: 0]
  ------------------
  554|      0|		cs = sldns_lookup_by_id(sldns_rr_classes, (int)dclass)->name;
  555|      0|	else {
  556|      0|		snprintf(c, sizeof(c), "CLASS%d", (int)dclass);
  557|      0|		cs = c;
  558|      0|	}
  559|      0|	log_info("%s %s %s %s", str, buf, ts, cs);
  560|      0|}

comm_base_create:
  182|  4.59k|{
  183|  4.59k|	struct comm_base* b = (struct comm_base*)calloc(1,
  184|  4.59k|		sizeof(struct comm_base));
  185|  4.59k|	const char *evnm="event", *evsys="", *evmethod="";
  186|       |
  187|  4.59k|	if(!b)
  ------------------
  |  Branch (187:5): [True: 0, False: 4.59k]
  ------------------
  188|      0|		return NULL;
  189|  4.59k|	b->eb = (struct internal_base*)calloc(1, sizeof(struct internal_base));
  190|  4.59k|	if(!b->eb) {
  ------------------
  |  Branch (190:5): [True: 0, False: 4.59k]
  ------------------
  191|      0|		free(b);
  192|      0|		return NULL;
  193|      0|	}
  194|  4.59k|	b->eb->base = ub_default_event_base(sigs, &b->eb->secs, &b->eb->now);
  195|  4.59k|	if(!b->eb->base) {
  ------------------
  |  Branch (195:5): [True: 0, False: 4.59k]
  ------------------
  196|      0|		free(b->eb);
  197|      0|		free(b);
  198|      0|		return NULL;
  199|      0|	}
  200|  4.59k|	ub_comm_base_now(b);
  201|  4.59k|	ub_get_event_sys(b->eb->base, &evnm, &evsys, &evmethod);
  202|  4.59k|	verbose(VERB_ALGO, "%s %s uses %s method.", evnm, evsys, evmethod);
  203|  4.59k|	return b;
  204|  4.59k|}
comm_base_delete:
  225|  4.59k|{
  226|  4.59k|	if(!b)
  ------------------
  |  Branch (226:5): [True: 0, False: 4.59k]
  ------------------
  227|      0|		return;
  228|  4.59k|	if(b->eb->slow_accept_enabled) {
  ------------------
  |  Branch (228:5): [True: 0, False: 4.59k]
  ------------------
  229|      0|		if(ub_event_del(b->eb->slow_accept) != 0) {
  ------------------
  |  Branch (229:6): [True: 0, False: 0]
  ------------------
  230|      0|			log_err("could not event_del slow_accept");
  231|      0|		}
  232|      0|		ub_event_free(b->eb->slow_accept);
  233|      0|	}
  234|  4.59k|	ub_event_base_free(b->eb->base);
  235|  4.59k|	b->eb->base = NULL;
  236|  4.59k|	free(b->eb);
  237|  4.59k|	free(b);
  238|  4.59k|}
comm_base_timept:
  258|  4.59k|{
  259|  4.59k|	*tt = &b->eb->secs;
  260|  4.59k|	*tv = &b->eb->now;
  261|  4.59k|}

rbtree_create:
   79|  4.59k|{
   80|  4.59k|	rbtree_type *rbtree;
   81|       |
   82|       |	/* Allocate memory for it */
   83|  4.59k|	rbtree = (rbtree_type *) malloc(sizeof(rbtree_type));
   84|  4.59k|	if (!rbtree) {
  ------------------
  |  Branch (84:6): [True: 0, False: 4.59k]
  ------------------
   85|      0|		return NULL;
   86|      0|	}
   87|       |
   88|       |	/* Initialize it */
   89|  4.59k|	rbtree_init(rbtree, cmpf);
   90|       |
   91|  4.59k|	return rbtree;
   92|  4.59k|}
rbtree_init:
   96|  4.59k|{
   97|       |	/* Initialize it */
   98|  4.59k|	rbtree->root = RBTREE_NULL;
  ------------------
  |  |   69|  4.59k|#define	RBTREE_NULL &rbtree_null_node
  ------------------
   99|  4.59k|	rbtree->count = 0;
  100|  4.59k|	rbtree->cmp = cmpf;
  101|  4.59k|}

regional_create:
   67|  4.59k|{
   68|  4.59k|	return regional_create_custom(REGIONAL_CHUNK_SIZE);
  ------------------
  |  |   56|  4.59k|#define REGIONAL_CHUNK_SIZE         8192
  ------------------
   69|  4.59k|}
regional_create_custom:
  105|  4.59k|{
  106|  4.59k|	if(size < sizeof(struct regional))
  ------------------
  |  Branch (106:5): [True: 0, False: 4.59k]
  ------------------
  107|      0|		size = sizeof(struct regional);
  108|  4.59k|	return regional_create_custom_large_object(size,
  109|  4.59k|		REGIONAL_LARGE_OBJECT_SIZE);
  ------------------
  |  |   62|  4.59k|#define REGIONAL_LARGE_OBJECT_SIZE  2048
  ------------------
  110|  4.59k|}
regional_free_all:
  120|  4.59k|{
  121|  4.59k|	char* p = r->next, *np;
  122|  17.3k|	while(p) {
  ------------------
  |  Branch (122:8): [True: 12.7k, False: 4.59k]
  ------------------
  123|  12.7k|		np = *(char**)p;
  124|  12.7k|		free(p);
  125|  12.7k|		p = np;
  126|  12.7k|	}
  127|  4.59k|	p = r->large_list;
  128|  4.68k|	while(p) {
  ------------------
  |  Branch (128:8): [True: 92, False: 4.59k]
  ------------------
  129|     92|		np = *(char**)p;
  130|     92|		free(p);
  131|     92|		p = np;
  132|     92|	}
  133|  4.59k|	regional_init(r);
  134|  4.59k|}
regional_destroy:
  138|  4.59k|{
  139|  4.59k|	if(!r) return;
  ------------------
  |  Branch (139:5): [True: 0, False: 4.59k]
  ------------------
  140|  4.59k|	regional_free_all(r);
  141|  4.59k|	free(r);
  142|  4.59k|}
regional_alloc:
  146|  3.21M|{
  147|  3.21M|	size_t a;
  148|  3.21M|	void *s;
  149|  3.21M|	if(
  150|  3.21M|#if SIZEOF_SIZE_T == 8
  151|  3.21M|		(unsigned long long)size >= 0xffffffffffffff00ULL
  ------------------
  |  Branch (151:3): [True: 0, False: 3.21M]
  ------------------
  152|       |#else
  153|       |		(unsigned)size >= (unsigned)0xffffff00UL
  154|       |#endif
  155|  3.21M|		)
  156|      0|		return NULL; /* protect against integer overflow in
  157|       |			malloc and ALIGN_UP */
  158|  3.21M|	a = ALIGN_UP(size, ALIGNMENT);
  ------------------
  |  |   51|  3.21M|#define ALIGN_UP(x, s)     (((x) + s - 1) & (~(s - 1)))
  ------------------
  159|       |	/* large objects */
  160|  3.21M|	if(a > r->large_object_size) {
  ------------------
  |  Branch (160:5): [True: 92, False: 3.21M]
  ------------------
  161|     92|		s = malloc(ALIGNMENT + size);
  ------------------
  |  |   53|     92|#define ALIGNMENT          (sizeof(uint64_t))
  ------------------
  162|     92|		if(!s) return NULL;
  ------------------
  |  Branch (162:6): [True: 0, False: 92]
  ------------------
  163|     92|		r->total_large += ALIGNMENT+size;
  ------------------
  |  |   53|     92|#define ALIGNMENT          (sizeof(uint64_t))
  ------------------
  164|     92|		*(char**)s = r->large_list;
  165|     92|		r->large_list = (char*)s;
  166|     92|		return (char*)s+ALIGNMENT;
  ------------------
  |  |   53|     92|#define ALIGNMENT          (sizeof(uint64_t))
  ------------------
  167|     92|	}
  168|       |	/* create a new chunk */
  169|  3.21M|	if(a > r->available) {
  ------------------
  |  Branch (169:5): [True: 12.7k, False: 3.19M]
  ------------------
  170|  12.7k|		s = malloc(REGIONAL_CHUNK_SIZE);
  ------------------
  |  |   56|  12.7k|#define REGIONAL_CHUNK_SIZE         8192
  ------------------
  171|  12.7k|		if(!s) return NULL;
  ------------------
  |  Branch (171:6): [True: 0, False: 12.7k]
  ------------------
  172|  12.7k|		*(char**)s = r->next;
  173|  12.7k|		r->next = (char*)s;
  174|  12.7k|		r->data = (char*)s + ALIGNMENT;
  ------------------
  |  |   53|  12.7k|#define ALIGNMENT          (sizeof(uint64_t))
  ------------------
  175|  12.7k|		r->available = REGIONAL_CHUNK_SIZE - ALIGNMENT;
  ------------------
  |  |   56|  12.7k|#define REGIONAL_CHUNK_SIZE         8192
  ------------------
              		r->available = REGIONAL_CHUNK_SIZE - ALIGNMENT;
  ------------------
  |  |   53|  12.7k|#define ALIGNMENT          (sizeof(uint64_t))
  ------------------
  176|  12.7k|	}
  177|       |	/* put in this chunk */
  178|  3.21M|	r->available -= a;
  179|  3.21M|	s = r->data;
  180|  3.21M|	r->data += a;
  181|  3.21M|	return s;
  182|  3.21M|}
regional_alloc_init:
  186|  1.44k|{
  187|  1.44k|	void *s = regional_alloc(r, size);
  188|  1.44k|	if(!s) return NULL;
  ------------------
  |  Branch (188:5): [True: 0, False: 1.44k]
  ------------------
  189|  1.44k|	memcpy(s, init, size);
  190|  1.44k|	return s;
  191|  1.44k|}
regional.c:regional_create_custom_large_object:
   91|  4.59k|{
   92|  4.59k|	struct regional* r;
   93|  4.59k|	size = ALIGN_UP(size, ALIGNMENT);
  ------------------
  |  |   51|  4.59k|#define ALIGN_UP(x, s)     (((x) + s - 1) & (~(s - 1)))
  ------------------
   94|  4.59k|	r = (struct regional*)malloc(size);
   95|  4.59k|	log_assert(sizeof(struct regional) <= size);
   96|  4.59k|	if(!r) return NULL;
  ------------------
  |  Branch (96:5): [True: 0, False: 4.59k]
  ------------------
   97|  4.59k|	r->first_size = size;
   98|  4.59k|	r->large_object_size = large_object_size;
   99|  4.59k|	regional_init(r);
  100|  4.59k|	return r;
  101|  4.59k|}
regional.c:regional_init:
   74|  9.18k|{
   75|  9.18k|	size_t a = ALIGN_UP(sizeof(struct regional), ALIGNMENT);
  ------------------
  |  |   51|  9.18k|#define ALIGN_UP(x, s)     (((x) + s - 1) & (~(s - 1)))
  ------------------
   76|  9.18k|	r->data = (char*)r + a;
   77|  9.18k|	r->available = r->first_size - a;
   78|  9.18k|	r->next = NULL;
   79|  9.18k|	r->large_list = NULL;
   80|  9.18k|	r->total_large = 0;
   81|  9.18k|}

hashlittle:
  347|  3.33M|{
  348|  3.33M|  uint32_t a,b,c;                                          /* internal state */
  349|  3.33M|  union { const void *ptr; size_t i; } u;     /* needed for Mac Powerbook G4 */
  350|       |
  351|       |  /* Set up the internal state */
  352|  3.33M|  a = b = c = raninit + ((uint32_t)length) + initval;
  353|       |
  354|  3.33M|  u.ptr = key;
  355|  3.33M|  if (HASH_LITTLE_ENDIAN && ((u.i & 0x3) == 0)) {
  ------------------
  |  |   93|  6.67M|#  define HASH_LITTLE_ENDIAN 1
  |  |  ------------------
  |  |  |  Branch (93:30): [Folded - Ignored]
  |  |  ------------------
  ------------------
  |  Branch (355:29): [True: 2.25M, False: 1.08M]
  ------------------
  356|  2.25M|    const uint32_t *k = (const uint32_t *)key;         /* read 32-bit chunks */
  357|  2.25M|#ifdef ARRAY_CLEAN_ACCESS
  358|  2.25M|    const uint8_t  *k8;
  359|  2.25M|#endif
  360|       |
  361|       |    /*------ all but last block: aligned reads and affect 32 bits of (a,b,c) */
  362|  2.30M|    while (length > 12)
  ------------------
  |  Branch (362:12): [True: 56.3k, False: 2.25M]
  ------------------
  363|  56.3k|    {
  364|  56.3k|      a += k[0];
  365|  56.3k|      b += k[1];
  366|  56.3k|      c += k[2];
  367|  56.3k|      mix(a,b,c);
  ------------------
  |  |  173|  56.3k|#define mix(a,b,c) \
  |  |  174|  56.3k|{ \
  |  |  175|  56.3k|  a -= c;  a ^= rot(c, 4);  c += b; \
  |  |  ------------------
  |  |  |  |  118|  56.3k|#define rot(x,k) (((x)<<(k)) | ((x)>>(32-(k))))
  |  |  ------------------
  |  |  176|  56.3k|  b -= a;  b ^= rot(a, 6);  a += c; \
  |  |  ------------------
  |  |  |  |  118|  56.3k|#define rot(x,k) (((x)<<(k)) | ((x)>>(32-(k))))
  |  |  ------------------
  |  |  177|  56.3k|  c -= b;  c ^= rot(b, 8);  b += a; \
  |  |  ------------------
  |  |  |  |  118|  56.3k|#define rot(x,k) (((x)<<(k)) | ((x)>>(32-(k))))
  |  |  ------------------
  |  |  178|  56.3k|  a -= c;  a ^= rot(c,16);  c += b; \
  |  |  ------------------
  |  |  |  |  118|  56.3k|#define rot(x,k) (((x)<<(k)) | ((x)>>(32-(k))))
  |  |  ------------------
  |  |  179|  56.3k|  b -= a;  b ^= rot(a,19);  a += c; \
  |  |  ------------------
  |  |  |  |  118|  56.3k|#define rot(x,k) (((x)<<(k)) | ((x)>>(32-(k))))
  |  |  ------------------
  |  |  180|  56.3k|  c -= b;  c ^= rot(b, 4);  b += a; \
  |  |  ------------------
  |  |  |  |  118|  56.3k|#define rot(x,k) (((x)<<(k)) | ((x)>>(32-(k))))
  |  |  ------------------
  |  |  181|  56.3k|}
  ------------------
  368|  56.3k|      length -= 12;
  369|  56.3k|      k += 3;
  370|  56.3k|    }
  371|       |
  372|       |    /*----------------------------- handle the last (probably partial) block */
  373|       |    /* 
  374|       |     * "k[2]&0xffffff" actually reads beyond the end of the string, but
  375|       |     * then masks off the part it's not allowed to read.  Because the
  376|       |     * string is aligned, the masked-off tail is in the same word as the
  377|       |     * rest of the string.  Every machine with memory protection I've seen
  378|       |     * does it on word boundaries, so is OK with this.  But VALGRIND will
  379|       |     * still catch it and complain.  The masking trick does make the hash
  380|       |     * noticeably faster for short strings (like English words).
  381|       |     */
  382|       |#ifndef ARRAY_CLEAN_ACCESS
  383|       |
  384|       |    switch(length)
  385|       |    {
  386|       |    case 12: c+=k[2]; b+=k[1]; a+=k[0]; break;
  387|       |    case 11: c+=k[2]&0xffffff; b+=k[1]; a+=k[0]; break;
  388|       |    case 10: c+=k[2]&0xffff; b+=k[1]; a+=k[0]; break;
  389|       |    case 9 : c+=k[2]&0xff; b+=k[1]; a+=k[0]; break;
  390|       |    case 8 : b+=k[1]; a+=k[0]; break;
  391|       |    case 7 : b+=k[1]&0xffffff; a+=k[0]; break;
  392|       |    case 6 : b+=k[1]&0xffff; a+=k[0]; break;
  393|       |    case 5 : b+=k[1]&0xff; a+=k[0]; break;
  394|       |    case 4 : a+=k[0]; break;
  395|       |    case 3 : a+=k[0]&0xffffff; break;
  396|       |    case 2 : a+=k[0]&0xffff; break;
  397|       |    case 1 : a+=k[0]&0xff; break;
  398|       |    case 0 : return c;              /* zero length strings require no mixing */
  399|       |    }
  400|       |
  401|       |#else /* make valgrind happy */
  402|       |
  403|  2.25M|    k8 = (const uint8_t *)k;
  404|  2.25M|    switch(length)
  ------------------
  |  Branch (404:12): [True: 0, False: 2.25M]
  ------------------
  405|  2.25M|    {
  406|  4.87k|    case 12: c+=k[2]; b+=k[1]; a+=k[0]; break;
  ------------------
  |  Branch (406:5): [True: 4.87k, False: 2.24M]
  ------------------
  407|  7.29k|    case 11: c+=((uint32_t)k8[10])<<16;  /* fall through */
  ------------------
  |  Branch (407:5): [True: 7.29k, False: 2.24M]
  ------------------
  408|  9.33k|    case 10: c+=((uint32_t)k8[9])<<8;    /* fall through */
  ------------------
  |  Branch (408:5): [True: 2.04k, False: 2.25M]
  ------------------
  409|  12.8k|    case 9 : c+=k8[8];                   /* fall through */
  ------------------
  |  Branch (409:5): [True: 3.53k, False: 2.24M]
  ------------------
  410|  14.9k|    case 8 : b+=k[1]; a+=k[0]; break;
  ------------------
  |  Branch (410:5): [True: 2.10k, False: 2.25M]
  ------------------
  411|  3.63k|    case 7 : b+=((uint32_t)k8[6])<<16;   /* fall through */
  ------------------
  |  Branch (411:5): [True: 3.63k, False: 2.24M]
  ------------------
  412|  6.13k|    case 6 : b+=((uint32_t)k8[5])<<8;    /* fall through */
  ------------------
  |  Branch (412:5): [True: 2.49k, False: 2.25M]
  ------------------
  413|  13.9k|    case 5 : b+=k8[4];                   /* fall through */
  ------------------
  |  Branch (413:5): [True: 7.78k, False: 2.24M]
  ------------------
  414|  1.10M|    case 4 : a+=k[0]; break;
  ------------------
  |  Branch (414:5): [True: 1.09M, False: 1.16M]
  ------------------
  415|  22.9k|    case 3 : a+=((uint32_t)k8[2])<<16;   /* fall through */
  ------------------
  |  Branch (415:5): [True: 22.9k, False: 2.23M]
  ------------------
  416|  1.12M|    case 2 : a+=((uint32_t)k8[1])<<8;    /* fall through */
  ------------------
  |  Branch (416:5): [True: 1.10M, False: 1.15M]
  ------------------
  417|  1.12M|    case 1 : a+=k8[0]; break;
  ------------------
  |  Branch (417:5): [True: 3.42k, False: 2.24M]
  ------------------
  418|      0|    case 0 : return c;
  ------------------
  |  Branch (418:5): [True: 0, False: 2.25M]
  ------------------
  419|  2.25M|    }
  420|       |
  421|  2.25M|#endif /* !valgrind */
  422|       |
  423|  2.25M|  } else if (HASH_LITTLE_ENDIAN && ((u.i & 0x1) == 0)) {
  ------------------
  |  |   93|  2.16M|#  define HASH_LITTLE_ENDIAN 1
  |  |  ------------------
  |  |  |  Branch (93:30): [Folded - Ignored]
  |  |  ------------------
  ------------------
  |  Branch (423:36): [True: 1.08M, False: 0]
  ------------------
  424|  1.08M|    const uint16_t *k = (const uint16_t *)key;         /* read 16-bit chunks */
  425|  1.08M|    const uint8_t  *k8;
  426|       |
  427|       |    /*--------------- all but last block: aligned reads and different mixing */
  428|  1.08M|    while (length > 12)
  ------------------
  |  Branch (428:12): [True: 0, False: 1.08M]
  ------------------
  429|      0|    {
  430|      0|      a += k[0] + (((uint32_t)k[1])<<16);
  431|      0|      b += k[2] + (((uint32_t)k[3])<<16);
  432|      0|      c += k[4] + (((uint32_t)k[5])<<16);
  433|      0|      mix(a,b,c);
  ------------------
  |  |  173|      0|#define mix(a,b,c) \
  |  |  174|      0|{ \
  |  |  175|      0|  a -= c;  a ^= rot(c, 4);  c += b; \
  |  |  ------------------
  |  |  |  |  118|      0|#define rot(x,k) (((x)<<(k)) | ((x)>>(32-(k))))
  |  |  ------------------
  |  |  176|      0|  b -= a;  b ^= rot(a, 6);  a += c; \
  |  |  ------------------
  |  |  |  |  118|      0|#define rot(x,k) (((x)<<(k)) | ((x)>>(32-(k))))
  |  |  ------------------
  |  |  177|      0|  c -= b;  c ^= rot(b, 8);  b += a; \
  |  |  ------------------
  |  |  |  |  118|      0|#define rot(x,k) (((x)<<(k)) | ((x)>>(32-(k))))
  |  |  ------------------
  |  |  178|      0|  a -= c;  a ^= rot(c,16);  c += b; \
  |  |  ------------------
  |  |  |  |  118|      0|#define rot(x,k) (((x)<<(k)) | ((x)>>(32-(k))))
  |  |  ------------------
  |  |  179|      0|  b -= a;  b ^= rot(a,19);  a += c; \
  |  |  ------------------
  |  |  |  |  118|      0|#define rot(x,k) (((x)<<(k)) | ((x)>>(32-(k))))
  |  |  ------------------
  |  |  180|      0|  c -= b;  c ^= rot(b, 4);  b += a; \
  |  |  ------------------
  |  |  |  |  118|      0|#define rot(x,k) (((x)<<(k)) | ((x)>>(32-(k))))
  |  |  ------------------
  |  |  181|      0|}
  ------------------
  434|      0|      length -= 12;
  435|      0|      k += 6;
  436|      0|    }
  437|       |
  438|       |    /*----------------------------- handle the last (probably partial) block */
  439|  1.08M|    k8 = (const uint8_t *)k;
  440|  1.08M|    switch(length)
  ------------------
  |  Branch (440:12): [True: 0, False: 1.08M]
  ------------------
  441|  1.08M|    {
  442|      0|    case 12: c+=k[4]+(((uint32_t)k[5])<<16);
  ------------------
  |  Branch (442:5): [True: 0, False: 1.08M]
  ------------------
  443|      0|             b+=k[2]+(((uint32_t)k[3])<<16);
  444|      0|             a+=k[0]+(((uint32_t)k[1])<<16);
  445|      0|             break;
  446|      0|    case 11: c+=((uint32_t)k8[10])<<16;     /* fall through */
  ------------------
  |  Branch (446:5): [True: 0, False: 1.08M]
  ------------------
  447|      0|    case 10: c+=k[4];
  ------------------
  |  Branch (447:5): [True: 0, False: 1.08M]
  ------------------
  448|      0|             b+=k[2]+(((uint32_t)k[3])<<16);
  449|      0|             a+=k[0]+(((uint32_t)k[1])<<16);
  450|      0|             break;
  451|      0|    case 9 : c+=k8[8];                      /* fall through */
  ------------------
  |  Branch (451:5): [True: 0, False: 1.08M]
  ------------------
  452|      0|    case 8 : b+=k[2]+(((uint32_t)k[3])<<16);
  ------------------
  |  Branch (452:5): [True: 0, False: 1.08M]
  ------------------
  453|      0|             a+=k[0]+(((uint32_t)k[1])<<16);
  454|      0|             break;
  455|      0|    case 7 : b+=((uint32_t)k8[6])<<16;      /* fall through */
  ------------------
  |  Branch (455:5): [True: 0, False: 1.08M]
  ------------------
  456|      0|    case 6 : b+=k[2];
  ------------------
  |  Branch (456:5): [True: 0, False: 1.08M]
  ------------------
  457|      0|             a+=k[0]+(((uint32_t)k[1])<<16);
  458|      0|             break;
  459|      0|    case 5 : b+=k8[4];                      /* fall through */
  ------------------
  |  Branch (459:5): [True: 0, False: 1.08M]
  ------------------
  460|      0|    case 4 : a+=k[0]+(((uint32_t)k[1])<<16);
  ------------------
  |  Branch (460:5): [True: 0, False: 1.08M]
  ------------------
  461|      0|             break;
  462|      0|    case 3 : a+=((uint32_t)k8[2])<<16;      /* fall through */
  ------------------
  |  Branch (462:5): [True: 0, False: 1.08M]
  ------------------
  463|  1.08M|    case 2 : a+=k[0];
  ------------------
  |  Branch (463:5): [True: 1.08M, False: 0]
  ------------------
  464|  1.08M|             break;
  465|      0|    case 1 : a+=k8[0];
  ------------------
  |  Branch (465:5): [True: 0, False: 1.08M]
  ------------------
  466|      0|             break;
  467|      0|    case 0 : return c;                     /* zero length requires no mixing */
  ------------------
  |  Branch (467:5): [True: 0, False: 1.08M]
  ------------------
  468|  1.08M|    }
  469|       |
  470|  1.08M|  } else {                        /* need to read the key one byte at a time */
  471|      0|    const uint8_t *k = (const uint8_t *)key;
  472|       |
  473|       |    /*--------------- all but the last block: affect some 32 bits of (a,b,c) */
  474|      0|    while (length > 12)
  ------------------
  |  Branch (474:12): [True: 0, False: 0]
  ------------------
  475|      0|    {
  476|      0|      a += k[0];
  477|      0|      a += ((uint32_t)k[1])<<8;
  478|      0|      a += ((uint32_t)k[2])<<16;
  479|      0|      a += ((uint32_t)k[3])<<24;
  480|      0|      b += k[4];
  481|      0|      b += ((uint32_t)k[5])<<8;
  482|      0|      b += ((uint32_t)k[6])<<16;
  483|      0|      b += ((uint32_t)k[7])<<24;
  484|      0|      c += k[8];
  485|      0|      c += ((uint32_t)k[9])<<8;
  486|      0|      c += ((uint32_t)k[10])<<16;
  487|      0|      c += ((uint32_t)k[11])<<24;
  488|      0|      mix(a,b,c);
  ------------------
  |  |  173|      0|#define mix(a,b,c) \
  |  |  174|      0|{ \
  |  |  175|      0|  a -= c;  a ^= rot(c, 4);  c += b; \
  |  |  ------------------
  |  |  |  |  118|      0|#define rot(x,k) (((x)<<(k)) | ((x)>>(32-(k))))
  |  |  ------------------
  |  |  176|      0|  b -= a;  b ^= rot(a, 6);  a += c; \
  |  |  ------------------
  |  |  |  |  118|      0|#define rot(x,k) (((x)<<(k)) | ((x)>>(32-(k))))
  |  |  ------------------
  |  |  177|      0|  c -= b;  c ^= rot(b, 8);  b += a; \
  |  |  ------------------
  |  |  |  |  118|      0|#define rot(x,k) (((x)<<(k)) | ((x)>>(32-(k))))
  |  |  ------------------
  |  |  178|      0|  a -= c;  a ^= rot(c,16);  c += b; \
  |  |  ------------------
  |  |  |  |  118|      0|#define rot(x,k) (((x)<<(k)) | ((x)>>(32-(k))))
  |  |  ------------------
  |  |  179|      0|  b -= a;  b ^= rot(a,19);  a += c; \
  |  |  ------------------
  |  |  |  |  118|      0|#define rot(x,k) (((x)<<(k)) | ((x)>>(32-(k))))
  |  |  ------------------
  |  |  180|      0|  c -= b;  c ^= rot(b, 4);  b += a; \
  |  |  ------------------
  |  |  |  |  118|      0|#define rot(x,k) (((x)<<(k)) | ((x)>>(32-(k))))
  |  |  ------------------
  |  |  181|      0|}
  ------------------
  489|      0|      length -= 12;
  490|      0|      k += 12;
  491|      0|    }
  492|       |
  493|       |    /*-------------------------------- last block: affect all 32 bits of (c) */
  494|      0|    switch(length)                   /* all the case statements fall through */
  ------------------
  |  Branch (494:12): [True: 0, False: 0]
  ------------------
  495|      0|    {
  496|      0|    case 12: c+=((uint32_t)k[11])<<24;
  ------------------
  |  Branch (496:5): [True: 0, False: 0]
  ------------------
  497|       |  	/* fallthrough */
  498|      0|    case 11: c+=((uint32_t)k[10])<<16;
  ------------------
  |  Branch (498:5): [True: 0, False: 0]
  ------------------
  499|       |  	/* fallthrough */
  500|      0|    case 10: c+=((uint32_t)k[9])<<8;
  ------------------
  |  Branch (500:5): [True: 0, False: 0]
  ------------------
  501|       |  	/* fallthrough */
  502|      0|    case 9 : c+=k[8];
  ------------------
  |  Branch (502:5): [True: 0, False: 0]
  ------------------
  503|       |  	/* fallthrough */
  504|      0|    case 8 : b+=((uint32_t)k[7])<<24;
  ------------------
  |  Branch (504:5): [True: 0, False: 0]
  ------------------
  505|       |  	/* fallthrough */
  506|      0|    case 7 : b+=((uint32_t)k[6])<<16;
  ------------------
  |  Branch (506:5): [True: 0, False: 0]
  ------------------
  507|       |  	/* fallthrough */
  508|      0|    case 6 : b+=((uint32_t)k[5])<<8;
  ------------------
  |  Branch (508:5): [True: 0, False: 0]
  ------------------
  509|       |  	/* fallthrough */
  510|      0|    case 5 : b+=k[4];
  ------------------
  |  Branch (510:5): [True: 0, False: 0]
  ------------------
  511|       |  	/* fallthrough */
  512|      0|    case 4 : a+=((uint32_t)k[3])<<24;
  ------------------
  |  Branch (512:5): [True: 0, False: 0]
  ------------------
  513|       |  	/* fallthrough */
  514|      0|    case 3 : a+=((uint32_t)k[2])<<16;
  ------------------
  |  Branch (514:5): [True: 0, False: 0]
  ------------------
  515|       |  	/* fallthrough */
  516|      0|    case 2 : a+=((uint32_t)k[1])<<8;
  ------------------
  |  Branch (516:5): [True: 0, False: 0]
  ------------------
  517|       |  	/* fallthrough */
  518|      0|    case 1 : a+=k[0];
  ------------------
  |  Branch (518:5): [True: 0, False: 0]
  ------------------
  519|      0|             break;
  520|      0|    case 0 : return c;
  ------------------
  |  Branch (520:5): [True: 0, False: 0]
  ------------------
  521|      0|    }
  522|      0|  }
  523|       |
  524|  3.33M|  final(a,b,c);
  ------------------
  |  |  208|  3.33M|#define final(a,b,c) \
  |  |  209|  3.33M|{ \
  |  |  210|  3.33M|  c ^= b; c -= rot(b,14); \
  |  |  ------------------
  |  |  |  |  118|  3.33M|#define rot(x,k) (((x)<<(k)) | ((x)>>(32-(k))))
  |  |  ------------------
  |  |  211|  3.33M|  a ^= c; a -= rot(c,11); \
  |  |  ------------------
  |  |  |  |  118|  3.33M|#define rot(x,k) (((x)<<(k)) | ((x)>>(32-(k))))
  |  |  ------------------
  |  |  212|  3.33M|  b ^= a; b -= rot(a,25); \
  |  |  ------------------
  |  |  |  |  118|  3.33M|#define rot(x,k) (((x)<<(k)) | ((x)>>(32-(k))))
  |  |  ------------------
  |  |  213|  3.33M|  c ^= b; c -= rot(b,16); \
  |  |  ------------------
  |  |  |  |  118|  3.33M|#define rot(x,k) (((x)<<(k)) | ((x)>>(32-(k))))
  |  |  ------------------
  |  |  214|  3.33M|  a ^= c; a -= rot(c,4);  \
  |  |  ------------------
  |  |  |  |  118|  3.33M|#define rot(x,k) (((x)<<(k)) | ((x)>>(32-(k))))
  |  |  ------------------
  |  |  215|  3.33M|  b ^= a; b -= rot(a,14); \
  |  |  ------------------
  |  |  |  |  118|  3.33M|#define rot(x,k) (((x)<<(k)) | ((x)>>(32-(k))))
  |  |  ------------------
  |  |  216|  3.33M|  c ^= b; c -= rot(b,24); \
  |  |  ------------------
  |  |  |  |  118|  3.33M|#define rot(x,k) (((x)<<(k)) | ((x)>>(32-(k))))
  |  |  ------------------
  |  |  217|  3.33M|}
  ------------------
  525|  3.33M|  return c;
  526|  3.33M|}

bin_init:
   49|  18.3k|{
   50|  18.3k|	size_t i;
   51|       |#ifdef THREADS_DISABLED
   52|       |	(void)array;
   53|       |#endif
   54|  18.8M|	for(i=0; i<size; i++) {
  ------------------
  |  Branch (54:11): [True: 18.8M, False: 18.3k]
  ------------------
   55|  18.8M|		lock_quick_init(&array[i].lock);
  ------------------
  |  |  143|  18.8M|#define lock_quick_init(lock) LOCKRET(pthread_spin_init(lock, PTHREAD_PROCESS_PRIVATE))
  |  |  ------------------
  |  |  |  |   67|  18.8M|#define LOCKRET(func) do {\
  |  |  |  |   68|  18.8M|	int lockret_err;		\
  |  |  |  |   69|  18.8M|	if( (lockret_err=(func)) != 0)		\
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (69:6): [True: 0, False: 18.8M]
  |  |  |  |  ------------------
  |  |  |  |   70|  18.8M|		log_err("%s at %d could not " #func ": %s", \
  |  |  |  |   71|      0|		__FILE__, __LINE__, strerror(lockret_err));	\
  |  |  |  |   72|  18.8M| 	} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (72:11): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
   56|  18.8M|		lock_protect(&array[i].lock, &array[i], 
   57|  18.8M|			sizeof(struct lruhash_bin));
   58|  18.8M|	}
   59|  18.3k|}
lruhash_create:
   66|  18.3k|{
   67|  18.3k|	struct lruhash* table = (struct lruhash*)calloc(1, 
   68|  18.3k|		sizeof(struct lruhash));
   69|  18.3k|	if(!table)
  ------------------
  |  Branch (69:5): [True: 0, False: 18.3k]
  ------------------
   70|      0|		return NULL;
   71|  18.3k|	lock_quick_init(&table->lock);
  ------------------
  |  |  143|  18.3k|#define lock_quick_init(lock) LOCKRET(pthread_spin_init(lock, PTHREAD_PROCESS_PRIVATE))
  |  |  ------------------
  |  |  |  |   67|  18.3k|#define LOCKRET(func) do {\
  |  |  |  |   68|  18.3k|	int lockret_err;		\
  |  |  |  |   69|  18.3k|	if( (lockret_err=(func)) != 0)		\
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (69:6): [True: 0, False: 18.3k]
  |  |  |  |  ------------------
  |  |  |  |   70|  18.3k|		log_err("%s at %d could not " #func ": %s", \
  |  |  |  |   71|      0|		__FILE__, __LINE__, strerror(lockret_err));	\
  |  |  |  |   72|  18.3k| 	} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (72:11): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
   72|  18.3k|	table->sizefunc = sizefunc;
   73|  18.3k|	table->compfunc = compfunc;
   74|  18.3k|	table->delkeyfunc = delkeyfunc;
   75|  18.3k|	table->deldatafunc = deldatafunc;
   76|  18.3k|	table->cb_arg = arg;
   77|  18.3k|	table->size = start_size;
   78|  18.3k|	table->size_mask = (int)(start_size-1);
   79|  18.3k|	table->lru_start = NULL;
   80|  18.3k|	table->lru_end = NULL;
   81|  18.3k|	table->num = 0;
   82|  18.3k|	table->space_used = 0;
   83|  18.3k|	table->space_max = maxmem;
   84|  18.3k|	table->max_collisions = 0;
   85|  18.3k|	table->array = calloc(table->size, sizeof(struct lruhash_bin));
   86|  18.3k|	if(!table->array) {
  ------------------
  |  Branch (86:5): [True: 0, False: 18.3k]
  ------------------
   87|      0|		lock_quick_destroy(&table->lock);
  ------------------
  |  |  144|      0|#define lock_quick_destroy(lock) LOCKRET(pthread_spin_destroy(lock))
  |  |  ------------------
  |  |  |  |   67|      0|#define LOCKRET(func) do {\
  |  |  |  |   68|      0|	int lockret_err;		\
  |  |  |  |   69|      0|	if( (lockret_err=(func)) != 0)		\
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (69:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |   70|      0|		log_err("%s at %d could not " #func ": %s", \
  |  |  |  |   71|      0|		__FILE__, __LINE__, strerror(lockret_err));	\
  |  |  |  |   72|      0| 	} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (72:11): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
   88|      0|		free(table);
   89|      0|		return NULL;
   90|      0|	}
   91|  18.3k|	bin_init(table->array, table->size);
   92|  18.3k|	lock_protect(&table->lock, table, sizeof(*table));
   93|  18.3k|	lock_protect(&table->lock, table->array, 
   94|  18.3k|		table->size*sizeof(struct lruhash_bin));
   95|  18.3k|	return table;
   96|  18.3k|}
bin_delete:
  100|  18.8M|{
  101|  18.8M|	struct lruhash_entry* p, *np;
  102|  18.8M|	void *d;
  103|  18.8M|	if(!bin)
  ------------------
  |  Branch (103:5): [True: 0, False: 18.8M]
  ------------------
  104|      0|		return;
  105|  18.8M|	lock_quick_destroy(&bin->lock);
  ------------------
  |  |  144|  18.8M|#define lock_quick_destroy(lock) LOCKRET(pthread_spin_destroy(lock))
  |  |  ------------------
  |  |  |  |   67|  18.8M|#define LOCKRET(func) do {\
  |  |  |  |   68|  18.8M|	int lockret_err;		\
  |  |  |  |   69|  18.8M|	if( (lockret_err=(func)) != 0)		\
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (69:6): [True: 0, False: 18.8M]
  |  |  |  |  ------------------
  |  |  |  |   70|  18.8M|		log_err("%s at %d could not " #func ": %s", \
  |  |  |  |   71|      0|		__FILE__, __LINE__, strerror(lockret_err));	\
  |  |  |  |   72|  18.8M| 	} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (72:11): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  106|  18.8M|	p = bin->overflow_list;
  107|  18.8M|	bin->overflow_list = NULL;
  108|  18.8M|	while(p) {
  ------------------
  |  Branch (108:8): [True: 12.6k, False: 18.8M]
  ------------------
  109|  12.6k|		np = p->overflow_next;
  110|  12.6k|		d = p->data;
  111|  12.6k|		(*table->delkeyfunc)(p->key, table->cb_arg);
  112|  12.6k|		(*table->deldatafunc)(d, table->cb_arg);
  113|  12.6k|		p = np;
  114|  12.6k|	}
  115|  18.8M|}
lruhash_delete:
  155|  18.3k|{
  156|  18.3k|	size_t i;
  157|  18.3k|	if(!table)
  ------------------
  |  Branch (157:5): [True: 0, False: 18.3k]
  ------------------
  158|      0|		return;
  159|       |	/* delete lock on hashtable to force check its OK */
  160|  18.3k|	lock_quick_destroy(&table->lock);
  ------------------
  |  |  144|  18.3k|#define lock_quick_destroy(lock) LOCKRET(pthread_spin_destroy(lock))
  |  |  ------------------
  |  |  |  |   67|  18.3k|#define LOCKRET(func) do {\
  |  |  |  |   68|  18.3k|	int lockret_err;		\
  |  |  |  |   69|  18.3k|	if( (lockret_err=(func)) != 0)		\
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (69:6): [True: 0, False: 18.3k]
  |  |  |  |  ------------------
  |  |  |  |   70|  18.3k|		log_err("%s at %d could not " #func ": %s", \
  |  |  |  |   71|      0|		__FILE__, __LINE__, strerror(lockret_err));	\
  |  |  |  |   72|  18.3k| 	} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (72:11): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  161|  18.8M|	for(i=0; i<table->size; i++)
  ------------------
  |  Branch (161:11): [True: 18.8M, False: 18.3k]
  ------------------
  162|  18.8M|		bin_delete(table, &table->array[i]);
  163|  18.3k|	free(table->array);
  164|  18.3k|	free(table);
  165|  18.3k|}
bin_overflow_remove:
  169|    304|{
  170|    304|	struct lruhash_entry* p = bin->overflow_list;
  171|    304|	struct lruhash_entry** prevp = &bin->overflow_list;
  172|    378|	while(p) {
  ------------------
  |  Branch (172:8): [True: 378, False: 0]
  ------------------
  173|    378|		if(p == entry) {
  ------------------
  |  Branch (173:6): [True: 304, False: 74]
  ------------------
  174|    304|			*prevp = p->overflow_next;
  175|    304|			return;
  176|    304|		}
  177|     74|		prevp = &p->overflow_next;
  178|     74|		p = p->overflow_next;
  179|     74|	}
  180|    304|}
reclaim_space:
  184|    126|{
  185|    126|	struct lruhash_entry* d;
  186|    126|	struct lruhash_bin* bin;
  187|    126|	log_assert(table);
  188|       |	/* does not delete MRU entry, so table will not be empty. */
  189|    430|	while(table->num > 1 && table->space_used > table->space_max) {
  ------------------
  |  Branch (189:8): [True: 402, False: 28]
  |  Branch (189:26): [True: 304, False: 98]
  ------------------
  190|       |		/* notice that since we hold the hashtable lock, nobody
  191|       |		   can change the lru chain. So it cannot be deleted underneath
  192|       |		   us. We still need the hashbin and entry write lock to make 
  193|       |		   sure we flush all users away from the entry. 
  194|       |		   which is unlikely, since it is LRU, if someone got a rdlock
  195|       |		   it would be moved to front, but to be sure. */
  196|    304|		d = table->lru_end;
  197|       |		/* specialised, delete from end of double linked list,
  198|       |		   and we know num>1, so there is a previous lru entry. */
  199|    304|		log_assert(d && d->lru_prev);
  200|    304|		table->lru_end = d->lru_prev;
  201|    304|		d->lru_prev->lru_next = NULL;
  202|       |		/* schedule entry for deletion */
  203|    304|		bin = &table->array[d->hash & table->size_mask];
  204|    304|		table->num --;
  205|    304|		lock_quick_lock(&bin->lock);
  ------------------
  |  |  145|    304|#define lock_quick_lock(lock) LOCKRET(pthread_spin_lock(lock))
  |  |  ------------------
  |  |  |  |   67|    304|#define LOCKRET(func) do {\
  |  |  |  |   68|    304|	int lockret_err;		\
  |  |  |  |   69|    304|	if( (lockret_err=(func)) != 0)		\
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (69:6): [True: 0, False: 304]
  |  |  |  |  ------------------
  |  |  |  |   70|    304|		log_err("%s at %d could not " #func ": %s", \
  |  |  |  |   71|      0|		__FILE__, __LINE__, strerror(lockret_err));	\
  |  |  |  |   72|    304| 	} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (72:11): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  206|    304|		bin_overflow_remove(bin, d);
  207|    304|		d->overflow_next = *list;
  208|    304|		*list = d;
  209|    304|		lock_rw_wrlock(&d->lock);
  ------------------
  |  |  120|    304|#define lock_rw_wrlock(lock) LOCKRET(pthread_rwlock_wrlock(lock))
  |  |  ------------------
  |  |  |  |   67|    304|#define LOCKRET(func) do {\
  |  |  |  |   68|    304|	int lockret_err;		\
  |  |  |  |   69|    304|	if( (lockret_err=(func)) != 0)		\
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (69:6): [True: 0, False: 304]
  |  |  |  |  ------------------
  |  |  |  |   70|    304|		log_err("%s at %d could not " #func ": %s", \
  |  |  |  |   71|      0|		__FILE__, __LINE__, strerror(lockret_err));	\
  |  |  |  |   72|    304| 	} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (72:11): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  210|    304|		table->space_used -= table->sizefunc(d->key, d->data);
  211|    304|		if(table->markdelfunc)
  ------------------
  |  Branch (211:6): [True: 304, False: 0]
  ------------------
  212|    304|			(*table->markdelfunc)(d->key);
  213|    304|		lock_rw_unlock(&d->lock);
  ------------------
  |  |  121|    304|#define lock_rw_unlock(lock) LOCKRET(pthread_rwlock_unlock(lock))
  |  |  ------------------
  |  |  |  |   67|    304|#define LOCKRET(func) do {\
  |  |  |  |   68|    304|	int lockret_err;		\
  |  |  |  |   69|    304|	if( (lockret_err=(func)) != 0)		\
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (69:6): [True: 0, False: 304]
  |  |  |  |  ------------------
  |  |  |  |   70|    304|		log_err("%s at %d could not " #func ": %s", \
  |  |  |  |   71|      0|		__FILE__, __LINE__, strerror(lockret_err));	\
  |  |  |  |   72|    304| 	} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (72:11): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  214|    304|		lock_quick_unlock(&bin->lock);
  ------------------
  |  |  146|    304|#define lock_quick_unlock(lock) LOCKRET(pthread_spin_unlock(lock))
  |  |  ------------------
  |  |  |  |   67|    304|#define LOCKRET(func) do {\
  |  |  |  |   68|    304|	int lockret_err;		\
  |  |  |  |   69|    304|	if( (lockret_err=(func)) != 0)		\
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (69:6): [True: 0, False: 304]
  |  |  |  |  ------------------
  |  |  |  |   70|    304|		log_err("%s at %d could not " #func ": %s", \
  |  |  |  |   71|      0|		__FILE__, __LINE__, strerror(lockret_err));	\
  |  |  |  |   72|    304| 	} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (72:11): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  215|    304|	}
  216|    126|}
bin_find_entry:
  221|  25.9k|{
  222|  25.9k|	size_t c = 0;
  223|  25.9k|	struct lruhash_entry* p = bin->overflow_list;
  224|  29.3k|	while(p) {
  ------------------
  |  Branch (224:8): [True: 3.43k, False: 25.9k]
  ------------------
  225|  3.43k|		if(p->hash == hash && table->compfunc(p->key, key) == 0)
  ------------------
  |  Branch (225:6): [True: 542, False: 2.89k]
  |  Branch (225:25): [True: 0, False: 542]
  ------------------
  226|      0|			break;
  227|  3.43k|		c++;
  228|  3.43k|		p = p->overflow_next;
  229|  3.43k|	}
  230|  25.9k|	if (collisions != NULL)
  ------------------
  |  Branch (230:6): [True: 12.9k, False: 12.9k]
  ------------------
  231|  12.9k|		*collisions = c;
  232|  25.9k|	return p;
  233|  25.9k|}
lru_front:
  272|  12.9k|{
  273|  12.9k|	entry->lru_prev = NULL;
  274|  12.9k|	entry->lru_next = table->lru_start;
  275|  12.9k|	if(!table->lru_start)
  ------------------
  |  Branch (275:5): [True: 1.21k, False: 11.7k]
  ------------------
  276|  1.21k|		table->lru_end = entry;
  277|  11.7k|	else	table->lru_start->lru_prev = entry;
  278|  12.9k|	table->lru_start = entry;
  279|  12.9k|}
lruhash_insert:
  307|  12.9k|{
  308|  12.9k|	struct lruhash_bin* bin;
  309|  12.9k|	struct lruhash_entry* found, *reclaimlist=NULL;
  310|  12.9k|	size_t need_size;
  311|  12.9k|	size_t collisions;
  312|  12.9k|	fptr_ok(fptr_whitelist_hash_sizefunc(table->sizefunc));
  ------------------
  |  |   71|  12.9k|	do { if(!(x)) \
  |  |  ------------------
  |  |  |  Branch (71:10): [True: 0, False: 12.9k]
  |  |  ------------------
  |  |   72|  12.9k|		fatal_exit("%s:%d: %s: pointer whitelist %s failed", \
  |  |   73|      0|		__FILE__, __LINE__, __func__, #x); \
  |  |   74|  12.9k|	} while(0);
  |  |  ------------------
  |  |  |  Branch (74:10): [Folded - Ignored]
  |  |  ------------------
  ------------------
  313|  12.9k|	fptr_ok(fptr_whitelist_hash_delkeyfunc(table->delkeyfunc));
  ------------------
  |  |   71|  12.9k|	do { if(!(x)) \
  |  |  ------------------
  |  |  |  Branch (71:10): [True: 0, False: 12.9k]
  |  |  ------------------
  |  |   72|  12.9k|		fatal_exit("%s:%d: %s: pointer whitelist %s failed", \
  |  |   73|      0|		__FILE__, __LINE__, __func__, #x); \
  |  |   74|  12.9k|	} while(0);
  |  |  ------------------
  |  |  |  Branch (74:10): [Folded - Ignored]
  |  |  ------------------
  ------------------
  314|  12.9k|	fptr_ok(fptr_whitelist_hash_deldatafunc(table->deldatafunc));
  ------------------
  |  |   71|  12.9k|	do { if(!(x)) \
  |  |  ------------------
  |  |  |  Branch (71:10): [True: 0, False: 12.9k]
  |  |  ------------------
  |  |   72|  12.9k|		fatal_exit("%s:%d: %s: pointer whitelist %s failed", \
  |  |   73|      0|		__FILE__, __LINE__, __func__, #x); \
  |  |   74|  12.9k|	} while(0);
  |  |  ------------------
  |  |  |  Branch (74:10): [Folded - Ignored]
  |  |  ------------------
  ------------------
  315|  12.9k|	fptr_ok(fptr_whitelist_hash_compfunc(table->compfunc));
  ------------------
  |  |   71|  12.9k|	do { if(!(x)) \
  |  |  ------------------
  |  |  |  Branch (71:10): [True: 0, False: 12.9k]
  |  |  ------------------
  |  |   72|  12.9k|		fatal_exit("%s:%d: %s: pointer whitelist %s failed", \
  |  |   73|      0|		__FILE__, __LINE__, __func__, #x); \
  |  |   74|  12.9k|	} while(0);
  |  |  ------------------
  |  |  |  Branch (74:10): [Folded - Ignored]
  |  |  ------------------
  ------------------
  316|  12.9k|	fptr_ok(fptr_whitelist_hash_markdelfunc(table->markdelfunc));
  ------------------
  |  |   71|  12.9k|	do { if(!(x)) \
  |  |  ------------------
  |  |  |  Branch (71:10): [True: 0, False: 12.9k]
  |  |  ------------------
  |  |   72|  12.9k|		fatal_exit("%s:%d: %s: pointer whitelist %s failed", \
  |  |   73|      0|		__FILE__, __LINE__, __func__, #x); \
  |  |   74|  12.9k|	} while(0);
  |  |  ------------------
  |  |  |  Branch (74:10): [Folded - Ignored]
  |  |  ------------------
  ------------------
  317|  12.9k|	need_size = table->sizefunc(entry->key, data);
  318|  12.9k|	if(cb_arg == NULL) cb_arg = table->cb_arg;
  ------------------
  |  Branch (318:5): [True: 0, False: 12.9k]
  ------------------
  319|       |
  320|       |	/* find bin */
  321|  12.9k|	lock_quick_lock(&table->lock);
  ------------------
  |  |  145|  12.9k|#define lock_quick_lock(lock) LOCKRET(pthread_spin_lock(lock))
  |  |  ------------------
  |  |  |  |   67|  12.9k|#define LOCKRET(func) do {\
  |  |  |  |   68|  12.9k|	int lockret_err;		\
  |  |  |  |   69|  12.9k|	if( (lockret_err=(func)) != 0)		\
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (69:6): [True: 0, False: 12.9k]
  |  |  |  |  ------------------
  |  |  |  |   70|  12.9k|		log_err("%s at %d could not " #func ": %s", \
  |  |  |  |   71|      0|		__FILE__, __LINE__, strerror(lockret_err));	\
  |  |  |  |   72|  12.9k| 	} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (72:11): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  322|  12.9k|	bin = &table->array[hash & table->size_mask];
  323|  12.9k|	lock_quick_lock(&bin->lock);
  ------------------
  |  |  145|  12.9k|#define lock_quick_lock(lock) LOCKRET(pthread_spin_lock(lock))
  |  |  ------------------
  |  |  |  |   67|  12.9k|#define LOCKRET(func) do {\
  |  |  |  |   68|  12.9k|	int lockret_err;		\
  |  |  |  |   69|  12.9k|	if( (lockret_err=(func)) != 0)		\
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (69:6): [True: 0, False: 12.9k]
  |  |  |  |  ------------------
  |  |  |  |   70|  12.9k|		log_err("%s at %d could not " #func ": %s", \
  |  |  |  |   71|      0|		__FILE__, __LINE__, strerror(lockret_err));	\
  |  |  |  |   72|  12.9k| 	} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (72:11): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  324|       |
  325|       |	/* see if entry exists already */
  326|  12.9k|	if(!(found=bin_find_entry(table, bin, hash, entry->key, &collisions))) {
  ------------------
  |  Branch (326:5): [True: 12.9k, False: 0]
  ------------------
  327|       |		/* if not: add to bin */
  328|  12.9k|		entry->overflow_next = bin->overflow_list;
  329|  12.9k|		bin->overflow_list = entry;
  330|  12.9k|		lru_front(table, entry);
  331|  12.9k|		table->num++;
  332|  12.9k|		if (table->max_collisions < collisions)
  ------------------
  |  Branch (332:7): [True: 596, False: 12.3k]
  ------------------
  333|    596|			table->max_collisions = collisions;
  334|  12.9k|		table->space_used += need_size;
  335|  12.9k|	} else {
  336|       |		/* if so: update data - needs a writelock */
  337|      0|		table->space_used += need_size -
  338|      0|			(*table->sizefunc)(found->key, found->data);
  339|      0|		(*table->delkeyfunc)(entry->key, cb_arg);
  340|      0|		lru_touch(table, found);
  341|      0|		lock_rw_wrlock(&found->lock);
  ------------------
  |  |  120|      0|#define lock_rw_wrlock(lock) LOCKRET(pthread_rwlock_wrlock(lock))
  |  |  ------------------
  |  |  |  |   67|      0|#define LOCKRET(func) do {\
  |  |  |  |   68|      0|	int lockret_err;		\
  |  |  |  |   69|      0|	if( (lockret_err=(func)) != 0)		\
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (69:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |   70|      0|		log_err("%s at %d could not " #func ": %s", \
  |  |  |  |   71|      0|		__FILE__, __LINE__, strerror(lockret_err));	\
  |  |  |  |   72|      0| 	} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (72:11): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  342|      0|		(*table->deldatafunc)(found->data, cb_arg);
  343|      0|		found->data = data;
  344|      0|		lock_rw_unlock(&found->lock);
  ------------------
  |  |  121|      0|#define lock_rw_unlock(lock) LOCKRET(pthread_rwlock_unlock(lock))
  |  |  ------------------
  |  |  |  |   67|      0|#define LOCKRET(func) do {\
  |  |  |  |   68|      0|	int lockret_err;		\
  |  |  |  |   69|      0|	if( (lockret_err=(func)) != 0)		\
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (69:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |   70|      0|		log_err("%s at %d could not " #func ": %s", \
  |  |  |  |   71|      0|		__FILE__, __LINE__, strerror(lockret_err));	\
  |  |  |  |   72|      0| 	} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (72:11): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  345|      0|	}
  346|  12.9k|	lock_quick_unlock(&bin->lock);
  ------------------
  |  |  146|  12.9k|#define lock_quick_unlock(lock) LOCKRET(pthread_spin_unlock(lock))
  |  |  ------------------
  |  |  |  |   67|  12.9k|#define LOCKRET(func) do {\
  |  |  |  |   68|  12.9k|	int lockret_err;		\
  |  |  |  |   69|  12.9k|	if( (lockret_err=(func)) != 0)		\
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (69:6): [True: 0, False: 12.9k]
  |  |  |  |  ------------------
  |  |  |  |   70|  12.9k|		log_err("%s at %d could not " #func ": %s", \
  |  |  |  |   71|      0|		__FILE__, __LINE__, strerror(lockret_err));	\
  |  |  |  |   72|  12.9k| 	} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (72:11): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  347|  12.9k|	if(table->space_used > table->space_max)
  ------------------
  |  Branch (347:5): [True: 126, False: 12.8k]
  ------------------
  348|    126|		reclaim_space(table, &reclaimlist);
  349|  12.9k|	if(table->num >= table->size)
  ------------------
  |  Branch (349:5): [True: 0, False: 12.9k]
  ------------------
  350|      0|		table_grow(table);
  351|  12.9k|	lock_quick_unlock(&table->lock);
  ------------------
  |  |  146|  12.9k|#define lock_quick_unlock(lock) LOCKRET(pthread_spin_unlock(lock))
  |  |  ------------------
  |  |  |  |   67|  12.9k|#define LOCKRET(func) do {\
  |  |  |  |   68|  12.9k|	int lockret_err;		\
  |  |  |  |   69|  12.9k|	if( (lockret_err=(func)) != 0)		\
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (69:6): [True: 0, False: 12.9k]
  |  |  |  |  ------------------
  |  |  |  |   70|  12.9k|		log_err("%s at %d could not " #func ": %s", \
  |  |  |  |   71|      0|		__FILE__, __LINE__, strerror(lockret_err));	\
  |  |  |  |   72|  12.9k| 	} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (72:11): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  352|       |
  353|       |	/* finish reclaim if any (outside of critical region) */
  354|  13.2k|	while(reclaimlist) {
  ------------------
  |  Branch (354:8): [True: 304, False: 12.9k]
  ------------------
  355|    304|		struct lruhash_entry* n = reclaimlist->overflow_next;
  356|    304|		void* d = reclaimlist->data;
  357|    304|		(*table->delkeyfunc)(reclaimlist->key, cb_arg);
  358|    304|		(*table->deldatafunc)(d, cb_arg);
  359|    304|		reclaimlist = n;
  360|    304|	}
  361|  12.9k|}
lruhash_lookup:
  365|  12.9k|{
  366|  12.9k|	struct lruhash_entry* entry;
  367|  12.9k|	struct lruhash_bin* bin;
  368|  12.9k|	fptr_ok(fptr_whitelist_hash_compfunc(table->compfunc));
  ------------------
  |  |   71|  12.9k|	do { if(!(x)) \
  |  |  ------------------
  |  |  |  Branch (71:10): [True: 0, False: 12.9k]
  |  |  ------------------
  |  |   72|  12.9k|		fatal_exit("%s:%d: %s: pointer whitelist %s failed", \
  |  |   73|      0|		__FILE__, __LINE__, __func__, #x); \
  |  |   74|  12.9k|	} while(0);
  |  |  ------------------
  |  |  |  Branch (74:10): [Folded - Ignored]
  |  |  ------------------
  ------------------
  369|       |
  370|  12.9k|	lock_quick_lock(&table->lock);
  ------------------
  |  |  145|  12.9k|#define lock_quick_lock(lock) LOCKRET(pthread_spin_lock(lock))
  |  |  ------------------
  |  |  |  |   67|  12.9k|#define LOCKRET(func) do {\
  |  |  |  |   68|  12.9k|	int lockret_err;		\
  |  |  |  |   69|  12.9k|	if( (lockret_err=(func)) != 0)		\
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (69:6): [True: 0, False: 12.9k]
  |  |  |  |  ------------------
  |  |  |  |   70|  12.9k|		log_err("%s at %d could not " #func ": %s", \
  |  |  |  |   71|      0|		__FILE__, __LINE__, strerror(lockret_err));	\
  |  |  |  |   72|  12.9k| 	} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (72:11): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  371|  12.9k|	bin = &table->array[hash & table->size_mask];
  372|  12.9k|	lock_quick_lock(&bin->lock);
  ------------------
  |  |  145|  12.9k|#define lock_quick_lock(lock) LOCKRET(pthread_spin_lock(lock))
  |  |  ------------------
  |  |  |  |   67|  12.9k|#define LOCKRET(func) do {\
  |  |  |  |   68|  12.9k|	int lockret_err;		\
  |  |  |  |   69|  12.9k|	if( (lockret_err=(func)) != 0)		\
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (69:6): [True: 0, False: 12.9k]
  |  |  |  |  ------------------
  |  |  |  |   70|  12.9k|		log_err("%s at %d could not " #func ": %s", \
  |  |  |  |   71|      0|		__FILE__, __LINE__, strerror(lockret_err));	\
  |  |  |  |   72|  12.9k| 	} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (72:11): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  373|  12.9k|	if((entry=bin_find_entry(table, bin, hash, key, NULL)))
  ------------------
  |  Branch (373:5): [True: 0, False: 12.9k]
  ------------------
  374|      0|		lru_touch(table, entry);
  375|  12.9k|	lock_quick_unlock(&table->lock);
  ------------------
  |  |  146|  12.9k|#define lock_quick_unlock(lock) LOCKRET(pthread_spin_unlock(lock))
  |  |  ------------------
  |  |  |  |   67|  12.9k|#define LOCKRET(func) do {\
  |  |  |  |   68|  12.9k|	int lockret_err;		\
  |  |  |  |   69|  12.9k|	if( (lockret_err=(func)) != 0)		\
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (69:6): [True: 0, False: 12.9k]
  |  |  |  |  ------------------
  |  |  |  |   70|  12.9k|		log_err("%s at %d could not " #func ": %s", \
  |  |  |  |   71|      0|		__FILE__, __LINE__, strerror(lockret_err));	\
  |  |  |  |   72|  12.9k| 	} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (72:11): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  376|       |
  377|  12.9k|	if(entry) {
  ------------------
  |  Branch (377:5): [True: 0, False: 12.9k]
  ------------------
  378|      0|		if(wr)	{ lock_rw_wrlock(&entry->lock); }
  ------------------
  |  |  120|      0|#define lock_rw_wrlock(lock) LOCKRET(pthread_rwlock_wrlock(lock))
  |  |  ------------------
  |  |  |  |   67|      0|#define LOCKRET(func) do {\
  |  |  |  |   68|      0|	int lockret_err;		\
  |  |  |  |   69|      0|	if( (lockret_err=(func)) != 0)		\
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (69:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |   70|      0|		log_err("%s at %d could not " #func ": %s", \
  |  |  |  |   71|      0|		__FILE__, __LINE__, strerror(lockret_err));	\
  |  |  |  |   72|      0| 	} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (72:11): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  |  Branch (378:6): [True: 0, False: 0]
  ------------------
  379|      0|		else	{ lock_rw_rdlock(&entry->lock); }
  ------------------
  |  |  119|      0|#define lock_rw_rdlock(lock) LOCKRET(pthread_rwlock_rdlock(lock))
  |  |  ------------------
  |  |  |  |   67|      0|#define LOCKRET(func) do {\
  |  |  |  |   68|      0|	int lockret_err;		\
  |  |  |  |   69|      0|	if( (lockret_err=(func)) != 0)		\
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (69:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |   70|      0|		log_err("%s at %d could not " #func ": %s", \
  |  |  |  |   71|      0|		__FILE__, __LINE__, strerror(lockret_err));	\
  |  |  |  |   72|      0| 	} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (72:11): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  380|      0|	}
  381|  12.9k|	lock_quick_unlock(&bin->lock);
  ------------------
  |  |  146|  12.9k|#define lock_quick_unlock(lock) LOCKRET(pthread_spin_unlock(lock))
  |  |  ------------------
  |  |  |  |   67|  12.9k|#define LOCKRET(func) do {\
  |  |  |  |   68|  12.9k|	int lockret_err;		\
  |  |  |  |   69|  12.9k|	if( (lockret_err=(func)) != 0)		\
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (69:6): [True: 0, False: 12.9k]
  |  |  |  |  ------------------
  |  |  |  |   70|  12.9k|		log_err("%s at %d could not " #func ": %s", \
  |  |  |  |   71|      0|		__FILE__, __LINE__, strerror(lockret_err));	\
  |  |  |  |   72|  12.9k| 	} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (72:11): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  382|  12.9k|	return entry;
  383|  12.9k|}
lruhash_setmarkdel:
  525|  18.3k|{
  526|  18.3k|	lock_quick_lock(&table->lock);
  ------------------
  |  |  145|  18.3k|#define lock_quick_lock(lock) LOCKRET(pthread_spin_lock(lock))
  |  |  ------------------
  |  |  |  |   67|  18.3k|#define LOCKRET(func) do {\
  |  |  |  |   68|  18.3k|	int lockret_err;		\
  |  |  |  |   69|  18.3k|	if( (lockret_err=(func)) != 0)		\
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (69:6): [True: 0, False: 18.3k]
  |  |  |  |  ------------------
  |  |  |  |   70|  18.3k|		log_err("%s at %d could not " #func ": %s", \
  |  |  |  |   71|      0|		__FILE__, __LINE__, strerror(lockret_err));	\
  |  |  |  |   72|  18.3k| 	} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (72:11): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  527|  18.3k|	table->markdelfunc = md;
  528|  18.3k|	lock_quick_unlock(&table->lock);
  ------------------
  |  |  146|  18.3k|#define lock_quick_unlock(lock) LOCKRET(pthread_spin_unlock(lock))
  |  |  ------------------
  |  |  |  |   67|  18.3k|#define LOCKRET(func) do {\
  |  |  |  |   68|  18.3k|	int lockret_err;		\
  |  |  |  |   69|  18.3k|	if( (lockret_err=(func)) != 0)		\
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (69:6): [True: 0, False: 18.3k]
  |  |  |  |  ------------------
  |  |  |  |   70|  18.3k|		log_err("%s at %d could not " #func ": %s", \
  |  |  |  |   71|      0|		__FILE__, __LINE__, strerror(lockret_err));	\
  |  |  |  |   72|  18.3k| 	} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (72:11): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  529|  18.3k|}

slabhash_create:
   52|  4.59k|{
   53|  4.59k|	size_t i;
   54|  4.59k|	struct slabhash* sl = (struct slabhash*)calloc(1, 
   55|  4.59k|		sizeof(struct slabhash));
   56|  4.59k|	if(!sl) return NULL;
  ------------------
  |  Branch (56:5): [True: 0, False: 4.59k]
  ------------------
   57|  4.59k|	sl->size = numtables;
   58|  4.59k|	log_assert(sl->size > 0);
   59|  4.59k|	sl->array = (struct lruhash**)calloc(sl->size, sizeof(struct lruhash*));
   60|  4.59k|	if(!sl->array) {
  ------------------
  |  Branch (60:5): [True: 0, False: 4.59k]
  ------------------
   61|      0|		free(sl);
   62|      0|		return NULL;
   63|      0|	}
   64|  4.59k|	sl->mask = (uint32_t)(sl->size - 1);
   65|  4.59k|	if(sl->mask == 0) {
  ------------------
  |  Branch (65:5): [True: 0, False: 4.59k]
  ------------------
   66|      0|		sl->shift = 0;
   67|  4.59k|	} else {
   68|  4.59k|		log_assert( (sl->size & sl->mask) == 0 
   69|  4.59k|			/* size must be power of 2 */ );
   70|  4.59k|		sl->shift = 0;
   71|   142k|		while(!(sl->mask & 0x80000000)) {
  ------------------
  |  Branch (71:9): [True: 137k, False: 4.59k]
  ------------------
   72|   137k|			sl->mask <<= 1;
   73|   137k|			sl->shift ++;
   74|   137k|		}
   75|  4.59k|	}
   76|  22.9k|	for(i=0; i<sl->size; i++) {
  ------------------
  |  Branch (76:11): [True: 18.3k, False: 4.59k]
  ------------------
   77|  18.3k|		sl->array[i] = lruhash_create(start_size, maxmem / sl->size,
   78|  18.3k|			sizefunc, compfunc, delkeyfunc, deldatafunc, arg);
   79|  18.3k|		if(!sl->array[i]) {
  ------------------
  |  Branch (79:6): [True: 0, False: 18.3k]
  ------------------
   80|      0|			slabhash_delete(sl);
   81|      0|			return NULL;
   82|      0|		}
   83|  18.3k|	}
   84|  4.59k|	return sl;
   85|  4.59k|}
slabhash_delete:
   88|  4.59k|{
   89|  4.59k|	if(!sl)
  ------------------
  |  Branch (89:5): [True: 0, False: 4.59k]
  ------------------
   90|      0|		return;
   91|  4.59k|	if(sl->array) {
  ------------------
  |  Branch (91:5): [True: 4.59k, False: 0]
  ------------------
   92|  4.59k|		size_t i;
   93|  22.9k|		for(i=0; i<sl->size; i++)
  ------------------
  |  Branch (93:12): [True: 18.3k, False: 4.59k]
  ------------------
   94|  18.3k|			lruhash_delete(sl->array[i]);
   95|  4.59k|		free(sl->array);
   96|  4.59k|	}
   97|  4.59k|	free(sl);
   98|  4.59k|}
slabhash_insert:
  118|  12.9k|{
  119|  12.9k|	lruhash_insert(sl->array[slab_idx(sl, hash)], hash, entry, data, arg);
  120|  12.9k|}
slabhash_lookup:
  124|  12.9k|{
  125|  12.9k|	return lruhash_lookup(sl->array[slab_idx(sl, hash)], hash, key, wr);
  126|  12.9k|}
slabhash_setmarkdel:
  219|  4.59k|{
  220|  4.59k|	size_t i;
  221|  22.9k|	for(i=0; i<sl->size; i++) {
  ------------------
  |  Branch (221:11): [True: 18.3k, False: 4.59k]
  ------------------
  222|  18.3k|		lruhash_setmarkdel(sl->array[i], md);
  223|  18.3k|	}
  224|  4.59k|}
slabhash.c:slab_idx:
  112|  25.9k|{
  113|  25.9k|	return ((hash & sl->mask) >> sl->shift);
  114|  25.9k|}

ub_get_event_sys:
  169|  4.59k|{
  170|       |#ifdef USE_WINSOCK
  171|       |	(void)base;
  172|       |	*n = "event";
  173|       |	*s = "winsock";
  174|       |	*m = "WSAWaitForMultipleEvents";
  175|       |#elif defined(USE_MINI_EVENT)
  176|  4.59k|	(void)base;
  177|  4.59k|	*n = "mini-event";
  178|  4.59k|	*s = "internal";
  179|  4.59k|	*m = "select";
  180|       |#else
  181|       |	struct event_base* b = AS_EVENT_BASE(base);
  182|       |	*s = event_get_version();
  183|       |#  if defined(HAVE_EV_LOOP) || defined(HAVE_EV_DEFAULT_LOOP)
  184|       |	*n = "libev";
  185|       |	if (!b)
  186|       |		b = (struct event_base*)ev_default_loop(EVFLAG_AUTO);
  187|       |#    ifdef EV_FEATURE_BACKENDS
  188|       |	*m = ub_ev_backend2str(ev_backend((struct ev_loop*)b));
  189|       |#    else
  190|       |	*m = "not obtainable";
  191|       |#    endif
  192|       |#  elif defined(HAVE_EVENT_BASE_GET_METHOD)
  193|       |	*n = "libevent";
  194|       |	if (!b)
  195|       |		b = event_base_new();
  196|       |	*m = event_base_get_method(b);
  197|       |#  else
  198|       |	*n = "unknown";
  199|       |	*m = "not obtainable";
  200|       |	(void)b;
  201|       |#  endif
  202|       |#  ifdef HAVE_EVENT_BASE_FREE
  203|       |	if (b && b != AS_EVENT_BASE(base))
  204|       |		event_base_free(b);
  205|       |#  endif
  206|       |#endif
  207|  4.59k|}
ub_default_event_base:
  211|  4.59k|{
  212|  4.59k|	void* base;
  213|       |
  214|  4.59k|	(void)base;
  215|  4.59k|#ifdef USE_MINI_EVENT
  216|  4.59k|	(void)sigs;
  217|       |	/* use mini event time-sharing feature */
  218|  4.59k|	base = event_init(time_secs, time_tv);
  ------------------
  |  |   69|  4.59k|#define event_init minievent_init
  ------------------
  219|       |#else
  220|       |	(void)time_secs;
  221|       |	(void)time_tv;
  222|       |#  if defined(HAVE_EV_LOOP) || defined(HAVE_EV_DEFAULT_LOOP)
  223|       |	/* libev */
  224|       |	if(sigs)
  225|       |		base = ev_default_loop(EVFLAG_AUTO);
  226|       |	else
  227|       |		base = ev_loop_new(EVFLAG_AUTO);
  228|       |#  else
  229|       |	(void)sigs;
  230|       |#    ifdef HAVE_EVENT_BASE_NEW
  231|       |	base = event_base_new();
  232|       |#    else
  233|       |	base = event_init();
  234|       |#    endif
  235|       |#  endif
  236|       |#endif
  237|  4.59k|	return (struct ub_event_base*)base;
  238|  4.59k|}
ub_event_base_free:
  264|  4.59k|{
  265|  4.59k|#ifdef USE_MINI_EVENT
  266|  4.59k|	event_base_free(AS_EVENT_BASE(base));
  ------------------
  |  |   74|  4.59k|#define event_base_free minievent_base_free
  ------------------
              	event_base_free(AS_EVENT_BASE(base));
  ------------------
  |  |  141|  4.59k|#define AS_EVENT_BASE(x) ((struct event_base*)x)
  ------------------
  267|       |#elif defined(HAVE_EVENT_BASE_FREE) && defined(HAVE_EVENT_BASE_ONCE)
  268|       |	/* only libevent 1.2+ has it, but in 1.2 it is broken - 
  269|       |	   assertion fails on signal handling ev that is not deleted
  270|       | 	   in libevent 1.3c (event_base_once appears) this is fixed. */
  271|       |	event_base_free(AS_EVENT_BASE(base));
  272|       |#else
  273|       |	(void)base;
  274|       |#endif /* HAVE_EVENT_BASE_FREE and HAVE_EVENT_BASE_ONCE */
  275|  4.59k|}
ub_comm_base_now:
  449|  4.59k|{
  450|  4.59k|#ifdef USE_MINI_EVENT
  451|       |/** minievent updates the time when it blocks. */
  452|  4.59k|	(void)cb; /* nothing to do */
  453|       |#else /* !USE_MINI_EVENT */
  454|       |/** fillup the time values in the event base */
  455|       |	time_t *tt;
  456|       |	struct timeval *tv;
  457|       |	comm_base_timept(cb, &tt, &tv);
  458|       |	if(gettimeofday(tv, NULL) < 0) {
  459|       |		log_err("gettimeofday: %s", strerror(errno));
  460|       |	}
  461|       |#ifndef S_SPLINT_S
  462|       |	*tt = tv->tv_sec;
  463|       |#endif
  464|       |#endif /* USE_MINI_EVENT */
  465|  4.59k|}

