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

priv_rrset_bad:
  234|  14.9k|{
  235|  14.9k|	if(priv->a.count == 0) 
  ------------------
  |  Branch (235:5): [True: 14.9k, False: 0]
  ------------------
  236|  14.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.04k|{
  859|       |	/* basic sanity checks */
  860|  2.04k|	log_nametypeclass(VERB_ALGO, "scrub for", zonename, LDNS_RR_TYPE_NS, 
  861|  2.04k|		qinfo->qclass);
  862|  2.04k|	if(msg->qdcount > 1)
  ------------------
  |  Branch (862:5): [True: 0, False: 2.04k]
  ------------------
  863|      0|		return 0;
  864|  2.04k|	if( !(msg->flags&BIT_QR) )
  ------------------
  |  |   72|  2.04k|#define BIT_QR 0x8000
  ------------------
  |  Branch (864:6): [True: 72, False: 1.97k]
  ------------------
  865|     72|		return 0;
  866|  1.97k|	msg->flags &= ~(BIT_AD|BIT_Z); /* force off bit AD and Z */
  ------------------
  |  |   60|  1.97k|#define BIT_AD 0x0020
  ------------------
              	msg->flags &= ~(BIT_AD|BIT_Z); /* force off bit AD and Z */
  ------------------
  |  |   62|  1.97k|#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.97k|	if((FLAGS_GET_RCODE(msg->flags) == LDNS_RCODE_NOERROR ||
  ------------------
  |  |   74|  1.97k|#define FLAGS_GET_RCODE(f) ((f) & 0xf)
  ------------------
  |  Branch (871:6): [True: 751, False: 1.22k]
  ------------------
  872|  1.97k|		FLAGS_GET_RCODE(msg->flags) == LDNS_RCODE_NXDOMAIN) &&
  ------------------
  |  |   74|  1.22k|#define FLAGS_GET_RCODE(f) ((f) & 0xf)
  ------------------
  |  Branch (872:3): [True: 188, False: 1.03k]
  ------------------
  873|  1.97k|		msg->qdcount == 0)
  ------------------
  |  Branch (873:3): [True: 9, False: 930]
  ------------------
  874|      9|		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.96k|	if(msg->qdcount == 1) {
  ------------------
  |  Branch (878:5): [True: 994, False: 970]
  ------------------
  879|    994|		if(dname_pkt_compare(pkt, msg->qname, qinfo->qname) != 0)
  ------------------
  |  Branch (879:6): [True: 36, False: 958]
  ------------------
  880|     36|			return 0;
  881|    958|		if(msg->qtype != qinfo->qtype || msg->qclass != qinfo->qclass)
  ------------------
  |  Branch (881:6): [True: 28, False: 930]
  |  Branch (881:36): [True: 23, False: 907]
  ------------------
  882|     51|			return 0;
  883|    958|	}
  884|       |
  885|       |	/* normalize the response, this cleans up the additional.  */
  886|  1.87k|	if(!scrub_normalize(pkt, msg, qinfo, region, env))
  ------------------
  |  Branch (886:5): [True: 102, False: 1.77k]
  ------------------
  887|    102|		return 0;
  888|       |	/* delete all out-of-zone information */
  889|  1.77k|	if(!scrub_sanitize(pkt, msg, qinfo, zonename, env, ie))
  ------------------
  |  Branch (889:5): [True: 0, False: 1.77k]
  ------------------
  890|      0|		return 0;
  891|  1.77k|	return 1;
  892|  1.77k|}
iter_scrub.c:scrub_normalize:
  385|  1.87k|{
  386|  1.87k|	uint8_t* sname = qinfo->qname;
  387|  1.87k|	size_t snamelen = qinfo->qname_len;
  388|  1.87k|	struct rrset_parse* rrset, *prev, *nsset=NULL;
  389|       |
  390|  1.87k|	if(FLAGS_GET_RCODE(msg->flags) != LDNS_RCODE_NOERROR &&
  ------------------
  |  |   74|  1.87k|#define FLAGS_GET_RCODE(f) ((f) & 0xf)
  ------------------
  |  Branch (390:5): [True: 1.17k, False: 701]
  ------------------
  391|  1.87k|		FLAGS_GET_RCODE(msg->flags) != LDNS_RCODE_NXDOMAIN)
  ------------------
  |  |   74|  1.17k|#define FLAGS_GET_RCODE(f) ((f) & 0xf)
  ------------------
  |  Branch (391:3): [True: 1.00k, False: 170]
  ------------------
  392|  1.00k|		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|    871|	prev = NULL;
  401|    871|	rrset = msg->rrset_first;
  402|  4.57k|	while(rrset && rrset->section == LDNS_SECTION_ANSWER) {
  ------------------
  |  Branch (402:8): [True: 4.35k, False: 219]
  |  Branch (402:17): [True: 3.80k, False: 550]
  ------------------
  403|  3.80k|		if(rrset->type == LDNS_RR_TYPE_DNAME && 
  ------------------
  |  Branch (403:6): [True: 1.03k, False: 2.77k]
  ------------------
  404|  3.80k|			pkt_strict_sub(pkt, sname, rrset->dname)) {
  ------------------
  |  Branch (404:4): [True: 660, False: 371]
  ------------------
  405|       |			/* check if next rrset is correct CNAME. else,
  406|       |			 * synthesize a CNAME */
  407|    660|			struct rrset_parse* nx = rrset->rrset_all_next;
  408|    660|			uint8_t alias[LDNS_MAX_DOMAINLEN+1];
  409|    660|			size_t aliaslen = 0;
  410|    660|			if(rrset->rr_count != 1) {
  ------------------
  |  Branch (410:7): [True: 5, False: 655]
  ------------------
  411|      5|				verbose(VERB_ALGO, "Found DNAME rrset with "
  412|      5|					"size > 1: %u", 
  413|      5|					(unsigned)rrset->rr_count);
  414|      5|				return 0;
  415|      5|			}
  416|    655|			if(!synth_cname(sname, snamelen, rrset, alias, 
  ------------------
  |  Branch (416:7): [True: 43, False: 612]
  ------------------
  417|    655|				&aliaslen, pkt)) {
  418|     43|				verbose(VERB_ALGO, "synthesized CNAME "
  419|     43|					"too long");
  420|     43|				return 0;
  421|     43|			}
  422|    612|			if(nx && nx->type == LDNS_RR_TYPE_CNAME && 
  ------------------
  |  Branch (422:7): [True: 573, False: 39]
  |  Branch (422:13): [True: 66, False: 507]
  ------------------
  423|    612|			   dname_pkt_compare(pkt, sname, nx->dname) == 0) {
  ------------------
  |  Branch (423:7): [True: 39, False: 27]
  ------------------
  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|    600|			prev = synth_cname_rrset(&sname, &snamelen, alias, 
  439|    600|				aliaslen, region, msg, rrset, rrset, nx, pkt);
  440|    600|			if(!prev) {
  ------------------
  |  Branch (440:7): [True: 0, False: 600]
  ------------------
  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|    600|			rrset = nx;
  447|    600|			continue;
  448|       |
  449|    600|		}
  450|       |
  451|       |		/* The only records in the ANSWER section not allowed to */
  452|  3.14k|		if(dname_pkt_compare(pkt, sname, rrset->dname) != 0) {
  ------------------
  |  Branch (452:6): [True: 1.93k, False: 1.21k]
  ------------------
  453|  1.93k|			remove_rrset("normalize: removing irrelevant RRset:", 
  454|  1.93k|				pkt, msg, prev, &rrset);
  455|  1.93k|			continue;
  456|  1.93k|		}
  457|       |
  458|       |		/* Follow the CNAME chain. */
  459|  1.21k|		if(rrset->type == LDNS_RR_TYPE_CNAME) {
  ------------------
  |  Branch (459:6): [True: 490, False: 722]
  ------------------
  460|    490|			struct rrset_parse* nx = rrset->rrset_all_next;
  461|    490|			uint8_t* oldsname = sname;
  462|       |			/* see if the next one is a DNAME, if so, swap them */
  463|    490|			if(nx && nx->section == LDNS_SECTION_ANSWER &&
  ------------------
  |  Branch (463:7): [True: 462, False: 28]
  |  Branch (463:13): [True: 458, False: 4]
  ------------------
  464|    490|				nx->type == LDNS_RR_TYPE_DNAME &&
  ------------------
  |  Branch (464:5): [True: 270, False: 188]
  ------------------
  465|    490|				nx->rr_count == 1 &&
  ------------------
  |  Branch (465:5): [True: 256, False: 14]
  ------------------
  466|    490|				pkt_strict_sub(pkt, sname, nx->dname)) {
  ------------------
  |  Branch (466:5): [True: 195, False: 61]
  ------------------
  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: 17, False: 38]
  ------------------
  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|     17|					verbose(VERB_ALGO, "normalize: re-order of DNAME and its CNAME");
  485|     17|					if(prev) prev->rrset_all_next = nx;
  ------------------
  |  Branch (485:9): [True: 17, False: 0]
  ------------------
  486|      0|					else msg->rrset_first = nx;
  487|     17|					if(nx->rrset_all_next == NULL)
  ------------------
  |  Branch (487:9): [True: 3, False: 14]
  ------------------
  488|      3|						msg->rrset_last = rrset;
  489|     17|					rrset->rrset_all_next =
  490|     17|						nx->rrset_all_next;
  491|     17|					nx->rrset_all_next = rrset;
  492|       |					/* prev = nx; unused, enable if there
  493|       |					 * is other rrset removal code after
  494|       |					 * this */
  495|     17|				}
  496|    195|			}
  497|       |
  498|       |			/* move to next name in CNAME chain */
  499|    490|			if(!parse_get_cname_target(rrset, &sname, &snamelen, pkt))
  ------------------
  |  Branch (499:7): [True: 51, False: 439]
  ------------------
  500|     51|				return 0;
  501|    439|			prev = rrset;
  502|    439|			rrset = rrset->rrset_all_next;
  503|       |			/* in CNAME ANY response, can have data after CNAME */
  504|    439|			if(qinfo->qtype == LDNS_RR_TYPE_ANY) {
  ------------------
  |  Branch (504:7): [True: 0, False: 439]
  ------------------
  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|    439|			continue;
  514|    490|		}
  515|       |
  516|       |		/* Otherwise, make sure that the RRset matches the qtype. */
  517|    722|		if(qinfo->qtype != LDNS_RR_TYPE_ANY && 
  ------------------
  |  Branch (517:6): [True: 722, False: 0]
  ------------------
  518|    722|			qinfo->qtype != rrset->type) {
  ------------------
  |  Branch (518:4): [True: 552, False: 170]
  ------------------
  519|    552|			remove_rrset("normalize: removing irrelevant RRset:", 
  520|    552|				pkt, msg, prev, &rrset);
  521|    552|			continue;
  522|    552|		}
  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|    170|		if(dname_pkt_compare(pkt, qinfo->qname, rrset->dname) == 0)
  ------------------
  |  Branch (527:6): [True: 35, False: 135]
  ------------------
  528|     35|			mark_additional_rrset(pkt, msg, rrset);
  529|       |		
  530|    170|		prev = rrset;
  531|    170|		rrset = rrset->rrset_all_next;
  532|    170|	}
  533|       |
  534|       |	/* Mark additional names from AUTHORITY */
  535|  10.3k|	while(rrset && rrset->section == LDNS_SECTION_AUTHORITY) {
  ------------------
  |  Branch (535:8): [True: 9.73k, False: 603]
  |  Branch (535:17): [True: 9.57k, False: 166]
  ------------------
  536|       |		/* protect internals of recursor by making sure to del these */
  537|  9.57k|		if(rrset->type==LDNS_RR_TYPE_DNAME ||
  ------------------
  |  Branch (537:6): [True: 114, False: 9.45k]
  ------------------
  538|  9.57k|			rrset->type==LDNS_RR_TYPE_CNAME ||
  ------------------
  |  Branch (538:4): [True: 129, False: 9.32k]
  ------------------
  539|  9.57k|			rrset->type==LDNS_RR_TYPE_A ||
  ------------------
  |  Branch (539:4): [True: 564, False: 8.76k]
  ------------------
  540|  9.57k|			rrset->type==LDNS_RR_TYPE_AAAA) {
  ------------------
  |  Branch (540:4): [True: 118, False: 8.64k]
  ------------------
  541|    925|			remove_rrset("normalize: removing irrelevant "
  542|    925|				"RRset:", pkt, msg, prev, &rrset);
  543|    925|			continue;
  544|    925|		}
  545|       |		/* Allowed list of types in the authority section */
  546|  8.64k|		if(env->cfg->harden_unknown_additional &&
  ------------------
  |  Branch (546:6): [True: 0, False: 8.64k]
  ------------------
  547|  8.64k|			!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|  8.64k|		if(rrset->type==LDNS_RR_TYPE_NS) {
  ------------------
  |  Branch (553:6): [True: 1.49k, False: 7.15k]
  ------------------
  554|       |			/* NS set must be pertinent to the query */
  555|  1.49k|			if(!sub_of_pkt(pkt, qinfo->qname, rrset->dname)) {
  ------------------
  |  Branch (555:7): [True: 193, False: 1.29k]
  ------------------
  556|    193|				remove_rrset("normalize: removing irrelevant "
  557|    193|					"RRset:", pkt, msg, prev, &rrset);
  558|    193|				continue;
  559|    193|			}
  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.29k|			if(FLAGS_GET_RCODE(msg->flags) == LDNS_RCODE_NXDOMAIN ||
  ------------------
  |  |   74|  1.29k|#define FLAGS_GET_RCODE(f) ((f) & 0xf)
  ------------------
  |  Branch (566:7): [True: 340, False: 959]
  ------------------
  567|  1.29k|			   (FLAGS_GET_RCODE(msg->flags) == LDNS_RCODE_NOERROR
  ------------------
  |  |   74|    959|#define FLAGS_GET_RCODE(f) ((f) & 0xf)
  ------------------
  |  Branch (567:8): [True: 959, False: 0]
  ------------------
  568|    959|			    && soa_in_auth(msg) && msg->an_rrsets == 0)) {
  ------------------
  |  Branch (568:11): [True: 659, False: 300]
  |  Branch (568:31): [True: 327, False: 332]
  ------------------
  569|    667|				remove_rrset("normalize: removing irrelevant "
  570|    667|					"RRset:", pkt, msg, prev, &rrset);
  571|    667|				continue;
  572|    667|			}
  573|    632|			if(nsset == NULL) {
  ------------------
  |  Branch (573:7): [True: 151, False: 481]
  ------------------
  574|    151|				nsset = rrset;
  575|    481|			} else {
  576|    481|				remove_rrset("normalize: removing irrelevant "
  577|    481|					"RRset:", pkt, msg, prev, &rrset);
  578|    481|				continue;
  579|    481|			}
  580|    632|		}
  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|  7.30k|		if(rrset->type==LDNS_RR_TYPE_DS &&
  ------------------
  |  Branch (583:6): [True: 63, False: 7.24k]
  ------------------
  584|  7.30k|			qinfo->qtype == LDNS_RR_TYPE_DS &&
  ------------------
  |  Branch (584:4): [True: 0, False: 63]
  ------------------
  585|  7.30k|			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|  7.30k|		mark_additional_rrset(pkt, msg, rrset);
  600|  7.30k|		prev = rrset;
  601|  7.30k|		rrset = rrset->rrset_all_next;
  602|  7.30k|	}
  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.94k|	while(rrset && rrset->section == LDNS_SECTION_ADDITIONAL) {
  ------------------
  |  Branch (608:8): [True: 3.17k, False: 769]
  |  Branch (608:17): [True: 3.17k, False: 0]
  ------------------
  609|  3.17k|		if(rrset->type==LDNS_RR_TYPE_A || 
  ------------------
  |  Branch (609:6): [True: 723, False: 2.45k]
  ------------------
  610|  3.17k|			rrset->type==LDNS_RR_TYPE_AAAA) 
  ------------------
  |  Branch (610:4): [True: 196, False: 2.25k]
  ------------------
  611|    919|		{
  612|    919|			if((rrset->flags & RRSET_SCRUB_OK)) {
  ------------------
  |  |   59|    919|#define RRSET_SCRUB_OK	0x80
  ------------------
  |  Branch (612:7): [True: 98, False: 821]
  ------------------
  613|       |				/* remove flag to clean up flags variable */
  614|     98|				rrset->flags &= ~RRSET_SCRUB_OK;
  ------------------
  |  |   59|     98|#define RRSET_SCRUB_OK	0x80
  ------------------
  615|    821|			} else {
  616|    821|				remove_rrset("normalize: removing irrelevant "
  617|    821|					"RRset:", pkt, msg, prev, &rrset);
  618|    821|				continue;
  619|    821|			}
  620|    919|		}
  621|       |		/* protect internals of recursor by making sure to del these */
  622|  2.35k|		if(rrset->type==LDNS_RR_TYPE_DNAME || 
  ------------------
  |  Branch (622:6): [True: 85, False: 2.26k]
  ------------------
  623|  2.35k|			rrset->type==LDNS_RR_TYPE_CNAME ||
  ------------------
  |  Branch (623:4): [True: 87, False: 2.18k]
  ------------------
  624|  2.35k|			rrset->type==LDNS_RR_TYPE_NS) {
  ------------------
  |  Branch (624:4): [True: 217, False: 1.96k]
  ------------------
  625|    389|			remove_rrset("normalize: removing irrelevant "
  626|    389|				"RRset:", pkt, msg, prev, &rrset);
  627|    389|			continue;
  628|    389|		}
  629|       |		/* Allowed list of types in the additional section */
  630|  1.96k|		if(env->cfg->harden_unknown_additional &&
  ------------------
  |  Branch (630:6): [True: 0, False: 1.96k]
  ------------------
  631|  1.96k|			!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.96k|		prev = rrset;
  637|  1.96k|		rrset = rrset->rrset_all_next;
  638|  1.96k|	}
  639|       |	
  640|    769|	return 1;
  641|    769|}
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|    850|{
  229|       |	/* we already know that sname is a strict subdomain of DNAME owner */
  230|    850|	uint8_t* dtarg = NULL;
  231|    850|	size_t dtarglen;
  232|    850|	if(!parse_get_cname_target(dname_rrset, &dtarg, &dtarglen, pkt))
  ------------------
  |  Branch (232:5): [True: 62, False: 788]
  ------------------
  233|     62|		return 0; 
  234|    788|	if(qnamelen <= dname_rrset->dname_len)
  ------------------
  |  Branch (234:5): [True: 101, False: 687]
  ------------------
  235|    101|		return 0;
  236|    687|	if(qnamelen == 0)
  ------------------
  |  Branch (236:5): [True: 0, False: 687]
  ------------------
  237|      0|		return 0;
  238|    687|	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|    687|	*aliaslen = qnamelen + dtarglen - dname_rrset->dname_len;
  242|    687|	if(*aliaslen > LDNS_MAX_DOMAINLEN)
  ------------------
  |  |   29|    687|#define LDNS_MAX_DOMAINLEN    255
  ------------------
  |  Branch (242:5): [True: 10, False: 677]
  ------------------
  243|     10|		return 0; /* should have been RCODE YXDOMAIN */
  244|       |	/* decompress dnames into buffer, we know it fits */
  245|    677|	dname_pkt_copy(pkt, alias, qname);
  246|    677|	dname_pkt_copy(pkt, alias+(qnamelen-dname_rrset->dname_len), dtarg);
  247|    677|	return 1;
  248|    687|}
iter_scrub.c:parse_get_cname_target:
  189|  1.44k|{
  190|  1.44k|	size_t oldpos, dlen;
  191|  1.44k|	if(rrset->rr_count != 1) {
  ------------------
  |  Branch (191:5): [True: 69, False: 1.37k]
  ------------------
  192|     69|		struct rr_parse* sig;
  193|     69|		verbose(VERB_ALGO, "Found CNAME rrset with "
  194|     69|			"size > 1: %u", (unsigned)rrset->rr_count);
  195|       |		/* use the first CNAME! */
  196|     69|		rrset->rr_count = 1;
  197|     69|		rrset->size = rrset->rr_first->size;
  198|    277|		for(sig=rrset->rrsig_first; sig; sig=sig->next)
  ------------------
  |  Branch (198:31): [True: 208, False: 69]
  ------------------
  199|    208|			rrset->size += sig->size;
  200|     69|		rrset->rr_last = rrset->rr_first;
  201|     69|		rrset->rr_first->next = NULL;
  202|     69|	}
  203|  1.44k|	if(rrset->rr_first->size < sizeof(uint16_t)+1)
  ------------------
  |  Branch (203:5): [True: 126, False: 1.31k]
  ------------------
  204|    126|		return 0; /* CNAME rdata too small */
  205|  1.31k|	*sname = rrset->rr_first->ttl_data + sizeof(uint32_t)
  206|  1.31k|		+ sizeof(uint16_t); /* skip ttl, rdatalen */
  207|  1.31k|	*snamelen = rrset->rr_first->size - sizeof(uint16_t);
  208|       |
  209|  1.31k|	if(rrset->rr_first->outside_packet) {
  ------------------
  |  Branch (209:5): [True: 0, False: 1.31k]
  ------------------
  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.31k|	oldpos = sldns_buffer_position(pkt);
  215|  1.31k|	sldns_buffer_set_position(pkt, (size_t)(*sname - sldns_buffer_begin(pkt)));
  216|  1.31k|	dlen = pkt_dname_len(pkt);
  217|  1.31k|	sldns_buffer_set_position(pkt, oldpos);
  218|  1.31k|	if(dlen == 0)
  ------------------
  |  Branch (218:5): [True: 0, False: 1.31k]
  ------------------
  219|      0|		return 0; /* parse fail on the rdata name */
  220|  1.31k|	*snamelen = dlen;
  221|  1.31k|	return 1;
  222|  1.31k|}
iter_scrub.c:synth_cname_rrset:
  256|    600|{
  257|    600|	struct rrset_parse* cn = (struct rrset_parse*)regional_alloc(region,
  258|    600|		sizeof(struct rrset_parse));
  259|    600|	if(!cn)
  ------------------
  |  Branch (259:5): [True: 0, False: 600]
  ------------------
  260|      0|		return NULL;
  261|    600|	memset(cn, 0, sizeof(*cn));
  262|    600|	cn->rr_first = (struct rr_parse*)regional_alloc(region, 
  263|    600|		sizeof(struct rr_parse));
  264|    600|	if(!cn->rr_first)
  ------------------
  |  Branch (264:5): [True: 0, False: 600]
  ------------------
  265|      0|		return NULL;
  266|    600|	cn->rr_last = cn->rr_first;
  267|       |	/* CNAME from sname to alias */
  268|    600|	cn->dname = (uint8_t*)regional_alloc(region, *snamelen);
  269|    600|	if(!cn->dname)
  ------------------
  |  Branch (269:5): [True: 0, False: 600]
  ------------------
  270|      0|		return NULL;
  271|    600|	dname_pkt_copy(pkt, cn->dname, *sname);
  272|    600|	cn->dname_len = *snamelen;
  273|    600|	cn->type = LDNS_RR_TYPE_CNAME;
  274|    600|	cn->section = rrset->section;
  275|    600|	cn->rrset_class = rrset->rrset_class;
  276|    600|	cn->rr_count = 1;
  277|    600|	cn->size = sizeof(uint16_t) + aliaslen;
  278|    600|	cn->hash=pkt_hash_rrset(pkt, cn->dname, cn->type, cn->rrset_class, 0);
  279|       |	/* allocate TTL + rdatalen + uncompressed dname */
  280|    600|	memset(cn->rr_first, 0, sizeof(struct rr_parse));
  281|    600|	cn->rr_first->outside_packet = 1;
  282|    600|	cn->rr_first->ttl_data = (uint8_t*)regional_alloc(region, 
  283|    600|		sizeof(uint32_t)+sizeof(uint16_t)+aliaslen);
  284|    600|	if(!cn->rr_first->ttl_data)
  ------------------
  |  Branch (284:5): [True: 0, False: 600]
  ------------------
  285|      0|		return NULL;
  286|    600|	sldns_write_uint32(cn->rr_first->ttl_data, 0); /* TTL = 0 */
  287|    600|	sldns_write_uint16(cn->rr_first->ttl_data+4, aliaslen);
  288|    600|	memmove(cn->rr_first->ttl_data+6, alias, aliaslen);
  289|    600|	cn->rr_first->size = sizeof(uint16_t)+aliaslen;
  290|       |
  291|       |	/* link it in */
  292|    600|	cn->rrset_all_next = nx;
  293|    600|	if(prev)
  ------------------
  |  Branch (293:5): [True: 600, False: 0]
  ------------------
  294|    600|		prev->rrset_all_next = cn;
  295|      0|	else	msg->rrset_first = cn;
  296|    600|	if(nx == NULL)
  ------------------
  |  Branch (296:5): [True: 39, False: 561]
  ------------------
  297|     39|		msg->rrset_last = cn;
  298|    600|	msg->rrset_count ++;
  299|    600|	msg->an_rrsets++;
  300|       |	/* it is not inserted in the msg hashtable. */
  301|       |
  302|    600|	*sname = cn->rr_first->ttl_data + sizeof(uint32_t)+sizeof(uint16_t);
  303|    600|	*snamelen = aliaslen;
  304|    600|	return cn;
  305|    600|}
iter_scrub.c:remove_rrset:
   65|  54.9k|{
   66|  54.9k|	if(verbosity >= VERB_QUERY && str
  ------------------
  |  Branch (66:5): [True: 0, False: 54.9k]
  |  Branch (66:32): [True: 0, False: 0]
  ------------------
   67|  54.9k|		&& (*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|  54.9k|	if(prev)
  ------------------
  |  Branch (73:5): [True: 17.3k, False: 37.6k]
  ------------------
   74|  17.3k|		prev->rrset_all_next = (*rrset)->rrset_all_next;
   75|  37.6k|	else	msg->rrset_first = (*rrset)->rrset_all_next;
   76|  54.9k|	if(msg->rrset_last == *rrset)
  ------------------
  |  Branch (76:5): [True: 1.68k, False: 53.2k]
  ------------------
   77|  1.68k|		msg->rrset_last = prev;
   78|  54.9k|	msg->rrset_count --;
   79|  54.9k|	switch((*rrset)->section) {
   80|  6.20k|		case LDNS_SECTION_ANSWER: msg->an_rrsets--; break;
  ------------------
  |  Branch (80:3): [True: 6.20k, False: 48.7k]
  ------------------
   81|  21.9k|		case LDNS_SECTION_AUTHORITY: msg->ns_rrsets--; break;
  ------------------
  |  Branch (81:3): [True: 21.9k, False: 32.9k]
  ------------------
   82|  26.7k|		case LDNS_SECTION_ADDITIONAL: msg->ar_rrsets--; break;
  ------------------
  |  Branch (82:3): [True: 26.7k, False: 28.1k]
  ------------------
   83|      0|		default: log_assert(0);
  ------------------
  |  Branch (83:3): [True: 0, False: 54.9k]
  ------------------
   84|  54.9k|	}
   85|  54.9k|	msgparse_bucket_remove(msg, *rrset);
   86|  54.9k|	*rrset = (*rrset)->rrset_all_next;
   87|  54.9k|}
iter_scrub.c:mark_additional_rrset:
  153|  7.34k|{
  154|       |	/* Mark A and AAAA for NS as appropriate additional section info. */
  155|  7.34k|	uint8_t* nm = NULL;
  156|  7.34k|	size_t nmlen = 0;
  157|  7.34k|	struct rr_parse* rr;
  158|       |
  159|  7.34k|	if(!has_additional(rrset->type))
  ------------------
  |  Branch (159:5): [True: 5.54k, False: 1.80k]
  ------------------
  160|  5.54k|		return;
  161|  8.08k|	for(rr = rrset->rr_first; rr; rr = rr->next) {
  ------------------
  |  Branch (161:28): [True: 6.28k, False: 1.80k]
  ------------------
  162|  6.28k|		if(get_additional_name(rrset, rr, &nm, &nmlen, pkt)) {
  ------------------
  |  Branch (162:6): [True: 2.26k, False: 4.02k]
  ------------------
  163|       |			/* mark A */
  164|  2.26k|			hashvalue_type h = pkt_hash_rrset(pkt, nm,
  165|  2.26k|				LDNS_RR_TYPE_A, rrset->rrset_class, 0);
  166|  2.26k|			struct rrset_parse* r = msgparse_hashtable_lookup(
  167|  2.26k|				msg, pkt, h, 0, nm, nmlen, 
  168|  2.26k|				LDNS_RR_TYPE_A, rrset->rrset_class);
  169|  2.26k|			if(r && r->section == LDNS_SECTION_ADDITIONAL) {
  ------------------
  |  Branch (169:7): [True: 755, False: 1.50k]
  |  Branch (169:12): [True: 57, False: 698]
  ------------------
  170|     57|				r->flags |= RRSET_SCRUB_OK;
  ------------------
  |  |   59|     57|#define RRSET_SCRUB_OK	0x80
  ------------------
  171|     57|			}
  172|       |			
  173|       |			/* mark AAAA */
  174|  2.26k|			h = pkt_hash_rrset(pkt, nm, LDNS_RR_TYPE_AAAA, 
  175|  2.26k|				rrset->rrset_class, 0);
  176|  2.26k|			r = msgparse_hashtable_lookup(msg, pkt, h, 0, nm, 
  177|  2.26k|				nmlen, LDNS_RR_TYPE_AAAA, rrset->rrset_class);
  178|  2.26k|			if(r && r->section == LDNS_SECTION_ADDITIONAL) {
  ------------------
  |  Branch (178:7): [True: 384, False: 1.87k]
  |  Branch (178:12): [True: 41, False: 343]
  ------------------
  179|     41|				r->flags |= RRSET_SCRUB_OK;
  ------------------
  |  |   59|     41|#define RRSET_SCRUB_OK	0x80
  ------------------
  180|     41|			}
  181|  2.26k|		}
  182|  6.28k|	}
  183|  1.80k|}
iter_scrub.c:has_additional:
   92|  40.7k|{
   93|  40.7k|	switch(t) {
  ------------------
  |  Branch (93:9): [True: 34.1k, False: 6.51k]
  ------------------
   94|  1.31k|		case LDNS_RR_TYPE_MB:
  ------------------
  |  Branch (94:3): [True: 1.31k, False: 39.3k]
  ------------------
   95|  1.94k|		case LDNS_RR_TYPE_MD:
  ------------------
  |  Branch (95:3): [True: 630, False: 40.0k]
  ------------------
   96|  2.97k|		case LDNS_RR_TYPE_MF:
  ------------------
  |  Branch (96:3): [True: 1.02k, False: 39.6k]
  ------------------
   97|  4.51k|		case LDNS_RR_TYPE_NS:
  ------------------
  |  Branch (97:3): [True: 1.53k, False: 39.1k]
  ------------------
   98|  4.86k|		case LDNS_RR_TYPE_MX:
  ------------------
  |  Branch (98:3): [True: 353, False: 40.3k]
  ------------------
   99|  5.22k|		case LDNS_RR_TYPE_KX:
  ------------------
  |  Branch (99:3): [True: 360, False: 40.3k]
  ------------------
  100|  6.29k|		case LDNS_RR_TYPE_SRV:
  ------------------
  |  Branch (100:3): [True: 1.07k, False: 39.6k]
  ------------------
  101|  6.29k|			return 1;
  102|    217|		case LDNS_RR_TYPE_NAPTR:
  ------------------
  |  Branch (102:3): [True: 217, False: 40.4k]
  ------------------
  103|       |			/* TODO: NAPTR not supported, glue stripped off */
  104|    217|			return 0;
  105|  40.7k|	}
  106|  34.1k|	return 0;
  107|  40.7k|}
iter_scrub.c:get_additional_name:
  113|  6.28k|{
  114|  6.28k|	size_t offset = 0;
  115|  6.28k|	size_t len, oldpos;
  116|  6.28k|	switch(rrset->type) {
  117|  2.49k|		case LDNS_RR_TYPE_MB:
  ------------------
  |  Branch (117:3): [True: 2.49k, False: 3.78k]
  ------------------
  118|  2.95k|		case LDNS_RR_TYPE_MD:
  ------------------
  |  Branch (118:3): [True: 460, False: 5.82k]
  ------------------
  119|  4.04k|		case LDNS_RR_TYPE_MF:
  ------------------
  |  Branch (119:3): [True: 1.08k, False: 5.20k]
  ------------------
  120|  4.49k|		case LDNS_RR_TYPE_NS:
  ------------------
  |  Branch (120:3): [True: 447, False: 5.83k]
  ------------------
  121|  4.49k|			offset = 0;
  122|  4.49k|			break;
  123|    384|		case LDNS_RR_TYPE_MX:
  ------------------
  |  Branch (123:3): [True: 384, False: 5.90k]
  ------------------
  124|    744|		case LDNS_RR_TYPE_KX:
  ------------------
  |  Branch (124:3): [True: 360, False: 5.92k]
  ------------------
  125|    744|			offset = 2;
  126|    744|			break;
  127|  1.05k|		case LDNS_RR_TYPE_SRV:
  ------------------
  |  Branch (127:3): [True: 1.05k, False: 5.23k]
  ------------------
  128|  1.05k|			offset = 6;
  129|  1.05k|			break;
  130|      0|		case LDNS_RR_TYPE_NAPTR:
  ------------------
  |  Branch (130:3): [True: 0, False: 6.28k]
  ------------------
  131|       |			/* TODO: NAPTR not supported, glue stripped off */
  132|      0|			return 0;
  133|      0|		default:
  ------------------
  |  Branch (133:3): [True: 0, False: 6.28k]
  ------------------
  134|      0|			return 0;
  135|  6.28k|	}
  136|  6.28k|	len = sldns_read_uint16(rr->ttl_data+sizeof(uint32_t));
  137|  6.28k|	if(len < offset+1)
  ------------------
  |  Branch (137:5): [True: 4.02k, False: 2.26k]
  ------------------
  138|  4.02k|		return 0; /* rdata field too small */
  139|  2.26k|	*nm = rr->ttl_data+sizeof(uint32_t)+sizeof(uint16_t)+offset;
  140|  2.26k|	oldpos = sldns_buffer_position(pkt);
  141|  2.26k|	sldns_buffer_set_position(pkt, (size_t)(*nm - sldns_buffer_begin(pkt)));
  142|  2.26k|	*nmlen = pkt_dname_len(pkt);
  143|  2.26k|	sldns_buffer_set_position(pkt, oldpos);
  144|  2.26k|	if(*nmlen == 0)
  ------------------
  |  Branch (144:5): [True: 0, False: 2.26k]
  ------------------
  145|      0|		return 0;
  146|  2.26k|	return 1;
  147|  2.26k|}
iter_scrub.c:sub_of_pkt:
  331|  1.62k|{
  332|  1.62k|	uint8_t buf[LDNS_MAX_DOMAINLEN+1];
  333|  1.62k|	dname_pkt_copy(pkt, buf, comprname);
  334|  1.62k|	return dname_subdomain_c(zone, buf);
  335|  1.62k|}
iter_scrub.c:soa_in_auth:
  340|  1.09k|{
  341|  1.09k|	struct rrset_parse* rrset;
  342|  71.2k|	for(rrset = msg->rrset_first; rrset; rrset = rrset->rrset_all_next)
  ------------------
  |  Branch (342:32): [True: 70.7k, False: 433]
  ------------------
  343|  70.7k|		if(rrset->type == LDNS_RR_TYPE_SOA &&
  ------------------
  |  Branch (343:6): [True: 954, False: 69.8k]
  ------------------
  344|  70.7k|			rrset->section == LDNS_SECTION_AUTHORITY) 
  ------------------
  |  Branch (344:4): [True: 659, False: 295]
  ------------------
  345|    659|			return 1;
  346|    433|	return 0;
  347|  1.09k|}
iter_scrub.c:scrub_sanitize:
  737|  1.77k|{
  738|  1.77k|	int del_addi = 0; /* if additional-holding rrsets are deleted, we
  739|       |		do not trust the normalized additional-A-AAAA any more */
  740|  1.77k|	struct rrset_parse* rrset, *prev;
  741|  1.77k|	prev = NULL;
  742|  1.77k|	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.77k|	if(rrset && rrset->type == LDNS_RR_TYPE_DNAME && 
  ------------------
  |  Branch (747:5): [True: 1.55k, False: 222]
  |  Branch (747:14): [True: 59, False: 1.49k]
  ------------------
  748|  1.77k|		rrset->section == LDNS_SECTION_ANSWER &&
  ------------------
  |  Branch (748:3): [True: 46, False: 13]
  ------------------
  749|  1.77k|		pkt_strict_sub(pkt, qinfo->qname, rrset->dname) &&
  ------------------
  |  Branch (749:3): [True: 23, False: 23]
  ------------------
  750|  1.77k|		pkt_sub(pkt, rrset->dname, zonename)) {
  ------------------
  |  Branch (750:3): [True: 17, False: 6]
  ------------------
  751|     17|		prev = rrset; /* DNAME allowed to stay in answer section */
  752|     17|		rrset = rrset->rrset_all_next;
  753|     17|	}
  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.94k|	while(rrset && rrset->section == LDNS_SECTION_ANSWER) {
  ------------------
  |  Branch (762:8): [True: 5.45k, False: 498]
  |  Branch (762:17): [True: 4.17k, False: 1.27k]
  ------------------
  763|  4.17k|		if(dname_pkt_compare(pkt, qinfo->qname, rrset->dname) != 0) {
  ------------------
  |  Branch (763:6): [True: 3.69k, False: 480]
  ------------------
  764|  3.69k|			if(has_additional(rrset->type)) del_addi = 1;
  ------------------
  |  Branch (764:7): [True: 491, False: 3.20k]
  ------------------
  765|  3.69k|			remove_rrset("sanitize: removing extraneous answer "
  766|  3.69k|				"RRset:", pkt, msg, prev, &rrset);
  767|  3.69k|			continue;
  768|  3.69k|		}
  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.77k|	prev = NULL;
  781|  1.77k|	rrset = msg->rrset_first;
  782|  48.9k|	while(rrset) {
  ------------------
  |  Branch (782:8): [True: 47.1k, False: 1.77k]
  ------------------
  783|       |
  784|       |		/* remove private addresses */
  785|  47.1k|		if( (rrset->type == LDNS_RR_TYPE_A || 
  ------------------
  |  Branch (785:8): [True: 13.1k, False: 34.0k]
  ------------------
  786|  47.1k|			rrset->type == LDNS_RR_TYPE_AAAA)) {
  ------------------
  |  Branch (786:4): [True: 1.87k, False: 32.2k]
  ------------------
  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|  14.9k|			if(priv_rrset_bad(ie->priv, pkt, rrset)) {
  ------------------
  |  Branch (792:7): [True: 0, False: 14.9k]
  ------------------
  793|      0|				remove_rrset(NULL, pkt, msg, prev, &rrset);
  794|      0|				continue;
  795|      0|			}
  796|  14.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|  47.1k|		if(!pkt_sub(pkt, rrset->dname, zonename)) {
  ------------------
  |  Branch (805:6): [True: 44.7k, False: 2.41k]
  ------------------
  806|  44.7k|			if(msg->an_rrsets == 0 && 
  ------------------
  |  Branch (806:7): [True: 42.5k, False: 2.21k]
  ------------------
  807|  44.7k|				rrset->type == LDNS_RR_TYPE_NS && 
  ------------------
  |  Branch (807:5): [True: 1.23k, False: 41.3k]
  ------------------
  808|  44.7k|				rrset->section == LDNS_SECTION_AUTHORITY &&
  ------------------
  |  Branch (808:5): [True: 533, False: 703]
  ------------------
  809|  44.7k|				FLAGS_GET_RCODE(msg->flags) == 
  ------------------
  |  |   74|    533|#define FLAGS_GET_RCODE(f) ((f) & 0xf)
  ------------------
  |  Branch (809:5): [True: 133, False: 400]
  ------------------
  810|    533|				LDNS_RCODE_NOERROR && !soa_in_auth(msg) &&
  ------------------
  |  Branch (810:27): [True: 133, False: 0]
  ------------------
  811|  44.7k|				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|  44.6k|			} else if(!env->cfg->harden_glue && (
  ------------------
  |  Branch (819:14): [True: 44.6k, False: 0]
  ------------------
  820|  44.6k|				rrset->type == LDNS_RR_TYPE_A ||
  ------------------
  |  Branch (820:5): [True: 13.1k, False: 31.5k]
  ------------------
  821|  44.6k|				rrset->type == LDNS_RR_TYPE_AAAA)) {
  ------------------
  |  Branch (821:5): [True: 1.87k, False: 29.6k]
  ------------------
  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|  14.9k|				store_rrset(pkt, msg, env, rrset);
  826|  14.9k|				remove_rrset("sanitize: storing potential "
  827|  14.9k|				"poison RRset:", pkt, msg, prev, &rrset);
  828|  14.9k|				continue;
  829|  29.6k|			} else {
  830|  29.6k|				if(has_additional(rrset->type)) del_addi = 1;
  ------------------
  |  Branch (830:8): [True: 4.00k, False: 25.6k]
  ------------------
  831|  29.6k|				remove_rrset("sanitize: removing potential "
  832|  29.6k|				"poison RRset:", pkt, msg, prev, &rrset);
  833|  29.6k|				continue;
  834|  29.6k|			}
  835|  44.7k|		}
  836|  2.54k|		if(del_addi && rrset->section == LDNS_SECTION_ADDITIONAL) {
  ------------------
  |  Branch (836:6): [True: 1.41k, False: 1.13k]
  |  Branch (836:18): [True: 264, False: 1.14k]
  ------------------
  837|    264|			remove_rrset("sanitize: removing potential "
  838|    264|			"poison reference RRset:", pkt, msg, prev, &rrset);
  839|    264|			continue;
  840|    264|		}
  841|       |		/* check if right hand side of NSEC is within zone */
  842|  2.28k|		if(rrset->type == LDNS_RR_TYPE_NSEC &&
  ------------------
  |  Branch (842:6): [True: 801, False: 1.48k]
  ------------------
  843|  2.28k|			sanitize_nsec_is_overreach(pkt, rrset, zonename)) {
  ------------------
  |  Branch (843:4): [True: 385, False: 416]
  ------------------
  844|    385|			remove_rrset("sanitize: removing overreaching NSEC "
  845|    385|				"RRset:", pkt, msg, prev, &rrset);
  846|    385|			continue;
  847|    385|		}
  848|  1.89k|		prev = rrset;
  849|  1.89k|		rrset = rrset->rrset_all_next;
  850|  1.89k|	}
  851|  1.77k|	return 1;
  852|  1.77k|}
iter_scrub.c:pkt_sub:
  322|  48.4k|{
  323|  48.4k|	uint8_t buf[LDNS_MAX_DOMAINLEN+1];
  324|  48.4k|	dname_pkt_copy(pkt, buf, comprname);
  325|  48.4k|	return dname_subdomain_c(buf, zone);
  326|  48.4k|}
iter_scrub.c:store_rrset:
  656|  14.9k|{
  657|  14.9k|	struct ub_packed_rrset_key* k;
  658|  14.9k|	struct packed_rrset_data* d;
  659|  14.9k|	struct rrset_ref ref;
  660|  14.9k|	time_t now = *env->now;
  661|       |
  662|  14.9k|	k = alloc_special_obtain(env->alloc);
  663|  14.9k|	if(!k)
  ------------------
  |  Branch (663:5): [True: 0, False: 14.9k]
  ------------------
  664|      0|		return;
  665|  14.9k|	k->entry.data = NULL;
  666|  14.9k|	if(!parse_copy_decompress_rrset(pkt, msg, rrset, NULL, k)) {
  ------------------
  |  Branch (666:5): [True: 0, False: 14.9k]
  ------------------
  667|      0|		alloc_special_release(env->alloc, k);
  668|      0|		return;
  669|      0|	}
  670|  14.9k|	d = (struct packed_rrset_data*)k->entry.data;
  671|  14.9k|	packed_rrset_ttl_add(d, now);
  672|  14.9k|	ref.key = k;
  673|  14.9k|	ref.id = k->id;
  674|       |	/*ignore ret: it was in the cache, ref updated */
  675|  14.9k|	(void)rrset_cache_update(env->rrset_cache, &ref, env->alloc, now);
  676|  14.9k|}
iter_scrub.c:sanitize_nsec_is_overreach:
  687|    801|{
  688|    801|	struct rr_parse* rr;
  689|    801|	uint8_t* rhs;
  690|    801|	size_t len;
  691|    801|	log_assert(rrset->type == LDNS_RR_TYPE_NSEC);
  692|  1.79k|	for(rr = rrset->rr_first; rr; rr = rr->next) {
  ------------------
  |  Branch (692:28): [True: 1.38k, False: 416]
  ------------------
  693|  1.38k|		size_t pos = sldns_buffer_position(pkt);
  694|  1.38k|		size_t rhspos;
  695|  1.38k|		rhs = rr->ttl_data+4+2;
  696|  1.38k|		len = sldns_read_uint16(rr->ttl_data+4);
  697|  1.38k|		rhspos = rhs-sldns_buffer_begin(pkt);
  698|  1.38k|		sldns_buffer_set_position(pkt, rhspos);
  699|  1.38k|		if(pkt_dname_len(pkt) == 0) {
  ------------------
  |  Branch (699:6): [True: 14, False: 1.36k]
  ------------------
  700|       |			/* malformed */
  701|     14|			sldns_buffer_set_position(pkt, pos);
  702|     14|			return 1;
  703|     14|		}
  704|  1.36k|		if(sldns_buffer_position(pkt)-rhspos > len) {
  ------------------
  |  Branch (704:6): [True: 184, False: 1.18k]
  ------------------
  705|       |			/* outside of rdata boundaries */
  706|    184|			sldns_buffer_set_position(pkt, pos);
  707|    184|			return 1;
  708|    184|		}
  709|  1.18k|		sldns_buffer_set_position(pkt, pos);
  710|  1.18k|		if(!pkt_sub(pkt, rhs, zonename)) {
  ------------------
  |  Branch (710:6): [True: 187, False: 998]
  ------------------
  711|       |			/* overreaching */
  712|    187|			return 1;
  713|    187|		}
  714|  1.18k|	}
  715|       |	/* all NSEC RRs OK */
  716|    416|	return 0;
  717|    801|}

rrset_markdel:
   55|    341|{
   56|    341|	struct ub_packed_rrset_key* r = (struct ub_packed_rrset_key*)key;
   57|    341|	r->id = 0;
   58|    341|}
rrset_cache_create:
   62|  4.66k|{
   63|  4.66k|	size_t slabs = (cfg?cfg->rrset_cache_slabs:HASH_DEFAULT_SLABS);
  ------------------
  |  |   49|      0|#define HASH_DEFAULT_SLABS 4
  ------------------
  |  Branch (63:18): [True: 4.66k, False: 0]
  ------------------
   64|  4.66k|	size_t startarray = HASH_DEFAULT_STARTARRAY;
  ------------------
  |  |  114|  4.66k|#define HASH_DEFAULT_STARTARRAY		1024 /* entries in array */
  ------------------
   65|  4.66k|	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.66k, False: 0]
  ------------------
   66|       |
   67|  4.66k|	struct rrset_cache *r = (struct rrset_cache*)slabhash_create(slabs,
   68|  4.66k|		startarray, maxmem, ub_rrset_sizefunc, ub_rrset_compare,
   69|  4.66k|		ub_rrset_key_delete, rrset_data_delete, alloc);
   70|  4.66k|	slabhash_setmarkdel(&r->table, &rrset_markdel);
   71|  4.66k|	return r;
   72|  4.66k|}
rrset_cache_delete:
   75|  4.66k|{
   76|  4.66k|	if(!r) 
  ------------------
  |  Branch (76:5): [True: 0, False: 4.66k]
  ------------------
   77|      0|		return;
   78|  4.66k|	slabhash_delete(&r->table);
   79|       |	/* slabhash delete also does free(r), since table is first in struct*/
   80|  4.66k|}
rrset_cache_update:
  188|  14.9k|{
  189|  14.9k|	struct lruhash_entry* e;
  190|  14.9k|	struct ub_packed_rrset_key* k = ref->key;
  191|  14.9k|	hashvalue_type h = k->entry.hash;
  192|  14.9k|	uint16_t rrset_type = ntohs(k->rk.type);
  193|  14.9k|	int equal = 0;
  194|  14.9k|	log_assert(ref->id != 0 && k->id != 0);
  195|  14.9k|	log_assert(k->rk.dname != NULL);
  196|       |	/* looks up item with a readlock - no editing! */
  197|  14.9k|	if((e=slabhash_lookup(&r->table, h, k, 0)) != 0) {
  ------------------
  |  Branch (197:5): [True: 0, False: 14.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|  14.9k|	log_assert(ref->key->id != 0);
  227|  14.9k|	slabhash_insert(&r->table, h, &k->entry, k->entry.data, alloc);
  228|  14.9k|	if(e) {
  ------------------
  |  Branch (228:5): [True: 0, False: 14.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|  14.9k|	return 0;
  240|  14.9k|}

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

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

dname.c:sldns_buffer_remaining:
  394|  4.65M|{
  395|  4.65M|	return sldns_buffer_remaining_at(buffer, buffer->_position);
  396|  4.65M|}
dname.c:sldns_buffer_remaining_at:
  380|  4.65M|{
  381|  4.65M|	sldns_buffer_invariant(buffer);
  382|  4.65M|	assert(at <= buffer->_limit);
  383|  4.65M|	return at < buffer->_limit ? buffer->_limit - at : 0;
  ------------------
  |  Branch (383:9): [True: 4.65M, False: 1.41k]
  ------------------
  384|  4.65M|}
dname.c:sldns_buffer_invariant:
  143|  4.65M|{
  144|  4.65M|}
dname.c:sldns_buffer_read_u8:
  638|  4.51M|{
  639|  4.51M|	uint8_t result = sldns_buffer_read_u8_at(buffer, buffer->_position);
  640|  4.51M|	buffer->_position += sizeof(uint8_t);
  641|  4.51M|	return result;
  642|  4.51M|}
dname.c:sldns_buffer_read_u8_at:
  626|  4.51M|{
  627|  4.51M|	assert(sldns_buffer_available_at(buffer, at, sizeof(uint8_t)));
  628|  4.51M|	return buffer->_data[at];
  629|  4.51M|}
dname.c:sldns_buffer_skip:
  259|   146k|{
  260|   146k|	assert(buffer->_position + count <= buffer->_limit);
  261|   146k|	buffer->_position += count;
  262|   146k|}
dname.c:sldns_buffer_limit:
  271|   280k|{
  272|   280k|	return buffer->_limit;
  273|   280k|}
dname.c:sldns_buffer_at:
  331|   151k|{
  332|   151k|	assert(at <= buffer->_limit);
  333|   151k|	return buffer->_data + at;
  334|   151k|}
dname.c:sldns_buffer_position:
  233|  53.4k|{
  234|  53.4k|	return buffer->_position;
  235|  53.4k|}
dname.c:sldns_buffer_set_position:
  245|   181k|{
  246|   181k|	assert(mark <= buffer->_limit);
  247|   181k|	buffer->_position = mark;
  248|   181k|}
msgparse.c:sldns_buffer_remaining:
  394|  11.1M|{
  395|  11.1M|	return sldns_buffer_remaining_at(buffer, buffer->_position);
  396|  11.1M|}
msgparse.c:sldns_buffer_remaining_at:
  380|  11.1M|{
  381|  11.1M|	sldns_buffer_invariant(buffer);
  382|  11.1M|	assert(at <= buffer->_limit);
  383|  11.1M|	return at < buffer->_limit ? buffer->_limit - at : 0;
  ------------------
  |  Branch (383:9): [True: 11.1M, False: 3.55k]
  ------------------
  384|  11.1M|}
msgparse.c:sldns_buffer_invariant:
  143|  11.1M|{
  144|  11.1M|}
msgparse.c:sldns_buffer_read:
  613|  4.03M|{
  614|  4.03M|	sldns_buffer_read_at(buffer, buffer->_position, data, count);
  615|  4.03M|	buffer->_position += count;
  616|  4.03M|}
msgparse.c:sldns_buffer_read_at:
  600|  4.03M|{
  601|  4.03M|	assert(sldns_buffer_available_at(buffer, at, count));
  602|  4.03M|	memcpy(data, buffer->_data + at, count);
  603|  4.03M|}
msgparse.c:sldns_buffer_read_u16:
  664|  10.9M|{
  665|  10.9M|	uint16_t result = sldns_buffer_read_u16_at(buffer, buffer->_position);
  666|  10.9M|	buffer->_position += sizeof(uint16_t);
  667|  10.9M|	return result;
  668|  10.9M|}
msgparse.c:sldns_buffer_read_u16_at:
  652|  10.9M|{
  653|  10.9M|	assert(sldns_buffer_available_at(buffer, at, sizeof(uint16_t)));
  654|  10.9M|	return sldns_read_uint16(buffer->_data + at);
  655|  10.9M|}
msgparse.c:sldns_buffer_limit:
  271|  7.54k|{
  272|  7.54k|	return buffer->_limit;
  273|  7.54k|}
msgparse.c:sldns_buffer_at:
  331|  10.0M|{
  332|  10.0M|	assert(at <= buffer->_limit);
  333|  10.0M|	return buffer->_data + at;
  334|  10.0M|}
msgparse.c:sldns_buffer_position:
  233|  2.43M|{
  234|  2.43M|	return buffer->_position;
  235|  2.43M|}
msgparse.c:sldns_buffer_skip:
  259|  10.5M|{
  260|  10.5M|	assert(buffer->_position + count <= buffer->_limit);
  261|  10.5M|	buffer->_position += count;
  262|  10.5M|}
msgparse.c:sldns_buffer_set_position:
  245|  4.10M|{
  246|  4.10M|	assert(mark <= buffer->_limit);
  247|  4.10M|	buffer->_position = mark;
  248|  4.10M|}
msgparse.c:sldns_read_uint16:
   36|  11.0M|{
   37|       |#ifdef ALLOW_UNALIGNED_ACCESSES
   38|       |        return ntohs(*(const uint16_t *) src);
   39|       |#else
   40|  11.0M|        const uint8_t *p = (const uint8_t *) src;
   41|  11.0M|        return ((uint16_t) p[0] << 8) | (uint16_t) p[1];
   42|  11.0M|#endif
   43|  11.0M|}
msgparse.c:sldns_buffer_begin:
  344|  1.82M|{
  345|  1.82M|	return sldns_buffer_at(buffer, 0);
  346|  1.82M|}
msgparse.c:sldns_buffer_read_u8:
  638|  10.2k|{
  639|  10.2k|	uint8_t result = sldns_buffer_read_u8_at(buffer, buffer->_position);
  640|  10.2k|	buffer->_position += sizeof(uint8_t);
  641|  10.2k|	return result;
  642|  10.2k|}
msgparse.c:sldns_buffer_read_u8_at:
  626|  10.2k|{
  627|  10.2k|	assert(sldns_buffer_available_at(buffer, at, sizeof(uint8_t)));
  628|  10.2k|	return buffer->_data[at];
  629|  10.2k|}
msgparse.c:sldns_buffer_current:
  367|  8.22M|{
  368|  8.22M|	return sldns_buffer_at(buffer, buffer->_position);
  369|  8.22M|}
msgreply.c:sldns_read_uint32:
   47|  2.65M|{
   48|       |#ifdef ALLOW_UNALIGNED_ACCESSES
   49|       |        return ntohl(*(const uint32_t *) src);
   50|       |#else
   51|  2.65M|        const uint8_t *p = (const uint8_t *) src;
   52|  2.65M|        return (  ((uint32_t) p[0] << 24)
   53|  2.65M|                | ((uint32_t) p[1] << 16)
   54|  2.65M|                | ((uint32_t) p[2] << 8)
   55|  2.65M|                |  (uint32_t) p[3]);
   56|  2.65M|#endif
   57|  2.65M|}
msgreply.c:sldns_buffer_set_position:
  245|  2.65M|{
  246|  2.65M|	assert(mark <= buffer->_limit);
  247|  2.65M|	buffer->_position = mark;
  248|  2.65M|}
msgreply.c:sldns_buffer_begin:
  344|  2.65M|{
  345|  2.65M|	return sldns_buffer_at(buffer, 0);
  346|  2.65M|}
msgreply.c:sldns_buffer_at:
  331|  2.73M|{
  332|  2.73M|	assert(at <= buffer->_limit);
  333|  2.73M|	return buffer->_data + at;
  334|  2.73M|}
msgreply.c:sldns_read_uint16:
   36|  2.65M|{
   37|       |#ifdef ALLOW_UNALIGNED_ACCESSES
   38|       |        return ntohs(*(const uint16_t *) src);
   39|       |#else
   40|  2.65M|        const uint8_t *p = (const uint8_t *) src;
   41|  2.65M|        return ((uint16_t) p[0] << 8) | (uint16_t) p[1];
   42|  2.65M|#endif
   43|  2.65M|}
msgreply.c:sldns_buffer_position:
  233|  16.9k|{
  234|  16.9k|	return buffer->_position;
  235|  16.9k|}
msgreply.c:sldns_buffer_skip:
  259|  59.4k|{
  260|  59.4k|	assert(buffer->_position + count <= buffer->_limit);
  261|  59.4k|	buffer->_position += count;
  262|  59.4k|}
msgreply.c:sldns_buffer_current:
  367|  74.2k|{
  368|  74.2k|	return sldns_buffer_at(buffer, buffer->_position);
  369|  74.2k|}
msgreply.c:sldns_buffer_remaining:
  394|  2.65M|{
  395|  2.65M|	return sldns_buffer_remaining_at(buffer, buffer->_position);
  396|  2.65M|}
msgreply.c:sldns_buffer_remaining_at:
  380|  2.65M|{
  381|  2.65M|	sldns_buffer_invariant(buffer);
  382|  2.65M|	assert(at <= buffer->_limit);
  383|  2.65M|	return at < buffer->_limit ? buffer->_limit - at : 0;
  ------------------
  |  Branch (383:9): [True: 2.65M, False: 262]
  ------------------
  384|  2.65M|}
msgreply.c:sldns_buffer_invariant:
  143|  2.65M|{
  144|  2.65M|}
msgreply.c:sldns_buffer_read_u16:
  664|  2.65M|{
  665|  2.65M|	uint16_t result = sldns_buffer_read_u16_at(buffer, buffer->_position);
  666|  2.65M|	buffer->_position += sizeof(uint16_t);
  667|  2.65M|	return result;
  668|  2.65M|}
msgreply.c:sldns_buffer_read_u16_at:
  652|  2.65M|{
  653|  2.65M|	assert(sldns_buffer_available_at(buffer, at, sizeof(uint16_t)));
  654|  2.65M|	return sldns_read_uint16(buffer->_data + at);
  655|  2.65M|}
iter_scrub.c:sldns_buffer_position:
  233|  6.33k|{
  234|  6.33k|	return buffer->_position;
  235|  6.33k|}
iter_scrub.c:sldns_buffer_set_position:
  245|  9.92k|{
  246|  9.92k|	assert(mark <= buffer->_limit);
  247|  9.92k|	buffer->_position = mark;
  248|  9.92k|}
iter_scrub.c:sldns_buffer_begin:
  344|  4.96k|{
  345|  4.96k|	return sldns_buffer_at(buffer, 0);
  346|  4.96k|}
iter_scrub.c:sldns_buffer_at:
  331|  4.96k|{
  332|  4.96k|	assert(at <= buffer->_limit);
  333|  4.96k|	return buffer->_data + at;
  334|  4.96k|}
iter_scrub.c:sldns_write_uint32:
   77|    600|{
   78|       |#ifdef ALLOW_UNALIGNED_ACCESSES
   79|       |        * (uint32_t *) dst = htonl(data);
   80|       |#else
   81|    600|        uint8_t *p = (uint8_t *) dst;
   82|    600|        p[0] = (uint8_t) ((data >> 24) & 0xff);
   83|    600|        p[1] = (uint8_t) ((data >> 16) & 0xff);
   84|    600|        p[2] = (uint8_t) ((data >> 8) & 0xff);
   85|    600|        p[3] = (uint8_t) (data & 0xff);
   86|    600|#endif
   87|    600|}
iter_scrub.c:sldns_write_uint16:
   65|    600|{
   66|       |#ifdef ALLOW_UNALIGNED_ACCESSES
   67|       |        * (uint16_t *) dst = htons(data);
   68|       |#else
   69|    600|        uint8_t *p = (uint8_t *) dst;
   70|    600|        p[0] = (uint8_t) ((data >> 8) & 0xff);
   71|    600|        p[1] = (uint8_t) (data & 0xff);
   72|    600|#endif
   73|    600|}
iter_scrub.c:sldns_read_uint16:
   36|  7.66k|{
   37|       |#ifdef ALLOW_UNALIGNED_ACCESSES
   38|       |        return ntohs(*(const uint16_t *) src);
   39|       |#else
   40|  7.66k|        const uint8_t *p = (const uint8_t *) src;
   41|  7.66k|        return ((uint16_t) p[0] << 8) | (uint16_t) p[1];
   42|  7.66k|#endif
   43|  7.66k|}
sbuffer.c:sldns_buffer_invariant:
  143|  9.33k|{
  144|  9.33k|}

alloc_init:
  105|  4.66k|{
  106|  4.66k|	memset(alloc, 0, sizeof(*alloc));
  107|  4.66k|	alloc->super = super;
  108|  4.66k|	alloc->thread_num = thread_num;
  109|  4.66k|	alloc->next_id = (uint64_t)thread_num; 	/* in steps, so that type */
  110|  4.66k|	alloc->next_id <<= THRNUM_SHIFT; 	/* of *_id is used. */
  ------------------
  |  |   51|  4.66k|#define THRNUM_SHIFT	48	/* for 65k threads, 2^48 rrsets per thr. */
  ------------------
  111|  4.66k|	alloc->last_id = 1; 			/* so no 64bit constants, */
  112|  4.66k|	alloc->last_id <<= THRNUM_SHIFT; 	/* or implicit 'int' ops. */
  ------------------
  |  |   51|  4.66k|#define THRNUM_SHIFT	48	/* for 65k threads, 2^48 rrsets per thr. */
  ------------------
  113|  4.66k|	alloc->last_id -= 1; 			/* for compiler portability. */
  114|  4.66k|	alloc->last_id |= alloc->next_id;
  115|  4.66k|	alloc->next_id += 1;			/* because id=0 is special. */
  116|  4.66k|	alloc->max_reg_blocks = 100;
  117|  4.66k|	alloc->num_reg_blocks = 0;
  118|  4.66k|	alloc->reg_list = NULL;
  119|  4.66k|	alloc->cleanup = NULL;
  120|  4.66k|	alloc->cleanup_arg = NULL;
  121|  4.66k|	if(alloc->super)
  ------------------
  |  Branch (121:5): [True: 0, False: 4.66k]
  ------------------
  122|      0|		prealloc_blocks(alloc, alloc->max_reg_blocks);
  123|  4.66k|	if(!alloc->super) {
  ------------------
  |  Branch (123:5): [True: 4.66k, False: 0]
  ------------------
  124|  4.66k|		lock_quick_init(&alloc->lock);
  ------------------
  |  |  143|  4.66k|#define lock_quick_init(lock) LOCKRET(pthread_spin_init(lock, PTHREAD_PROCESS_PRIVATE))
  |  |  ------------------
  |  |  |  |   67|  4.66k|#define LOCKRET(func) do {\
  |  |  |  |   68|  4.66k|	int lockret_err;		\
  |  |  |  |   69|  4.66k|	if( (lockret_err=(func)) != 0)		\
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (69:6): [True: 0, False: 4.66k]
  |  |  |  |  ------------------
  |  |  |  |   70|  4.66k|		log_err("%s at %d could not " #func ": %s", \
  |  |  |  |   71|      0|		__FILE__, __LINE__, strerror(lockret_err));	\
  |  |  |  |   72|  4.66k| 	} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (72:11): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  125|  4.66k|		lock_protect(&alloc->lock, alloc, sizeof(*alloc));
  126|  4.66k|	}
  127|  4.66k|}
alloc_clear:
  161|  4.66k|{
  162|  4.66k|	alloc_special_type* p;
  163|  4.66k|	struct regional* r, *nr;
  164|  4.66k|	if(!alloc)
  ------------------
  |  Branch (164:5): [True: 0, False: 4.66k]
  ------------------
  165|      0|		return;
  166|  4.66k|	if(!alloc->super) {
  ------------------
  |  Branch (166:5): [True: 4.66k, False: 0]
  ------------------
  167|  4.66k|		lock_quick_destroy(&alloc->lock);
  ------------------
  |  |  144|  4.66k|#define lock_quick_destroy(lock) LOCKRET(pthread_spin_destroy(lock))
  |  |  ------------------
  |  |  |  |   67|  4.66k|#define LOCKRET(func) do {\
  |  |  |  |   68|  4.66k|	int lockret_err;		\
  |  |  |  |   69|  4.66k|	if( (lockret_err=(func)) != 0)		\
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (69:6): [True: 0, False: 4.66k]
  |  |  |  |  ------------------
  |  |  |  |   70|  4.66k|		log_err("%s at %d could not " #func ": %s", \
  |  |  |  |   71|      0|		__FILE__, __LINE__, strerror(lockret_err));	\
  |  |  |  |   72|  4.66k| 	} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (72:11): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  168|  4.66k|	}
  169|  4.66k|	if(alloc->super && alloc->quar) {
  ------------------
  |  Branch (169:5): [True: 0, False: 4.66k]
  |  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.66k|	} else {
  180|  4.66k|		alloc_clear_special_list(alloc);
  181|  4.66k|	}
  182|  4.66k|	alloc->quar = 0;
  183|  4.66k|	alloc->num_quar = 0;
  184|  4.66k|	r = alloc->reg_list;
  185|  4.66k|	while(r) {
  ------------------
  |  Branch (185:8): [True: 0, False: 4.66k]
  ------------------
  186|      0|		nr = (struct regional*)r->next;
  187|      0|		free(r);
  188|      0|		r = nr;
  189|      0|	}
  190|  4.66k|	alloc->reg_list = NULL;
  191|  4.66k|	alloc->num_reg_blocks = 0;
  192|  4.66k|}
alloc_get_id:
  196|  14.9k|{
  197|  14.9k|	uint64_t id = alloc->next_id++;
  198|  14.9k|	if(id == alloc->last_id) {
  ------------------
  |  Branch (198:5): [True: 0, False: 14.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|  14.9k|	return id;
  211|  14.9k|}
alloc_special_obtain:
  215|  14.9k|{
  216|  14.9k|	alloc_special_type* p;
  217|  14.9k|	log_assert(alloc);
  218|       |	/* see if in local cache */
  219|  14.9k|	if(alloc->quar) {
  ------------------
  |  Branch (219:5): [True: 13.2k, False: 1.75k]
  ------------------
  220|  13.2k|		p = alloc->quar;
  221|  13.2k|		alloc->quar = alloc_special_next(p);
  ------------------
  |  |   60|  13.2k|#define alloc_special_next(x) ((alloc_special_type*)((x)->entry.overflow_next))
  ------------------
  222|  13.2k|		alloc->num_quar--;
  223|  13.2k|		p->id = alloc_get_id(alloc);
  224|  13.2k|		return p;
  225|  13.2k|	}
  226|       |	/* see if in global cache */
  227|  1.75k|	if(alloc->super) {
  ------------------
  |  Branch (227:5): [True: 0, False: 1.75k]
  ------------------
  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.75k|	prealloc_setup(alloc);
  243|  1.75k|	if(!(p = (alloc_special_type*)malloc(sizeof(alloc_special_type)))) {
  ------------------
  |  Branch (243:5): [True: 0, False: 1.75k]
  ------------------
  244|      0|		log_err("alloc_special_obtain: out of memory");
  245|      0|		return NULL;
  246|      0|	}
  247|  1.75k|	alloc_setup_special(p);
  248|  1.75k|	p->id = alloc_get_id(alloc);
  249|  1.75k|	return p;
  250|  1.75k|}
alloc_special_release:
  280|  14.9k|{
  281|  14.9k|	log_assert(alloc);
  282|  14.9k|	if(!mem)
  ------------------
  |  Branch (282:5): [True: 0, False: 14.9k]
  ------------------
  283|      0|		return;
  284|  14.9k|	if(!alloc->super) { 
  ------------------
  |  Branch (284:5): [True: 14.9k, False: 0]
  ------------------
  285|  14.9k|		lock_quick_lock(&alloc->lock); /* superalloc needs locking */
  ------------------
  |  |  145|  14.9k|#define lock_quick_lock(lock) LOCKRET(pthread_spin_lock(lock))
  |  |  ------------------
  |  |  |  |   67|  14.9k|#define LOCKRET(func) do {\
  |  |  |  |   68|  14.9k|	int lockret_err;		\
  |  |  |  |   69|  14.9k|	if( (lockret_err=(func)) != 0)		\
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (69:6): [True: 0, False: 14.9k]
  |  |  |  |  ------------------
  |  |  |  |   70|  14.9k|		log_err("%s at %d could not " #func ": %s", \
  |  |  |  |   71|      0|		__FILE__, __LINE__, strerror(lockret_err));	\
  |  |  |  |   72|  14.9k| 	} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (72:11): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  286|  14.9k|	}
  287|       |
  288|  14.9k|	alloc_special_clean(mem);
  ------------------
  |  |   58|  14.9k|#define alloc_special_clean(x) (x)->id = 0;
  ------------------
  289|  14.9k|	if(alloc->super && alloc->num_quar >= ALLOC_SPECIAL_MAX) {
  ------------------
  |  |   66|      0|#define ALLOC_SPECIAL_MAX 10
  ------------------
  |  Branch (289:5): [True: 0, False: 14.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|  14.9k|	alloc_set_special_next(mem, alloc->quar);
  ------------------
  |  |   63|  14.9k|	((x)->entry.overflow_next) = (struct lruhash_entry*)(y);
  ------------------
  296|  14.9k|	alloc->quar = mem;
  297|  14.9k|	alloc->num_quar++;
  298|  14.9k|	if(!alloc->super) {
  ------------------
  |  Branch (298:5): [True: 14.9k, False: 0]
  ------------------
  299|  14.9k|		lock_quick_unlock(&alloc->lock);
  ------------------
  |  |  146|  14.9k|#define lock_quick_unlock(lock) LOCKRET(pthread_spin_unlock(lock))
  |  |  ------------------
  |  |  |  |   67|  14.9k|#define LOCKRET(func) do {\
  |  |  |  |   68|  14.9k|	int lockret_err;		\
  |  |  |  |   69|  14.9k|	if( (lockret_err=(func)) != 0)		\
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (69:6): [True: 0, False: 14.9k]
  |  |  |  |  ------------------
  |  |  |  |   70|  14.9k|		log_err("%s at %d could not " #func ": %s", \
  |  |  |  |   71|      0|		__FILE__, __LINE__, strerror(lockret_err));	\
  |  |  |  |   72|  14.9k| 	} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (72:11): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  300|  14.9k|	}
  301|  14.9k|}
alloc.c:alloc_clear_special_list:
  132|  4.66k|{
  133|  4.66k|	alloc_special_type* p, *np;
  134|       |	/* free */
  135|  4.66k|	p = alloc->quar;
  136|  23.9k|	while(p) {
  ------------------
  |  Branch (136:8): [True: 19.3k, False: 4.66k]
  ------------------
  137|  19.3k|		np = alloc_special_next(p);
  ------------------
  |  |   60|  19.3k|#define alloc_special_next(x) ((alloc_special_type*)((x)->entry.overflow_next))
  ------------------
  138|       |		/* deinit special type */
  139|  19.3k|		lock_rw_destroy(&p->entry.lock);
  ------------------
  |  |  118|  19.3k|#define lock_rw_destroy(lock) LOCKRET(pthread_rwlock_destroy(lock))
  |  |  ------------------
  |  |  |  |   67|  19.3k|#define LOCKRET(func) do {\
  |  |  |  |   68|  19.3k|	int lockret_err;		\
  |  |  |  |   69|  19.3k|	if( (lockret_err=(func)) != 0)		\
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (69:6): [True: 0, False: 19.3k]
  |  |  |  |  ------------------
  |  |  |  |   70|  19.3k|		log_err("%s at %d could not " #func ": %s", \
  |  |  |  |   71|      0|		__FILE__, __LINE__, strerror(lockret_err));	\
  |  |  |  |   72|  19.3k| 	} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (72:11): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  140|  19.3k|		free(p);
  141|  19.3k|		p = np;
  142|  19.3k|	}
  143|  4.66k|}
alloc.c:prealloc_setup:
   68|  1.75k|{
   69|  1.75k|	alloc_special_type* p;
   70|  1.75k|	int i;
   71|  19.3k|	for(i=0; i<ALLOC_SPECIAL_MAX; i++) {
  ------------------
  |  |   66|  19.3k|#define ALLOC_SPECIAL_MAX 10
  ------------------
  |  Branch (71:11): [True: 17.5k, False: 1.75k]
  ------------------
   72|  17.5k|		if(!(p = (alloc_special_type*)malloc(
  ------------------
  |  Branch (72:6): [True: 0, False: 17.5k]
  ------------------
   73|  17.5k|			sizeof(alloc_special_type)))) {
   74|      0|			log_err("prealloc: out of memory");
   75|      0|			return;
   76|      0|		}
   77|  17.5k|		alloc_setup_special(p);
   78|  17.5k|		alloc_set_special_next(p, alloc->quar);
  ------------------
  |  |   63|  17.5k|	((x)->entry.overflow_next) = (struct lruhash_entry*)(y);
  ------------------
   79|  17.5k|		alloc->quar = p;
   80|  17.5k|		alloc->num_quar++;
   81|  17.5k|	}
   82|  1.75k|}
alloc.c:alloc_setup_special:
   56|  19.3k|{
   57|  19.3k|	memset(t, 0, sizeof(*t));
   58|  19.3k|	lock_rw_init(&t->entry.lock);
  ------------------
  |  |  117|  19.3k|#define lock_rw_init(lock) LOCKRET(pthread_rwlock_init(lock, NULL))
  |  |  ------------------
  |  |  |  |   67|  19.3k|#define LOCKRET(func) do {\
  |  |  |  |   68|  19.3k|	int lockret_err;		\
  |  |  |  |   69|  19.3k|	if( (lockret_err=(func)) != 0)		\
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (69:6): [True: 0, False: 19.3k]
  |  |  |  |  ------------------
  |  |  |  |   70|  19.3k|		log_err("%s at %d could not " #func ": %s", \
  |  |  |  |   71|      0|		__FILE__, __LINE__, strerror(lockret_err));	\
  |  |  |  |   72|  19.3k| 	} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (72:11): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
   59|  19.3k|	t->entry.key = t;
   60|  19.3k|}

query_dname_compare:
  101|     64|{
  102|     64|	register uint8_t lab1, lab2;
  103|     64|	log_assert(d1 && d2);
  104|     64|	lab1 = *d1++;
  105|     64|	lab2 = *d2++;
  106|    402|	while( lab1 != 0 || lab2 != 0 ) {
  ------------------
  |  Branch (106:9): [True: 356, False: 46]
  |  Branch (106:22): [True: 0, False: 46]
  ------------------
  107|       |		/* compare label length */
  108|       |		/* if one dname ends, it has labellength 0 */
  109|    356|		if(lab1 != lab2) {
  ------------------
  |  Branch (109:6): [True: 0, False: 356]
  ------------------
  110|      0|			if(lab1 < lab2)
  ------------------
  |  Branch (110:7): [True: 0, False: 0]
  ------------------
  111|      0|				return -1;
  112|      0|			return 1;
  113|      0|		}
  114|    356|		log_assert(lab1 == lab2 && lab1 != 0);
  115|       |		/* compare lowercased labels. */
  116|  7.11k|		while(lab1--) {
  ------------------
  |  Branch (116:9): [True: 6.78k, False: 338]
  ------------------
  117|       |			/* compare bytes first for speed */
  118|  6.78k|			if(*d1 != *d2 && 
  ------------------
  |  Branch (118:7): [True: 26, False: 6.75k]
  ------------------
  119|  6.78k|				tolower((unsigned char)*d1) != tolower((unsigned char)*d2)) {
  ------------------
  |  Branch (119:5): [True: 18, False: 8]
  ------------------
  120|     18|				if(tolower((unsigned char)*d1) < tolower((unsigned char)*d2))
  ------------------
  |  Branch (120:8): [True: 10, False: 8]
  ------------------
  121|     10|					return -1;
  122|      8|				return 1;
  123|     18|			}
  124|  6.76k|			d1++;
  125|  6.76k|			d2++;
  126|  6.76k|		}
  127|       |		/* next pair of labels. */
  128|    338|		lab1 = *d1++;
  129|    338|		lab2 = *d2++;
  130|    338|	}
  131|     46|	return 0;
  132|     64|}
pkt_dname_len:
  184|  4.10M|{
  185|  4.10M|	size_t len = 0;
  186|  4.10M|	int ptrcount = 0;
  187|  4.10M|	uint8_t labellen;
  188|  4.10M|	size_t endpos = 0;
  189|       |
  190|       |	/* read dname and determine length */
  191|       |	/* check compression pointers, loops, out of bounds */
  192|  4.38M|	while(1) {
  ------------------
  |  Branch (192:8): [Folded - Ignored]
  ------------------
  193|       |		/* read next label */
  194|  4.38M|		if(sldns_buffer_remaining(pkt) < 1)
  ------------------
  |  Branch (194:6): [True: 905, False: 4.38M]
  ------------------
  195|    905|			return 0;
  196|  4.38M|		labellen = sldns_buffer_read_u8(pkt);
  197|  4.38M|		if(LABEL_IS_PTR(labellen)) {
  ------------------
  |  |  202|  4.38M|#define LABEL_IS_PTR(x) ( ((x)&0xc0) == 0xc0 )
  |  |  ------------------
  |  |  |  Branch (202:25): [True: 130k, False: 4.25M]
  |  |  ------------------
  ------------------
  198|       |			/* compression ptr */
  199|   130k|			uint16_t ptr;
  200|   130k|			if(sldns_buffer_remaining(pkt) < 1)
  ------------------
  |  Branch (200:7): [True: 245, False: 129k]
  ------------------
  201|    245|				return 0;
  202|   129k|			ptr = PTR_OFFSET(labellen, sldns_buffer_read_u8(pkt));
  ------------------
  |  |  205|   129k|#define PTR_OFFSET(x, y) ( ((x)&0x3f)<<8 | (y) )
  ------------------
  203|   129k|			if(ptrcount++ > MAX_COMPRESS_PTRS)
  ------------------
  |  |   51|   129k|#define MAX_COMPRESS_PTRS 256
  ------------------
  |  Branch (203:7): [True: 204, False: 129k]
  ------------------
  204|    204|				return 0; /* loop! */
  205|   129k|			if(sldns_buffer_limit(pkt) <= ptr)
  ------------------
  |  Branch (205:7): [True: 400, False: 129k]
  ------------------
  206|    400|				return 0; /* out of bounds! */
  207|   129k|			if(!endpos)
  ------------------
  |  Branch (207:7): [True: 53.4k, False: 75.7k]
  ------------------
  208|  53.4k|				endpos = sldns_buffer_position(pkt);
  209|   129k|			sldns_buffer_set_position(pkt, ptr);
  210|  4.25M|		} else {
  211|       |			/* label contents */
  212|  4.25M|			if(labellen > 0x3f)
  ------------------
  |  Branch (212:7): [True: 404, False: 4.25M]
  ------------------
  213|    404|				return 0; /* label too long */
  214|  4.25M|			len += 1 + labellen;
  215|  4.25M|			if(len > LDNS_MAX_DOMAINLEN)
  ------------------
  |  |   29|  4.25M|#define LDNS_MAX_DOMAINLEN    255
  ------------------
  |  Branch (215:7): [True: 275, False: 4.24M]
  ------------------
  216|    275|				return 0;
  217|  4.24M|			if(labellen == 0) {
  ------------------
  |  Branch (217:7): [True: 4.10M, False: 146k]
  ------------------
  218|       |				/* end of dname */
  219|  4.10M|				break;
  220|  4.10M|			}
  221|   146k|			if(sldns_buffer_remaining(pkt) < labellen)
  ------------------
  |  Branch (221:7): [True: 423, False: 146k]
  ------------------
  222|    423|				return 0;
  223|   146k|			sldns_buffer_skip(pkt, (ssize_t)labellen);
  224|   146k|		}
  225|  4.38M|	}
  226|  4.10M|	if(endpos)
  ------------------
  |  Branch (226:5): [True: 52.1k, False: 4.05M]
  ------------------
  227|  52.1k|		sldns_buffer_set_position(pkt, endpos);
  228|       |
  229|  4.10M|	return len;
  230|  4.10M|}
dname_pkt_compare:
  234|  4.07M|{
  235|  4.07M|	uint8_t len1, len2;
  236|  4.07M|	int count1 = 0, count2 = 0;
  237|  4.07M|	log_assert(pkt && d1 && d2);
  238|  4.07M|	len1 = *d1++;
  239|  4.07M|	len2 = *d2++;
  240|  4.23M|	while( len1 != 0 || len2 != 0 ) {
  ------------------
  |  Branch (240:9): [True: 151k, False: 4.08M]
  |  Branch (240:22): [True: 20.2k, False: 4.06M]
  ------------------
  241|       |		/* resolve ptrs */
  242|   171k|		if(LABEL_IS_PTR(len1)) {
  ------------------
  |  |  202|   171k|#define LABEL_IS_PTR(x) ( ((x)&0xc0) == 0xc0 )
  |  |  ------------------
  |  |  |  Branch (202:25): [True: 42.3k, False: 129k]
  |  |  ------------------
  ------------------
  243|  42.3k|			if((size_t)PTR_OFFSET(len1, *d1)
  ------------------
  |  |  205|  42.3k|#define PTR_OFFSET(x, y) ( ((x)&0x3f)<<8 | (y) )
  ------------------
  |  Branch (243:7): [True: 0, False: 42.3k]
  ------------------
  244|  42.3k|				>= sldns_buffer_limit(pkt))
  245|      0|				return -1;
  246|  42.3k|			if(count1++ > MAX_COMPRESS_PTRS)
  ------------------
  |  |   51|  42.3k|#define MAX_COMPRESS_PTRS 256
  ------------------
  |  Branch (246:7): [True: 0, False: 42.3k]
  ------------------
  247|      0|				return -1;
  248|  42.3k|			d1 = sldns_buffer_at(pkt, PTR_OFFSET(len1, *d1));
  ------------------
  |  |  205|  42.3k|#define PTR_OFFSET(x, y) ( ((x)&0x3f)<<8 | (y) )
  ------------------
  249|  42.3k|			len1 = *d1++;
  250|  42.3k|			continue;
  251|  42.3k|		}
  252|   129k|		if(LABEL_IS_PTR(len2)) {
  ------------------
  |  |  202|   129k|#define LABEL_IS_PTR(x) ( ((x)&0xc0) == 0xc0 )
  |  |  ------------------
  |  |  |  Branch (202:25): [True: 45.4k, False: 84.0k]
  |  |  ------------------
  ------------------
  253|  45.4k|			if((size_t)PTR_OFFSET(len2, *d2)
  ------------------
  |  |  205|  45.4k|#define PTR_OFFSET(x, y) ( ((x)&0x3f)<<8 | (y) )
  ------------------
  |  Branch (253:7): [True: 0, False: 45.4k]
  ------------------
  254|  45.4k|				>= sldns_buffer_limit(pkt))
  255|      0|				return 1;
  256|  45.4k|			if(count2++ > MAX_COMPRESS_PTRS)
  ------------------
  |  |   51|  45.4k|#define MAX_COMPRESS_PTRS 256
  ------------------
  |  Branch (256:7): [True: 0, False: 45.4k]
  ------------------
  257|      0|				return 1;
  258|  45.4k|			d2 = sldns_buffer_at(pkt, PTR_OFFSET(len2, *d2));
  ------------------
  |  |  205|  45.4k|#define PTR_OFFSET(x, y) ( ((x)&0x3f)<<8 | (y) )
  ------------------
  259|  45.4k|			len2 = *d2++;
  260|  45.4k|			continue;
  261|  45.4k|		}
  262|       |		/* check label length */
  263|  84.0k|		log_assert(len1 <= LDNS_MAX_LABELLEN);
  264|  84.0k|		log_assert(len2 <= LDNS_MAX_LABELLEN);
  265|  84.0k|		if(len1 != len2) {
  ------------------
  |  Branch (265:6): [True: 7.95k, False: 76.0k]
  ------------------
  266|  7.95k|			if(len1 < len2) return -1;
  ------------------
  |  Branch (266:7): [True: 1.63k, False: 6.31k]
  ------------------
  267|  6.31k|			return 1;
  268|  7.95k|		}
  269|  76.0k|		log_assert(len1 == len2 && len1 != 0);
  270|       |		/* compare labels */
  271|  1.03M|		while(len1--) {
  ------------------
  |  Branch (271:9): [True: 960k, False: 73.6k]
  ------------------
  272|   960k|			if(tolower((unsigned char)*d1) != tolower((unsigned char)*d2)) {
  ------------------
  |  Branch (272:7): [True: 2.43k, False: 957k]
  ------------------
  273|  2.43k|				if(tolower((unsigned char)*d1) < tolower((unsigned char)*d2))
  ------------------
  |  Branch (273:8): [True: 1.34k, False: 1.09k]
  ------------------
  274|  1.34k|					return -1;
  275|  1.09k|				return 1;
  276|  2.43k|			}
  277|   957k|			d1++;
  278|   957k|			d2++;
  279|   957k|		}
  280|  73.6k|		len1 = *d1++;
  281|  73.6k|		len2 = *d2++;
  282|  73.6k|	}
  283|  4.06M|	return 0;
  284|  4.07M|}
dname_pkt_hash:
  312|  4.03M|{
  313|  4.03M|	uint8_t labuf[LDNS_MAX_LABELLEN+1];
  314|  4.03M|	uint8_t lablen;
  315|  4.03M|	int i;
  316|  4.03M|	int count = 0;
  317|       |
  318|       |	/* preserve case of query, make hash label by label */
  319|  4.03M|	lablen = *dname++;
  320|  4.19M|	while(lablen) {
  ------------------
  |  Branch (320:8): [True: 161k, False: 4.03M]
  ------------------
  321|   161k|		if(LABEL_IS_PTR(lablen)) {
  ------------------
  |  |  202|   161k|#define LABEL_IS_PTR(x) ( ((x)&0xc0) == 0xc0 )
  |  |  ------------------
  |  |  |  Branch (202:25): [True: 52.8k, False: 108k]
  |  |  ------------------
  ------------------
  322|       |			/* follow pointer */
  323|  52.8k|			if((size_t)PTR_OFFSET(lablen, *dname)
  ------------------
  |  |  205|  52.8k|#define PTR_OFFSET(x, y) ( ((x)&0x3f)<<8 | (y) )
  ------------------
  |  Branch (323:7): [True: 0, False: 52.8k]
  ------------------
  324|  52.8k|				>= sldns_buffer_limit(pkt))
  325|      0|				return h;
  326|  52.8k|			if(count++ > MAX_COMPRESS_PTRS)
  ------------------
  |  |   51|  52.8k|#define MAX_COMPRESS_PTRS 256
  ------------------
  |  Branch (326:7): [True: 0, False: 52.8k]
  ------------------
  327|      0|				return h;
  328|  52.8k|			dname = sldns_buffer_at(pkt, PTR_OFFSET(lablen, *dname));
  ------------------
  |  |  205|  52.8k|#define PTR_OFFSET(x, y) ( ((x)&0x3f)<<8 | (y) )
  ------------------
  329|  52.8k|			lablen = *dname++;
  330|  52.8k|			continue;
  331|  52.8k|		}
  332|   108k|		log_assert(lablen <= LDNS_MAX_LABELLEN);
  333|   108k|		labuf[0] = lablen;
  334|   108k|		i=0;
  335|  1.49M|		while(lablen--) {
  ------------------
  |  Branch (335:9): [True: 1.38M, False: 108k]
  ------------------
  336|  1.38M|			labuf[++i] = (uint8_t)tolower((unsigned char)*dname);
  337|  1.38M|			dname++;
  338|  1.38M|		}
  339|   108k|		h = hashlittle(labuf, labuf[0] + 1, h);
  340|   108k|		lablen = *dname++;
  341|   108k|	}
  342|       |
  343|  4.03M|	return h;
  344|  4.03M|}
dname_pkt_copy:
  347|  78.1k|{
  348|       |	/* copy over the dname and decompress it at the same time */
  349|  78.1k|	size_t comprcount = 0;
  350|  78.1k|	size_t len = 0;
  351|  78.1k|	uint8_t lablen;
  352|  78.1k|	lablen = *dname++;
  353|   128k|	while(lablen) {
  ------------------
  |  Branch (353:8): [True: 50.8k, False: 78.1k]
  ------------------
  354|  50.8k|		if(LABEL_IS_PTR(lablen)) {
  ------------------
  |  |  202|  50.8k|#define LABEL_IS_PTR(x) ( ((x)&0xc0) == 0xc0 )
  |  |  ------------------
  |  |  |  Branch (202:25): [True: 10.4k, False: 40.3k]
  |  |  ------------------
  ------------------
  355|  10.4k|			if(comprcount++ > MAX_COMPRESS_PTRS) {
  ------------------
  |  |   51|  10.4k|#define MAX_COMPRESS_PTRS 256
  ------------------
  |  Branch (355:7): [True: 0, False: 10.4k]
  ------------------
  356|       |				/* too many compression pointers */
  357|      0|				*to = 0; /* end the result prematurely */
  358|      0|				return;
  359|      0|			}
  360|       |			/* follow pointer */
  361|  10.4k|			if((size_t)PTR_OFFSET(lablen, *dname)
  ------------------
  |  |  205|  10.4k|#define PTR_OFFSET(x, y) ( ((x)&0x3f)<<8 | (y) )
  ------------------
  |  Branch (361:7): [True: 0, False: 10.4k]
  ------------------
  362|  10.4k|				>= sldns_buffer_limit(pkt))
  363|      0|				return;
  364|  10.4k|			dname = sldns_buffer_at(pkt, PTR_OFFSET(lablen, *dname));
  ------------------
  |  |  205|  10.4k|#define PTR_OFFSET(x, y) ( ((x)&0x3f)<<8 | (y) )
  ------------------
  365|  10.4k|			lablen = *dname++;
  366|  10.4k|			continue;
  367|  10.4k|		}
  368|  40.3k|		if(lablen > LDNS_MAX_LABELLEN) {
  ------------------
  |  |   27|  40.3k|#define LDNS_MAX_LABELLEN     63
  ------------------
  |  Branch (368:6): [True: 0, False: 40.3k]
  ------------------
  369|      0|			*to = 0; /* end the result prematurely */
  370|      0|			return;
  371|      0|		}
  372|  40.3k|		log_assert(lablen <= LDNS_MAX_LABELLEN);
  373|  40.3k|		len += (size_t)lablen+1;
  374|  40.3k|		if(len >= LDNS_MAX_DOMAINLEN) {
  ------------------
  |  |   29|  40.3k|#define LDNS_MAX_DOMAINLEN    255
  ------------------
  |  Branch (374:6): [True: 0, False: 40.3k]
  ------------------
  375|      0|			*to = 0; /* end the result prematurely */
  376|      0|			log_err("bad dname in dname_pkt_copy");
  377|      0|			return;
  378|      0|		}
  379|  40.3k|		*to++ = lablen;
  380|  40.3k|		memmove(to, dname, lablen);
  381|  40.3k|		dname += lablen;
  382|  40.3k|		to += lablen;
  383|  40.3k|		lablen = *dname++;
  384|  40.3k|	}
  385|       |	/* copy last \0 */
  386|  78.1k|	*to = 0;
  387|  78.1k|}
dname_count_labels:
  432|   102k|{
  433|   102k|	uint8_t lablen;
  434|   102k|	int labs = 1;
  435|       |
  436|   102k|	lablen = *dname++;
  437|   180k|	while(lablen) {
  ------------------
  |  Branch (437:8): [True: 77.5k, False: 102k]
  ------------------
  438|  77.5k|		labs++;
  439|  77.5k|		dname += lablen;
  440|  77.5k|		lablen = *dname++;
  441|  77.5k|	}
  442|   102k|	return labs;
  443|   102k|}
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.82k, False: 5.12k]
  ------------------
  494|  21.4k|		while(atlabel > labs2) {
  ------------------
  |  Branch (494:9): [True: 15.6k, False: 5.82k]
  ------------------
  495|  15.6k|			len1 = *d1++;
  496|  15.6k|			d1 += len1;
  497|  15.6k|			atlabel--;
  498|  15.6k|		}
  499|  5.82k|		log_assert(atlabel == labs2);
  500|  5.82k|	} else if(labs1 < labs2) {
  ------------------
  |  Branch (500:12): [True: 0, False: 5.12k]
  ------------------
  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.9k|	while(atlabel > 1) {
  ------------------
  |  Branch (514:8): [True: 9.96k, False: 10.9k]
  ------------------
  515|  9.96k|		len1 = *d1++;
  516|  9.96k|		len2 = *d2++;
  517|  9.96k|		if(len1 != len2) {
  ------------------
  |  Branch (517:6): [True: 4.86k, False: 5.09k]
  ------------------
  518|  4.86k|			log_assert(len1 != 0 && len2 != 0);
  519|  4.86k|			if(len1<len2)
  ------------------
  |  Branch (519:7): [True: 2.30k, False: 2.56k]
  ------------------
  520|  2.30k|				lastdiff = -1;
  521|  2.56k|			else	lastdiff = 1;
  522|  4.86k|			lastmlabs = atlabel;
  523|  4.86k|			d1 += len1;
  524|  4.86k|			d2 += len2;
  525|  5.09k|		} 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|  13.6k|			while(len1) {
  ------------------
  |  Branch (530:10): [True: 9.72k, False: 3.95k]
  ------------------
  531|  9.72k|				if(*d1 != *d2 && tolower((unsigned char)*d1) 
  ------------------
  |  Branch (531:8): [True: 4.17k, False: 5.54k]
  |  Branch (531:22): [True: 1.13k, False: 3.03k]
  ------------------
  532|  4.17k|					!= tolower((unsigned char)*d2)) {
  533|  1.13k|					if(tolower((unsigned char)*d1) < 
  ------------------
  |  Branch (533:9): [True: 702, False: 437]
  ------------------
  534|  1.13k|						tolower((unsigned char)*d2)) {
  535|    702|						lastdiff = -1;
  536|    702|						lastmlabs = atlabel;
  537|    702|						d1 += len1;
  538|    702|						d2 += len1;
  539|    702|						break;
  540|    702|					}
  541|    437|					lastdiff = 1;
  542|    437|					lastmlabs = atlabel;
  543|    437|					d1 += len1;
  544|    437|					d2 += len1;
  545|    437|					break; /* out of memlowercmp */
  546|  1.13k|				}
  547|  8.58k|				d1++;
  548|  8.58k|				d2++;
  549|  8.58k|				len1--;
  550|  8.58k|			}
  551|  5.09k|		}
  552|  9.96k|		atlabel--;
  553|  9.96k|	}
  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: 5.73k, False: 5.20k]
  ------------------
  558|       |		/* all labels compared were equal, check if one has more
  559|       |		 * labels, so that example.com. > com. */
  560|  5.73k|		if(labs1 > labs2)
  ------------------
  |  Branch (560:6): [True: 3.93k, False: 1.80k]
  ------------------
  561|  3.93k|			return 1;
  562|  1.80k|		else if(labs1 < labs2)
  ------------------
  |  Branch (562:11): [True: 0, False: 1.80k]
  ------------------
  563|      0|			return -1;
  564|  5.73k|	}
  565|  7.01k|	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: 221, False: 1.11k]
  ------------------
  684|    221|		return 0;
  685|  1.11k|	if(dname_lab_cmp(d1, labs1, d2, labs2, &m) > 0) {
  ------------------
  |  Branch (685:5): [True: 956, False: 156]
  ------------------
  686|       |		/* subdomain if all labels match */
  687|    956|		return (m == labs2);
  688|    956|	}
  689|    156|	return 0;
  690|  1.11k|}
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|  50.0k|{
  702|  50.0k|	int m;
  703|       |	/* check subdomain: d1: www.example.com. and d2: example.com. */
  704|       |	/*  	or 	    d1: example.com. and d2: example.com. */
  705|  50.0k|	int labs1 = dname_count_labels(d1);
  706|  50.0k|	int labs2 = dname_count_labels(d2);
  707|  50.0k|	if(labs2 > labs1) 
  ------------------
  |  Branch (707:5): [True: 40.1k, False: 9.83k]
  ------------------
  708|  40.1k|		return 0;
  709|  9.83k|	if(dname_lab_cmp(d1, labs1, d2, labs2, &m) < 0) {
  ------------------
  |  Branch (709:5): [True: 2.40k, False: 7.42k]
  ------------------
  710|       |		/* must have been example.com , www.example.com - wrong */
  711|       |		/* or otherwise different dnames */
  712|  2.40k|		return 0;
  713|  2.40k|	}
  714|  7.42k|	return (m == labs2);
  715|  9.83k|}

pkt_hash_rrset:
  171|  10.1k|{
  172|       |	/* note this MUST be identical to rrset_key_hash in packed_rrset.c */
  173|       |	/* this routine handles compressed names */
  174|  10.1k|	hashvalue_type h = 0xab;
  175|  10.1k|	h = dname_pkt_hash(pkt, dname, h);
  176|  10.1k|	h = hashlittle(&type, sizeof(type), h);		/* host order */
  177|  10.1k|	h = hashlittle(&dclass, sizeof(dclass), h);	/* netw order */
  178|  10.1k|	h = hashlittle(&rrset_flags, sizeof(uint32_t), h);
  179|  10.1k|	return h;
  180|  10.1k|}
msgparse_hashtable_lookup:
  226|  1.27M|{
  227|  1.27M|	struct rrset_parse* p = msg->hashtable[h & (PARSE_TABLE_SIZE-1)];
  ------------------
  |  |   77|  1.27M|#define PARSE_TABLE_SIZE 32
  ------------------
  228|  5.20M|	while(p) {
  ------------------
  |  Branch (228:8): [True: 4.60M, False: 601k]
  ------------------
  229|  4.60M|		if(rrset_parse_equals(p, pkt, h, rrset_flags, dname, dnamelen,
  ------------------
  |  Branch (229:6): [True: 668k, False: 3.93M]
  ------------------
  230|  4.60M|			type, dclass))
  231|   668k|			return p;
  232|  3.93M|		p = p->rrset_bucket_next;
  233|  3.93M|	}
  234|   601k|	return NULL;
  235|  1.27M|}
msgparse_bucket_remove:
  268|  55.5k|{
  269|  55.5k|	struct rrset_parse** p;
  270|  55.5k|	p = &msg->hashtable[ rrset->hash & (PARSE_TABLE_SIZE-1) ];
  ------------------
  |  |   77|  55.5k|#define PARSE_TABLE_SIZE 32
  ------------------
  271|   355k|	while(*p) {
  ------------------
  |  Branch (271:8): [True: 355k, False: 485]
  ------------------
  272|   355k|		if(*p == rrset) {
  ------------------
  |  Branch (272:6): [True: 55.0k, False: 300k]
  ------------------
  273|  55.0k|			*p = rrset->rrset_bucket_next;
  274|  55.0k|			return;
  275|  55.0k|		}
  276|   300k|		p = &( (*p)->rrset_bucket_next );
  277|   300k|	}
  278|  55.5k|}
get_rdf_size:
  602|   228k|{
  603|   228k|	switch(rdf) {
  604|      0|		case LDNS_RDF_TYPE_CLASS:
  ------------------
  |  Branch (604:3): [True: 0, False: 228k]
  ------------------
  605|  32.8k|		case LDNS_RDF_TYPE_ALG:
  ------------------
  |  Branch (605:3): [True: 32.8k, False: 196k]
  ------------------
  606|  65.6k|		case LDNS_RDF_TYPE_INT8:
  ------------------
  |  Branch (606:3): [True: 32.7k, False: 196k]
  ------------------
  607|  65.6k|			return 1;
  608|      0|			break;
  609|  32.9k|		case LDNS_RDF_TYPE_INT16:
  ------------------
  |  Branch (609:3): [True: 32.9k, False: 195k]
  ------------------
  610|  66.1k|		case LDNS_RDF_TYPE_TYPE:
  ------------------
  |  Branch (610:3): [True: 33.1k, False: 195k]
  ------------------
  611|  66.1k|		case LDNS_RDF_TYPE_CERT_ALG:
  ------------------
  |  Branch (611:3): [True: 0, False: 228k]
  ------------------
  612|  66.1k|			return 2;
  613|      0|			break;
  614|  32.5k|		case LDNS_RDF_TYPE_INT32:
  ------------------
  |  Branch (614:3): [True: 32.5k, False: 196k]
  ------------------
  615|  97.2k|		case LDNS_RDF_TYPE_TIME:
  ------------------
  |  Branch (615:3): [True: 64.6k, False: 164k]
  ------------------
  616|  97.2k|		case LDNS_RDF_TYPE_A:
  ------------------
  |  Branch (616:3): [True: 0, False: 228k]
  ------------------
  617|  97.2k|		case LDNS_RDF_TYPE_PERIOD:
  ------------------
  |  Branch (617:3): [True: 0, False: 228k]
  ------------------
  618|  97.2k|			return 4;
  619|      0|			break;
  620|      0|		case LDNS_RDF_TYPE_TSIGTIME:
  ------------------
  |  Branch (620:3): [True: 0, False: 228k]
  ------------------
  621|      0|			return 6;
  622|      0|			break;
  623|      0|		case LDNS_RDF_TYPE_AAAA:
  ------------------
  |  Branch (623:3): [True: 0, False: 228k]
  ------------------
  624|      0|			return 16;
  625|      0|			break;
  626|      0|		default:
  ------------------
  |  Branch (626:3): [True: 0, False: 228k]
  ------------------
  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|   228k|	}
  631|      0|	return 0;
  632|   228k|}
parse_packet:
  909|  4.66k|{
  910|  4.66k|	int ret;
  911|  4.66k|	if(sldns_buffer_remaining(pkt) < LDNS_HEADER_SIZE)
  ------------------
  |  |   26|  4.66k|#define	LDNS_HEADER_SIZE	12
  ------------------
  |  Branch (911:5): [True: 10, False: 4.65k]
  ------------------
  912|     10|		return LDNS_RCODE_FORMERR;
  913|       |	/* read the header */
  914|  4.65k|	sldns_buffer_read(pkt, &msg->id, sizeof(uint16_t));
  915|  4.65k|	msg->flags = sldns_buffer_read_u16(pkt);
  916|  4.65k|	msg->qdcount = sldns_buffer_read_u16(pkt);
  917|  4.65k|	msg->ancount = sldns_buffer_read_u16(pkt);
  918|  4.65k|	msg->nscount = sldns_buffer_read_u16(pkt);
  919|  4.65k|	msg->arcount = sldns_buffer_read_u16(pkt);
  920|  4.65k|	if(msg->qdcount > 1)
  ------------------
  |  Branch (920:5): [True: 15, False: 4.64k]
  ------------------
  921|     15|		return LDNS_RCODE_FORMERR;
  922|  4.64k|	if((ret = parse_query_section(pkt, msg)) != 0)
  ------------------
  |  Branch (922:5): [True: 38, False: 4.60k]
  ------------------
  923|     38|		return ret;
  924|  4.60k|	if((ret = parse_section(pkt, msg, region, LDNS_SECTION_ANSWER,
  ------------------
  |  Branch (924:5): [True: 1.40k, False: 3.20k]
  ------------------
  925|  4.60k|		msg->ancount, &msg->an_rrsets)) != 0)
  926|  1.40k|		return ret;
  927|  3.20k|	if((ret = parse_section(pkt, msg, region, LDNS_SECTION_AUTHORITY,
  ------------------
  |  Branch (927:5): [True: 739, False: 2.46k]
  ------------------
  928|  3.20k|		msg->nscount, &msg->ns_rrsets)) != 0)
  929|    739|		return ret;
  930|  2.46k|	if(sldns_buffer_remaining(pkt) == 0 && msg->arcount == 1) {
  ------------------
  |  Branch (930:5): [True: 1.13k, False: 1.32k]
  |  Branch (930:41): [True: 307, False: 830]
  ------------------
  931|       |		/* BIND accepts leniently that an EDNS record is missing.
  932|       |		 * so, we do too. */
  933|  2.15k|	} else if((ret = parse_section(pkt, msg, region,
  ------------------
  |  Branch (933:12): [True: 411, False: 1.74k]
  ------------------
  934|  2.15k|		LDNS_SECTION_ADDITIONAL, msg->arcount, &msg->ar_rrsets)) != 0)
  935|    411|		return ret;
  936|       |	/* if(sldns_buffer_remaining(pkt) > 0) { */
  937|       |		/* there is spurious data at end of packet. ignore */
  938|       |	/* } */
  939|  2.05k|	msg->rrset_count = msg->an_rrsets + msg->ns_rrsets + msg->ar_rrsets;
  940|  2.05k|	return 0;
  941|  2.46k|}
parse_extract_edns_from_response_msg:
 1061|  2.05k|{
 1062|  2.05k|	struct rrset_parse* rrset = msg->rrset_first;
 1063|  2.05k|	struct rrset_parse* prev = 0;
 1064|  2.05k|	struct rrset_parse* found = 0;
 1065|  2.05k|	struct rrset_parse* found_prev = 0;
 1066|  2.05k|	size_t rdata_len;
 1067|  2.05k|	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|  59.9k|	while(rrset) {
  ------------------
  |  Branch (1070:8): [True: 57.8k, False: 2.04k]
  ------------------
 1071|  57.8k|		if(rrset->type == LDNS_RR_TYPE_OPT) {
  ------------------
  |  Branch (1071:6): [True: 164, False: 57.7k]
  ------------------
 1072|       |			/* only one OPT RR allowed. */
 1073|    164|			if(found) return LDNS_RCODE_FORMERR;
  ------------------
  |  Branch (1073:7): [True: 1, False: 163]
  ------------------
 1074|       |			/* found it! */
 1075|    163|			found_prev = prev;
 1076|    163|			found = rrset;
 1077|    163|		}
 1078|  57.8k|		prev = rrset;
 1079|  57.8k|		rrset = rrset->rrset_all_next;
 1080|  57.8k|	}
 1081|  2.04k|	if(!found) {
  ------------------
  |  Branch (1081:5): [True: 1.88k, False: 162]
  ------------------
 1082|  1.88k|		memset(edns, 0, sizeof(*edns));
 1083|  1.88k|		edns->udp_size = 512;
 1084|  1.88k|		return 0;
 1085|  1.88k|	}
 1086|       |	/* check the found RRset */
 1087|       |	/* most lenient check possible. ignore dname, use last opt */
 1088|    162|	if(found->section != LDNS_SECTION_ADDITIONAL)
  ------------------
  |  Branch (1088:5): [True: 2, False: 160]
  ------------------
 1089|      2|		return LDNS_RCODE_FORMERR; 
 1090|    160|	if(found->rr_count == 0)
  ------------------
  |  Branch (1090:5): [True: 2, False: 158]
  ------------------
 1091|      2|		return LDNS_RCODE_FORMERR;
 1092|    158|	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|    158|	log_assert(found->rr_first && found->rr_last);
 1098|       |
 1099|       |	/* remove from packet */
 1100|    158|	if(found_prev)	found_prev->rrset_all_next = found->rrset_all_next;
  ------------------
  |  Branch (1100:5): [True: 37, False: 121]
  ------------------
 1101|    121|	else	msg->rrset_first = found->rrset_all_next;
 1102|    158|	if(found == msg->rrset_last)
  ------------------
  |  Branch (1102:5): [True: 119, False: 39]
  ------------------
 1103|    119|		msg->rrset_last = found_prev;
 1104|    158|	msg->arcount --;
 1105|    158|	msg->ar_rrsets --;
 1106|    158|	msg->rrset_count --;
 1107|       |	
 1108|       |	/* take the data ! */
 1109|    158|	edns->edns_present = 1;
 1110|    158|	edns->ext_rcode = found->rr_last->ttl_data[0];
 1111|    158|	edns->edns_version = found->rr_last->ttl_data[1];
 1112|    158|	edns->bits = sldns_read_uint16(&found->rr_last->ttl_data[2]);
 1113|    158|	edns->udp_size = ntohs(found->rrset_class);
 1114|    158|	edns->opt_list_in = NULL;
 1115|    158|	edns->opt_list_out = NULL;
 1116|    158|	edns->opt_list_inplace_cb_out = NULL;
 1117|    158|	edns->padding_block_size = 0;
 1118|       |
 1119|       |	/* take the options */
 1120|    158|	rdata_len = found->rr_first->size-2;
 1121|    158|	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|  13.9k|	while(rdata_len >= 4) {
  ------------------
  |  Branch (1125:8): [True: 13.8k, False: 86]
  ------------------
 1126|  13.8k|		uint16_t opt_code = sldns_read_uint16(rdata_ptr);
 1127|  13.8k|		uint16_t opt_len = sldns_read_uint16(rdata_ptr+2);
 1128|  13.8k|		rdata_ptr += 4;
 1129|  13.8k|		rdata_len -= 4;
 1130|  13.8k|		if(opt_len > rdata_len)
  ------------------
  |  Branch (1130:6): [True: 72, False: 13.8k]
  ------------------
 1131|     72|			break; /* option code partial */
 1132|       |
 1133|  13.8k|		if(!edns_opt_list_append(&edns->opt_list_in,
  ------------------
  |  Branch (1133:6): [True: 0, False: 13.8k]
  ------------------
 1134|  13.8k|				opt_code, opt_len, rdata_ptr, region)) {
 1135|      0|			log_err("out of memory");
 1136|      0|			break;
 1137|      0|		}
 1138|  13.8k|		rdata_ptr += opt_len;
 1139|  13.8k|		rdata_len -= opt_len;
 1140|  13.8k|	}
 1141|       |	/* ignore rrsigs */
 1142|    158|	return LDNS_RCODE_NOERROR;
 1143|    158|}
msgparse.c:rrset_parse_equals:
  213|  4.60M|{
  214|  4.60M|	if(p->hash == h && p->dname_len == dnamelen && p->type == type &&
  ------------------
  |  Branch (214:5): [True: 672k, False: 3.93M]
  |  Branch (214:21): [True: 671k, False: 1.65k]
  |  Branch (214:49): [True: 669k, False: 1.15k]
  ------------------
  215|  4.60M|		p->rrset_class == dclass && p->flags == rrset_flags &&
  ------------------
  |  Branch (215:3): [True: 669k, False: 461]
  |  Branch (215:31): [True: 669k, False: 352]
  ------------------
  216|  4.60M|		dname_pkt_compare(pkt, dname, p->dname) == 0)
  ------------------
  |  Branch (216:3): [True: 668k, False: 603]
  ------------------
  217|   668k|		return 1;
  218|  3.93M|	return 0;
  219|  4.60M|}
msgparse.c:parse_query_section:
  582|  4.64k|{
  583|  4.64k|	if(msg->qdcount == 0)
  ------------------
  |  Branch (583:5): [True: 2.87k, False: 1.77k]
  ------------------
  584|  2.87k|		return 0;
  585|  1.77k|	if(msg->qdcount > 1)
  ------------------
  |  Branch (585:5): [True: 0, False: 1.77k]
  ------------------
  586|      0|		return LDNS_RCODE_FORMERR;
  587|  1.77k|	log_assert(msg->qdcount == 1);
  588|  1.77k|	if(sldns_buffer_remaining(pkt) <= 0)
  ------------------
  |  Branch (588:5): [True: 1, False: 1.77k]
  ------------------
  589|      1|		return LDNS_RCODE_FORMERR;
  590|  1.77k|	msg->qname = sldns_buffer_current(pkt);
  591|  1.77k|	if((msg->qname_len = pkt_dname_len(pkt)) == 0)
  ------------------
  |  Branch (591:5): [True: 23, False: 1.74k]
  ------------------
  592|     23|		return LDNS_RCODE_FORMERR;
  593|  1.74k|	if(sldns_buffer_remaining(pkt) < sizeof(uint16_t)*2)
  ------------------
  |  Branch (593:5): [True: 14, False: 1.73k]
  ------------------
  594|     14|		return LDNS_RCODE_FORMERR;
  595|  1.73k|	msg->qtype = sldns_buffer_read_u16(pkt);
  596|  1.73k|	msg->qclass = sldns_buffer_read_u16(pkt);
  597|  1.73k|	return 0;
  598|  1.74k|}
msgparse.c:parse_section:
  826|  9.95k|{
  827|  9.95k|	uint16_t i;
  828|  9.95k|	uint8_t* dname, *prev_dname_f = NULL, *prev_dname_l = NULL;
  829|  9.95k|	size_t dnamelen, prev_dnamelen = 0;
  830|  9.95k|	uint16_t type, prev_type = 0;
  831|  9.95k|	uint16_t dclass, prev_dclass = 0;
  832|  9.95k|	uint32_t rrset_flags = 0;
  833|  9.95k|	hashvalue_type hash = 0;
  834|  9.95k|	struct rrset_parse* rrset = NULL;
  835|  9.95k|	int r;
  836|       |
  837|  9.95k|	if(num_rrs == 0)
  ------------------
  |  Branch (837:5): [True: 4.24k, False: 5.71k]
  ------------------
  838|  4.24k|		return 0;
  839|  5.71k|	if(sldns_buffer_remaining(pkt) <= 0)
  ------------------
  |  Branch (839:5): [True: 57, False: 5.65k]
  ------------------
  840|     57|		return LDNS_RCODE_FORMERR;
  841|  4.03M|	for(i=0; i<num_rrs; i++) {
  ------------------
  |  Branch (841:11): [True: 4.02M, False: 3.16k]
  ------------------
  842|       |		/* parse this RR. */
  843|  4.02M|		dname = sldns_buffer_current(pkt);
  844|  4.02M|		if((dnamelen = pkt_dname_len(pkt)) == 0)
  ------------------
  |  Branch (844:6): [True: 924, False: 4.02M]
  ------------------
  845|    924|			return LDNS_RCODE_FORMERR;
  846|  4.02M|		if(sldns_buffer_remaining(pkt) < 10) /* type, class, ttl, len */
  ------------------
  |  Branch (846:6): [True: 235, False: 4.02M]
  ------------------
  847|    235|			return LDNS_RCODE_FORMERR;
  848|  4.02M|		type = sldns_buffer_read_u16(pkt);
  849|  4.02M|		sldns_buffer_read(pkt, &dclass, sizeof(dclass));
  850|       |
  851|  4.02M|		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|  4.02M|		if(!find_rrset(msg, pkt, dname, dnamelen, type, dclass, &hash, 
  ------------------
  |  Branch (878:6): [True: 0, False: 4.02M]
  ------------------
  879|  4.02M|			&rrset_flags, &prev_dname_f, &prev_dname_l, 
  880|  4.02M|			&prev_dnamelen, &prev_type, &prev_dclass, &rrset, 
  881|  4.02M|			section, region))
  882|      0|			return LDNS_RCODE_SERVFAIL;
  883|  4.02M|		if(!rrset) {
  ------------------
  |  Branch (883:6): [True: 87.9k, False: 3.93M]
  ------------------
  884|       |			/* it is a new RR set. hash&flags already calculated.*/
  885|  87.9k|			(*num_rrsets)++;
  886|  87.9k|			rrset = new_rrset(msg, dname, dnamelen, type, dclass,
  887|  87.9k|				hash, rrset_flags, section, region);
  888|  87.9k|			if(!rrset) 
  ------------------
  |  Branch (888:7): [True: 0, False: 87.9k]
  ------------------
  889|      0|				return LDNS_RCODE_SERVFAIL;
  890|  87.9k|		}
  891|  3.93M|		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|  4.02M|		if((r=add_rr_to_rrset(rrset, pkt, msg, region, section, 
  ------------------
  |  Branch (900:6): [True: 1.33k, False: 4.02M]
  ------------------
  901|  4.02M|			type)) != 0)
  902|  1.33k|			return r;
  903|  4.02M|	}
  904|  3.16k|	return 0;
  905|  5.65k|}
msgparse.c:find_rrset:
  470|  4.02M|{
  471|  4.02M|	hashvalue_type dname_h = pkt_hash_rrset_first(pkt, dname);
  472|  4.02M|	uint16_t covtype;
  473|  4.02M|	if(*rrset_prev) {
  ------------------
  |  Branch (473:5): [True: 4.02M, False: 5.57k]
  ------------------
  474|       |		/* check if equal to previous item */
  475|  4.02M|		if(type == *prev_type && dclass == *prev_dclass &&
  ------------------
  |  Branch (475:6): [True: 3.80M, False: 221k]
  |  Branch (475:28): [True: 3.39M, False: 404k]
  ------------------
  476|  4.02M|			dnamelen == *prev_dnamelen &&
  ------------------
  |  Branch (476:4): [True: 3.38M, False: 11.3k]
  ------------------
  477|  4.02M|			smart_compare(pkt, dname, *prev_dname_first, 
  ------------------
  |  Branch (477:4): [True: 3.38M, False: 1.83k]
  ------------------
  478|  3.38M|				*prev_dname_last) == 0 &&
  479|  4.02M|			type != LDNS_RR_TYPE_RRSIG) {
  ------------------
  |  Branch (479:4): [True: 3.37M, False: 8.20k]
  ------------------
  480|       |			/* same as previous */
  481|  3.37M|			*prev_dname_last = dname;
  482|  3.37M|			return 1;
  483|  3.37M|		}
  484|       |		/* check if rrsig over previous item */
  485|   647k|		if(type == LDNS_RR_TYPE_RRSIG && dclass == *prev_dclass &&
  ------------------
  |  Branch (485:6): [True: 35.4k, False: 612k]
  |  Branch (485:36): [True: 28.7k, False: 6.71k]
  ------------------
  486|   647k|			pkt_rrsig_covered_equals(pkt, sldns_buffer_current(pkt),
  ------------------
  |  Branch (486:4): [True: 12.0k, False: 16.6k]
  ------------------
  487|  28.7k|				*prev_type) &&
  488|   647k|			smart_compare(pkt, dname, *prev_dname_first,
  ------------------
  |  Branch (488:4): [True: 10.0k, False: 2.05k]
  ------------------
  489|  12.0k|				*prev_dname_last) == 0) {
  490|       |			/* covers previous */
  491|  10.0k|			*prev_dname_last = dname;
  492|  10.0k|			return 1;
  493|  10.0k|		}
  494|   647k|	}
  495|       |	/* find by hashing and lookup in hashtable */
  496|   642k|	*rrset_flags = pkt_rrset_flags(pkt, type, section);
  497|       |	
  498|       |	/* if rrsig - try to lookup matching data set first */
  499|   642k|	if(type == LDNS_RR_TYPE_RRSIG && pkt_rrsig_covered(pkt, 
  ------------------
  |  Branch (499:5): [True: 26.7k, False: 616k]
  |  Branch (499:35): [True: 18.4k, False: 8.25k]
  ------------------
  500|  26.7k|		sldns_buffer_current(pkt), &covtype)) {
  501|  18.4k|		*hash = pkt_hash_rrset_rest(dname_h, covtype, dclass, 
  502|  18.4k|			*rrset_flags);
  503|  18.4k|		*rrset_prev = msgparse_hashtable_lookup(msg, pkt, *hash, 
  504|  18.4k|			*rrset_flags, dname, dnamelen, covtype, dclass);
  505|  18.4k|		if(!*rrset_prev && covtype == LDNS_RR_TYPE_NSEC) {
  ------------------
  |  Branch (505:6): [True: 9.82k, False: 8.62k]
  |  Branch (505:22): [True: 1.11k, False: 8.71k]
  ------------------
  506|       |			/* if NSEC try with NSEC apex bit twiddled */
  507|  1.11k|			*rrset_flags ^= PACKED_RRSET_NSEC_AT_APEX;
  ------------------
  |  |   53|  1.11k|#define PACKED_RRSET_NSEC_AT_APEX 0x1
  ------------------
  508|  1.11k|			*hash = pkt_hash_rrset_rest(dname_h, covtype, dclass, 
  509|  1.11k|				*rrset_flags);
  510|  1.11k|			*rrset_prev = msgparse_hashtable_lookup(msg, pkt, 
  511|  1.11k|				*hash, *rrset_flags, dname, dnamelen, covtype, 
  512|  1.11k|				dclass);
  513|  1.11k|			if(!*rrset_prev) /* untwiddle if not found */
  ------------------
  |  Branch (513:7): [True: 850, False: 263]
  ------------------
  514|    850|				*rrset_flags ^= PACKED_RRSET_NSEC_AT_APEX;
  ------------------
  |  |   53|    850|#define PACKED_RRSET_NSEC_AT_APEX 0x1
  ------------------
  515|  1.11k|		}
  516|  18.4k|		if(!*rrset_prev && covtype == LDNS_RR_TYPE_SOA) {
  ------------------
  |  Branch (516:6): [True: 9.56k, False: 8.88k]
  |  Branch (516:22): [True: 1.14k, False: 8.42k]
  ------------------
  517|       |			/* if SOA try with SOA neg flag twiddled */
  518|  1.14k|			*rrset_flags ^= PACKED_RRSET_SOA_NEG;
  ------------------
  |  |   59|  1.14k|#define PACKED_RRSET_SOA_NEG 0x4
  ------------------
  519|  1.14k|			*hash = pkt_hash_rrset_rest(dname_h, covtype, dclass, 
  520|  1.14k|				*rrset_flags);
  521|  1.14k|			*rrset_prev = msgparse_hashtable_lookup(msg, pkt, 
  522|  1.14k|				*hash, *rrset_flags, dname, dnamelen, covtype, 
  523|  1.14k|				dclass);
  524|  1.14k|			if(!*rrset_prev) /* untwiddle if not found */
  ------------------
  |  Branch (524:7): [True: 913, False: 227]
  ------------------
  525|    913|				*rrset_flags ^= PACKED_RRSET_SOA_NEG;
  ------------------
  |  |   59|    913|#define PACKED_RRSET_SOA_NEG 0x4
  ------------------
  526|  1.14k|		}
  527|  18.4k|		if(*rrset_prev) {
  ------------------
  |  Branch (527:6): [True: 9.11k, False: 9.33k]
  ------------------
  528|  9.11k|			*prev_dname_first = (*rrset_prev)->dname;
  529|  9.11k|			*prev_dname_last = dname;
  530|  9.11k|			*prev_dnamelen = dnamelen;
  531|  9.11k|			*prev_type = covtype;
  532|  9.11k|			*prev_dclass = dclass;
  533|  9.11k|			return 1;
  534|  9.11k|		}
  535|  18.4k|	}
  536|   633k|	if(type != LDNS_RR_TYPE_RRSIG) {
  ------------------
  |  Branch (536:5): [True: 616k, False: 17.5k]
  ------------------
  537|   616k|		int hasother = 0;
  538|       |		/* find matching rrsig */
  539|   616k|		*hash = pkt_hash_rrset_rest(dname_h, LDNS_RR_TYPE_RRSIG, 
  540|   616k|			dclass, 0);
  541|   616k|		*rrset_prev = msgparse_hashtable_lookup(msg, pkt, *hash, 
  542|   616k|			0, dname, dnamelen, LDNS_RR_TYPE_RRSIG, 
  543|   616k|			dclass);
  544|   616k|		if(*rrset_prev && rrset_has_sigover(pkt, *rrset_prev, type,
  ------------------
  |  Branch (544:6): [True: 117k, False: 498k]
  |  Branch (544:21): [True: 5.06k, False: 112k]
  ------------------
  545|   117k|			&hasother)) {
  546|       |			/* yes! */
  547|  5.06k|			*prev_dname_first = (*rrset_prev)->dname;
  548|  5.06k|			*prev_dname_last = dname;
  549|  5.06k|			*prev_dnamelen = dnamelen;
  550|  5.06k|			*prev_type = type;
  551|  5.06k|			*prev_dclass = dclass;
  552|  5.06k|			*rrset_prev = change_rrsig_rrset(*rrset_prev, msg, 
  553|  5.06k|				pkt, type, *rrset_flags, hasother, section, 
  554|  5.06k|				region);
  555|  5.06k|			if(!*rrset_prev) return 0;
  ------------------
  |  Branch (555:7): [True: 0, False: 5.06k]
  ------------------
  556|  5.06k|			return 1;
  557|  5.06k|		}
  558|   616k|	}
  559|       |
  560|   628k|	*hash = pkt_hash_rrset_rest(dname_h, type, dclass, *rrset_flags);
  561|   628k|	*rrset_prev = msgparse_hashtable_lookup(msg, pkt, *hash, *rrset_flags, 
  562|   628k|		dname, dnamelen, type, dclass);
  563|   628k|	if(*rrset_prev)
  ------------------
  |  Branch (563:5): [True: 540k, False: 87.9k]
  ------------------
  564|   540k|		*prev_dname_first = (*rrset_prev)->dname;
  565|  87.9k|	else 	*prev_dname_first = dname;
  566|   628k|	*prev_dname_last = dname;
  567|   628k|	*prev_dnamelen = dnamelen;
  568|   628k|	*prev_type = type;
  569|   628k|	*prev_dclass = dclass;
  570|   628k|	return 1;
  571|   633k|}
msgparse.c:pkt_hash_rrset_first:
  185|  4.02M|{
  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|  4.02M|	hashvalue_type h = 0xab;
  190|  4.02M|	h = dname_pkt_hash(pkt, dname, h);
  191|  4.02M|	return h;
  192|  4.02M|}
msgparse.c:smart_compare:
   57|  3.39M|{
   58|  3.39M|	if(LABEL_IS_PTR(*dnow)) {
  ------------------
  |  |  202|  3.39M|#define LABEL_IS_PTR(x) ( ((x)&0xc0) == 0xc0 )
  |  |  ------------------
  |  |  |  Branch (202:25): [True: 7.54k, False: 3.38M]
  |  |  ------------------
  ------------------
   59|       |		/* ptr points to a previous dname */
   60|  7.54k|		uint8_t* p;
   61|  7.54k|		if((size_t)PTR_OFFSET(dnow[0], dnow[1])
  ------------------
  |  |  205|  7.54k|#define PTR_OFFSET(x, y) ( ((x)&0x3f)<<8 | (y) )
  ------------------
  |  Branch (61:6): [True: 0, False: 7.54k]
  ------------------
   62|  7.54k|			>= sldns_buffer_limit(pkt))
   63|      0|			return -1;
   64|  7.54k|		p = sldns_buffer_at(pkt, PTR_OFFSET(dnow[0], dnow[1]));
  ------------------
  |  |  205|  7.54k|#define PTR_OFFSET(x, y) ( ((x)&0x3f)<<8 | (y) )
  ------------------
   65|  7.54k|		if( p == dprfirst || p == dprlast )
  ------------------
  |  Branch (65:7): [True: 430, False: 7.11k]
  |  Branch (65:24): [True: 32, False: 7.08k]
  ------------------
   66|    462|			return 0;
   67|       |		/* prev dname is also a ptr, both ptrs are the same. */
   68|  7.08k|		if(LABEL_IS_PTR(*dprlast) &&
  ------------------
  |  |  202|  14.1k|#define LABEL_IS_PTR(x) ( ((x)&0xc0) == 0xc0 )
  |  |  ------------------
  |  |  |  Branch (202:25): [True: 5.29k, False: 1.78k]
  |  |  ------------------
  ------------------
   69|  7.08k|			dprlast[0] == dnow[0] && dprlast[1] == dnow[1])
  ------------------
  |  Branch (69:4): [True: 3.04k, False: 2.25k]
  |  Branch (69:29): [True: 1.12k, False: 1.92k]
  ------------------
   70|  1.12k|			return 0;
   71|  7.08k|	}
   72|  3.39M|	return dname_pkt_compare(pkt, dnow, dprlast);
   73|  3.39M|}
msgparse.c:pkt_rrsig_covered_equals:
  259|  1.79M|{
  260|  1.79M|	uint16_t t;
  261|  1.79M|	if(pkt_rrsig_covered(pkt, here, &t) && t == type)
  ------------------
  |  Branch (261:5): [True: 605k, False: 1.19M]
  |  Branch (261:41): [True: 210k, False: 394k]
  ------------------
  262|   210k|		return 1;
  263|  1.58M|	return 0;
  264|  1.79M|}
msgparse.c:pkt_rrset_flags:
  158|   642k|{
  159|   642k|	uint32_t f = 0;
  160|   642k|	if(type == LDNS_RR_TYPE_NSEC && nsec_at_apex(pkt)) {
  ------------------
  |  Branch (160:5): [True: 18.2k, False: 624k]
  |  Branch (160:34): [True: 1.18k, False: 17.0k]
  ------------------
  161|  1.18k|		f |= PACKED_RRSET_NSEC_AT_APEX;
  ------------------
  |  |   53|  1.18k|#define PACKED_RRSET_NSEC_AT_APEX 0x1
  ------------------
  162|   641k|	} else if(type == LDNS_RR_TYPE_SOA && sec == LDNS_SECTION_AUTHORITY) {
  ------------------
  |  Branch (162:12): [True: 1.83k, False: 639k]
  |  Branch (162:40): [True: 708, False: 1.12k]
  ------------------
  163|    708|		f |= PACKED_RRSET_SOA_NEG;
  ------------------
  |  |   59|    708|#define PACKED_RRSET_SOA_NEG 0x4
  ------------------
  164|    708|	}
  165|   642k|	return f;
  166|   642k|}
msgparse.c:nsec_at_apex:
  113|  18.2k|{
  114|       |	/* we are at ttl position in packet. */
  115|  18.2k|	size_t pos = sldns_buffer_position(pkt);
  116|  18.2k|	uint16_t rdatalen;
  117|  18.2k|	if(sldns_buffer_remaining(pkt) < 7) /* ttl+len+root */
  ------------------
  |  Branch (117:5): [True: 84, False: 18.1k]
  ------------------
  118|     84|		return 0; /* eek! */
  119|  18.1k|	sldns_buffer_skip(pkt, 4); /* ttl */;
  120|  18.1k|	rdatalen = sldns_buffer_read_u16(pkt);
  121|  18.1k|	if(sldns_buffer_remaining(pkt) < rdatalen) {
  ------------------
  |  Branch (121:5): [True: 52, False: 18.1k]
  ------------------
  122|     52|		sldns_buffer_set_position(pkt, pos);
  123|     52|		return 0; /* parse error happens later */
  124|     52|	}
  125|       |	/* must validate the nsec next domain name format */
  126|  18.1k|	if(pkt_dname_len(pkt) == 0) {
  ------------------
  |  Branch (126:5): [True: 1.74k, False: 16.3k]
  ------------------
  127|  1.74k|		sldns_buffer_set_position(pkt, pos);
  128|  1.74k|		return 0; /* parse error */
  129|  1.74k|	}
  130|       |
  131|       |	/* see if SOA bit is set. */
  132|  16.3k|	if(sldns_buffer_position(pkt) < pos+4+rdatalen) {
  ------------------
  |  Branch (132:5): [True: 4.03k, False: 12.3k]
  ------------------
  133|       |		/* nsec type bitmap contains items */
  134|  4.03k|		uint8_t win, blen, bits;
  135|       |		/* need: windownum, bitmap len, firstbyte */
  136|  4.03k|		if(sldns_buffer_position(pkt)+3 > pos+4+rdatalen) {
  ------------------
  |  Branch (136:6): [True: 633, False: 3.40k]
  ------------------
  137|    633|			sldns_buffer_set_position(pkt, pos);
  138|    633|			return 0; /* malformed nsec */
  139|    633|		}
  140|  3.40k|		win = sldns_buffer_read_u8(pkt);
  141|  3.40k|		blen = sldns_buffer_read_u8(pkt);
  142|  3.40k|		bits = sldns_buffer_read_u8(pkt);
  143|       |		/* 0window always first window. bitlen >=1 or parse
  144|       |		   error really. bit 0x2 is SOA. */
  145|  3.40k|		if(win == 0 && blen >= 1 && (bits & 0x02)) {
  ------------------
  |  Branch (145:6): [True: 2.56k, False: 836]
  |  Branch (145:18): [True: 1.95k, False: 613]
  |  Branch (145:31): [True: 1.18k, False: 762]
  ------------------
  146|  1.18k|			sldns_buffer_set_position(pkt, pos);
  147|  1.18k|			return 1;
  148|  1.18k|		}
  149|  3.40k|	}
  150|       |
  151|  14.5k|	sldns_buffer_set_position(pkt, pos);
  152|  14.5k|	return 0;
  153|  16.3k|}
msgparse.c:pkt_rrsig_covered:
  240|  1.82M|{
  241|  1.82M|	size_t pos = sldns_buffer_position(pkt);
  242|  1.82M|	sldns_buffer_set_position(pkt, (size_t)(here-sldns_buffer_begin(pkt)));
  243|       |	/* ttl + len + size of small rrsig(rootlabel, no signature) */
  244|  1.82M|	if(sldns_buffer_remaining(pkt) < 4+2+19)
  ------------------
  |  Branch (244:5): [True: 1.50k, False: 1.82M]
  ------------------
  245|  1.50k|		return 0;
  246|  1.82M|	sldns_buffer_skip(pkt, 4); /* ttl */
  247|  1.82M|	if(sldns_buffer_read_u16(pkt) < 19) /* too short */ {
  ------------------
  |  Branch (247:5): [True: 1.20M, False: 623k]
  ------------------
  248|  1.20M|		sldns_buffer_set_position(pkt, pos);
  249|  1.20M|		return 0;
  250|  1.20M|	}
  251|   623k|	*type = sldns_buffer_read_u16(pkt);
  252|   623k|	sldns_buffer_set_position(pkt, pos);
  253|   623k|	return 1;
  254|  1.82M|}
msgparse.c:pkt_hash_rrset_rest:
  198|  1.26M|{
  199|       |	/* works together with pkt_hash_rrset_first */
  200|       |	/* note this MUST be identical to rrset_key_hash in packed_rrset.c */
  201|  1.26M|	hashvalue_type h;
  202|  1.26M|	h = hashlittle(&type, sizeof(type), dname_h);	/* host order */
  203|  1.26M|	h = hashlittle(&dclass, sizeof(dclass), h);	/* netw order */
  204|  1.26M|	h = hashlittle(&rrset_flags, sizeof(uint32_t), h);
  205|  1.26M|	return h;
  206|  1.26M|}
msgparse.c:rrset_has_sigover:
  328|   117k|{
  329|   117k|	int res = 0;
  330|   117k|	struct rr_parse* rr = rrset->rr_first;
  331|   117k|	log_assert( rrset->type == LDNS_RR_TYPE_RRSIG );
  332|  1.73M|	while(rr) {
  ------------------
  |  Branch (332:8): [True: 1.61M, False: 117k]
  ------------------
  333|  1.61M|		if(pkt_rrsig_covered_equals(pkt, rr->ttl_data, type))
  ------------------
  |  Branch (333:6): [True: 99.6k, False: 1.51M]
  ------------------
  334|  99.6k|			res = 1;
  335|  1.51M|		else	*hasother = 1;
  336|  1.61M|		rr = rr->next;
  337|  1.61M|	}
  338|   117k|	return res;
  339|   117k|}
msgparse.c:change_rrsig_rrset:
  395|  5.06k|{
  396|  5.06k|	struct rrset_parse* dataset = sigset;
  397|  5.06k|	hashvalue_type hash = pkt_hash_rrset(pkt, sigset->dname, datatype, 
  398|  5.06k|		sigset->rrset_class, rrset_flags);
  399|  5.06k|	log_assert( sigset->type == LDNS_RR_TYPE_RRSIG );
  400|  5.06k|	log_assert( datatype != LDNS_RR_TYPE_RRSIG );
  401|  5.06k|	if(hasother) {
  ------------------
  |  Branch (401:5): [True: 4.51k, False: 545]
  ------------------
  402|       |		/* need to make new rrset to hold data type */
  403|  4.51k|		dataset = new_rrset(msg, sigset->dname, sigset->dname_len, 
  404|  4.51k|			datatype, sigset->rrset_class, hash, rrset_flags, 
  405|  4.51k|			section, region);
  406|  4.51k|		if(!dataset) 
  ------------------
  |  Branch (406:6): [True: 0, False: 4.51k]
  ------------------
  407|      0|			return NULL;
  408|  4.51k|		switch(section) {
  409|  3.20k|			case LDNS_SECTION_ANSWER: msg->an_rrsets++; break;
  ------------------
  |  Branch (409:4): [True: 3.20k, False: 1.31k]
  ------------------
  410|    995|			case LDNS_SECTION_AUTHORITY: msg->ns_rrsets++; break;
  ------------------
  |  Branch (410:4): [True: 995, False: 3.52k]
  ------------------
  411|    319|			case LDNS_SECTION_ADDITIONAL: msg->ar_rrsets++; break;
  ------------------
  |  Branch (411:4): [True: 319, False: 4.19k]
  ------------------
  412|      0|			default: log_assert(0);
  ------------------
  |  Branch (412:4): [True: 0, False: 4.51k]
  ------------------
  413|  4.51k|		}
  414|  4.51k|		if(!moveover_rrsigs(pkt, region, sigset, dataset, 
  ------------------
  |  Branch (414:6): [True: 0, False: 4.51k]
  ------------------
  415|  4.51k|			msg->qtype == LDNS_RR_TYPE_RRSIG ||
  ------------------
  |  Branch (415:4): [True: 3.38k, False: 1.13k]
  ------------------
  416|  4.51k|			(msg->qtype == LDNS_RR_TYPE_ANY &&
  ------------------
  |  Branch (416:5): [True: 935, False: 201]
  ------------------
  417|  1.13k|			section != LDNS_SECTION_ANSWER) ))
  ------------------
  |  Branch (417:4): [True: 927, False: 8]
  ------------------
  418|      0|			return NULL;
  419|  4.51k|		return dataset;
  420|  4.51k|	}
  421|       |	/* changeover the type of the rrset to data set */
  422|    545|	msgparse_bucket_remove(msg, dataset);
  423|       |	/* insert into new hash bucket */
  424|    545|	dataset->rrset_bucket_next = msg->hashtable[hash&(PARSE_TABLE_SIZE-1)];
  ------------------
  |  |   77|    545|#define PARSE_TABLE_SIZE 32
  ------------------
  425|    545|	msg->hashtable[hash&(PARSE_TABLE_SIZE-1)] = dataset;
  ------------------
  |  |   77|    545|#define PARSE_TABLE_SIZE 32
  ------------------
  426|    545|	dataset->hash = hash;
  427|       |	/* use section of data item for result */
  428|    545|	change_section(msg, dataset, section);
  429|    545|	dataset->type = datatype;
  430|    545|	dataset->flags = rrset_flags;
  431|    545|	dataset->rrsig_count += dataset->rr_count;
  432|    545|	dataset->rr_count = 0;
  433|       |	/* move sigs to end of siglist */
  434|    545|	if(dataset->rrsig_last)
  ------------------
  |  Branch (434:5): [True: 0, False: 545]
  ------------------
  435|      0|		dataset->rrsig_last->next = dataset->rr_first;
  436|    545|	else	dataset->rrsig_first = dataset->rr_first;
  437|    545|	dataset->rrsig_last = dataset->rr_last;
  438|    545|	dataset->rr_first = 0;
  439|    545|	dataset->rr_last = 0;
  440|    545|	return dataset;
  441|  5.06k|}
msgparse.c:moveover_rrsigs:
  345|  4.51k|{
  346|  4.51k|	struct rr_parse* sig = sigset->rr_first;
  347|  4.51k|	struct rr_parse* prev = NULL;
  348|  4.51k|	struct rr_parse* insert;
  349|  4.51k|	struct rr_parse* nextsig;
  350|   159k|	while(sig) {
  ------------------
  |  Branch (350:8): [True: 154k, False: 4.51k]
  ------------------
  351|   154k|		nextsig = sig->next;
  352|   154k|		if(pkt_rrsig_covered_equals(pkt, sig->ttl_data, 
  ------------------
  |  Branch (352:6): [True: 98.7k, False: 56.0k]
  ------------------
  353|   154k|			dataset->type)) {
  354|  98.7k|			if(duplicate) {
  ------------------
  |  Branch (354:7): [True: 97.1k, False: 1.58k]
  ------------------
  355|       |				/* new */
  356|  97.1k|				insert = (struct rr_parse*)regional_alloc(
  357|  97.1k|					region, sizeof(struct rr_parse));
  358|  97.1k|				if(!insert) return 0;
  ------------------
  |  Branch (358:8): [True: 0, False: 97.1k]
  ------------------
  359|  97.1k|				insert->outside_packet = 0;
  360|  97.1k|				insert->ttl_data = sig->ttl_data;
  361|  97.1k|				insert->size = sig->size;
  362|       |				/* prev not used */
  363|  97.1k|			} else {
  364|       |				/* remove from sigset */
  365|  1.58k|				if(prev) prev->next = sig->next;
  ------------------
  |  Branch (365:8): [True: 1.12k, False: 462]
  ------------------
  366|    462|				else	sigset->rr_first = sig->next;
  367|  1.58k|				if(sigset->rr_last == sig)
  ------------------
  |  Branch (367:8): [True: 102, False: 1.48k]
  ------------------
  368|    102|					sigset->rr_last = prev;
  369|  1.58k|				sigset->rr_count--;
  370|  1.58k|				sigset->size -= sig->size;
  371|  1.58k|				insert = sig;
  372|       |				/* prev not changed */
  373|  1.58k|			}
  374|       |			/* add to dataset */
  375|  98.7k|			dataset->rrsig_count++;
  376|  98.7k|			insert->next = 0;
  377|  98.7k|			if(dataset->rrsig_last) 
  ------------------
  |  Branch (377:7): [True: 94.2k, False: 4.51k]
  ------------------
  378|  94.2k|				dataset->rrsig_last->next = insert;
  379|  4.51k|			else	dataset->rrsig_first = insert;
  380|  98.7k|			dataset->rrsig_last = insert;
  381|  98.7k|			dataset->size += insert->size;
  382|  98.7k|		} else  {
  383|  56.0k|			prev = sig;
  384|  56.0k|		}
  385|   154k|		sig = nextsig;
  386|   154k|	}
  387|  4.51k|	return 1;
  388|  4.51k|}
msgparse.c:change_section:
  284|    545|{
  285|    545|	struct rrset_parse *p, *prev;
  286|       |	/* remove from list */
  287|    545|	if(section == rrset->section)
  ------------------
  |  Branch (287:5): [True: 418, False: 127]
  ------------------
  288|    418|		return;
  289|    127|	p = msg->rrset_first;
  290|    127|	prev = 0;
  291|    580|	while(p) {
  ------------------
  |  Branch (291:8): [True: 580, False: 0]
  ------------------
  292|    580|		if(p == rrset) {
  ------------------
  |  Branch (292:6): [True: 127, False: 453]
  ------------------
  293|    127|			if(prev) prev->rrset_all_next = p->rrset_all_next;
  ------------------
  |  Branch (293:7): [True: 69, False: 58]
  ------------------
  294|     58|			else	msg->rrset_first = p->rrset_all_next;
  295|    127|			if(msg->rrset_last == rrset)
  ------------------
  |  Branch (295:7): [True: 24, False: 103]
  ------------------
  296|     24|				msg->rrset_last = prev;
  297|    127|			break;
  298|    127|		}
  299|    453|		prev = p;
  300|    453|		p = p->rrset_all_next;
  301|    453|	}
  302|       |	/* remove from count */
  303|    127|	switch(rrset->section) {
  304|     85|		case LDNS_SECTION_ANSWER: msg->an_rrsets--; break;
  ------------------
  |  Branch (304:3): [True: 85, False: 42]
  ------------------
  305|     42|		case LDNS_SECTION_AUTHORITY: msg->ns_rrsets--; break;
  ------------------
  |  Branch (305:3): [True: 42, False: 85]
  ------------------
  306|      0|		case LDNS_SECTION_ADDITIONAL: msg->ar_rrsets--; break;
  ------------------
  |  Branch (306:3): [True: 0, False: 127]
  ------------------
  307|      0|		default: log_assert(0);
  ------------------
  |  Branch (307:3): [True: 0, False: 127]
  ------------------
  308|    127|	}
  309|       |	/* insert at end of list */
  310|    127|	rrset->rrset_all_next = 0;
  311|    127|	if(msg->rrset_last)
  ------------------
  |  Branch (311:5): [True: 119, False: 8]
  ------------------
  312|    119|		msg->rrset_last->rrset_all_next = rrset;
  313|      8|	else	msg->rrset_first = rrset;
  314|    127|	msg->rrset_last = rrset;
  315|       |	/* up count of new section */
  316|    127|	switch(section) {
  317|     65|		case LDNS_SECTION_AUTHORITY: msg->ns_rrsets++; break;
  ------------------
  |  Branch (317:3): [True: 65, False: 62]
  ------------------
  318|     62|		case LDNS_SECTION_ADDITIONAL: msg->ar_rrsets++; break;
  ------------------
  |  Branch (318:3): [True: 62, False: 65]
  ------------------
  319|      0|		default: log_assert(0);
  ------------------
  |  Branch (319:3): [True: 0, False: 127]
  ------------------
  320|    127|	}
  321|    127|	rrset->section = section;
  322|    127|}
msgparse.c:new_rrset:
   83|  92.4k|{
   84|  92.4k|	struct rrset_parse* p = regional_alloc(region, sizeof(*p));
   85|  92.4k|	if(!p) return NULL;
  ------------------
  |  Branch (85:5): [True: 0, False: 92.4k]
  ------------------
   86|  92.4k|	p->rrset_bucket_next = msg->hashtable[hash & (PARSE_TABLE_SIZE-1)];
  ------------------
  |  |   77|  92.4k|#define PARSE_TABLE_SIZE 32
  ------------------
   87|  92.4k|	msg->hashtable[hash & (PARSE_TABLE_SIZE-1)] = p;
  ------------------
  |  |   77|  92.4k|#define PARSE_TABLE_SIZE 32
  ------------------
   88|  92.4k|	p->rrset_all_next = 0;
   89|  92.4k|	if(msg->rrset_last)
  ------------------
  |  Branch (89:5): [True: 88.0k, False: 4.40k]
  ------------------
   90|  88.0k|		msg->rrset_last->rrset_all_next = p;
   91|  4.40k|	else 	msg->rrset_first = p;
   92|  92.4k|	msg->rrset_last = p;
   93|  92.4k|	p->hash = hash;
   94|  92.4k|	p->section = section;
   95|  92.4k|	p->dname = dname;
   96|  92.4k|	p->dname_len = dnamelen;
   97|  92.4k|	p->type = type;
   98|  92.4k|	p->rrset_class = dclass;
   99|  92.4k|	p->flags = rrset_flags;
  100|  92.4k|	p->rr_count = 0;
  101|  92.4k|	p->size = 0;
  102|  92.4k|	p->rr_first = 0;
  103|  92.4k|	p->rr_last = 0;
  104|  92.4k|	p->rrsig_count = 0;
  105|  92.4k|	p->rrsig_first = 0;
  106|  92.4k|	p->rrsig_last = 0;
  107|  92.4k|	return p;
  108|  92.4k|}
msgparse.c:add_rr_to_rrset:
  754|  4.02M|{
  755|  4.02M|	struct rr_parse* rr;
  756|       |	/* check section of rrset. */
  757|  4.02M|	if(rrset->section != section && type != LDNS_RR_TYPE_RRSIG &&
  ------------------
  |  Branch (757:5): [True: 330k, False: 3.69M]
  |  Branch (757:34): [True: 325k, False: 5.66k]
  ------------------
  758|  4.02M|		rrset->type != LDNS_RR_TYPE_RRSIG) {
  ------------------
  |  Branch (758:3): [True: 325k, 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|   325k|		if(!skip_ttl_rdata(pkt))
  ------------------
  |  Branch (770:6): [True: 127, False: 325k]
  ------------------
  771|    127|			return LDNS_RCODE_FORMERR;
  772|   325k|		return 0;
  773|   325k|	} 
  774|       |
  775|  3.70M|	if( (msg->qtype == LDNS_RR_TYPE_RRSIG ||
  ------------------
  |  Branch (775:7): [True: 123k, False: 3.57M]
  ------------------
  776|  3.70M|	     msg->qtype == LDNS_RR_TYPE_ANY) 
  ------------------
  |  Branch (776:7): [True: 313k, False: 3.26M]
  ------------------
  777|  3.70M|	    && sig_is_double(pkt, rrset, sldns_buffer_current(pkt))) {
  ------------------
  |  Branch (777:9): [True: 4.68k, False: 432k]
  ------------------
  778|  4.68k|		if(!skip_ttl_rdata(pkt))
  ------------------
  |  Branch (778:6): [True: 0, False: 4.68k]
  ------------------
  779|      0|			return LDNS_RCODE_FORMERR;
  780|  4.68k|		return 0;
  781|  4.68k|	}
  782|       |	
  783|       |	/* create rr */
  784|  3.69M|	if(!(rr = (struct rr_parse*)regional_alloc(region, sizeof(*rr))))
  ------------------
  |  Branch (784:5): [True: 0, False: 3.69M]
  ------------------
  785|      0|		return LDNS_RCODE_SERVFAIL;
  786|  3.69M|	rr->outside_packet = 0;
  787|  3.69M|	rr->ttl_data = sldns_buffer_current(pkt);
  788|  3.69M|	rr->next = 0;
  789|  3.69M|	if(type == LDNS_RR_TYPE_RRSIG && rrset->type != LDNS_RR_TYPE_RRSIG) {
  ------------------
  |  Branch (789:5): [True: 32.2k, False: 3.66M]
  |  Branch (789:35): [True: 13.8k, False: 18.4k]
  ------------------
  790|  13.8k|		if(rrset->rrsig_last) 
  ------------------
  |  Branch (790:6): [True: 13.4k, False: 397]
  ------------------
  791|  13.4k|			rrset->rrsig_last->next = rr;
  792|    397|		else	rrset->rrsig_first = rr;
  793|  13.8k|		rrset->rrsig_last = rr;
  794|  13.8k|		rrset->rrsig_count++;
  795|  3.68M|	} else {
  796|  3.68M|		if(rrset->rr_last)
  ------------------
  |  Branch (796:6): [True: 3.59M, False: 92.9k]
  ------------------
  797|  3.59M|			rrset->rr_last->next = rr;
  798|  92.9k|		else	rrset->rr_first = rr;
  799|  3.68M|		rrset->rr_last = rr;
  800|  3.68M|		rrset->rr_count++;
  801|  3.68M|	}
  802|       |
  803|       |	/* calc decompressed size */
  804|  3.69M|	if(!calc_size(pkt, type, rr))
  ------------------
  |  Branch (804:5): [True: 1.21k, False: 3.69M]
  ------------------
  805|  1.21k|		return LDNS_RCODE_FORMERR;
  806|  3.69M|	rrset->size += rr->size;
  807|       |
  808|  3.69M|	return 0;
  809|  3.69M|}
msgparse.c:skip_ttl_rdata:
  695|   329k|{
  696|   329k|	uint16_t rdatalen;
  697|   329k|	if(sldns_buffer_remaining(pkt) < 6) /* ttl + rdatalen */
  ------------------
  |  Branch (697:5): [True: 0, False: 329k]
  ------------------
  698|      0|		return 0;
  699|   329k|	sldns_buffer_skip(pkt, 4); /* ttl */
  700|   329k|	rdatalen = sldns_buffer_read_u16(pkt);
  701|   329k|	if(sldns_buffer_remaining(pkt) < rdatalen)
  ------------------
  |  Branch (701:5): [True: 127, False: 329k]
  ------------------
  702|    127|		return 0;
  703|   329k|	sldns_buffer_skip(pkt, (ssize_t)rdatalen);
  704|   329k|	return 1;
  705|   329k|}
msgparse.c:sig_is_double:
  710|   437k|{
  711|   437k|	uint16_t rlen, siglen;
  712|   437k|	size_t pos = sldns_buffer_position(pkt);
  713|   437k|	struct rr_parse* sig;
  714|   437k|	if(sldns_buffer_remaining(pkt) < 6) 
  ------------------
  |  Branch (714:5): [True: 0, False: 437k]
  ------------------
  715|      0|		return 0;
  716|   437k|	sldns_buffer_skip(pkt, 4); /* ttl */
  717|   437k|	rlen = sldns_buffer_read_u16(pkt);
  718|   437k|	if(sldns_buffer_remaining(pkt) < rlen) {
  ------------------
  |  Branch (718:5): [True: 210, False: 437k]
  ------------------
  719|    210|		sldns_buffer_set_position(pkt, pos);
  720|    210|		return 0;
  721|    210|	}
  722|   437k|	sldns_buffer_set_position(pkt, pos);
  723|       |
  724|   437k|	sig = rrset->rrsig_first;
  725|  1.40M|	while(sig) {
  ------------------
  |  Branch (725:8): [True: 970k, False: 432k]
  ------------------
  726|       |		/* check if rdatalen is same */
  727|   970k|		memmove(&siglen, sig->ttl_data+4, sizeof(siglen));
  728|   970k|		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|   970k|		if(siglen == rlen) {
  ------------------
  |  Branch (737:6): [True: 53.4k, False: 917k]
  ------------------
  738|  53.4k|			if(siglen>0 && memcmp(sig->ttl_data+6, ttldata+6, 
  ------------------
  |  Branch (738:7): [True: 53.4k, False: 0]
  |  Branch (738:19): [True: 4.68k, False: 48.7k]
  ------------------
  739|  53.4k|				siglen) == 0) {
  740|       |				/* same! */
  741|  4.68k|				return 1;
  742|  4.68k|			}
  743|  53.4k|		}
  744|   965k|		sig = sig->next;
  745|   965k|	}
  746|   432k|	return 0;
  747|   437k|}
msgparse.c:calc_size:
  637|  3.69M|{
  638|  3.69M|	const sldns_rr_descriptor* desc;
  639|  3.69M|	uint16_t pkt_len; /* length of rr inside the packet */
  640|  3.69M|	rr->size = sizeof(uint16_t); /* the rdatalen */
  641|  3.69M|	sldns_buffer_skip(pkt, 4); /* skip ttl */
  642|  3.69M|	pkt_len = sldns_buffer_read_u16(pkt);
  643|  3.69M|	if(sldns_buffer_remaining(pkt) < pkt_len)
  ------------------
  |  Branch (643:5): [True: 981, False: 3.69M]
  ------------------
  644|    981|		return 0;
  645|  3.69M|	desc = sldns_rr_descript(type);
  646|  3.69M|	if(pkt_len > 0 && desc && desc->_dname_count > 0) {
  ------------------
  |  Branch (646:5): [True: 77.8k, False: 3.61M]
  |  Branch (646:20): [True: 77.8k, False: 0]
  |  Branch (646:28): [True: 44.7k, False: 33.1k]
  ------------------
  647|  44.7k|		int count = (int)desc->_dname_count;
  648|  44.7k|		int rdf = 0;
  649|  44.7k|		size_t len;
  650|  44.7k|		size_t oldpos;
  651|       |		/* skip first part. */
  652|   258k|		while(pkt_len > 0 && count) {
  ------------------
  |  Branch (652:9): [True: 227k, False: 31.2k]
  |  Branch (652:24): [True: 213k, False: 13.2k]
  ------------------
  653|   213k|			switch(desc->_wireformat[rdf]) {
  654|  43.9k|			case LDNS_RDF_TYPE_DNAME:
  ------------------
  |  Branch (654:4): [True: 43.9k, False: 169k]
  ------------------
  655|       |				/* decompress every domain name */
  656|  43.9k|				oldpos = sldns_buffer_position(pkt);
  657|  43.9k|				if((len = pkt_dname_len(pkt)) == 0)
  ------------------
  |  Branch (657:8): [True: 151, False: 43.8k]
  ------------------
  658|    151|					return 0; /* malformed dname */
  659|  43.8k|				if(sldns_buffer_position(pkt)-oldpos > pkt_len)
  ------------------
  |  Branch (659:8): [True: 27, False: 43.7k]
  ------------------
  660|     27|					return 0; /* dname exceeds rdata */
  661|  43.7k|				pkt_len -= sldns_buffer_position(pkt)-oldpos;
  662|  43.7k|				rr->size += len;
  663|  43.7k|				count--;
  664|  43.7k|				len = 0;
  665|  43.7k|				break;
  666|    491|			case LDNS_RDF_TYPE_STR:
  ------------------
  |  Branch (666:4): [True: 491, False: 213k]
  ------------------
  667|    491|				if(pkt_len < 1) {
  ------------------
  |  Branch (667:8): [True: 0, False: 491]
  ------------------
  668|       |					/* NOTREACHED, due to 'while(>0)' */
  669|      0|					return 0; /* len byte exceeds rdata */
  670|      0|				}
  671|    491|				len = sldns_buffer_current(pkt)[0] + 1;
  672|    491|				break;
  673|   169k|			default:
  ------------------
  |  Branch (673:4): [True: 169k, False: 44.4k]
  ------------------
  674|   169k|				len = get_rdf_size(desc->_wireformat[rdf]);
  675|   213k|			}
  676|   213k|			if(len) {
  ------------------
  |  Branch (676:7): [True: 169k, False: 43.7k]
  ------------------
  677|   169k|				if(pkt_len < len)
  ------------------
  |  Branch (677:8): [True: 52, False: 169k]
  ------------------
  678|     52|					return 0; /* exceeds rdata */
  679|   169k|				pkt_len -= len;
  680|   169k|				sldns_buffer_skip(pkt, (ssize_t)len);
  681|   169k|				rr->size += len;
  682|   169k|			}
  683|   213k|			rdf++;
  684|   213k|		}
  685|  44.7k|	}
  686|       |	/* remaining rdata */
  687|  3.69M|	rr->size += pkt_len;
  688|  3.69M|	sldns_buffer_skip(pkt, (ssize_t)pkt_len);
  689|  3.69M|	return 1;
  690|  3.69M|}

parse_copy_decompress_rrset:
  414|  14.9k|{
  415|  14.9k|	struct packed_rrset_data* data;
  416|  14.9k|	pk->rk.flags = pset->flags;
  417|  14.9k|	pk->rk.dname_len = pset->dname_len;
  418|  14.9k|	if(region)
  ------------------
  |  Branch (418:5): [True: 0, False: 14.9k]
  ------------------
  419|      0|		pk->rk.dname = (uint8_t*)regional_alloc(
  420|      0|			region, pset->dname_len);
  421|  14.9k|	else	pk->rk.dname = 
  422|  14.9k|			(uint8_t*)malloc(pset->dname_len);
  423|  14.9k|	if(!pk->rk.dname)
  ------------------
  |  Branch (423:5): [True: 0, False: 14.9k]
  ------------------
  424|      0|		return 0;
  425|       |	/** copy & decompress dname */
  426|  14.9k|	dname_pkt_copy(pkt, pk->rk.dname, pset->dname);
  427|       |	/** copy over type and class */
  428|  14.9k|	pk->rk.type = htons(pset->type);
  429|  14.9k|	pk->rk.rrset_class = pset->rrset_class;
  430|       |	/** read data part. */
  431|  14.9k|	if(!parse_create_rrset(pkt, pset, &data, region)) {
  ------------------
  |  Branch (431:5): [True: 0, False: 14.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|  14.9k|	pk->entry.data = (void*)data;
  439|  14.9k|	pk->entry.key = (void*)pk;
  440|  14.9k|	pk->entry.hash = pset->hash;
  441|  14.9k|	data->trust = get_rrset_trust(msg, pset);
  442|  14.9k|	return 1;
  443|  14.9k|}
edns_opt_list_append:
 1025|  13.8k|{
 1026|  13.8k|	struct edns_option** prevp;
 1027|  13.8k|	struct edns_option* opt;
 1028|       |
 1029|       |	/* allocate new element */
 1030|  13.8k|	opt = (struct edns_option*)regional_alloc(region, sizeof(*opt));
 1031|  13.8k|	if(!opt)
  ------------------
  |  Branch (1031:5): [True: 0, False: 13.8k]
  ------------------
 1032|      0|		return 0;
 1033|  13.8k|	opt->next = NULL;
 1034|  13.8k|	opt->opt_code = code;
 1035|  13.8k|	opt->opt_len = len;
 1036|  13.8k|	opt->opt_data = NULL;
 1037|  13.8k|	if(len > 0) {
  ------------------
  |  Branch (1037:5): [True: 1.15k, False: 12.6k]
  ------------------
 1038|  1.15k|		opt->opt_data = regional_alloc_init(region, data, len);
 1039|  1.15k|		if(!opt->opt_data)
  ------------------
  |  Branch (1039:6): [True: 0, False: 1.15k]
  ------------------
 1040|      0|			return 0;
 1041|  1.15k|	}
 1042|       |
 1043|       |	/* append at end of list */
 1044|  13.8k|	prevp = list;
 1045|  15.4M|	while(*prevp != NULL) {
  ------------------
  |  Branch (1045:8): [True: 15.4M, False: 13.8k]
  ------------------
 1046|  15.4M|		prevp = &((*prevp)->next);
 1047|  15.4M|	}
 1048|  13.8k|	*prevp = opt;
 1049|  13.8k|	return 1;
 1050|  13.8k|}
msgreply.c:parse_create_rrset:
  346|  14.9k|{
  347|       |	/* allocate */
  348|  14.9k|	size_t s;
  349|  14.9k|	if(pset->rr_count > RR_COUNT_MAX || pset->rrsig_count > RR_COUNT_MAX ||
  ------------------
  |  |   76|  29.9k|#define RR_COUNT_MAX 0xffffff
  ------------------
              	if(pset->rr_count > RR_COUNT_MAX || pset->rrsig_count > RR_COUNT_MAX ||
  ------------------
  |  |   76|  29.9k|#define RR_COUNT_MAX 0xffffff
  ------------------
  |  Branch (349:5): [True: 0, False: 14.9k]
  |  Branch (349:38): [True: 0, False: 14.9k]
  ------------------
  350|  14.9k|		pset->size > RR_COUNT_MAX)
  ------------------
  |  |   76|  14.9k|#define RR_COUNT_MAX 0xffffff
  ------------------
  |  Branch (350:3): [True: 0, False: 14.9k]
  ------------------
  351|      0|		return 0; /* protect against integer overflow */
  352|  14.9k|	s = sizeof(struct packed_rrset_data) + 
  353|  14.9k|		(pset->rr_count + pset->rrsig_count) * 
  354|  14.9k|		(sizeof(size_t)+sizeof(uint8_t*)+sizeof(time_t)) + 
  355|  14.9k|		pset->size;
  356|  14.9k|	if(region)
  ------------------
  |  Branch (356:5): [True: 0, False: 14.9k]
  ------------------
  357|      0|		*data = regional_alloc_zero(region, s);
  358|  14.9k|	else	*data = calloc(1, s);
  359|  14.9k|	if(!*data)
  ------------------
  |  Branch (359:5): [True: 0, False: 14.9k]
  ------------------
  360|      0|		return 0;
  361|       |	/* copy & decompress */
  362|  14.9k|	if(!parse_rr_copy(pkt, pset, *data)) {
  ------------------
  |  Branch (362:5): [True: 0, False: 14.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|  14.9k|	return 1;
  370|  14.9k|}
msgreply.c:parse_rr_copy:
  303|  14.9k|{
  304|  14.9k|	size_t i;
  305|  14.9k|	struct rr_parse* rr = pset->rr_first;
  306|  14.9k|	uint8_t* nextrdata;
  307|  14.9k|	size_t total = pset->rr_count + pset->rrsig_count;
  308|  14.9k|	data->ttl = MAX_TTL;
  309|  14.9k|	data->count = pset->rr_count;
  310|  14.9k|	data->rrsig_count = pset->rrsig_count;
  311|  14.9k|	data->trust = rrset_trust_none;
  312|  14.9k|	data->security = sec_status_unchecked;
  313|       |	/* layout: struct - rr_len - rr_data - rr_ttl - rdata - rrsig */
  314|  14.9k|	data->rr_len = (size_t*)((uint8_t*)data + 
  315|  14.9k|		sizeof(struct packed_rrset_data));
  316|  14.9k|	data->rr_data = (uint8_t**)&(data->rr_len[total]);
  317|  14.9k|	data->rr_ttl = (time_t*)&(data->rr_data[total]);
  318|  14.9k|	nextrdata = (uint8_t*)&(data->rr_ttl[total]);
  319|  2.66M|	for(i=0; i<data->count; i++) {
  ------------------
  |  Branch (319:11): [True: 2.64M, False: 14.9k]
  ------------------
  320|  2.64M|		data->rr_len[i] = rr->size;
  321|  2.64M|		data->rr_data[i] = nextrdata;
  322|  2.64M|		nextrdata += rr->size;
  323|  2.64M|		if(!rdata_copy(pkt, data, data->rr_data[i], rr, 
  ------------------
  |  Branch (323:6): [True: 0, False: 2.64M]
  ------------------
  324|  2.64M|			&data->rr_ttl[i], pset->type, pset->section))
  325|      0|			return 0;
  326|  2.64M|		rr = rr->next;
  327|  2.64M|	}
  328|       |	/* if rrsig, its rdata is at nextrdata */
  329|  14.9k|	rr = pset->rrsig_first;
  330|  23.4k|	for(i=data->count; i<total; i++) {
  ------------------
  |  Branch (330:21): [True: 8.49k, False: 14.9k]
  ------------------
  331|  8.49k|		data->rr_len[i] = rr->size;
  332|  8.49k|		data->rr_data[i] = nextrdata;
  333|  8.49k|		nextrdata += rr->size;
  334|  8.49k|		if(!rdata_copy(pkt, data, data->rr_data[i], rr, 
  ------------------
  |  Branch (334:6): [True: 0, False: 8.49k]
  ------------------
  335|  8.49k|			&data->rr_ttl[i], LDNS_RR_TYPE_RRSIG, pset->section))
  336|      0|			return 0;
  337|  8.49k|		rr = rr->next;
  338|  8.49k|	}
  339|  14.9k|	return 1;
  340|  14.9k|}
msgreply.c:rdata_copy:
  213|  2.65M|{
  214|  2.65M|	uint16_t pkt_len;
  215|  2.65M|	const sldns_rr_descriptor* desc;
  216|       |
  217|  2.65M|	*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.65M|	if(*rr_ttl & 0x80000000U)
  ------------------
  |  Branch (219:5): [True: 9.16k, False: 2.64M]
  ------------------
  220|  9.16k|		*rr_ttl = 0;
  221|  2.65M|	if(type == LDNS_RR_TYPE_SOA && section == LDNS_SECTION_AUTHORITY) {
  ------------------
  |  Branch (221:5): [True: 0, False: 2.65M]
  |  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.65M|	if(!SERVE_ORIGINAL_TTL && (*rr_ttl < MIN_TTL))
  ------------------
  |  Branch (227:5): [True: 2.65M, False: 0]
  |  Branch (227:28): [True: 0, False: 2.65M]
  ------------------
  228|      0|		*rr_ttl = MIN_TTL;
  229|  2.65M|	if(!SERVE_ORIGINAL_TTL && (*rr_ttl > MAX_TTL))
  ------------------
  |  Branch (229:5): [True: 2.65M, False: 0]
  |  Branch (229:28): [True: 281k, False: 2.37M]
  ------------------
  230|   281k|		*rr_ttl = MAX_TTL;
  231|  2.65M|	if(type == LDNS_RR_TYPE_SOA && section == LDNS_SECTION_AUTHORITY) {
  ------------------
  |  Branch (231:5): [True: 0, False: 2.65M]
  |  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.65M|	if(*rr_ttl < data->ttl)
  ------------------
  |  Branch (237:5): [True: 10.9k, False: 2.64M]
  ------------------
  238|  10.9k|		data->ttl = *rr_ttl;
  239|       |
  240|  2.65M|	if(rr->outside_packet) {
  ------------------
  |  Branch (240:5): [True: 0, False: 2.65M]
  ------------------
  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.65M|	sldns_buffer_set_position(pkt, (size_t)
  247|  2.65M|		(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.65M|	pkt_len = htons(rr->size - 2);
  251|  2.65M|	memmove(to, &pkt_len, sizeof(uint16_t));
  252|  2.65M|	to += 2;
  253|       |	/* read packet rdata len */
  254|  2.65M|	pkt_len = sldns_buffer_read_u16(pkt);
  255|  2.65M|	if(sldns_buffer_remaining(pkt) < pkt_len)
  ------------------
  |  Branch (255:5): [True: 0, False: 2.65M]
  ------------------
  256|      0|		return 0;
  257|  2.65M|	desc = sldns_rr_descript(type);
  258|  2.65M|	if(pkt_len > 0 && desc && desc->_dname_count > 0) {
  ------------------
  |  Branch (258:5): [True: 12.3k, False: 2.64M]
  |  Branch (258:20): [True: 12.3k, False: 0]
  |  Branch (258:28): [True: 8.49k, False: 3.82k]
  ------------------
  259|  8.49k|		int count = (int)desc->_dname_count;
  260|  8.49k|		int rdf = 0;
  261|  8.49k|		size_t len;
  262|  8.49k|		size_t oldpos;
  263|       |		/* decompress dnames. */
  264|  76.4k|		while(pkt_len > 0 && count) {
  ------------------
  |  Branch (264:9): [True: 70.4k, False: 6.01k]
  |  Branch (264:24): [True: 67.9k, False: 2.48k]
  ------------------
  265|  67.9k|			switch(desc->_wireformat[rdf]) {
  266|  8.49k|			case LDNS_RDF_TYPE_DNAME:
  ------------------
  |  Branch (266:4): [True: 8.49k, False: 59.4k]
  ------------------
  267|  8.49k|				oldpos = sldns_buffer_position(pkt);
  268|  8.49k|				dname_pkt_copy(pkt, to, 
  269|  8.49k|					sldns_buffer_current(pkt));
  270|  8.49k|				to += pkt_dname_len(pkt);
  271|  8.49k|				pkt_len -= sldns_buffer_position(pkt)-oldpos;
  272|  8.49k|				count--;
  273|  8.49k|				len = 0;
  274|  8.49k|				break;
  275|      0|			case LDNS_RDF_TYPE_STR:
  ------------------
  |  Branch (275:4): [True: 0, False: 67.9k]
  ------------------
  276|      0|				len = sldns_buffer_current(pkt)[0] + 1;
  277|      0|				break;
  278|  59.4k|			default:
  ------------------
  |  Branch (278:4): [True: 59.4k, False: 8.49k]
  ------------------
  279|  59.4k|				len = get_rdf_size(desc->_wireformat[rdf]);
  280|  59.4k|				break;
  281|  67.9k|			}
  282|  67.9k|			if(len) {
  ------------------
  |  Branch (282:7): [True: 59.4k, False: 8.49k]
  ------------------
  283|  59.4k|				log_assert(len <= pkt_len);
  284|  59.4k|				memmove(to, sldns_buffer_current(pkt), len);
  285|  59.4k|				to += len;
  286|  59.4k|				sldns_buffer_skip(pkt, (ssize_t)len);
  287|  59.4k|				pkt_len -= len;
  288|  59.4k|			}
  289|  67.9k|			rdf++;
  290|  67.9k|		}
  291|  8.49k|	}
  292|       |	/* copy remaining rdata */
  293|  2.65M|	if(pkt_len >  0)
  ------------------
  |  Branch (293:5): [True: 6.30k, False: 2.65M]
  ------------------
  294|  6.30k|		memmove(to, sldns_buffer_current(pkt), pkt_len);
  295|       |	
  296|  2.65M|	return 1;
  297|  2.65M|}
msgreply.c:get_rrset_trust:
  375|  14.9k|{
  376|  14.9k|	uint16_t AA = msg->flags & BIT_AA;
  ------------------
  |  |   70|  14.9k|#define BIT_AA 0x0400
  ------------------
  377|  14.9k|	if(rrset->section == LDNS_SECTION_ANSWER) {
  ------------------
  |  Branch (377:5): [True: 0, False: 14.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|  14.9k|	} else if(rrset->section == LDNS_SECTION_AUTHORITY) {
  ------------------
  |  Branch (398:12): [True: 5.38k, False: 9.60k]
  ------------------
  399|  5.38k|		if(AA)	return rrset_trust_auth_AA;
  ------------------
  |  Branch (399:6): [True: 3.49k, False: 1.88k]
  ------------------
  400|  1.88k|		else	return rrset_trust_auth_noAA;
  401|  9.60k|	} else {
  402|       |		/* addit section */
  403|  9.60k|		if(AA)	return rrset_trust_add_AA;
  ------------------
  |  Branch (403:6): [True: 6.28k, False: 3.31k]
  ------------------
  404|  3.31k|		else	return rrset_trust_add_noAA;
  405|  9.60k|	}
  406|       |	/* NOTREACHED */
  407|      0|	return rrset_trust_none;
  408|  14.9k|}

ub_rrset_sizefunc:
   71|  15.3k|{
   72|  15.3k|	struct ub_packed_rrset_key* k = (struct ub_packed_rrset_key*)key;
   73|  15.3k|	struct packed_rrset_data* d = (struct packed_rrset_data*)data;
   74|  15.3k|	size_t s = sizeof(struct ub_packed_rrset_key) + k->rk.dname_len;
   75|  15.3k|	s += packed_rrset_sizeof(d) + lock_get_mem(&k->entry.lock);
  ------------------
  |  |   88|  15.3k|#define lock_get_mem(lock) (0) /* nothing */
  ------------------
   76|  15.3k|	return s;
   77|  15.3k|}
packed_rrset_sizeof:
   81|  15.3k|{
   82|  15.3k|	size_t s;
   83|  15.3k|	if(d->rrsig_count > 0) {
  ------------------
  |  Branch (83:5): [True: 114, False: 15.2k]
  ------------------
   84|    114|		s = ((uint8_t*)d->rr_data[d->count+d->rrsig_count-1] - 
   85|    114|			(uint8_t*)d) + d->rr_len[d->count+d->rrsig_count-1];
   86|  15.2k|	} else {
   87|  15.2k|		log_assert(d->count > 0);
   88|  15.2k|		s = ((uint8_t*)d->rr_data[d->count-1] - (uint8_t*)d) + 
   89|  15.2k|			d->rr_len[d->count-1];
   90|  15.2k|	}
   91|  15.3k|	return s;
   92|  15.3k|}
ub_rrset_compare:
   96|    562|{
   97|    562|	struct ub_packed_rrset_key* key1 = (struct ub_packed_rrset_key*)k1;
   98|    562|	struct ub_packed_rrset_key* key2 = (struct ub_packed_rrset_key*)k2;
   99|    562|	int c;
  100|    562|	if(key1 == key2)
  ------------------
  |  Branch (100:5): [True: 0, False: 562]
  ------------------
  101|      0|		return 0;
  102|    562|	if(key1->rk.type != key2->rk.type) {
  ------------------
  |  Branch (102:5): [True: 4, False: 558]
  ------------------
  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|    558|	if(key1->rk.dname_len != key2->rk.dname_len) {
  ------------------
  |  Branch (107:5): [True: 494, False: 64]
  ------------------
  108|    494|		if(key1->rk.dname_len < key2->rk.dname_len)
  ------------------
  |  Branch (108:6): [True: 274, False: 220]
  ------------------
  109|    274|			return -1;
  110|    220|		return 1;
  111|    494|	}
  112|     64|	if((c=query_dname_compare(key1->rk.dname, key2->rk.dname)) != 0)
  ------------------
  |  Branch (112:5): [True: 18, False: 46]
  ------------------
  113|     18|		return c;
  114|     46|	if(key1->rk.rrset_class != key2->rk.rrset_class) {
  ------------------
  |  Branch (114:5): [True: 46, False: 0]
  ------------------
  115|     46|		if(key1->rk.rrset_class < key2->rk.rrset_class)
  ------------------
  |  Branch (115:6): [True: 26, False: 20]
  ------------------
  116|     26|			return -1;
  117|     20|		return 1;
  118|     46|	}
  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|  14.9k|{
  130|  14.9k|	struct ub_packed_rrset_key* k = (struct ub_packed_rrset_key*)key;
  131|  14.9k|	struct alloc_cache* a = (struct alloc_cache*)userdata;
  132|  14.9k|	k->id = 0;
  133|  14.9k|	free(k->rk.dname);
  134|  14.9k|	k->rk.dname = NULL;
  135|  14.9k|	alloc_special_release(a, k);
  136|  14.9k|}
rrset_data_delete:
  140|  14.9k|{
  141|  14.9k|	struct packed_rrset_data* d = (struct packed_rrset_data*)data;
  142|  14.9k|	free(d);
  143|  14.9k|}
packed_rrset_ttl_add:
  220|  14.9k|{
  221|  14.9k|	size_t i;
  222|  14.9k|	size_t total = data->count + data->rrsig_count;
  223|  14.9k|	data->ttl_add = add;
  224|  14.9k|	data->ttl += add;
  225|  2.67M|	for(i=0; i<total; i++)
  ------------------
  |  Branch (225:11): [True: 2.65M, False: 14.9k]
  ------------------
  226|  2.65M|		data->rr_ttl[i] += add;
  227|  14.9k|}

fptr_whitelist_hash_sizefunc:
  253|  14.9k|{
  254|  14.9k|	if(fptr == &msgreply_sizefunc) return 1;
  ------------------
  |  Branch (254:5): [True: 0, False: 14.9k]
  ------------------
  255|  14.9k|	else if(fptr == &ub_rrset_sizefunc) return 1;
  ------------------
  |  Branch (255:10): [True: 14.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|  14.9k|}
fptr_whitelist_hash_compfunc:
  273|  29.9k|{
  274|  29.9k|	if(fptr == &query_info_compare) return 1;
  ------------------
  |  Branch (274:5): [True: 0, False: 29.9k]
  ------------------
  275|  29.9k|	else if(fptr == &ub_rrset_compare) return 1;
  ------------------
  |  Branch (275:10): [True: 29.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|  29.9k|}
fptr_whitelist_hash_delkeyfunc:
  290|  14.9k|{
  291|  14.9k|	if(fptr == &query_entry_delete) return 1;
  ------------------
  |  Branch (291:5): [True: 0, False: 14.9k]
  ------------------
  292|  14.9k|	else if(fptr == &ub_rrset_key_delete) return 1;
  ------------------
  |  Branch (292:10): [True: 14.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|  14.9k|}
fptr_whitelist_hash_deldatafunc:
  307|  14.9k|{
  308|  14.9k|	if(fptr == &reply_info_delete) return 1;
  ------------------
  |  Branch (308:5): [True: 0, False: 14.9k]
  ------------------
  309|  14.9k|	else if(fptr == &rrset_data_delete) return 1;
  ------------------
  |  Branch (309:10): [True: 14.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|  14.9k|}
fptr_whitelist_hash_markdelfunc:
  326|  14.9k|{
  327|  14.9k|	if(fptr == NULL) return 1;
  ------------------
  |  Branch (327:5): [True: 0, False: 14.9k]
  ------------------
  328|  14.9k|	else if(fptr == &rrset_markdel) return 1;
  ------------------
  |  Branch (328:10): [True: 14.9k, False: 0]
  ------------------
  329|       |#ifdef CLIENT_SUBNET
  330|       |	else if(fptr == &subnet_markdel) return 1;
  331|       |#endif
  332|      0|	return 0;
  333|  14.9k|}

log_init:
   87|  4.66k|{
   88|  4.66k|	FILE *f;
   89|  4.66k|	if(!key_created) {
  ------------------
  |  Branch (89:5): [True: 1, False: 4.66k]
  ------------------
   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.66k|	lock_basic_lock(&log_lock);
  ------------------
  |  |  102|  4.66k|#define lock_basic_lock(lock) LOCKRET(pthread_mutex_lock(lock))
  |  |  ------------------
  |  |  |  |   67|  4.66k|#define LOCKRET(func) do {\
  |  |  |  |   68|  4.66k|	int lockret_err;		\
  |  |  |  |   69|  4.66k|	if( (lockret_err=(func)) != 0)		\
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (69:6): [True: 0, False: 4.66k]
  |  |  |  |  ------------------
  |  |  |  |   70|  4.66k|		log_err("%s at %d could not " #func ": %s", \
  |  |  |  |   71|      0|		__FILE__, __LINE__, strerror(lockret_err));	\
  |  |  |  |   72|  4.66k| 	} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (72:11): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
   95|  4.66k|	if(logfile 
  ------------------
  |  Branch (95:5): [True: 4.66k, False: 1]
  ------------------
   96|  4.66k|#if defined(HAVE_SYSLOG_H) || defined(UB_ON_WINDOWS)
   97|  4.66k|	|| logging_to_syslog
  ------------------
  |  Branch (97:5): [True: 0, False: 1]
  ------------------
   98|  4.66k|#endif
   99|  4.66k|	) {
  100|  4.66k|		lock_basic_unlock(&log_lock); /* verbose() needs the lock */
  ------------------
  |  |  103|  4.66k|#define lock_basic_unlock(lock) LOCKRET(pthread_mutex_unlock(lock))
  |  |  ------------------
  |  |  |  |   67|  4.66k|#define LOCKRET(func) do {\
  |  |  |  |   68|  4.66k|	int lockret_err;		\
  |  |  |  |   69|  4.66k|	if( (lockret_err=(func)) != 0)		\
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (69:6): [True: 0, False: 4.66k]
  |  |  |  |  ------------------
  |  |  |  |   70|  4.66k|		log_err("%s at %d could not " #func ": %s", \
  |  |  |  |   71|      0|		__FILE__, __LINE__, strerror(lockret_err));	\
  |  |  |  |   72|  4.66k| 	} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (72:11): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  101|  4.66k|		verbose(VERB_QUERY, "switching log to %s", 
  102|  4.66k|			use_syslog?"syslog":(filename&&filename[0]?filename:"stderr"));
  ------------------
  |  Branch (102:4): [True: 0, False: 4.66k]
  |  Branch (102:25): [True: 4.66k, False: 0]
  |  Branch (102:35): [True: 4.66k, False: 0]
  ------------------
  103|  4.66k|		lock_basic_lock(&log_lock);
  ------------------
  |  |  102|  4.66k|#define lock_basic_lock(lock) LOCKRET(pthread_mutex_lock(lock))
  |  |  ------------------
  |  |  |  |   67|  4.66k|#define LOCKRET(func) do {\
  |  |  |  |   68|  4.66k|	int lockret_err;		\
  |  |  |  |   69|  4.66k|	if( (lockret_err=(func)) != 0)		\
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (69:6): [True: 0, False: 4.66k]
  |  |  |  |  ------------------
  |  |  |  |   70|  4.66k|		log_err("%s at %d could not " #func ": %s", \
  |  |  |  |   71|      0|		__FILE__, __LINE__, strerror(lockret_err));	\
  |  |  |  |   72|  4.66k| 	} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (72:11): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  104|  4.66k|	}
  105|  4.66k|	if(logfile && logfile != stderr) {
  ------------------
  |  Branch (105:5): [True: 4.66k, False: 1]
  |  Branch (105:16): [True: 4.66k, False: 0]
  ------------------
  106|  4.66k|		FILE* cl = logfile;
  107|  4.66k|		logfile = NULL; /* set to NULL before it is closed, so that
  108|       |			other threads have a valid logfile or NULL */
  109|  4.66k|		fclose(cl);
  110|  4.66k|	}
  111|  4.66k|#ifdef HAVE_SYSLOG_H
  112|  4.66k|	if(logging_to_syslog) {
  ------------------
  |  Branch (112:5): [True: 0, False: 4.66k]
  ------------------
  113|      0|		closelog();
  114|      0|		logging_to_syslog = 0;
  115|      0|	}
  116|  4.66k|	if(use_syslog) {
  ------------------
  |  Branch (116:5): [True: 0, False: 4.66k]
  ------------------
  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);
  ------------------
  |  |  844|      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.66k|	if(!filename || !filename[0]) {
  ------------------
  |  Branch (136:5): [True: 0, False: 4.66k]
  |  Branch (136:18): [True: 0, False: 4.66k]
  ------------------
  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.66k|	if(chrootdir && chrootdir[0] && strncmp(filename, chrootdir,
  ------------------
  |  Branch (142:5): [True: 0, False: 4.66k]
  |  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.66k|	f = fopen(filename, "a");
  146|  4.66k|	if(!f) {
  ------------------
  |  Branch (146:5): [True: 0, False: 4.66k]
  ------------------
  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.66k|#ifndef UB_ON_WINDOWS
  153|       |	/* line buffering does not work on windows */
  154|  4.66k|	setvbuf(f, NULL, (int)_IOLBF, 0);
  155|  4.66k|#endif
  156|  4.66k|	logfile = f;
  157|  4.66k|	lock_basic_unlock(&log_lock);
  ------------------
  |  |  103|  4.66k|#define lock_basic_unlock(lock) LOCKRET(pthread_mutex_unlock(lock))
  |  |  ------------------
  |  |  |  |   67|  4.66k|#define LOCKRET(func) do {\
  |  |  |  |   68|  4.66k|	int lockret_err;		\
  |  |  |  |   69|  4.66k|	if( (lockret_err=(func)) != 0)		\
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (69:6): [True: 0, False: 4.66k]
  |  |  |  |  ------------------
  |  |  |  |   70|  4.66k|		log_err("%s at %d could not " #func ": %s", \
  |  |  |  |   71|      0|		__FILE__, __LINE__, strerror(lockret_err));	\
  |  |  |  |   72|  4.66k| 	} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (72:11): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  158|  4.66k|}
verbose:
  357|  9.46k|{
  358|  9.46k|        va_list args;
  359|  9.46k|	va_start(args, format);
  360|  9.46k|	if(verbosity >= level) {
  ------------------
  |  Branch (360:5): [True: 0, False: 9.46k]
  ------------------
  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.46k|	va_end(args);
  368|  9.46k|}

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

log_nametypeclass:
  533|  2.04k|{
  534|  2.04k|	char buf[LDNS_MAX_DOMAINLEN+1];
  535|  2.04k|	char t[12], c[12];
  536|  2.04k|	const char *ts, *cs; 
  537|  2.04k|	if(verbosity < v)
  ------------------
  |  Branch (537:5): [True: 2.04k, False: 0]
  ------------------
  538|  2.04k|		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:
  195|  4.66k|{
  196|  4.66k|	struct comm_base* b = (struct comm_base*)calloc(1,
  197|  4.66k|		sizeof(struct comm_base));
  198|  4.66k|	const char *evnm="event", *evsys="", *evmethod="";
  199|       |
  200|  4.66k|	if(!b)
  ------------------
  |  Branch (200:5): [True: 0, False: 4.66k]
  ------------------
  201|      0|		return NULL;
  202|  4.66k|	b->eb = (struct internal_base*)calloc(1, sizeof(struct internal_base));
  203|  4.66k|	if(!b->eb) {
  ------------------
  |  Branch (203:5): [True: 0, False: 4.66k]
  ------------------
  204|      0|		free(b);
  205|      0|		return NULL;
  206|      0|	}
  207|  4.66k|	b->eb->base = ub_default_event_base(sigs, &b->eb->secs, &b->eb->now);
  208|  4.66k|	if(!b->eb->base) {
  ------------------
  |  Branch (208:5): [True: 0, False: 4.66k]
  ------------------
  209|      0|		free(b->eb);
  210|      0|		free(b);
  211|      0|		return NULL;
  212|      0|	}
  213|  4.66k|	ub_comm_base_now(b);
  214|  4.66k|	ub_get_event_sys(b->eb->base, &evnm, &evsys, &evmethod);
  215|  4.66k|	verbose(VERB_ALGO, "%s %s uses %s method.", evnm, evsys, evmethod);
  216|  4.66k|	return b;
  217|  4.66k|}
comm_base_delete:
  238|  4.66k|{
  239|  4.66k|	if(!b)
  ------------------
  |  Branch (239:5): [True: 0, False: 4.66k]
  ------------------
  240|      0|		return;
  241|  4.66k|	if(b->eb->slow_accept_enabled) {
  ------------------
  |  Branch (241:5): [True: 0, False: 4.66k]
  ------------------
  242|      0|		if(ub_event_del(b->eb->slow_accept) != 0) {
  ------------------
  |  Branch (242:6): [True: 0, False: 0]
  ------------------
  243|      0|			log_err("could not event_del slow_accept");
  244|      0|		}
  245|      0|		ub_event_free(b->eb->slow_accept);
  246|      0|	}
  247|  4.66k|	ub_event_base_free(b->eb->base);
  248|  4.66k|	b->eb->base = NULL;
  249|  4.66k|	free(b->eb);
  250|  4.66k|	free(b);
  251|  4.66k|}
comm_base_timept:
  271|  4.66k|{
  272|  4.66k|	*tt = &b->eb->secs;
  273|  4.66k|	*tv = &b->eb->now;
  274|  4.66k|}

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

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

hashlittle:
  347|  3.93M|{
  348|  3.93M|  uint32_t a,b,c;                                          /* internal state */
  349|  3.93M|  union { const void *ptr; size_t i; } u;     /* needed for Mac Powerbook G4 */
  350|       |
  351|       |  /* Set up the internal state */
  352|  3.93M|  a = b = c = raninit + ((uint32_t)length) + initval;
  353|       |
  354|  3.93M|  u.ptr = key;
  355|  3.93M|  if (HASH_LITTLE_ENDIAN && ((u.i & 0x3) == 0)) {
  ------------------
  |  |   93|  7.87M|#  define HASH_LITTLE_ENDIAN 1
  |  |  ------------------
  |  |  |  Branch (93:30): [Folded - Ignored]
  |  |  ------------------
  ------------------
  |  Branch (355:29): [True: 2.66M, False: 1.27M]
  ------------------
  356|  2.66M|    const uint32_t *k = (const uint32_t *)key;         /* read 32-bit chunks */
  357|  2.66M|#ifdef ARRAY_CLEAN_ACCESS
  358|  2.66M|    const uint8_t  *k8;
  359|  2.66M|#endif
  360|       |
  361|       |    /*------ all but last block: aligned reads and affect 32 bits of (a,b,c) */
  362|  2.73M|    while (length > 12)
  ------------------
  |  Branch (362:12): [True: 77.9k, False: 2.66M]
  ------------------
  363|  77.9k|    {
  364|  77.9k|      a += k[0];
  365|  77.9k|      b += k[1];
  366|  77.9k|      c += k[2];
  367|  77.9k|      mix(a,b,c);
  ------------------
  |  |  173|  77.9k|#define mix(a,b,c) \
  |  |  174|  77.9k|{ \
  |  |  175|  77.9k|  a -= c;  a ^= rot(c, 4);  c += b; \
  |  |  ------------------
  |  |  |  |  118|  77.9k|#define rot(x,k) (((x)<<(k)) | ((x)>>(32-(k))))
  |  |  ------------------
  |  |  176|  77.9k|  b -= a;  b ^= rot(a, 6);  a += c; \
  |  |  ------------------
  |  |  |  |  118|  77.9k|#define rot(x,k) (((x)<<(k)) | ((x)>>(32-(k))))
  |  |  ------------------
  |  |  177|  77.9k|  c -= b;  c ^= rot(b, 8);  b += a; \
  |  |  ------------------
  |  |  |  |  118|  77.9k|#define rot(x,k) (((x)<<(k)) | ((x)>>(32-(k))))
  |  |  ------------------
  |  |  178|  77.9k|  a -= c;  a ^= rot(c,16);  c += b; \
  |  |  ------------------
  |  |  |  |  118|  77.9k|#define rot(x,k) (((x)<<(k)) | ((x)>>(32-(k))))
  |  |  ------------------
  |  |  179|  77.9k|  b -= a;  b ^= rot(a,19);  a += c; \
  |  |  ------------------
  |  |  |  |  118|  77.9k|#define rot(x,k) (((x)<<(k)) | ((x)>>(32-(k))))
  |  |  ------------------
  |  |  180|  77.9k|  c -= b;  c ^= rot(b, 4);  b += a; \
  |  |  ------------------
  |  |  |  |  118|  77.9k|#define rot(x,k) (((x)<<(k)) | ((x)>>(32-(k))))
  |  |  ------------------
  |  |  181|  77.9k|}
  ------------------
  368|  77.9k|      length -= 12;
  369|  77.9k|      k += 3;
  370|  77.9k|    }
  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.66M|    k8 = (const uint8_t *)k;
  404|  2.66M|    switch(length)
  ------------------
  |  Branch (404:12): [True: 0, False: 2.66M]
  ------------------
  405|  2.66M|    {
  406|  3.90k|    case 12: c+=k[2]; b+=k[1]; a+=k[0]; break;
  ------------------
  |  Branch (406:5): [True: 3.90k, False: 2.65M]
  ------------------
  407|  10.5k|    case 11: c+=((uint32_t)k8[10])<<16;  /* fall through */
  ------------------
  |  Branch (407:5): [True: 10.5k, False: 2.65M]
  ------------------
  408|  13.0k|    case 10: c+=((uint32_t)k8[9])<<8;    /* fall through */
  ------------------
  |  Branch (408:5): [True: 2.51k, False: 2.65M]
  ------------------
  409|  23.6k|    case 9 : c+=k8[8];                   /* fall through */
  ------------------
  |  Branch (409:5): [True: 10.6k, False: 2.65M]
  ------------------
  410|  26.3k|    case 8 : b+=k[1]; a+=k[0]; break;
  ------------------
  |  Branch (410:5): [True: 2.73k, False: 2.65M]
  ------------------
  411|  3.33k|    case 7 : b+=((uint32_t)k8[6])<<16;   /* fall through */
  ------------------
  |  Branch (411:5): [True: 3.33k, False: 2.65M]
  ------------------
  412|  6.59k|    case 6 : b+=((uint32_t)k8[5])<<8;    /* fall through */
  ------------------
  |  Branch (412:5): [True: 3.25k, False: 2.65M]
  ------------------
  413|  13.2k|    case 5 : b+=k8[4];                   /* fall through */
  ------------------
  |  Branch (413:5): [True: 6.61k, False: 2.65M]
  ------------------
  414|  1.29M|    case 4 : a+=k[0]; break;
  ------------------
  |  Branch (414:5): [True: 1.28M, False: 1.37M]
  ------------------
  415|  26.8k|    case 3 : a+=((uint32_t)k8[2])<<16;   /* fall through */
  ------------------
  |  Branch (415:5): [True: 26.8k, False: 2.63M]
  ------------------
  416|  1.32M|    case 2 : a+=((uint32_t)k8[1])<<8;    /* fall through */
  ------------------
  |  Branch (416:5): [True: 1.30M, False: 1.36M]
  ------------------
  417|  1.33M|    case 1 : a+=k8[0]; break;
  ------------------
  |  Branch (417:5): [True: 3.98k, False: 2.65M]
  ------------------
  418|      0|    case 0 : return c;
  ------------------
  |  Branch (418:5): [True: 0, False: 2.66M]
  ------------------
  419|  2.66M|    }
  420|       |
  421|  2.66M|#endif /* !valgrind */
  422|       |
  423|  2.66M|  } else if (HASH_LITTLE_ENDIAN && ((u.i & 0x1) == 0)) {
  ------------------
  |  |   93|  2.55M|#  define HASH_LITTLE_ENDIAN 1
  |  |  ------------------
  |  |  |  Branch (93:30): [Folded - Ignored]
  |  |  ------------------
  ------------------
  |  Branch (423:36): [True: 1.27M, False: 0]
  ------------------
  424|  1.27M|    const uint16_t *k = (const uint16_t *)key;         /* read 16-bit chunks */
  425|  1.27M|    const uint8_t  *k8;
  426|       |
  427|       |    /*--------------- all but last block: aligned reads and different mixing */
  428|  1.27M|    while (length > 12)
  ------------------
  |  Branch (428:12): [True: 0, False: 1.27M]
  ------------------
  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.27M|    k8 = (const uint8_t *)k;
  440|  1.27M|    switch(length)
  ------------------
  |  Branch (440:12): [True: 0, False: 1.27M]
  ------------------
  441|  1.27M|    {
  442|      0|    case 12: c+=k[4]+(((uint32_t)k[5])<<16);
  ------------------
  |  Branch (442:5): [True: 0, False: 1.27M]
  ------------------
  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.27M]
  ------------------
  447|      0|    case 10: c+=k[4];
  ------------------
  |  Branch (447:5): [True: 0, False: 1.27M]
  ------------------
  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.27M]
  ------------------
  452|      0|    case 8 : b+=k[2]+(((uint32_t)k[3])<<16);
  ------------------
  |  Branch (452:5): [True: 0, False: 1.27M]
  ------------------
  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.27M]
  ------------------
  456|      0|    case 6 : b+=k[2];
  ------------------
  |  Branch (456:5): [True: 0, False: 1.27M]
  ------------------
  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.27M]
  ------------------
  460|      0|    case 4 : a+=k[0]+(((uint32_t)k[1])<<16);
  ------------------
  |  Branch (460:5): [True: 0, False: 1.27M]
  ------------------
  461|      0|             break;
  462|      0|    case 3 : a+=((uint32_t)k8[2])<<16;      /* fall through */
  ------------------
  |  Branch (462:5): [True: 0, False: 1.27M]
  ------------------
  463|  1.27M|    case 2 : a+=k[0];
  ------------------
  |  Branch (463:5): [True: 1.27M, False: 0]
  ------------------
  464|  1.27M|             break;
  465|      0|    case 1 : a+=k8[0];
  ------------------
  |  Branch (465:5): [True: 0, False: 1.27M]
  ------------------
  466|      0|             break;
  467|      0|    case 0 : return c;                     /* zero length requires no mixing */
  ------------------
  |  Branch (467:5): [True: 0, False: 1.27M]
  ------------------
  468|  1.27M|    }
  469|       |
  470|  1.27M|  } 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.93M|  final(a,b,c);
  ------------------
  |  |  208|  3.93M|#define final(a,b,c) \
  |  |  209|  3.93M|{ \
  |  |  210|  3.93M|  c ^= b; c -= rot(b,14); \
  |  |  ------------------
  |  |  |  |  118|  3.93M|#define rot(x,k) (((x)<<(k)) | ((x)>>(32-(k))))
  |  |  ------------------
  |  |  211|  3.93M|  a ^= c; a -= rot(c,11); \
  |  |  ------------------
  |  |  |  |  118|  3.93M|#define rot(x,k) (((x)<<(k)) | ((x)>>(32-(k))))
  |  |  ------------------
  |  |  212|  3.93M|  b ^= a; b -= rot(a,25); \
  |  |  ------------------
  |  |  |  |  118|  3.93M|#define rot(x,k) (((x)<<(k)) | ((x)>>(32-(k))))
  |  |  ------------------
  |  |  213|  3.93M|  c ^= b; c -= rot(b,16); \
  |  |  ------------------
  |  |  |  |  118|  3.93M|#define rot(x,k) (((x)<<(k)) | ((x)>>(32-(k))))
  |  |  ------------------
  |  |  214|  3.93M|  a ^= c; a -= rot(c,4);  \
  |  |  ------------------
  |  |  |  |  118|  3.93M|#define rot(x,k) (((x)<<(k)) | ((x)>>(32-(k))))
  |  |  ------------------
  |  |  215|  3.93M|  b ^= a; b -= rot(a,14); \
  |  |  ------------------
  |  |  |  |  118|  3.93M|#define rot(x,k) (((x)<<(k)) | ((x)>>(32-(k))))
  |  |  ------------------
  |  |  216|  3.93M|  c ^= b; c -= rot(b,24); \
  |  |  ------------------
  |  |  |  |  118|  3.93M|#define rot(x,k) (((x)<<(k)) | ((x)>>(32-(k))))
  |  |  ------------------
  |  |  217|  3.93M|}
  ------------------
  525|  3.93M|  return c;
  526|  3.93M|}

bin_init:
   49|  18.6k|{
   50|  18.6k|	size_t i;
   51|       |#ifdef THREADS_DISABLED
   52|       |	(void)array;
   53|       |#endif
   54|  19.1M|	for(i=0; i<size; i++) {
  ------------------
  |  Branch (54:11): [True: 19.1M, False: 18.6k]
  ------------------
   55|  19.1M|		lock_quick_init(&array[i].lock);
  ------------------
  |  |  143|  19.1M|#define lock_quick_init(lock) LOCKRET(pthread_spin_init(lock, PTHREAD_PROCESS_PRIVATE))
  |  |  ------------------
  |  |  |  |   67|  19.1M|#define LOCKRET(func) do {\
  |  |  |  |   68|  19.1M|	int lockret_err;		\
  |  |  |  |   69|  19.1M|	if( (lockret_err=(func)) != 0)		\
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (69:6): [True: 0, False: 19.1M]
  |  |  |  |  ------------------
  |  |  |  |   70|  19.1M|		log_err("%s at %d could not " #func ": %s", \
  |  |  |  |   71|      0|		__FILE__, __LINE__, strerror(lockret_err));	\
  |  |  |  |   72|  19.1M| 	} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (72:11): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
   56|  19.1M|		lock_protect(&array[i].lock, &array[i], 
   57|  19.1M|			sizeof(struct lruhash_bin));
   58|  19.1M|	}
   59|  18.6k|}
lruhash_create:
   66|  18.6k|{
   67|  18.6k|	struct lruhash* table = (struct lruhash*)calloc(1, 
   68|  18.6k|		sizeof(struct lruhash));
   69|  18.6k|	if(!table)
  ------------------
  |  Branch (69:5): [True: 0, False: 18.6k]
  ------------------
   70|      0|		return NULL;
   71|  18.6k|	lock_quick_init(&table->lock);
  ------------------
  |  |  143|  18.6k|#define lock_quick_init(lock) LOCKRET(pthread_spin_init(lock, PTHREAD_PROCESS_PRIVATE))
  |  |  ------------------
  |  |  |  |   67|  18.6k|#define LOCKRET(func) do {\
  |  |  |  |   68|  18.6k|	int lockret_err;		\
  |  |  |  |   69|  18.6k|	if( (lockret_err=(func)) != 0)		\
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (69:6): [True: 0, False: 18.6k]
  |  |  |  |  ------------------
  |  |  |  |   70|  18.6k|		log_err("%s at %d could not " #func ": %s", \
  |  |  |  |   71|      0|		__FILE__, __LINE__, strerror(lockret_err));	\
  |  |  |  |   72|  18.6k| 	} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (72:11): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
   72|  18.6k|	table->sizefunc = sizefunc;
   73|  18.6k|	table->compfunc = compfunc;
   74|  18.6k|	table->delkeyfunc = delkeyfunc;
   75|  18.6k|	table->deldatafunc = deldatafunc;
   76|  18.6k|	table->cb_arg = arg;
   77|  18.6k|	table->size = start_size;
   78|  18.6k|	table->size_mask = (int)(start_size-1);
   79|  18.6k|	table->lru_start = NULL;
   80|  18.6k|	table->lru_end = NULL;
   81|  18.6k|	table->num = 0;
   82|  18.6k|	table->space_used = 0;
   83|  18.6k|	table->space_max = maxmem;
   84|  18.6k|	table->max_collisions = 0;
   85|  18.6k|	table->array = calloc(table->size, sizeof(struct lruhash_bin));
   86|  18.6k|	if(!table->array) {
  ------------------
  |  Branch (86:5): [True: 0, False: 18.6k]
  ------------------
   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.6k|	bin_init(table->array, table->size);
   92|  18.6k|	lock_protect(&table->lock, table, sizeof(*table));
   93|  18.6k|	lock_protect(&table->lock, table->array, 
   94|  18.6k|		table->size*sizeof(struct lruhash_bin));
   95|  18.6k|	return table;
   96|  18.6k|}
bin_delete:
  100|  19.1M|{
  101|  19.1M|	struct lruhash_entry* p, *np;
  102|  19.1M|	void *d;
  103|  19.1M|	if(!bin)
  ------------------
  |  Branch (103:5): [True: 0, False: 19.1M]
  ------------------
  104|      0|		return;
  105|  19.1M|	lock_quick_destroy(&bin->lock);
  ------------------
  |  |  144|  19.1M|#define lock_quick_destroy(lock) LOCKRET(pthread_spin_destroy(lock))
  |  |  ------------------
  |  |  |  |   67|  19.1M|#define LOCKRET(func) do {\
  |  |  |  |   68|  19.1M|	int lockret_err;		\
  |  |  |  |   69|  19.1M|	if( (lockret_err=(func)) != 0)		\
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (69:6): [True: 0, False: 19.1M]
  |  |  |  |  ------------------
  |  |  |  |   70|  19.1M|		log_err("%s at %d could not " #func ": %s", \
  |  |  |  |   71|      0|		__FILE__, __LINE__, strerror(lockret_err));	\
  |  |  |  |   72|  19.1M| 	} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (72:11): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  106|  19.1M|	p = bin->overflow_list;
  107|  19.1M|	bin->overflow_list = NULL;
  108|  19.1M|	while(p) {
  ------------------
  |  Branch (108:8): [True: 14.6k, False: 19.1M]
  ------------------
  109|  14.6k|		np = p->overflow_next;
  110|  14.6k|		d = p->data;
  111|  14.6k|		(*table->delkeyfunc)(p->key, table->cb_arg);
  112|  14.6k|		(*table->deldatafunc)(d, table->cb_arg);
  113|  14.6k|		p = np;
  114|  14.6k|	}
  115|  19.1M|}
lruhash_delete:
  155|  18.6k|{
  156|  18.6k|	size_t i;
  157|  18.6k|	if(!table)
  ------------------
  |  Branch (157:5): [True: 0, False: 18.6k]
  ------------------
  158|      0|		return;
  159|       |	/* delete lock on hashtable to force check its OK */
  160|  18.6k|	lock_quick_destroy(&table->lock);
  ------------------
  |  |  144|  18.6k|#define lock_quick_destroy(lock) LOCKRET(pthread_spin_destroy(lock))
  |  |  ------------------
  |  |  |  |   67|  18.6k|#define LOCKRET(func) do {\
  |  |  |  |   68|  18.6k|	int lockret_err;		\
  |  |  |  |   69|  18.6k|	if( (lockret_err=(func)) != 0)		\
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (69:6): [True: 0, False: 18.6k]
  |  |  |  |  ------------------
  |  |  |  |   70|  18.6k|		log_err("%s at %d could not " #func ": %s", \
  |  |  |  |   71|      0|		__FILE__, __LINE__, strerror(lockret_err));	\
  |  |  |  |   72|  18.6k| 	} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (72:11): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  161|  19.1M|	for(i=0; i<table->size; i++)
  ------------------
  |  Branch (161:11): [True: 19.1M, False: 18.6k]
  ------------------
  162|  19.1M|		bin_delete(table, &table->array[i]);
  163|  18.6k|	free(table->array);
  164|  18.6k|	free(table);
  165|  18.6k|}
bin_overflow_remove:
  169|    341|{
  170|    341|	struct lruhash_entry* p = bin->overflow_list;
  171|    341|	struct lruhash_entry** prevp = &bin->overflow_list;
  172|    416|	while(p) {
  ------------------
  |  Branch (172:8): [True: 416, False: 0]
  ------------------
  173|    416|		if(p == entry) {
  ------------------
  |  Branch (173:6): [True: 341, False: 75]
  ------------------
  174|    341|			*prevp = p->overflow_next;
  175|    341|			return;
  176|    341|		}
  177|     75|		prevp = &p->overflow_next;
  178|     75|		p = p->overflow_next;
  179|     75|	}
  180|    341|}
reclaim_space:
  184|    158|{
  185|    158|	struct lruhash_entry* d;
  186|    158|	struct lruhash_bin* bin;
  187|    158|	log_assert(table);
  188|       |	/* does not delete MRU entry, so table will not be empty. */
  189|    499|	while(table->num > 1 && table->space_used > table->space_max) {
  ------------------
  |  Branch (189:8): [True: 472, False: 27]
  |  Branch (189:26): [True: 341, False: 131]
  ------------------
  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|    341|		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|    341|		log_assert(d && d->lru_prev);
  200|    341|		table->lru_end = d->lru_prev;
  201|    341|		d->lru_prev->lru_next = NULL;
  202|       |		/* schedule entry for deletion */
  203|    341|		bin = &table->array[d->hash & table->size_mask];
  204|    341|		table->num --;
  205|    341|		lock_quick_lock(&bin->lock);
  ------------------
  |  |  145|    341|#define lock_quick_lock(lock) LOCKRET(pthread_spin_lock(lock))
  |  |  ------------------
  |  |  |  |   67|    341|#define LOCKRET(func) do {\
  |  |  |  |   68|    341|	int lockret_err;		\
  |  |  |  |   69|    341|	if( (lockret_err=(func)) != 0)		\
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (69:6): [True: 0, False: 341]
  |  |  |  |  ------------------
  |  |  |  |   70|    341|		log_err("%s at %d could not " #func ": %s", \
  |  |  |  |   71|      0|		__FILE__, __LINE__, strerror(lockret_err));	\
  |  |  |  |   72|    341| 	} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (72:11): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  206|    341|		bin_overflow_remove(bin, d);
  207|    341|		d->overflow_next = *list;
  208|    341|		*list = d;
  209|    341|		lock_rw_wrlock(&d->lock);
  ------------------
  |  |  120|    341|#define lock_rw_wrlock(lock) LOCKRET(pthread_rwlock_wrlock(lock))
  |  |  ------------------
  |  |  |  |   67|    341|#define LOCKRET(func) do {\
  |  |  |  |   68|    341|	int lockret_err;		\
  |  |  |  |   69|    341|	if( (lockret_err=(func)) != 0)		\
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (69:6): [True: 0, False: 341]
  |  |  |  |  ------------------
  |  |  |  |   70|    341|		log_err("%s at %d could not " #func ": %s", \
  |  |  |  |   71|      0|		__FILE__, __LINE__, strerror(lockret_err));	\
  |  |  |  |   72|    341| 	} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (72:11): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  210|    341|		table->space_used -= table->sizefunc(d->key, d->data);
  211|    341|		if(table->markdelfunc)
  ------------------
  |  Branch (211:6): [True: 341, False: 0]
  ------------------
  212|    341|			(*table->markdelfunc)(d->key);
  213|    341|		lock_rw_unlock(&d->lock);
  ------------------
  |  |  121|    341|#define lock_rw_unlock(lock) LOCKRET(pthread_rwlock_unlock(lock))
  |  |  ------------------
  |  |  |  |   67|    341|#define LOCKRET(func) do {\
  |  |  |  |   68|    341|	int lockret_err;		\
  |  |  |  |   69|    341|	if( (lockret_err=(func)) != 0)		\
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (69:6): [True: 0, False: 341]
  |  |  |  |  ------------------
  |  |  |  |   70|    341|		log_err("%s at %d could not " #func ": %s", \
  |  |  |  |   71|      0|		__FILE__, __LINE__, strerror(lockret_err));	\
  |  |  |  |   72|    341| 	} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (72:11): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  214|    341|		lock_quick_unlock(&bin->lock);
  ------------------
  |  |  146|    341|#define lock_quick_unlock(lock) LOCKRET(pthread_spin_unlock(lock))
  |  |  ------------------
  |  |  |  |   67|    341|#define LOCKRET(func) do {\
  |  |  |  |   68|    341|	int lockret_err;		\
  |  |  |  |   69|    341|	if( (lockret_err=(func)) != 0)		\
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (69:6): [True: 0, False: 341]
  |  |  |  |  ------------------
  |  |  |  |   70|    341|		log_err("%s at %d could not " #func ": %s", \
  |  |  |  |   71|      0|		__FILE__, __LINE__, strerror(lockret_err));	\
  |  |  |  |   72|    341| 	} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (72:11): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  215|    341|	}
  216|    158|}
bin_find_entry:
  221|  29.9k|{
  222|  29.9k|	size_t c = 0;
  223|  29.9k|	struct lruhash_entry* p = bin->overflow_list;
  224|  33.8k|	while(p) {
  ------------------
  |  Branch (224:8): [True: 3.83k, False: 29.9k]
  ------------------
  225|  3.83k|		if(p->hash == hash && table->compfunc(p->key, key) == 0)
  ------------------
  |  Branch (225:6): [True: 562, False: 3.26k]
  |  Branch (225:25): [True: 0, False: 562]
  ------------------
  226|      0|			break;
  227|  3.83k|		c++;
  228|  3.83k|		p = p->overflow_next;
  229|  3.83k|	}
  230|  29.9k|	if (collisions != NULL)
  ------------------
  |  Branch (230:6): [True: 14.9k, False: 14.9k]
  ------------------
  231|  14.9k|		*collisions = c;
  232|  29.9k|	return p;
  233|  29.9k|}
lru_front:
  272|  14.9k|{
  273|  14.9k|	entry->lru_prev = NULL;
  274|  14.9k|	entry->lru_next = table->lru_start;
  275|  14.9k|	if(!table->lru_start)
  ------------------
  |  Branch (275:5): [True: 1.32k, False: 13.6k]
  ------------------
  276|  1.32k|		table->lru_end = entry;
  277|  13.6k|	else	table->lru_start->lru_prev = entry;
  278|  14.9k|	table->lru_start = entry;
  279|  14.9k|}
lruhash_insert:
  307|  14.9k|{
  308|  14.9k|	struct lruhash_bin* bin;
  309|  14.9k|	struct lruhash_entry* found, *reclaimlist=NULL;
  310|  14.9k|	size_t need_size;
  311|  14.9k|	size_t collisions;
  312|  14.9k|	fptr_ok(fptr_whitelist_hash_sizefunc(table->sizefunc));
  ------------------
  |  |   71|  14.9k|	do { if(!(x)) \
  |  |  ------------------
  |  |  |  Branch (71:10): [True: 0, False: 14.9k]
  |  |  ------------------
  |  |   72|  14.9k|		fatal_exit("%s:%d: %s: pointer whitelist %s failed", \
  |  |   73|      0|		__FILE__, __LINE__, __func__, #x); \
  |  |   74|  14.9k|	} while(0);
  |  |  ------------------
  |  |  |  Branch (74:10): [Folded - Ignored]
  |  |  ------------------
  ------------------
  313|  14.9k|	fptr_ok(fptr_whitelist_hash_delkeyfunc(table->delkeyfunc));
  ------------------
  |  |   71|  14.9k|	do { if(!(x)) \
  |  |  ------------------
  |  |  |  Branch (71:10): [True: 0, False: 14.9k]
  |  |  ------------------
  |  |   72|  14.9k|		fatal_exit("%s:%d: %s: pointer whitelist %s failed", \
  |  |   73|      0|		__FILE__, __LINE__, __func__, #x); \
  |  |   74|  14.9k|	} while(0);
  |  |  ------------------
  |  |  |  Branch (74:10): [Folded - Ignored]
  |  |  ------------------
  ------------------
  314|  14.9k|	fptr_ok(fptr_whitelist_hash_deldatafunc(table->deldatafunc));
  ------------------
  |  |   71|  14.9k|	do { if(!(x)) \
  |  |  ------------------
  |  |  |  Branch (71:10): [True: 0, False: 14.9k]
  |  |  ------------------
  |  |   72|  14.9k|		fatal_exit("%s:%d: %s: pointer whitelist %s failed", \
  |  |   73|      0|		__FILE__, __LINE__, __func__, #x); \
  |  |   74|  14.9k|	} while(0);
  |  |  ------------------
  |  |  |  Branch (74:10): [Folded - Ignored]
  |  |  ------------------
  ------------------
  315|  14.9k|	fptr_ok(fptr_whitelist_hash_compfunc(table->compfunc));
  ------------------
  |  |   71|  14.9k|	do { if(!(x)) \
  |  |  ------------------
  |  |  |  Branch (71:10): [True: 0, False: 14.9k]
  |  |  ------------------
  |  |   72|  14.9k|		fatal_exit("%s:%d: %s: pointer whitelist %s failed", \
  |  |   73|      0|		__FILE__, __LINE__, __func__, #x); \
  |  |   74|  14.9k|	} while(0);
  |  |  ------------------
  |  |  |  Branch (74:10): [Folded - Ignored]
  |  |  ------------------
  ------------------
  316|  14.9k|	fptr_ok(fptr_whitelist_hash_markdelfunc(table->markdelfunc));
  ------------------
  |  |   71|  14.9k|	do { if(!(x)) \
  |  |  ------------------
  |  |  |  Branch (71:10): [True: 0, False: 14.9k]
  |  |  ------------------
  |  |   72|  14.9k|		fatal_exit("%s:%d: %s: pointer whitelist %s failed", \
  |  |   73|      0|		__FILE__, __LINE__, __func__, #x); \
  |  |   74|  14.9k|	} while(0);
  |  |  ------------------
  |  |  |  Branch (74:10): [Folded - Ignored]
  |  |  ------------------
  ------------------
  317|  14.9k|	need_size = table->sizefunc(entry->key, data);
  318|  14.9k|	if(cb_arg == NULL) cb_arg = table->cb_arg;
  ------------------
  |  Branch (318:5): [True: 0, False: 14.9k]
  ------------------
  319|       |
  320|       |	/* find bin */
  321|  14.9k|	lock_quick_lock(&table->lock);
  ------------------
  |  |  145|  14.9k|#define lock_quick_lock(lock) LOCKRET(pthread_spin_lock(lock))
  |  |  ------------------
  |  |  |  |   67|  14.9k|#define LOCKRET(func) do {\
  |  |  |  |   68|  14.9k|	int lockret_err;		\
  |  |  |  |   69|  14.9k|	if( (lockret_err=(func)) != 0)		\
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (69:6): [True: 0, False: 14.9k]
  |  |  |  |  ------------------
  |  |  |  |   70|  14.9k|		log_err("%s at %d could not " #func ": %s", \
  |  |  |  |   71|      0|		__FILE__, __LINE__, strerror(lockret_err));	\
  |  |  |  |   72|  14.9k| 	} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (72:11): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  322|  14.9k|	bin = &table->array[hash & table->size_mask];
  323|  14.9k|	lock_quick_lock(&bin->lock);
  ------------------
  |  |  145|  14.9k|#define lock_quick_lock(lock) LOCKRET(pthread_spin_lock(lock))
  |  |  ------------------
  |  |  |  |   67|  14.9k|#define LOCKRET(func) do {\
  |  |  |  |   68|  14.9k|	int lockret_err;		\
  |  |  |  |   69|  14.9k|	if( (lockret_err=(func)) != 0)		\
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (69:6): [True: 0, False: 14.9k]
  |  |  |  |  ------------------
  |  |  |  |   70|  14.9k|		log_err("%s at %d could not " #func ": %s", \
  |  |  |  |   71|      0|		__FILE__, __LINE__, strerror(lockret_err));	\
  |  |  |  |   72|  14.9k| 	} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (72:11): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  324|       |
  325|       |	/* see if entry exists already */
  326|  14.9k|	if(!(found=bin_find_entry(table, bin, hash, entry->key, &collisions))) {
  ------------------
  |  Branch (326:5): [True: 14.9k, False: 0]
  ------------------
  327|       |		/* if not: add to bin */
  328|  14.9k|		entry->overflow_next = bin->overflow_list;
  329|  14.9k|		bin->overflow_list = entry;
  330|  14.9k|		lru_front(table, entry);
  331|  14.9k|		table->num++;
  332|  14.9k|		if (table->max_collisions < collisions)
  ------------------
  |  Branch (332:7): [True: 644, False: 14.3k]
  ------------------
  333|    644|			table->max_collisions = collisions;
  334|  14.9k|		table->space_used += need_size;
  335|  14.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|  14.9k|	lock_quick_unlock(&bin->lock);
  ------------------
  |  |  146|  14.9k|#define lock_quick_unlock(lock) LOCKRET(pthread_spin_unlock(lock))
  |  |  ------------------
  |  |  |  |   67|  14.9k|#define LOCKRET(func) do {\
  |  |  |  |   68|  14.9k|	int lockret_err;		\
  |  |  |  |   69|  14.9k|	if( (lockret_err=(func)) != 0)		\
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (69:6): [True: 0, False: 14.9k]
  |  |  |  |  ------------------
  |  |  |  |   70|  14.9k|		log_err("%s at %d could not " #func ": %s", \
  |  |  |  |   71|      0|		__FILE__, __LINE__, strerror(lockret_err));	\
  |  |  |  |   72|  14.9k| 	} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (72:11): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  347|  14.9k|	if(table->space_used > table->space_max)
  ------------------
  |  Branch (347:5): [True: 158, False: 14.8k]
  ------------------
  348|    158|		reclaim_space(table, &reclaimlist);
  349|  14.9k|	if(table->num >= table->size)
  ------------------
  |  Branch (349:5): [True: 0, False: 14.9k]
  ------------------
  350|      0|		table_grow(table);
  351|  14.9k|	lock_quick_unlock(&table->lock);
  ------------------
  |  |  146|  14.9k|#define lock_quick_unlock(lock) LOCKRET(pthread_spin_unlock(lock))
  |  |  ------------------
  |  |  |  |   67|  14.9k|#define LOCKRET(func) do {\
  |  |  |  |   68|  14.9k|	int lockret_err;		\
  |  |  |  |   69|  14.9k|	if( (lockret_err=(func)) != 0)		\
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (69:6): [True: 0, False: 14.9k]
  |  |  |  |  ------------------
  |  |  |  |   70|  14.9k|		log_err("%s at %d could not " #func ": %s", \
  |  |  |  |   71|      0|		__FILE__, __LINE__, strerror(lockret_err));	\
  |  |  |  |   72|  14.9k| 	} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (72:11): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  352|       |
  353|       |	/* finish reclaim if any (outside of critical region) */
  354|  15.3k|	while(reclaimlist) {
  ------------------
  |  Branch (354:8): [True: 341, False: 14.9k]
  ------------------
  355|    341|		struct lruhash_entry* n = reclaimlist->overflow_next;
  356|    341|		void* d = reclaimlist->data;
  357|    341|		(*table->delkeyfunc)(reclaimlist->key, cb_arg);
  358|    341|		(*table->deldatafunc)(d, cb_arg);
  359|    341|		reclaimlist = n;
  360|    341|	}
  361|  14.9k|}
lruhash_lookup:
  365|  14.9k|{
  366|  14.9k|	struct lruhash_entry* entry;
  367|  14.9k|	struct lruhash_bin* bin;
  368|  14.9k|	fptr_ok(fptr_whitelist_hash_compfunc(table->compfunc));
  ------------------
  |  |   71|  14.9k|	do { if(!(x)) \
  |  |  ------------------
  |  |  |  Branch (71:10): [True: 0, False: 14.9k]
  |  |  ------------------
  |  |   72|  14.9k|		fatal_exit("%s:%d: %s: pointer whitelist %s failed", \
  |  |   73|      0|		__FILE__, __LINE__, __func__, #x); \
  |  |   74|  14.9k|	} while(0);
  |  |  ------------------
  |  |  |  Branch (74:10): [Folded - Ignored]
  |  |  ------------------
  ------------------
  369|       |
  370|  14.9k|	lock_quick_lock(&table->lock);
  ------------------
  |  |  145|  14.9k|#define lock_quick_lock(lock) LOCKRET(pthread_spin_lock(lock))
  |  |  ------------------
  |  |  |  |   67|  14.9k|#define LOCKRET(func) do {\
  |  |  |  |   68|  14.9k|	int lockret_err;		\
  |  |  |  |   69|  14.9k|	if( (lockret_err=(func)) != 0)		\
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (69:6): [True: 0, False: 14.9k]
  |  |  |  |  ------------------
  |  |  |  |   70|  14.9k|		log_err("%s at %d could not " #func ": %s", \
  |  |  |  |   71|      0|		__FILE__, __LINE__, strerror(lockret_err));	\
  |  |  |  |   72|  14.9k| 	} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (72:11): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  371|  14.9k|	bin = &table->array[hash & table->size_mask];
  372|  14.9k|	lock_quick_lock(&bin->lock);
  ------------------
  |  |  145|  14.9k|#define lock_quick_lock(lock) LOCKRET(pthread_spin_lock(lock))
  |  |  ------------------
  |  |  |  |   67|  14.9k|#define LOCKRET(func) do {\
  |  |  |  |   68|  14.9k|	int lockret_err;		\
  |  |  |  |   69|  14.9k|	if( (lockret_err=(func)) != 0)		\
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (69:6): [True: 0, False: 14.9k]
  |  |  |  |  ------------------
  |  |  |  |   70|  14.9k|		log_err("%s at %d could not " #func ": %s", \
  |  |  |  |   71|      0|		__FILE__, __LINE__, strerror(lockret_err));	\
  |  |  |  |   72|  14.9k| 	} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (72:11): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  373|  14.9k|	if((entry=bin_find_entry(table, bin, hash, key, NULL)))
  ------------------
  |  Branch (373:5): [True: 0, False: 14.9k]
  ------------------
  374|      0|		lru_touch(table, entry);
  375|  14.9k|	lock_quick_unlock(&table->lock);
  ------------------
  |  |  146|  14.9k|#define lock_quick_unlock(lock) LOCKRET(pthread_spin_unlock(lock))
  |  |  ------------------
  |  |  |  |   67|  14.9k|#define LOCKRET(func) do {\
  |  |  |  |   68|  14.9k|	int lockret_err;		\
  |  |  |  |   69|  14.9k|	if( (lockret_err=(func)) != 0)		\
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (69:6): [True: 0, False: 14.9k]
  |  |  |  |  ------------------
  |  |  |  |   70|  14.9k|		log_err("%s at %d could not " #func ": %s", \
  |  |  |  |   71|      0|		__FILE__, __LINE__, strerror(lockret_err));	\
  |  |  |  |   72|  14.9k| 	} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (72:11): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  376|       |
  377|  14.9k|	if(entry) {
  ------------------
  |  Branch (377:5): [True: 0, False: 14.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|  14.9k|	lock_quick_unlock(&bin->lock);
  ------------------
  |  |  146|  14.9k|#define lock_quick_unlock(lock) LOCKRET(pthread_spin_unlock(lock))
  |  |  ------------------
  |  |  |  |   67|  14.9k|#define LOCKRET(func) do {\
  |  |  |  |   68|  14.9k|	int lockret_err;		\
  |  |  |  |   69|  14.9k|	if( (lockret_err=(func)) != 0)		\
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (69:6): [True: 0, False: 14.9k]
  |  |  |  |  ------------------
  |  |  |  |   70|  14.9k|		log_err("%s at %d could not " #func ": %s", \
  |  |  |  |   71|      0|		__FILE__, __LINE__, strerror(lockret_err));	\
  |  |  |  |   72|  14.9k| 	} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (72:11): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  382|  14.9k|	return entry;
  383|  14.9k|}
lruhash_setmarkdel:
  525|  18.6k|{
  526|  18.6k|	lock_quick_lock(&table->lock);
  ------------------
  |  |  145|  18.6k|#define lock_quick_lock(lock) LOCKRET(pthread_spin_lock(lock))
  |  |  ------------------
  |  |  |  |   67|  18.6k|#define LOCKRET(func) do {\
  |  |  |  |   68|  18.6k|	int lockret_err;		\
  |  |  |  |   69|  18.6k|	if( (lockret_err=(func)) != 0)		\
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (69:6): [True: 0, False: 18.6k]
  |  |  |  |  ------------------
  |  |  |  |   70|  18.6k|		log_err("%s at %d could not " #func ": %s", \
  |  |  |  |   71|      0|		__FILE__, __LINE__, strerror(lockret_err));	\
  |  |  |  |   72|  18.6k| 	} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (72:11): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  527|  18.6k|	table->markdelfunc = md;
  528|  18.6k|	lock_quick_unlock(&table->lock);
  ------------------
  |  |  146|  18.6k|#define lock_quick_unlock(lock) LOCKRET(pthread_spin_unlock(lock))
  |  |  ------------------
  |  |  |  |   67|  18.6k|#define LOCKRET(func) do {\
  |  |  |  |   68|  18.6k|	int lockret_err;		\
  |  |  |  |   69|  18.6k|	if( (lockret_err=(func)) != 0)		\
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (69:6): [True: 0, False: 18.6k]
  |  |  |  |  ------------------
  |  |  |  |   70|  18.6k|		log_err("%s at %d could not " #func ": %s", \
  |  |  |  |   71|      0|		__FILE__, __LINE__, strerror(lockret_err));	\
  |  |  |  |   72|  18.6k| 	} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (72:11): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  529|  18.6k|}

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

ub_get_event_sys:
  169|  4.66k|{
  170|       |#ifdef USE_WINSOCK
  171|       |	(void)base;
  172|       |	*n = "event";
  173|       |	*s = "winsock";
  174|       |	*m = "WSAWaitForMultipleEvents";
  175|       |#elif defined(USE_MINI_EVENT)
  176|  4.66k|	(void)base;
  177|  4.66k|	*n = "mini-event";
  178|  4.66k|	*s = "internal";
  179|  4.66k|	*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.66k|}
ub_default_event_base:
  211|  4.66k|{
  212|  4.66k|	void* base;
  213|       |
  214|  4.66k|	(void)base;
  215|  4.66k|#ifdef USE_MINI_EVENT
  216|  4.66k|	(void)sigs;
  217|       |	/* use mini event time-sharing feature */
  218|  4.66k|	base = event_init(time_secs, time_tv);
  ------------------
  |  |   69|  4.66k|#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.66k|	return (struct ub_event_base*)base;
  238|  4.66k|}
ub_event_base_free:
  264|  4.66k|{
  265|  4.66k|#ifdef USE_MINI_EVENT
  266|  4.66k|	event_base_free(AS_EVENT_BASE(base));
  ------------------
  |  |   74|  4.66k|#define event_base_free minievent_base_free
  ------------------
              	event_base_free(AS_EVENT_BASE(base));
  ------------------
  |  |  141|  4.66k|#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.66k|}
ub_comm_base_now:
  449|  4.66k|{
  450|  4.66k|#ifdef USE_MINI_EVENT
  451|       |/** minievent updates the time when it blocks. */
  452|  4.66k|	(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.66k|}

