coap_get_log_level:
  103|  1.19M|coap_get_log_level(void) {
  104|  1.19M|  return maxlog;
  105|  1.19M|}
coap_set_log_level:
  108|  3.16k|coap_set_log_level(coap_log_t level) {
  109|  3.16k|  if (level > COAP_MAX_LOGGING_LEVEL)
  ------------------
  |  |   48|  3.16k|#define COAP_MAX_LOGGING_LEVEL 8
  ------------------
  |  Branch (109:7): [True: 0, False: 3.16k]
  ------------------
  110|      0|    level = COAP_MAX_LOGGING_LEVEL;
  ------------------
  |  |   48|      0|#define COAP_MAX_LOGGING_LEVEL 8
  ------------------
  111|  3.16k|  maxlog = level;
  112|  3.16k|}
coap_show_pdu:
  812|  1.58k|coap_show_pdu(coap_log_t level, const coap_pdu_t *pdu) {
  813|       |#if COAP_CONSTRAINED_STACK
  814|       |  /* Proxy-Uri: can be 1034 bytes long */
  815|       |  /* buf and outbuf can be protected by m_show_pdu if needed */
  816|       |  static unsigned char buf[USE_BUF_SIZE];
  817|       |  static char outbuf[COAP_DEBUG_BUF_SIZE];
  818|       |#else /* ! COAP_CONSTRAINED_STACK */
  819|       |  /* Proxy-Uri: can be 1034 bytes long */
  820|  1.58k|  unsigned char buf[USE_BUF_SIZE];
  821|  1.58k|  char outbuf[COAP_DEBUG_BUF_SIZE];
  822|  1.58k|#endif /* ! COAP_CONSTRAINED_STACK */
  823|  1.58k|  size_t buf_len = 0; /* takes the number of bytes written to buf */
  824|  1.58k|  int have_options = 0;
  825|  1.58k|  uint32_t i;
  826|  1.58k|  coap_opt_iterator_t opt_iter;
  827|  1.58k|  coap_opt_t *option;
  828|  1.58k|  int content_format = -1;
  829|  1.58k|  size_t data_len;
  830|  1.58k|  const uint8_t *data;
  831|  1.58k|  uint32_t opt_len;
  832|  1.58k|  const uint8_t *opt_val;
  833|  1.58k|  size_t outbuflen = 0;
  834|  1.58k|  int is_oscore_payload = 0;
  835|  1.58k|  const char *exp;
  836|  1.58k|  uint32_t value;
  837|       |
  838|       |  /* Save time if not needed */
  839|  1.58k|  if (level > coap_get_log_level())
  ------------------
  |  Branch (839:7): [True: 1.58k, False: 0]
  ------------------
  840|  1.58k|    return;
  841|       |
  842|       |#if COAP_THREAD_SAFE
  843|       |  coap_mutex_lock(&m_show_pdu);
  844|       |#endif /* COAP_THREAD_SAFE */
  845|      0|  if (!pdu->session || COAP_PROTO_NOT_RELIABLE(pdu->session->proto)) {
  ------------------
  |  |   41|      0|#define COAP_PROTO_NOT_RELIABLE(p) ((p)==COAP_PROTO_UDP || (p)==COAP_PROTO_DTLS)
  |  |  ------------------
  |  |  |  Branch (41:37): [True: 0, False: 0]
  |  |  |  Branch (41:60): [True: 0, False: 0]
  |  |  ------------------
  ------------------
  |  Branch (845:7): [True: 0, False: 0]
  ------------------
  846|      0|    snprintf(outbuf, sizeof(outbuf), "v:%d t:%s c:%s i:%04x {",
  847|      0|             COAP_DEFAULT_VERSION, msg_type_string(pdu->type),
  ------------------
  |  |   35|      0|#define COAP_DEFAULT_VERSION      1 /* version of CoAP supported */
  ------------------
  848|      0|             msg_code_string(pdu->code), pdu->mid);
  849|      0|  } else if (pdu->session->proto == COAP_PROTO_WS ||
  ------------------
  |  Branch (849:14): [True: 0, False: 0]
  ------------------
  850|      0|             pdu->session->proto == COAP_PROTO_WSS) {
  ------------------
  |  Branch (850:14): [True: 0, False: 0]
  ------------------
  851|      0|    if (pdu->type != COAP_MESSAGE_CON)
  ------------------
  |  Branch (851:9): [True: 0, False: 0]
  ------------------
  852|      0|      coap_log_alert("WebSocket: type != CON\n");
  ------------------
  |  |   90|      0|#define coap_log_alert(...) coap_log(COAP_LOG_ALERT, __VA_ARGS__)
  |  |  ------------------
  |  |  |  |  290|      0|#define coap_log(level, ...) do { \
  |  |  |  |  291|      0|    if ((level) < (coap_get_log_level() + 1)) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (291:9): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  292|      0|      coap_log_impl((level), __VA_ARGS__); \
  |  |  |  |  293|      0|  } while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (293:11): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  853|      0|    snprintf(outbuf, sizeof(outbuf), "v:WebSocket c:%s {",
  854|      0|             msg_code_string(pdu->code));
  855|      0|  } else {
  856|      0|    if (pdu->type != COAP_MESSAGE_CON)
  ------------------
  |  Branch (856:9): [True: 0, False: 0]
  ------------------
  857|      0|      coap_log_alert("Reliable: type != CON\n");
  ------------------
  |  |   90|      0|#define coap_log_alert(...) coap_log(COAP_LOG_ALERT, __VA_ARGS__)
  |  |  ------------------
  |  |  |  |  290|      0|#define coap_log(level, ...) do { \
  |  |  |  |  291|      0|    if ((level) < (coap_get_log_level() + 1)) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (291:9): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  292|      0|      coap_log_impl((level), __VA_ARGS__); \
  |  |  |  |  293|      0|  } while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (293:11): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  858|      0|    snprintf(outbuf, sizeof(outbuf), "v:Reliable c:%s {",
  859|      0|             msg_code_string(pdu->code));
  860|      0|  }
  861|       |
  862|      0|  for (i = 0; i < pdu->actual_token.length; i++) {
  ------------------
  |  Branch (862:15): [True: 0, False: 0]
  ------------------
  863|      0|    outbuflen = strlen(outbuf);
  864|      0|    snprintf(&outbuf[outbuflen], sizeof(outbuf)-outbuflen,
  865|      0|             "%02x", pdu->actual_token.s[i]);
  866|      0|  }
  867|      0|  outbuflen = strlen(outbuf);
  868|      0|  snprintf(&outbuf[outbuflen], sizeof(outbuf)-outbuflen,  "}");
  869|       |
  870|       |  /* show options, if any */
  871|      0|  coap_option_iterator_init(pdu, &opt_iter, COAP_OPT_ALL);
  ------------------
  |  |  230|      0|#define COAP_OPT_ALL NULL
  ------------------
  872|       |
  873|      0|  outbuflen = strlen(outbuf);
  874|      0|  snprintf(&outbuf[outbuflen], sizeof(outbuf)-outbuflen,  " [");
  875|      0|  while ((option = coap_option_next(&opt_iter))) {
  ------------------
  |  Branch (875:10): [True: 0, False: 0]
  ------------------
  876|      0|    buf[0] = '\000';
  877|      0|    if (!have_options) {
  ------------------
  |  Branch (877:9): [True: 0, False: 0]
  ------------------
  878|      0|      have_options = 1;
  879|      0|    } else {
  880|      0|      outbuflen = strlen(outbuf);
  881|      0|      snprintf(&outbuf[outbuflen], sizeof(outbuf)-outbuflen,  ",");
  882|      0|    }
  883|       |
  884|      0|    if (pdu->code == COAP_SIGNALING_CODE_CSM) {
  ------------------
  |  Branch (884:9): [True: 0, False: 0]
  ------------------
  885|      0|      switch ((coap_sig_csm_opt_t)opt_iter.number) {
  886|      0|      case COAP_SIG_OPT_EXTENDED_TOKEN_LENGTH:
  ------------------
  |  Branch (886:7): [True: 0, False: 0]
  ------------------
  887|      0|      case COAP_SIG_OPT_MAX_MESSAGE_SIZE:
  ------------------
  |  Branch (887:7): [True: 0, False: 0]
  ------------------
  888|      0|        buf_len = snprintf((char *)buf, sizeof(buf), "%u",
  889|      0|                           coap_decode_var_bytes(coap_opt_value(option),
  890|      0|                                                 coap_opt_length(option)));
  891|      0|        break;
  892|      0|      case COAP_SIG_OPT_BLOCK_WISE_TRANSFER:
  ------------------
  |  Branch (892:7): [True: 0, False: 0]
  ------------------
  893|      0|      default:
  ------------------
  |  Branch (893:7): [True: 0, False: 0]
  ------------------
  894|      0|        buf_len = 0;
  895|      0|        break;
  896|      0|      }
  897|      0|    } else if (pdu->code == COAP_SIGNALING_CODE_PING ||
  ------------------
  |  Branch (897:16): [True: 0, False: 0]
  ------------------
  898|      0|               pdu->code == COAP_SIGNALING_CODE_PONG) {
  ------------------
  |  Branch (898:16): [True: 0, False: 0]
  ------------------
  899|      0|      switch ((coap_sig_ping_opt_t)opt_iter.number) {
  900|      0|      case COAP_SIG_OPT_CUSTODY:
  ------------------
  |  Branch (900:7): [True: 0, False: 0]
  ------------------
  901|      0|      default:
  ------------------
  |  Branch (901:7): [True: 0, False: 0]
  ------------------
  902|      0|        buf_len = 0;
  903|      0|      }
  904|      0|    } else if (pdu->code == COAP_SIGNALING_CODE_RELEASE) {
  ------------------
  |  Branch (904:16): [True: 0, False: 0]
  ------------------
  905|      0|      switch ((coap_sig_release_opt_t)opt_iter.number) {
  906|      0|      case COAP_SIG_OPT_ALTERNATIVE_ADDRESS:
  ------------------
  |  Branch (906:7): [True: 0, False: 0]
  ------------------
  907|      0|        buf_len = print_readable(coap_opt_value(option),
  908|      0|                                 coap_opt_length(option),
  909|      0|                                 buf, sizeof(buf), 0);
  910|      0|        break;
  911|      0|      case COAP_SIG_OPT_HOLD_OFF:
  ------------------
  |  Branch (911:7): [True: 0, False: 0]
  ------------------
  912|      0|        buf_len = snprintf((char *)buf, sizeof(buf), "%u",
  913|      0|                           coap_decode_var_bytes(coap_opt_value(option),
  914|      0|                                                 coap_opt_length(option)));
  915|      0|        break;
  916|      0|      default:
  ------------------
  |  Branch (916:7): [True: 0, False: 0]
  ------------------
  917|      0|        buf_len = 0;
  918|      0|        break;
  919|      0|      }
  920|      0|    } else if (pdu->code == COAP_SIGNALING_CODE_ABORT) {
  ------------------
  |  Branch (920:16): [True: 0, False: 0]
  ------------------
  921|      0|      switch ((coap_sig_abort_opt_t)opt_iter.number) {
  922|      0|      case COAP_SIG_OPT_BAD_CSM_OPTION:
  ------------------
  |  Branch (922:7): [True: 0, False: 0]
  ------------------
  923|      0|        buf_len = snprintf((char *)buf, sizeof(buf), "%u",
  924|      0|                           coap_decode_var_bytes(coap_opt_value(option),
  925|      0|                                                 coap_opt_length(option)));
  926|      0|        break;
  927|      0|      default:
  ------------------
  |  Branch (927:7): [True: 0, False: 0]
  ------------------
  928|      0|        buf_len = 0;
  929|      0|        break;
  930|      0|      }
  931|      0|    } else {
  932|      0|      switch ((coap_code_opt_num_t)opt_iter.number) {
  933|      0|      case COAP_OPTION_CONTENT_FORMAT:
  ------------------
  |  Branch (933:7): [True: 0, False: 0]
  ------------------
  934|      0|      case COAP_OPTION_ACCEPT:
  ------------------
  |  Branch (934:7): [True: 0, False: 0]
  ------------------
  935|      0|        content_format = (int)coap_decode_var_bytes(coap_opt_value(option),
  936|      0|                                                    coap_opt_length(option));
  937|       |
  938|      0|        buf_len = print_content_format(content_format, buf, sizeof(buf));
  939|      0|        break;
  940|       |
  941|      0|      case COAP_OPTION_BLOCK1:
  ------------------
  |  Branch (941:7): [True: 0, False: 0]
  ------------------
  942|      0|      case COAP_OPTION_BLOCK2:
  ------------------
  |  Branch (942:7): [True: 0, False: 0]
  ------------------
  943|      0|      case COAP_OPTION_Q_BLOCK1:
  ------------------
  |  Branch (943:7): [True: 0, False: 0]
  ------------------
  944|      0|      case COAP_OPTION_Q_BLOCK2:
  ------------------
  |  Branch (944:7): [True: 0, False: 0]
  ------------------
  945|       |        /* split block option into number/more/size where more is the
  946|       |         * letter M if set, the _ otherwise */
  947|      0|        if (COAP_OPT_BLOCK_SZX(option) == 7) {
  ------------------
  |  |   96|      0|  (coap_opt_length(opt) ? (COAP_OPT_BLOCK_END_BYTE(opt) & 0x07) : 0)
  |  |  ------------------
  |  |  |  |   87|      0|  ((coap_opt_length(opt) && coap_opt_value(opt)) ? \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (87:5): [True: 0, False: 0]
  |  |  |  |  |  Branch (87:29): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |   88|      0|   *(coap_opt_value(opt) + (coap_opt_length(opt)-1)) : 0)
  |  |  ------------------
  |  |  |  Branch (96:4): [True: 0, False: 0]
  |  |  ------------------
  ------------------
  |  Branch (947:13): [True: 0, False: 0]
  ------------------
  948|      0|          if (coap_get_data(pdu, &data_len, &data))
  ------------------
  |  Branch (948:15): [True: 0, False: 0]
  ------------------
  949|      0|            buf_len = snprintf((char *)buf, sizeof(buf), "%u/%c/BERT(%" PRIuS ")",
  950|      0|                               coap_opt_block_num(option), /* block number */
  951|      0|                               COAP_OPT_BLOCK_MORE(option) ? 'M' : '_', /* M bit */
  ------------------
  |  |   92|      0|  (coap_opt_length(opt) ? (COAP_OPT_BLOCK_END_BYTE(opt) & 0x08) : 0)
  |  |  ------------------
  |  |  |  |   87|      0|  ((coap_opt_length(opt) && coap_opt_value(opt)) ? \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (87:5): [True: 0, False: 0]
  |  |  |  |  |  Branch (87:29): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |   88|      0|   *(coap_opt_value(opt) + (coap_opt_length(opt)-1)) : 0)
  |  |  ------------------
  |  |  |  Branch (92:3): [True: 0, False: 0]
  |  |  |  Branch (92:4): [True: 0, False: 0]
  |  |  ------------------
  ------------------
  952|      0|                               data_len);
  953|      0|          else
  954|      0|            buf_len = snprintf((char *)buf, sizeof(buf), "%u/%c/BERT",
  955|      0|                               coap_opt_block_num(option), /* block number */
  956|      0|                               COAP_OPT_BLOCK_MORE(option) ? 'M' : '_'); /* M bit */
  ------------------
  |  |   92|      0|  (coap_opt_length(opt) ? (COAP_OPT_BLOCK_END_BYTE(opt) & 0x08) : 0)
  |  |  ------------------
  |  |  |  |   87|      0|  ((coap_opt_length(opt) && coap_opt_value(opt)) ? \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (87:5): [True: 0, False: 0]
  |  |  |  |  |  Branch (87:29): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |   88|      0|   *(coap_opt_value(opt) + (coap_opt_length(opt)-1)) : 0)
  |  |  ------------------
  |  |  |  Branch (92:3): [True: 0, False: 0]
  |  |  |  Branch (92:4): [True: 0, False: 0]
  |  |  ------------------
  ------------------
  957|      0|        } else {
  958|      0|          buf_len = snprintf((char *)buf, sizeof(buf), "%u/%c/%u",
  959|      0|                             coap_opt_block_num(option), /* block number */
  960|      0|                             COAP_OPT_BLOCK_MORE(option) ? 'M' : '_', /* M bit */
  ------------------
  |  |   92|      0|  (coap_opt_length(opt) ? (COAP_OPT_BLOCK_END_BYTE(opt) & 0x08) : 0)
  |  |  ------------------
  |  |  |  |   87|      0|  ((coap_opt_length(opt) && coap_opt_value(opt)) ? \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (87:5): [True: 0, False: 0]
  |  |  |  |  |  Branch (87:29): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |   88|      0|   *(coap_opt_value(opt) + (coap_opt_length(opt)-1)) : 0)
  |  |  ------------------
  |  |  |  Branch (92:3): [True: 0, False: 0]
  |  |  |  Branch (92:4): [True: 0, False: 0]
  |  |  ------------------
  ------------------
  961|      0|                             (1 << (COAP_OPT_BLOCK_SZX(option) + 4))); /* block size */
  ------------------
  |  |   96|      0|  (coap_opt_length(opt) ? (COAP_OPT_BLOCK_END_BYTE(opt) & 0x07) : 0)
  |  |  ------------------
  |  |  |  |   87|      0|  ((coap_opt_length(opt) && coap_opt_value(opt)) ? \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (87:5): [True: 0, False: 0]
  |  |  |  |  |  Branch (87:29): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |   88|      0|   *(coap_opt_value(opt) + (coap_opt_length(opt)-1)) : 0)
  |  |  ------------------
  |  |  |  Branch (96:4): [True: 0, False: 0]
  |  |  ------------------
  ------------------
  962|      0|        }
  963|       |
  964|      0|        break;
  965|       |
  966|      0|      case COAP_OPTION_OSCORE:
  ------------------
  |  Branch (966:7): [True: 0, False: 0]
  ------------------
  967|      0|        opt_len = coap_opt_length(option);
  968|      0|        buf[0] = '\000';
  969|      0|        if (opt_len) {
  ------------------
  |  Branch (969:13): [True: 0, False: 0]
  ------------------
  970|      0|          size_t ofs = 1;
  971|      0|          size_t cnt;
  972|       |
  973|      0|          opt_val = coap_opt_value(option);
  974|      0|          if (opt_val[0] & 0x20) {
  ------------------
  |  Branch (974:15): [True: 0, False: 0]
  ------------------
  975|       |            /* Group Flag */
  976|      0|            snprintf((char *)buf, sizeof(buf), "grp");
  977|      0|          }
  978|      0|          if (opt_val[0] & 0x07) {
  ------------------
  |  Branch (978:15): [True: 0, False: 0]
  ------------------
  979|       |            /* Partial IV */
  980|      0|            cnt = opt_val[0] & 0x07;
  981|      0|            if (cnt > opt_len - ofs)
  ------------------
  |  Branch (981:17): [True: 0, False: 0]
  ------------------
  982|      0|              goto no_more;
  983|      0|            buf_len = strlen((char *)buf);
  984|      0|            snprintf((char *)&buf[buf_len], sizeof(buf)-buf_len, "%spIV=0x",
  985|      0|                     buf_len ? "," : "");
  ------------------
  |  Branch (985:22): [True: 0, False: 0]
  ------------------
  986|      0|            for (i = 0; (uint32_t)i < cnt; i++) {
  ------------------
  |  Branch (986:25): [True: 0, False: 0]
  ------------------
  987|      0|              buf_len = strlen((char *)buf);
  988|      0|              snprintf((char *)&buf[buf_len], sizeof(buf)-buf_len,
  989|      0|                       "%02x", opt_val[ofs + i]);
  990|      0|            }
  991|      0|            ofs += cnt;
  992|      0|          }
  993|      0|          if (opt_val[0] & 0x10) {
  ------------------
  |  Branch (993:15): [True: 0, False: 0]
  ------------------
  994|       |            /* kid context */
  995|      0|            if (ofs >= opt_len)
  ------------------
  |  Branch (995:17): [True: 0, False: 0]
  ------------------
  996|      0|              goto no_more;
  997|      0|            cnt = opt_val[ofs];
  998|      0|            if (cnt > opt_len - ofs - 1)
  ------------------
  |  Branch (998:17): [True: 0, False: 0]
  ------------------
  999|      0|              goto no_more;
 1000|      0|            ofs++;
 1001|      0|            buf_len = strlen((char *)buf);
 1002|      0|            snprintf((char *)&buf[buf_len], sizeof(buf)-buf_len, "%skc=0x",
 1003|      0|                     buf_len ? "," : "");
  ------------------
  |  Branch (1003:22): [True: 0, False: 0]
  ------------------
 1004|      0|            for (i = 0; (uint32_t)i < cnt; i++) {
  ------------------
  |  Branch (1004:25): [True: 0, False: 0]
  ------------------
 1005|      0|              buf_len = strlen((char *)buf);
 1006|      0|              snprintf((char *)&buf[buf_len], sizeof(buf)-buf_len,
 1007|      0|                       "%02x", opt_val[ofs + i]);
 1008|      0|            }
 1009|      0|            ofs += cnt;
 1010|      0|          }
 1011|      0|          if (opt_val[0] & 0x08) {
  ------------------
  |  Branch (1011:15): [True: 0, False: 0]
  ------------------
 1012|       |            /* kid */
 1013|      0|            if (ofs >= opt_len)
  ------------------
  |  Branch (1013:17): [True: 0, False: 0]
  ------------------
 1014|      0|              goto no_more;
 1015|      0|            cnt = opt_len - ofs;
 1016|      0|            buf_len = strlen((char *)buf);
 1017|      0|            snprintf((char *)&buf[buf_len], sizeof(buf)-buf_len, "%skid=0x",
 1018|      0|                     buf_len ? "," : "");
  ------------------
  |  Branch (1018:22): [True: 0, False: 0]
  ------------------
 1019|      0|            for (i = 0; (uint32_t)i < cnt; i++) {
  ------------------
  |  Branch (1019:25): [True: 0, False: 0]
  ------------------
 1020|      0|              buf_len = strlen((char *)buf);
 1021|      0|              snprintf((char *)&buf[buf_len], sizeof(buf)-buf_len,
 1022|      0|                       "%02x", opt_val[ofs + i]);
 1023|      0|            }
 1024|      0|          }
 1025|      0|        }
 1026|      0|no_more:
 1027|      0|        buf_len = strlen((char *)buf);
 1028|      0|        is_oscore_payload = 1;
 1029|      0|        break;
 1030|       |
 1031|      0|      case COAP_OPTION_URI_PORT:
  ------------------
  |  Branch (1031:7): [True: 0, False: 0]
  ------------------
 1032|      0|      case COAP_OPTION_MAXAGE:
  ------------------
  |  Branch (1032:7): [True: 0, False: 0]
  ------------------
 1033|      0|      case COAP_OPTION_OBSERVE:
  ------------------
  |  Branch (1033:7): [True: 0, False: 0]
  ------------------
 1034|      0|      case COAP_OPTION_SIZE1:
  ------------------
  |  Branch (1034:7): [True: 0, False: 0]
  ------------------
 1035|      0|      case COAP_OPTION_SIZE2:
  ------------------
  |  Branch (1035:7): [True: 0, False: 0]
  ------------------
 1036|      0|      case COAP_OPTION_HOP_LIMIT:
  ------------------
  |  Branch (1036:7): [True: 0, False: 0]
  ------------------
 1037|      0|        if (coap_opt_length(option)) {
  ------------------
  |  Branch (1037:13): [True: 0, False: 0]
  ------------------
 1038|       |          /* show values as unsigned decimal value */
 1039|      0|          buf_len = snprintf((char *)buf, sizeof(buf), "%u",
 1040|      0|                             coap_decode_var_bytes(coap_opt_value(option),
 1041|      0|                                                   coap_opt_length(option)));
 1042|      0|        }
 1043|      0|        break;
 1044|       |
 1045|      0|      case COAP_OPTION_IF_MATCH:
  ------------------
  |  Branch (1045:7): [True: 0, False: 0]
  ------------------
 1046|      0|      case COAP_OPTION_ETAG:
  ------------------
  |  Branch (1046:7): [True: 0, False: 0]
  ------------------
 1047|      0|      case COAP_OPTION_ECHO:
  ------------------
  |  Branch (1047:7): [True: 0, False: 0]
  ------------------
 1048|      0|      case COAP_OPTION_NORESPONSE:
  ------------------
  |  Branch (1048:7): [True: 0, False: 0]
  ------------------
 1049|      0|      case COAP_OPTION_RTAG:
  ------------------
  |  Branch (1049:7): [True: 0, False: 0]
  ------------------
 1050|      0|        opt_len = coap_opt_length(option);
 1051|      0|        opt_val = coap_opt_value(option);
 1052|      0|        snprintf((char *)buf, sizeof(buf), "0x");
 1053|      0|        for (i = 0; (uint32_t)i < opt_len; i++) {
  ------------------
  |  Branch (1053:21): [True: 0, False: 0]
  ------------------
 1054|      0|          buf_len = strlen((char *)buf);
 1055|      0|          snprintf((char *)&buf[buf_len], sizeof(buf)-buf_len,
 1056|      0|                   "%02x", opt_val[i]);
 1057|      0|        }
 1058|      0|        buf_len = strlen((char *)buf);
 1059|      0|        break;
 1060|      0|      case COAP_OPTION_URI_PATH_ABB:
  ------------------
  |  Branch (1060:7): [True: 0, False: 0]
  ------------------
 1061|      0|        value = coap_decode_var_bytes(coap_opt_value(option),
 1062|      0|                                      coap_opt_length(option));
 1063|      0|        exp = coap_map_abbrev_uri_path(coap_upa_server_mapping_chain, value);
 1064|      0|        if (!exp) {
  ------------------
  |  Branch (1064:13): [True: 0, False: 0]
  ------------------
 1065|      0|          exp = coap_map_abbrev_uri_path(coap_upa_client_fallback_chain, value);
 1066|      0|        }
 1067|      0|        if (exp) {
  ------------------
  |  Branch (1067:13): [True: 0, False: 0]
  ------------------
 1068|      0|          snprintf((char *)&buf, sizeof(buf), "%s", exp);
 1069|      0|        } else {
 1070|      0|          snprintf((char *)&buf, sizeof(buf), "(%" PRIu32 ")", value);
 1071|      0|        }
 1072|      0|        buf_len = strlen((char *)buf);
 1073|      0|        break;
 1074|      0|      case COAP_OPTION_URI_PATH:
  ------------------
  |  Branch (1074:7): [True: 0, False: 0]
  ------------------
 1075|      0|      case COAP_OPTION_PROXY_URI:
  ------------------
  |  Branch (1075:7): [True: 0, False: 0]
  ------------------
 1076|      0|      case COAP_OPTION_URI_HOST:
  ------------------
  |  Branch (1076:7): [True: 0, False: 0]
  ------------------
 1077|      0|      case COAP_OPTION_LOCATION_PATH:
  ------------------
  |  Branch (1077:7): [True: 0, False: 0]
  ------------------
 1078|      0|      case COAP_OPTION_LOCATION_QUERY:
  ------------------
  |  Branch (1078:7): [True: 0, False: 0]
  ------------------
 1079|      0|      case COAP_OPTION_PROXY_SCHEME:
  ------------------
  |  Branch (1079:7): [True: 0, False: 0]
  ------------------
 1080|      0|      case COAP_OPTION_URI_QUERY:
  ------------------
  |  Branch (1080:7): [True: 0, False: 0]
  ------------------
 1081|      0|        buf_len = print_readable(coap_opt_value(option),
 1082|      0|                                 coap_opt_length(option),
 1083|      0|                                 buf, sizeof(buf), 0);
 1084|      0|        break;
 1085|      0|      case COAP_OPTION_IF_NONE_MATCH:
  ------------------
  |  Branch (1085:7): [True: 0, False: 0]
  ------------------
 1086|      0|      case COAP_OPTION_EDHOC:
  ------------------
  |  Branch (1086:7): [True: 0, False: 0]
  ------------------
 1087|      0|      default:
  ------------------
  |  Branch (1087:7): [True: 0, False: 0]
  ------------------
 1088|      0|        buf_len = print_readable(coap_opt_value(option),
 1089|      0|                                 coap_opt_length(option),
 1090|      0|                                 buf, sizeof(buf), 1);
 1091|      0|      }
 1092|      0|    }
 1093|      0|    outbuflen = strlen(outbuf);
 1094|      0|    snprintf(&outbuf[outbuflen], sizeof(outbuf)-outbuflen,
 1095|      0|             " %s:%.*s", coap_option_string(pdu->code, opt_iter.number),
 1096|      0|             (int)buf_len, buf);
 1097|      0|  }
 1098|       |
 1099|      0|  outbuflen = strlen(outbuf);
 1100|      0|  snprintf(&outbuf[outbuflen], sizeof(outbuf)-outbuflen,  " ]");
 1101|       |
 1102|      0|  if (coap_get_data(pdu, &data_len, &data)) {
  ------------------
  |  Branch (1102:7): [True: 0, False: 0]
  ------------------
 1103|      0|    if (!enable_data_for_show_pdu) {
  ------------------
  |  Branch (1103:9): [True: 0, False: 0]
  ------------------
 1104|       |      /* Only output data if wanted */
 1105|      0|      outbuflen = strlen(outbuf);
 1106|      0|      snprintf(&outbuf[outbuflen], sizeof(outbuf)-outbuflen,  " :: ");
 1107|      0|      outbuflen = strlen(outbuf);
 1108|      0|      snprintf(&outbuf[outbuflen], sizeof(outbuf)-outbuflen,
 1109|      0|               "data length %"PRIuS " (data suppressed)\n", data_len);
 1110|      0|      COAP_DO_SHOW_OUTPUT_LINE;
  ------------------
  |  |  779|      0|  do {                                      \
  |  |  780|      0|    if (use_fprintf_for_show_pdu) {         \
  |  |  ------------------
  |  |  |  Branch (780:9): [True: 0, False: 0]
  |  |  ------------------
  |  |  781|      0|      fprintf(COAP_DEBUG_FD, "%s", outbuf); \
  |  |  ------------------
  |  |  |  |   37|      0|#define COAP_DEBUG_FD stdout
  |  |  ------------------
  |  |  782|      0|    }                                       \
  |  |  783|      0|    else {                                  \
  |  |  784|      0|      coap_log(level, "%s", outbuf);        \
  |  |  ------------------
  |  |  |  |  290|      0|#define coap_log(level, ...) do { \
  |  |  |  |  291|      0|    if ((level) < (coap_get_log_level() + 1)) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (291:9): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  292|      0|      coap_log_impl((level), __VA_ARGS__); \
  |  |  |  |  293|      0|  } while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (293:11): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  785|      0|    }                                       \
  |  |  786|      0|  } while (0)
  |  |  ------------------
  |  |  |  Branch (786:12): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1111|       |#if COAP_THREAD_SAFE
 1112|       |      coap_mutex_unlock(&m_show_pdu);
 1113|       |#endif /* COAP_THREAD_SAFE */
 1114|      0|      return;
 1115|      0|    }
 1116|       |
 1117|      0|    outbuflen = strlen(outbuf);
 1118|      0|    snprintf(&outbuf[outbuflen], sizeof(outbuf)-outbuflen,  " :: ");
 1119|       |
 1120|      0|    if (is_binary(content_format) || !isprint(data[0]) || is_oscore_payload) {
  ------------------
  |  Branch (1120:9): [True: 0, False: 0]
  |  Branch (1120:38): [True: 0, False: 0]
  |  Branch (1120:59): [True: 0, False: 0]
  ------------------
 1121|      0|      size_t keep_data_len = data_len;
 1122|      0|      const uint8_t *keep_data = data;
 1123|       |
 1124|      0|      outbuflen = strlen(outbuf);
 1125|      0|      snprintf(&outbuf[outbuflen], sizeof(outbuf)-outbuflen,
 1126|      0|               "binary data length %"PRIuS "\n", data_len);
 1127|      0|      COAP_DO_SHOW_OUTPUT_LINE;
  ------------------
  |  |  779|      0|  do {                                      \
  |  |  780|      0|    if (use_fprintf_for_show_pdu) {         \
  |  |  ------------------
  |  |  |  Branch (780:9): [True: 0, False: 0]
  |  |  ------------------
  |  |  781|      0|      fprintf(COAP_DEBUG_FD, "%s", outbuf); \
  |  |  ------------------
  |  |  |  |   37|      0|#define COAP_DEBUG_FD stdout
  |  |  ------------------
  |  |  782|      0|    }                                       \
  |  |  783|      0|    else {                                  \
  |  |  784|      0|      coap_log(level, "%s", outbuf);        \
  |  |  ------------------
  |  |  |  |  290|      0|#define coap_log(level, ...) do { \
  |  |  |  |  291|      0|    if ((level) < (coap_get_log_level() + 1)) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (291:9): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  292|      0|      coap_log_impl((level), __VA_ARGS__); \
  |  |  |  |  293|      0|  } while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (293:11): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  785|      0|    }                                       \
  |  |  786|      0|  } while (0)
  |  |  ------------------
  |  |  |  Branch (786:12): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1128|       |      /*
 1129|       |       * Output hex dump of binary data as a continuous entry
 1130|       |       */
 1131|      0|      outbuf[0] = '\000';
 1132|      0|      snprintf(outbuf, sizeof(outbuf),  "<<");
 1133|      0|      while (data_len--) {
  ------------------
  |  Branch (1133:14): [True: 0, False: 0]
  ------------------
 1134|      0|        outbuflen = strlen(outbuf);
 1135|      0|        snprintf(&outbuf[outbuflen], sizeof(outbuf)-outbuflen,
 1136|      0|                 "%02x", *data++);
 1137|      0|      }
 1138|      0|      outbuflen = strlen(outbuf);
 1139|      0|      snprintf(&outbuf[outbuflen], sizeof(outbuf)-outbuflen,  ">>");
 1140|      0|      data_len = keep_data_len;
 1141|      0|      data = keep_data;
 1142|      0|      outbuflen = strlen(outbuf);
 1143|      0|      if (outbuflen == sizeof(outbuf)-1)
  ------------------
  |  Branch (1143:11): [True: 0, False: 0]
  ------------------
 1144|      0|        outbuflen--;
 1145|      0|      snprintf(&outbuf[outbuflen], sizeof(outbuf)-outbuflen,  "\n");
 1146|      0|      COAP_DO_SHOW_OUTPUT_LINE;
  ------------------
  |  |  779|      0|  do {                                      \
  |  |  780|      0|    if (use_fprintf_for_show_pdu) {         \
  |  |  ------------------
  |  |  |  Branch (780:9): [True: 0, False: 0]
  |  |  ------------------
  |  |  781|      0|      fprintf(COAP_DEBUG_FD, "%s", outbuf); \
  |  |  ------------------
  |  |  |  |   37|      0|#define COAP_DEBUG_FD stdout
  |  |  ------------------
  |  |  782|      0|    }                                       \
  |  |  783|      0|    else {                                  \
  |  |  784|      0|      coap_log(level, "%s", outbuf);        \
  |  |  ------------------
  |  |  |  |  290|      0|#define coap_log(level, ...) do { \
  |  |  |  |  291|      0|    if ((level) < (coap_get_log_level() + 1)) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (291:9): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  292|      0|      coap_log_impl((level), __VA_ARGS__); \
  |  |  |  |  293|      0|  } while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (293:11): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  785|      0|    }                                       \
  |  |  786|      0|  } while (0)
  |  |  ------------------
  |  |  |  Branch (786:12): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1147|       |      /*
 1148|       |       * Output ascii readable (if possible), immediately under the
 1149|       |       * hex value of the character output above to help binary debugging
 1150|       |       */
 1151|      0|      outbuf[0] = '\000';
 1152|      0|      snprintf(outbuf, sizeof(outbuf),  "<<");
 1153|      0|      while (data_len--) {
  ------------------
  |  Branch (1153:14): [True: 0, False: 0]
  ------------------
 1154|      0|        outbuflen = strlen(outbuf);
 1155|      0|        snprintf(&outbuf[outbuflen], sizeof(outbuf)-outbuflen,
 1156|      0|                 "%c ", isprint(*data) ? *data : '.');
  ------------------
  |  Branch (1156:25): [True: 0, False: 0]
  ------------------
 1157|      0|        data++;
 1158|      0|      }
 1159|      0|      outbuflen = strlen(outbuf);
 1160|      0|      snprintf(&outbuf[outbuflen], sizeof(outbuf)-outbuflen,  ">>");
 1161|      0|    } else {
 1162|      0|      size_t max_length;
 1163|       |
 1164|      0|      outbuflen = strlen(outbuf);
 1165|      0|      max_length = sizeof(outbuf)-outbuflen;
 1166|      0|      if (max_length > 1) {
  ------------------
  |  Branch (1166:11): [True: 0, False: 0]
  ------------------
 1167|      0|        outbuf[outbuflen++] = '\'';
 1168|      0|        outbuf[outbuflen] = '\000';
 1169|      0|        max_length--;
 1170|      0|      }
 1171|      0|      if (max_length > 1) {
  ------------------
  |  Branch (1171:11): [True: 0, False: 0]
  ------------------
 1172|      0|        outbuflen += print_readable(data, data_len,
 1173|      0|                                    (unsigned char *)&outbuf[outbuflen],
 1174|      0|                                    max_length, 0);
 1175|      0|      }
 1176|       |      /* print_readable may be handling unprintables - hence headroom of 4 */
 1177|      0|      if (outbuflen < sizeof(outbuf)-4-1) {
  ------------------
  |  Branch (1177:11): [True: 0, False: 0]
  ------------------
 1178|      0|        outbuf[outbuflen++] = '\'';
 1179|      0|        outbuf[outbuflen] = '\000';
 1180|      0|      }
 1181|      0|    }
 1182|      0|  }
 1183|       |
 1184|      0|  outbuflen = strlen(outbuf);
 1185|      0|  if (outbuflen == sizeof(outbuf)-1)
  ------------------
  |  Branch (1185:7): [True: 0, False: 0]
  ------------------
 1186|      0|    outbuflen--;
 1187|      0|  snprintf(&outbuf[outbuflen], sizeof(outbuf)-outbuflen,  "\n");
 1188|      0|  COAP_DO_SHOW_OUTPUT_LINE;
  ------------------
  |  |  779|      0|  do {                                      \
  |  |  780|      0|    if (use_fprintf_for_show_pdu) {         \
  |  |  ------------------
  |  |  |  Branch (780:9): [True: 0, False: 0]
  |  |  ------------------
  |  |  781|      0|      fprintf(COAP_DEBUG_FD, "%s", outbuf); \
  |  |  ------------------
  |  |  |  |   37|      0|#define COAP_DEBUG_FD stdout
  |  |  ------------------
  |  |  782|      0|    }                                       \
  |  |  783|      0|    else {                                  \
  |  |  784|      0|      coap_log(level, "%s", outbuf);        \
  |  |  ------------------
  |  |  |  |  290|      0|#define coap_log(level, ...) do { \
  |  |  |  |  291|      0|    if ((level) < (coap_get_log_level() + 1)) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (291:9): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  292|      0|      coap_log_impl((level), __VA_ARGS__); \
  |  |  |  |  293|      0|  } while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (293:11): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  785|      0|    }                                       \
  |  |  786|      0|  } while (0)
  |  |  ------------------
  |  |  |  Branch (786:12): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1189|       |
 1190|       |#if COAP_THREAD_SAFE
 1191|       |  coap_mutex_unlock(&m_show_pdu);
 1192|       |#endif /* COAP_THREAD_SAFE */
 1193|      0|}
coap_debug_reset:
 1581|  3.16k|coap_debug_reset(void) {
 1582|       |  log_handler = NULL;
 1583|  3.16k|  maxlog = COAP_LOG_WARN;
 1584|  3.16k|  use_fprintf_for_show_pdu = 1;
 1585|  3.16k|  num_packet_loss_intervals = 0;
 1586|  3.16k|  packet_loss_level = 0;
 1587|  3.16k|  num_packet_fail_intervals = 0;
 1588|  3.16k|  packet_fail_level = 0;
 1589|  3.16k|  send_packet_count = 0;
 1590|  3.16k|  num_packet_drop_intervals = 0;
 1591|  3.16k|  packet_drop_level = 0;
 1592|  3.16k|  recv_packet_count = 0;
 1593|  3.16k|}

coap_fls:
   21|  38.1k|coap_fls(unsigned int i) {
   22|  38.1k|  return coap_flsll(i);
   23|  38.1k|}
coap_flsll:
   28|  38.1k|coap_flsll(long long j) {
   29|  38.1k|  unsigned long long i = (unsigned long long)j;
   30|  38.1k|  int n;
   31|   100k|  for (n = 0; i; n++)
  ------------------
  |  Branch (31:15): [True: 61.9k, False: 38.1k]
  ------------------
   32|  61.9k|    i >>= 1;
   33|  38.1k|  return n;
   34|  38.1k|}
coap_decode_var_bytes:
   38|     15|coap_decode_var_bytes(const uint8_t *buf, size_t len) {
   39|     15|  unsigned int i, n = 0;
   40|     28|  for (i = 0; i < len; ++i)
  ------------------
  |  Branch (40:15): [True: 13, False: 15]
  ------------------
   41|     13|    n = (n << 8) + buf[i];
   42|       |
   43|     15|  return n;
   44|     15|}

coap_memory_init:
  623|  3.16k|coap_memory_init(void) {
  624|  3.16k|}
coap_malloc_type:
  627|  7.77k|coap_malloc_type(coap_memory_tag_t type, size_t size) {
  628|  7.77k|  void *ptr;
  629|       |
  630|  7.77k|  (void)type;
  631|  7.77k|  ptr = malloc(size);
  632|       |#if COAP_MEMORY_TYPE_TRACK
  633|       |  assert(type < COAP_MEM_TAG_LAST);
  634|       |  if (ptr) {
  635|       |    track_counts[type]++;
  636|       |    if (track_counts[type] > peak_counts[type])
  637|       |      peak_counts[type] = track_counts[type];
  638|       |  } else {
  639|       |    fail_counts[type]++;
  640|       |  }
  641|       |#endif /* COAP_MEMORY_TYPE_TRACK */
  642|  7.77k|  return ptr;
  643|  7.77k|}
coap_realloc_type:
  646|    566|coap_realloc_type(coap_memory_tag_t type, void *p, size_t size) {
  647|    566|  void *ptr;
  648|       |
  649|    566|  (void)type;
  650|    566|  ptr = realloc(p, size);
  651|       |#if COAP_MEMORY_TYPE_TRACK
  652|       |  if (ptr) {
  653|       |    assert(type < COAP_MEM_TAG_LAST);
  654|       |    if (!p)
  655|       |      track_counts[type]++;
  656|       |    if (track_counts[type] > peak_counts[type])
  657|       |      peak_counts[type] = track_counts[type];
  658|       |  } else {
  659|       |    fail_counts[type]++;
  660|       |  }
  661|       |#endif /* COAP_MEMORY_TYPE_TRACK */
  662|    566|  return ptr;
  663|    566|}
coap_free_type:
  666|  12.6k|coap_free_type(coap_memory_tag_t type, void *p) {
  667|  12.6k|  (void)type;
  668|       |#if COAP_MEMORY_TYPE_TRACK
  669|       |  assert(type < COAP_MEM_TAG_LAST);
  670|       |  if (p)
  671|       |    track_counts[type]--;
  672|       |#endif /* COAP_MEMORY_TYPE_TRACK */
  673|  12.6k|  free(p);
  674|  12.6k|}

coap_startup:
 5447|  3.16k|coap_startup(void) {
 5448|  3.16k|  coap_tick_t now;
 5449|  3.16k|#ifndef WITH_CONTIKI
 5450|  3.16k|  uint64_t us;
 5451|  3.16k|#endif /* !WITH_CONTIKI */
 5452|       |
 5453|  3.16k|  if (coap_started)
  ------------------
  |  Branch (5453:7): [True: 0, False: 3.16k]
  ------------------
 5454|      0|    return;
 5455|  3.16k|  coap_started = 1;
 5456|       |
 5457|       |#if COAP_THREAD_SAFE
 5458|       |  coap_lock_init(&global_lock);
 5459|       |  coap_mutex_init(&m_show_pdu);
 5460|       |  coap_mutex_init(&m_log_impl);
 5461|       |  coap_mutex_init(&m_io_threads);
 5462|       |#endif /* COAP_THREAD_SAFE */
 5463|       |
 5464|       |#if defined(HAVE_WINSOCK2_H)
 5465|       |  WORD wVersionRequested = MAKEWORD(2, 2);
 5466|       |  WSADATA wsaData;
 5467|       |  WSAStartup(wVersionRequested, &wsaData);
 5468|       |#endif
 5469|  3.16k|  coap_clock_init();
 5470|  3.16k|  coap_ticks(&now);
 5471|  3.16k|#ifndef WITH_CONTIKI
 5472|  3.16k|  us = coap_ticks_to_rt_us(now);
 5473|       |  /* Be accurate to the nearest (approx) us */
 5474|  3.16k|  coap_prng_init_lkd((unsigned int)us);
 5475|       |#else /* WITH_CONTIKI */
 5476|       |  coap_start_io_process();
 5477|       |#endif /* WITH_CONTIKI */
 5478|  3.16k|  coap_memory_init();
 5479|  3.16k|  coap_dtls_startup();
 5480|       |#ifdef WITH_LWIP
 5481|       |  coap_io_lwip_init();
 5482|       |#endif /* WITH_LWIP */
 5483|  3.16k|#if COAP_SERVER_SUPPORT
 5484|  3.16k|  static coap_str_const_t well_known = { sizeof(".well-known/core")-1,
 5485|  3.16k|                                         (const uint8_t *)".well-known/core"
 5486|  3.16k|                                       };
 5487|  3.16k|  memset(&resource_uri_wellknown, 0, sizeof(resource_uri_wellknown));
 5488|  3.16k|  resource_uri_wellknown.ref = 1;
 5489|  3.16k|  resource_uri_wellknown.handler[COAP_REQUEST_GET-1] = hnd_get_wellknown_lkd;
 5490|  3.16k|  resource_uri_wellknown.flags = COAP_RESOURCE_FLAGS_HAS_MCAST_SUPPORT;
  ------------------
  |  |   89|  3.16k|#define COAP_RESOURCE_FLAGS_HAS_MCAST_SUPPORT 0x8
  ------------------
 5491|  3.16k|  resource_uri_wellknown.uri_path = &well_known;
 5492|  3.16k|#endif /* COAP_SERVER_SUPPORT */
 5493|  3.16k|  send_recv_terminate = 0;
 5494|  3.16k|  coap_prng_lkd(&coap_unique_id, sizeof(coap_unique_id));
 5495|  3.16k|}
coap_cleanup:
 5498|  3.16k|coap_cleanup(void) {
 5499|  3.16k|  if (!coap_started)
  ------------------
  |  Branch (5499:7): [True: 0, False: 3.16k]
  ------------------
 5500|      0|    return;
 5501|  3.16k|  coap_started = 0;
 5502|       |#if defined(HAVE_WINSOCK2_H)
 5503|       |  WSACleanup();
 5504|       |#elif defined(WITH_CONTIKI)
 5505|       |  coap_stop_io_process();
 5506|       |#endif
 5507|       |#ifdef WITH_LWIP
 5508|       |  coap_io_lwip_cleanup();
 5509|       |#endif /* WITH_LWIP */
 5510|  3.16k|  coap_dtls_shutdown();
 5511|       |
 5512|  3.16k|  coap_delete_upa_chain(coap_upa_client_fallback_chain);
 5513|  3.16k|  coap_upa_client_fallback_chain = NULL;
 5514|  3.16k|  coap_delete_upa_chain(coap_upa_server_mapping_chain);
 5515|  3.16k|  coap_upa_server_mapping_chain = NULL;
 5516|       |#if COAP_THREAD_SAFE
 5517|       |  coap_mutex_destroy(&m_show_pdu);
 5518|       |  coap_mutex_destroy(&m_log_impl);
 5519|       |  coap_mutex_destroy(&m_io_threads);
 5520|       |#endif /* COAP_THREAD_SAFE */
 5521|       |
 5522|  3.16k|  coap_debug_reset();
 5523|  3.16k|}

coap_dtls_is_supported:
  191|      3|coap_dtls_is_supported(void) {
  192|      3|  if (SSLeay() < 0x10100000L) {
  ------------------
  |  Branch (192:7): [True: 0, False: 3]
  ------------------
  193|      0|    coap_log_warn("OpenSSL version 1.1.0 or later is required\n");
  ------------------
  |  |  108|      0|#define coap_log_warn(...) coap_log(COAP_LOG_WARN, __VA_ARGS__)
  |  |  ------------------
  |  |  |  |  290|      0|#define coap_log(level, ...) do { \
  |  |  |  |  291|      0|    if ((level) < (coap_get_log_level() + 1)) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (291:9): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  292|      0|      coap_log_impl((level), __VA_ARGS__); \
  |  |  |  |  293|      0|  } while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (293:11): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  194|      0|    return 0;
  195|      0|  }
  196|      3|#if OPENSSL_VERSION_NUMBER >= 0x10101000L
  197|       |  /*
  198|       |   * For 1.1.1, we need to use SSL_CTX_set_client_hello_cb()
  199|       |   * which is not in 1.1.0 instead of SSL_CTX_set_tlsext_servername_callback()
  200|       |   *
  201|       |   * However, there could be a runtime undefined external reference error
  202|       |   * as SSL_CTX_set_client_hello_cb() is not there in 1.1.0.
  203|       |   */
  204|      3|  if (SSLeay() < 0x10101000L) {
  ------------------
  |  Branch (204:7): [True: 0, False: 3]
  ------------------
  205|      0|    coap_log_warn("OpenSSL version 1.1.1 or later is required\n");
  ------------------
  |  |  108|      0|#define coap_log_warn(...) coap_log(COAP_LOG_WARN, __VA_ARGS__)
  |  |  ------------------
  |  |  |  |  290|      0|#define coap_log(level, ...) do { \
  |  |  |  |  291|      0|    if ((level) < (coap_get_log_level() + 1)) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (291:9): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  292|      0|      coap_log_impl((level), __VA_ARGS__); \
  |  |  |  |  293|      0|  } while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (293:11): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  206|      0|    return 0;
  207|      0|  }
  208|      3|#endif /* OPENSSL_VERSION_NUMBER >= 0x10101000L */
  209|      3|  return 1;
  210|      3|}
coap_tls_is_supported:
  213|      2|coap_tls_is_supported(void) {
  214|      2|#if !COAP_DISABLE_TCP
  215|      2|  if (SSLeay() < 0x10100000L) {
  ------------------
  |  Branch (215:7): [True: 0, False: 2]
  ------------------
  216|      0|    coap_log_warn("OpenSSL version 1.1.0 or later is required\n");
  ------------------
  |  |  108|      0|#define coap_log_warn(...) coap_log(COAP_LOG_WARN, __VA_ARGS__)
  |  |  ------------------
  |  |  |  |  290|      0|#define coap_log(level, ...) do { \
  |  |  |  |  291|      0|    if ((level) < (coap_get_log_level() + 1)) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (291:9): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  292|      0|      coap_log_impl((level), __VA_ARGS__); \
  |  |  |  |  293|      0|  } while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (293:11): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  217|      0|    return 0;
  218|      0|  }
  219|      2|#if OPENSSL_VERSION_NUMBER >= 0x10101000L
  220|      2|  if (SSLeay() < 0x10101000L) {
  ------------------
  |  Branch (220:7): [True: 0, False: 2]
  ------------------
  221|      0|    coap_log_warn("OpenSSL version 1.1.1 or later is required\n");
  ------------------
  |  |  108|      0|#define coap_log_warn(...) coap_log(COAP_LOG_WARN, __VA_ARGS__)
  |  |  ------------------
  |  |  |  |  290|      0|#define coap_log(level, ...) do { \
  |  |  |  |  291|      0|    if ((level) < (coap_get_log_level() + 1)) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (291:9): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  292|      0|      coap_log_impl((level), __VA_ARGS__); \
  |  |  |  |  293|      0|  } while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (293:11): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  222|      0|    return 0;
  223|      0|  }
  224|      2|#endif /* OPENSSL_VERSION_NUMBER >= 0x10101000L */
  225|      2|  return 1;
  226|       |#else /* COAP_DISABLE_TCP */
  227|       |  return 0;
  228|       |#endif /* COAP_DISABLE_TCP */
  229|      2|}
coap_dtls_startup:
  304|  3.16k|coap_dtls_startup(void) {
  305|  3.16k|  SSL_load_error_strings();
  306|  3.16k|  SSL_library_init();
  307|  3.16k|#if OPENSSL_VERSION_NUMBER < 0x40000000L
  308|       |  ENGINE_load_dynamic();
  309|  3.16k|#endif /* OPENSSL_VERSION_NUMBER < 0x40000000L */
  310|  3.16k|}
coap_dtls_shutdown:
  313|  3.16k|coap_dtls_shutdown(void) {
  314|  3.16k|#if OPENSSL_VERSION_NUMBER < 0x30000000L
  315|  3.16k|  if (pkcs11_engine) {
  ------------------
  |  Branch (315:7): [True: 0, False: 3.16k]
  ------------------
  316|       |    /* Release the functional reference from ENGINE_init() */
  317|      0|    ENGINE_finish(pkcs11_engine);
  318|      0|    pkcs11_engine = NULL;
  319|      0|  }
  320|  3.16k|  if (defined_engine) {
  ------------------
  |  Branch (320:7): [True: 0, False: 3.16k]
  ------------------
  321|       |    /* Release the functional reference from ENGINE_init() */
  322|      0|    ENGINE_finish(defined_engine);
  323|      0|    defined_engine = NULL;
  324|      0|  }
  325|       |#elif OPENSSL_VERSION_NUMBER < 0x40000000L
  326|       |  pkcs11_engine = NULL;
  327|       |  defined_engine = NULL;
  328|       |#endif /* OPENSSL_VERSION_NUMBER >= 0x30000000L && < 0x40000000L */
  329|       |  ERR_free_strings();
  ------------------
  |  Branch (329:3): [Folded, False: 3.16k]
  ------------------
  330|  3.16k|  coap_dtls_set_log_level(COAP_LOG_EMERG);
  331|  3.16k|}
coap_dtls_set_log_level:
  590|  3.16k|coap_dtls_set_log_level(coap_log_t level) {
  591|  3.16k|  dtls_log_level = level;
  592|  3.16k|}

coap_opt_parse:
   41|  49.2M|coap_opt_parse(const coap_opt_t *opt, size_t length, coap_option_t *result) {
   42|       |
   43|  49.2M|  const coap_opt_t *opt_start = opt; /* store where parsing starts  */
   44|       |
   45|  49.2M|  assert(opt);
  ------------------
  |  Branch (45:3): [True: 49.2M, False: 0]
  ------------------
   46|  49.2M|  assert(result);
  ------------------
  |  Branch (46:3): [True: 49.2M, False: 0]
  ------------------
   47|       |
   48|  49.2M|  if (length < 1)
  ------------------
  |  Branch (48:7): [True: 4.52k, False: 49.2M]
  ------------------
   49|  4.52k|    return 0;
   50|       |
   51|  49.2M|  result->delta = (*opt & 0xf0) >> 4;
   52|  49.2M|  result->length = *opt & 0x0f;
   53|       |
   54|  49.2M|  switch (result->delta) {
   55|    545|  case 15:
  ------------------
  |  Branch (55:3): [True: 545, False: 49.2M]
  ------------------
   56|    545|    if (*opt != COAP_PAYLOAD_START) {
  ------------------
  |  |   96|    545|#define COAP_PAYLOAD_START 0xFF /* payload marker */
  ------------------
  |  Branch (56:9): [True: 165, False: 380]
  ------------------
   57|    165|      coap_log_debug("ignored reserved option delta 15\n");
  ------------------
  |  |  126|    165|#define coap_log_debug(...) coap_log(COAP_LOG_DEBUG, __VA_ARGS__)
  |  |  ------------------
  |  |  |  |  290|    165|#define coap_log(level, ...) do { \
  |  |  |  |  291|    165|    if ((level) < (coap_get_log_level() + 1)) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (291:9): [True: 0, False: 165]
  |  |  |  |  ------------------
  |  |  |  |  292|    165|      coap_log_impl((level), __VA_ARGS__); \
  |  |  |  |  293|    165|  } while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (293:11): [Folded, False: 165]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
   58|    165|    }
   59|    545|    return 0;
   60|  1.18k|  case 14:
  ------------------
  |  Branch (60:3): [True: 1.18k, False: 49.2M]
  ------------------
   61|       |    /* Handle two-byte value: First, the MSB + 269 is stored as delta value.
   62|       |     * After that, the option pointer is advanced to the LSB which is handled
   63|       |     * just like case delta == 13. */
   64|  1.18k|    ADVANCE_OPT_CHECK(opt,length,1);
  ------------------
  |  |   34|  1.18k|#define ADVANCE_OPT_CHECK(o,e,step) do { \
  |  |   35|  1.18k|    ADVANCE_OPT(o,e,step);               \
  |  |  ------------------
  |  |  |  |   22|  1.18k|#define ADVANCE_OPT(o,e,step) if ((e) < step) {           \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (22:35): [True: 0, False: 1.18k]
  |  |  |  |  ------------------
  |  |  |  |   23|      0|    coap_log_debug("cannot advance opt past end\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |  126|      0|#define coap_log_debug(...) coap_log(COAP_LOG_DEBUG, __VA_ARGS__)
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  290|      0|#define coap_log(level, ...) do { \
  |  |  |  |  |  |  |  |  291|      0|    if ((level) < (coap_get_log_level() + 1)) \
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  Branch (291:9): [True: 0, False: 0]
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  292|      0|      coap_log_impl((level), __VA_ARGS__); \
  |  |  |  |  |  |  |  |  293|      0|  } while(0)
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  Branch (293:11): [Folded, False: 0]
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  |  |   24|      0|    return 0;                                             \
  |  |  |  |   25|  1.18k|  } else {                                                \
  |  |  |  |   26|  1.18k|    (e) -= step;                                          \
  |  |  |  |   27|  1.18k|    (o) = ((o)) + step;                                   \
  |  |  |  |   28|  1.18k|  }
  |  |  ------------------
  |  |   36|  1.18k|    if ((e) < 1)                         \
  |  |  ------------------
  |  |  |  Branch (36:9): [True: 42, False: 1.14k]
  |  |  ------------------
  |  |   37|  1.18k|      return 0;                          \
  |  |   38|  1.18k|  } while (0)
  |  |  ------------------
  |  |  |  Branch (38:12): [Folded, False: 1.14k]
  |  |  ------------------
  ------------------
   65|  1.14k|    result->delta = ((*opt & 0xff) << 8) + 269;
   66|  1.14k|    if (result->delta < 269) {
  ------------------
  |  Branch (66:9): [True: 3, False: 1.13k]
  ------------------
   67|      3|      coap_log_debug("delta too large\n");
  ------------------
  |  |  126|      3|#define coap_log_debug(...) coap_log(COAP_LOG_DEBUG, __VA_ARGS__)
  |  |  ------------------
  |  |  |  |  290|      3|#define coap_log(level, ...) do { \
  |  |  |  |  291|      3|    if ((level) < (coap_get_log_level() + 1)) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (291:9): [True: 0, False: 3]
  |  |  |  |  ------------------
  |  |  |  |  292|      3|      coap_log_impl((level), __VA_ARGS__); \
  |  |  |  |  293|      3|  } while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (293:11): [Folded, False: 3]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
   68|      3|      return 0;
   69|      3|    }
   70|       |  /* fall through */
   71|  5.36k|  case 13:
  ------------------
  |  Branch (71:3): [True: 4.22k, False: 49.2M]
  ------------------
   72|  5.36k|    ADVANCE_OPT_CHECK(opt,length,1);
  ------------------
  |  |   34|  5.36k|#define ADVANCE_OPT_CHECK(o,e,step) do { \
  |  |   35|  5.36k|    ADVANCE_OPT(o,e,step);               \
  |  |  ------------------
  |  |  |  |   22|  5.36k|#define ADVANCE_OPT(o,e,step) if ((e) < step) {           \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (22:35): [True: 0, False: 5.36k]
  |  |  |  |  ------------------
  |  |  |  |   23|      0|    coap_log_debug("cannot advance opt past end\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |  126|      0|#define coap_log_debug(...) coap_log(COAP_LOG_DEBUG, __VA_ARGS__)
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  290|      0|#define coap_log(level, ...) do { \
  |  |  |  |  |  |  |  |  291|      0|    if ((level) < (coap_get_log_level() + 1)) \
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  Branch (291:9): [True: 0, False: 0]
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  292|      0|      coap_log_impl((level), __VA_ARGS__); \
  |  |  |  |  |  |  |  |  293|      0|  } while(0)
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  Branch (293:11): [Folded, False: 0]
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  |  |   24|      0|    return 0;                                             \
  |  |  |  |   25|  5.36k|  } else {                                                \
  |  |  |  |   26|  5.36k|    (e) -= step;                                          \
  |  |  |  |   27|  5.36k|    (o) = ((o)) + step;                                   \
  |  |  |  |   28|  5.36k|  }
  |  |  ------------------
  |  |   36|  5.36k|    if ((e) < 1)                         \
  |  |  ------------------
  |  |  |  Branch (36:9): [True: 78, False: 5.28k]
  |  |  ------------------
  |  |   37|  5.36k|      return 0;                          \
  |  |   38|  5.36k|  } while (0)
  |  |  ------------------
  |  |  |  Branch (38:12): [Folded, False: 5.28k]
  |  |  ------------------
  ------------------
   73|  5.28k|    result->delta += *opt & 0xff;
   74|  5.28k|    break;
   75|       |
   76|  49.2M|  default:
  ------------------
  |  Branch (76:3): [True: 49.2M, False: 5.95k]
  ------------------
   77|  49.2M|    ;
   78|  49.2M|  }
   79|       |
   80|  49.2M|  switch (result->length) {
   81|     87|  case 15:
  ------------------
  |  Branch (81:3): [True: 87, False: 49.2M]
  ------------------
   82|     87|    coap_log_debug("found reserved option length 15\n");
  ------------------
  |  |  126|     87|#define coap_log_debug(...) coap_log(COAP_LOG_DEBUG, __VA_ARGS__)
  |  |  ------------------
  |  |  |  |  290|     87|#define coap_log(level, ...) do { \
  |  |  |  |  291|     87|    if ((level) < (coap_get_log_level() + 1)) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (291:9): [True: 0, False: 87]
  |  |  |  |  ------------------
  |  |  |  |  292|     87|      coap_log_impl((level), __VA_ARGS__); \
  |  |  |  |  293|     87|  } while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (293:11): [Folded, False: 87]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
   83|     87|    return 0;
   84|  6.99k|  case 14:
  ------------------
  |  Branch (84:3): [True: 6.99k, False: 49.2M]
  ------------------
   85|       |    /* Handle two-byte value: First, the MSB + 269 is stored as delta value.
   86|       |     * After that, the option pointer is advanced to the LSB which is handled
   87|       |     * just like case delta == 13. */
   88|  6.99k|    ADVANCE_OPT_CHECK(opt,length,1);
  ------------------
  |  |   34|  6.99k|#define ADVANCE_OPT_CHECK(o,e,step) do { \
  |  |   35|  6.99k|    ADVANCE_OPT(o,e,step);               \
  |  |  ------------------
  |  |  |  |   22|  6.99k|#define ADVANCE_OPT(o,e,step) if ((e) < step) {           \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (22:35): [True: 0, False: 6.99k]
  |  |  |  |  ------------------
  |  |  |  |   23|      0|    coap_log_debug("cannot advance opt past end\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |  126|      0|#define coap_log_debug(...) coap_log(COAP_LOG_DEBUG, __VA_ARGS__)
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  290|      0|#define coap_log(level, ...) do { \
  |  |  |  |  |  |  |  |  291|      0|    if ((level) < (coap_get_log_level() + 1)) \
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  Branch (291:9): [True: 0, False: 0]
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  292|      0|      coap_log_impl((level), __VA_ARGS__); \
  |  |  |  |  |  |  |  |  293|      0|  } while(0)
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  Branch (293:11): [Folded, False: 0]
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  |  |   24|      0|    return 0;                                             \
  |  |  |  |   25|  6.99k|  } else {                                                \
  |  |  |  |   26|  6.99k|    (e) -= step;                                          \
  |  |  |  |   27|  6.99k|    (o) = ((o)) + step;                                   \
  |  |  |  |   28|  6.99k|  }
  |  |  ------------------
  |  |   36|  6.99k|    if ((e) < 1)                         \
  |  |  ------------------
  |  |  |  Branch (36:9): [True: 30, False: 6.96k]
  |  |  ------------------
  |  |   37|  6.99k|      return 0;                          \
  |  |   38|  6.99k|  } while (0)
  |  |  ------------------
  |  |  |  Branch (38:12): [Folded, False: 6.96k]
  |  |  ------------------
  ------------------
   89|  6.96k|    result->length = ((*opt & 0xff) << 8) + 269;
   90|       |  /* fall through */
   91|   427k|  case 13:
  ------------------
  |  Branch (91:3): [True: 420k, False: 48.8M]
  ------------------
   92|   427k|    ADVANCE_OPT_CHECK(opt,length,1);
  ------------------
  |  |   34|   427k|#define ADVANCE_OPT_CHECK(o,e,step) do { \
  |  |   35|   427k|    ADVANCE_OPT(o,e,step);               \
  |  |  ------------------
  |  |  |  |   22|   427k|#define ADVANCE_OPT(o,e,step) if ((e) < step) {           \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (22:35): [True: 0, False: 427k]
  |  |  |  |  ------------------
  |  |  |  |   23|      0|    coap_log_debug("cannot advance opt past end\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |  126|      0|#define coap_log_debug(...) coap_log(COAP_LOG_DEBUG, __VA_ARGS__)
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  290|      0|#define coap_log(level, ...) do { \
  |  |  |  |  |  |  |  |  291|      0|    if ((level) < (coap_get_log_level() + 1)) \
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  Branch (291:9): [True: 0, False: 0]
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  292|      0|      coap_log_impl((level), __VA_ARGS__); \
  |  |  |  |  |  |  |  |  293|      0|  } while(0)
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  Branch (293:11): [Folded, False: 0]
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  |  |   24|      0|    return 0;                                             \
  |  |  |  |   25|   427k|  } else {                                                \
  |  |  |  |   26|   427k|    (e) -= step;                                          \
  |  |  |  |   27|   427k|    (o) = ((o)) + step;                                   \
  |  |  |  |   28|   427k|  }
  |  |  ------------------
  |  |   36|   427k|    if ((e) < 1)                         \
  |  |  ------------------
  |  |  |  Branch (36:9): [True: 54, False: 427k]
  |  |  ------------------
  |  |   37|   427k|      return 0;                          \
  |  |   38|   427k|  } while (0)
  |  |  ------------------
  |  |  |  Branch (38:12): [Folded, False: 427k]
  |  |  ------------------
  ------------------
   93|   427k|    result->length += *opt & 0xff;
   94|   427k|    break;
   95|       |
   96|  48.8M|  default:
  ------------------
  |  Branch (96:3): [True: 48.8M, False: 427k]
  ------------------
   97|  48.8M|    ;
   98|  49.2M|  }
   99|       |
  100|       |  /* ADVANCE_OPT() is correct here */
  101|  49.2M|  ADVANCE_OPT(opt,length,1);
  ------------------
  |  |   22|  49.2M|#define ADVANCE_OPT(o,e,step) if ((e) < step) {           \
  |  |  ------------------
  |  |  |  Branch (22:35): [True: 0, False: 49.2M]
  |  |  ------------------
  |  |   23|      0|    coap_log_debug("cannot advance opt past end\n"); \
  |  |  ------------------
  |  |  |  |  126|      0|#define coap_log_debug(...) coap_log(COAP_LOG_DEBUG, __VA_ARGS__)
  |  |  |  |  ------------------
  |  |  |  |  |  |  290|      0|#define coap_log(level, ...) do { \
  |  |  |  |  |  |  291|      0|    if ((level) < (coap_get_log_level() + 1)) \
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  Branch (291:9): [True: 0, False: 0]
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  292|      0|      coap_log_impl((level), __VA_ARGS__); \
  |  |  |  |  |  |  293|      0|  } while(0)
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  Branch (293:11): [Folded, False: 0]
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |   24|      0|    return 0;                                             \
  |  |   25|  49.2M|  } else {                                                \
  |  |   26|  49.2M|    (e) -= step;                                          \
  |  |   27|  49.2M|    (o) = ((o)) + step;                                   \
  |  |   28|  49.2M|  }
  ------------------
  102|       |  /* opt now points to value, if present */
  103|       |
  104|  49.2M|  result->value = opt;
  105|  49.2M|  if (length < result->length) {
  ------------------
  |  Branch (105:7): [True: 942, False: 49.2M]
  ------------------
  106|    942|    coap_log_debug("invalid option length\n");
  ------------------
  |  |  126|    942|#define coap_log_debug(...) coap_log(COAP_LOG_DEBUG, __VA_ARGS__)
  |  |  ------------------
  |  |  |  |  290|    942|#define coap_log(level, ...) do { \
  |  |  |  |  291|    942|    if ((level) < (coap_get_log_level() + 1)) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (291:9): [True: 0, False: 942]
  |  |  |  |  ------------------
  |  |  |  |  292|    942|      coap_log_impl((level), __VA_ARGS__); \
  |  |  |  |  293|    942|  } while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (293:11): [Folded, False: 942]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  107|    942|    return 0;
  108|    942|  }
  109|       |
  110|  49.2M|#undef ADVANCE_OPT
  111|  49.2M|#undef ADVANCE_OPT_CHECK
  112|       |
  113|  49.2M|  return (opt + result->length) - opt_start;
  114|  49.2M|}
coap_option_iterator_init:
  118|  7.06k|                          const coap_opt_filter_t *filter) {
  119|  7.06k|  assert(pdu);
  ------------------
  |  Branch (119:3): [True: 7.06k, False: 0]
  ------------------
  120|  7.06k|  assert(pdu->token);
  ------------------
  |  Branch (120:3): [True: 7.06k, False: 0]
  ------------------
  121|  7.06k|  assert(oi);
  ------------------
  |  Branch (121:3): [True: 7.06k, False: 0]
  ------------------
  122|       |
  123|  7.06k|  memset(oi, 0, sizeof(coap_opt_iterator_t));
  124|       |
  125|  7.06k|  oi->next_option = pdu->token + pdu->e_token_length;
  126|  7.06k|  if (pdu->token + pdu->used_size <= oi->next_option) {
  ------------------
  |  Branch (126:7): [True: 210, False: 6.85k]
  ------------------
  127|    210|    oi->bad = 1;
  128|    210|    return NULL;
  129|    210|  }
  130|       |
  131|  6.85k|  oi->length = pdu->used_size - pdu->e_token_length;
  132|       |
  133|  6.85k|  if (filter) {
  ------------------
  |  Branch (133:7): [True: 6.85k, False: 0]
  ------------------
  134|  6.85k|    memcpy(&oi->filter, filter, sizeof(coap_opt_filter_t));
  135|  6.85k|    oi->filtered = 1;
  136|  6.85k|  }
  137|  6.85k|  return oi;
  138|  7.06k|}
coap_option_next:
  153|  11.8M|coap_option_next(coap_opt_iterator_t *oi) {
  154|  11.8M|  coap_option_t option;
  155|  11.8M|  coap_opt_t *current_opt = NULL;
  156|  11.8M|  size_t optsize;
  157|       |
  158|  11.8M|  assert(oi);
  ------------------
  |  Branch (158:3): [True: 11.8M, False: 0]
  ------------------
  159|       |
  160|  11.8M|  if (opt_finished(oi))
  ------------------
  |  Branch (160:7): [True: 1.56k, False: 11.8M]
  ------------------
  161|  1.56k|    return NULL;
  162|       |
  163|  37.1M|  while (1) {
  ------------------
  |  Branch (163:10): [True: 37.1M, Folded]
  ------------------
  164|       |    /* oi->next_option always points to the next option to deliver; as
  165|       |     * opt_finished() filters out any bad conditions, we can assume that
  166|       |     * oi->next_option is valid. */
  167|  37.1M|    current_opt = oi->next_option;
  168|       |
  169|       |    /*
  170|       |     * Advance internal pointer to next option.
  171|       |     * optsize will be 0 when no more options
  172|       |     */
  173|  37.1M|    optsize = coap_opt_parse(oi->next_option, oi->length, &option);
  174|  37.1M|    if (optsize) {
  ------------------
  |  Branch (174:9): [True: 37.1M, False: 4.90k]
  ------------------
  175|  37.1M|      assert(optsize <= oi->length);
  ------------------
  |  Branch (175:7): [True: 37.1M, False: 0]
  ------------------
  176|       |
  177|  37.1M|      oi->next_option += optsize;
  178|  37.1M|      oi->length -= optsize;
  179|       |
  180|  37.1M|      oi->number += option.delta;
  181|  37.1M|    } else {                        /* current option is malformed */
  182|  4.90k|      oi->bad = 1;
  183|  4.90k|      return NULL;
  184|  4.90k|    }
  185|       |
  186|       |    /* Exit the while loop when:
  187|       |     *   - no filtering is done at all
  188|       |     *   - the filter matches for the current option
  189|       |     */
  190|  37.1M|    if (!oi->filtered ||
  ------------------
  |  Branch (190:9): [True: 0, False: 37.1M]
  ------------------
  191|  37.1M|        coap_option_filter_get(&oi->filter, oi->number) > 0)
  ------------------
  |  Branch (191:9): [True: 11.8M, False: 25.2M]
  ------------------
  192|  11.8M|      break;
  193|  37.1M|  }
  194|       |
  195|  11.8M|  return current_opt;
  196|  11.8M|}
coap_check_option:
  200|  3.18k|                  coap_opt_iterator_t *oi) {
  201|  3.18k|  coap_opt_filter_t f;
  202|       |
  203|  3.18k|  coap_option_filter_clear(&f);
  204|  3.18k|  coap_option_filter_set(&f, number);
  205|       |
  206|  3.18k|  coap_option_iterator_init(pdu, oi, &f);
  207|       |
  208|  3.18k|  return coap_option_next(oi);
  209|  3.18k|}
coap_opt_length:
  212|  24.0M|coap_opt_length(const coap_opt_t *opt) {
  213|  24.0M|  uint32_t length;
  214|       |
  215|  24.0M|  length = *opt & 0x0f;
  216|  24.0M|  switch (*opt & 0xf0) {
  217|      0|  case 0xf0:
  ------------------
  |  Branch (217:3): [True: 0, False: 24.0M]
  ------------------
  218|      0|    coap_log_debug("illegal option delta\n");
  ------------------
  |  |  126|      0|#define coap_log_debug(...) coap_log(COAP_LOG_DEBUG, __VA_ARGS__)
  |  |  ------------------
  |  |  |  |  290|      0|#define coap_log(level, ...) do { \
  |  |  |  |  291|      0|    if ((level) < (coap_get_log_level() + 1)) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (291:9): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  292|      0|      coap_log_impl((level), __VA_ARGS__); \
  |  |  |  |  293|      0|  } while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (293:11): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  219|      0|    return 0;
  220|    615|  case 0xe0:
  ------------------
  |  Branch (220:3): [True: 615, False: 24.0M]
  ------------------
  221|    615|    ++opt;
  222|       |  /* fall through */
  223|       |  /* to skip another byte */
  224|  3.27k|  case 0xd0:
  ------------------
  |  Branch (224:3): [True: 2.66k, False: 24.0M]
  ------------------
  225|  3.27k|    ++opt;
  226|       |  /* fall through */
  227|       |  /* to skip another byte */
  228|  24.0M|  default:
  ------------------
  |  Branch (228:3): [True: 24.0M, False: 3.27k]
  ------------------
  229|  24.0M|    ++opt;
  230|  24.0M|  }
  231|       |
  232|  24.0M|  switch (length) {
  233|      0|  case 0x0f:
  ------------------
  |  Branch (233:3): [True: 0, False: 24.0M]
  ------------------
  234|      0|    coap_log_debug("illegal option length\n");
  ------------------
  |  |  126|      0|#define coap_log_debug(...) coap_log(COAP_LOG_DEBUG, __VA_ARGS__)
  |  |  ------------------
  |  |  |  |  290|      0|#define coap_log(level, ...) do { \
  |  |  |  |  291|      0|    if ((level) < (coap_get_log_level() + 1)) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (291:9): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  292|      0|      coap_log_impl((level), __VA_ARGS__); \
  |  |  |  |  293|      0|  } while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (293:11): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  235|      0|    return 0;
  236|  6.27k|  case 0x0e:
  ------------------
  |  Branch (236:3): [True: 6.27k, False: 23.9M]
  ------------------
  237|  6.27k|    length = (*opt++ << 8) + 269;
  238|       |  /* fall through */
  239|   210k|  case 0x0d:
  ------------------
  |  Branch (239:3): [True: 204k, False: 23.8M]
  ------------------
  240|   210k|    length += *opt++;
  241|   210k|    break;
  242|  23.7M|  default:
  ------------------
  |  Branch (242:3): [True: 23.7M, False: 210k]
  ------------------
  243|  23.7M|    ;
  244|  24.0M|  }
  245|  24.0M|  return length;
  246|  24.0M|}
coap_opt_value:
  249|  24.0M|coap_opt_value(const coap_opt_t *opt) {
  250|  24.0M|  size_t ofs = 1;
  251|       |
  252|  24.0M|  switch (*opt & 0xf0) {
  253|      0|  case 0xf0:
  ------------------
  |  Branch (253:3): [True: 0, False: 24.0M]
  ------------------
  254|      0|    coap_log_debug("illegal option delta\n");
  ------------------
  |  |  126|      0|#define coap_log_debug(...) coap_log(COAP_LOG_DEBUG, __VA_ARGS__)
  |  |  ------------------
  |  |  |  |  290|      0|#define coap_log(level, ...) do { \
  |  |  |  |  291|      0|    if ((level) < (coap_get_log_level() + 1)) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (291:9): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  292|      0|      coap_log_impl((level), __VA_ARGS__); \
  |  |  |  |  293|      0|  } while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (293:11): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  255|      0|    return 0;
  256|    615|  case 0xe0:
  ------------------
  |  Branch (256:3): [True: 615, False: 24.0M]
  ------------------
  257|    615|    ++ofs;
  258|       |  /* fall through */
  259|  3.27k|  case 0xd0:
  ------------------
  |  Branch (259:3): [True: 2.66k, False: 24.0M]
  ------------------
  260|  3.27k|    ++ofs;
  261|  3.27k|    break;
  262|  24.0M|  default:
  ------------------
  |  Branch (262:3): [True: 24.0M, False: 3.27k]
  ------------------
  263|  24.0M|    ;
  264|  24.0M|  }
  265|       |
  266|  24.0M|  switch (*opt & 0x0f) {
  267|      0|  case 0x0f:
  ------------------
  |  Branch (267:3): [True: 0, False: 24.0M]
  ------------------
  268|      0|    coap_log_debug("illegal option length\n");
  ------------------
  |  |  126|      0|#define coap_log_debug(...) coap_log(COAP_LOG_DEBUG, __VA_ARGS__)
  |  |  ------------------
  |  |  |  |  290|      0|#define coap_log(level, ...) do { \
  |  |  |  |  291|      0|    if ((level) < (coap_get_log_level() + 1)) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (291:9): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  292|      0|      coap_log_impl((level), __VA_ARGS__); \
  |  |  |  |  293|      0|  } while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (293:11): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  269|      0|    return 0;
  270|  6.27k|  case 0x0e:
  ------------------
  |  Branch (270:3): [True: 6.27k, False: 23.9M]
  ------------------
  271|  6.27k|    ++ofs;
  272|       |  /* fall through */
  273|   210k|  case 0x0d:
  ------------------
  |  Branch (273:3): [True: 204k, False: 23.8M]
  ------------------
  274|   210k|    ++ofs;
  275|   210k|    break;
  276|  23.7M|  default:
  ------------------
  |  Branch (276:3): [True: 23.7M, False: 210k]
  ------------------
  277|  23.7M|    ;
  278|  24.0M|  }
  279|       |
  280|  24.0M|  return (const uint8_t *)opt + ofs;
  281|  24.0M|}
coap_option_filter_clear:
  491|  8.89k|coap_option_filter_clear(coap_opt_filter_t *filter) {
  492|  8.89k|  memset(filter, 0, sizeof(coap_opt_filter_t));
  493|  8.89k|}
coap_option_filter_set:
  496|  1.19M|coap_option_filter_set(coap_opt_filter_t *filter, coap_option_num_t option) {
  497|  1.19M|  return coap_option_filter_op(filter, option, FILTER_SET);
  498|  1.19M|}
coap_option_filter_get:
  506|  37.1M|coap_option_filter_get(coap_opt_filter_t *filter, coap_option_num_t option) {
  507|  37.1M|  return coap_option_filter_op(filter, option, FILTER_GET);
  508|  37.1M|}
coap_option.c:opt_finished:
  141|  11.8M|opt_finished(coap_opt_iterator_t *oi) {
  142|  11.8M|  assert(oi);
  ------------------
  |  Branch (142:3): [True: 11.8M, False: 0]
  ------------------
  143|       |
  144|  11.8M|  if (oi->bad || oi->length == 0 ||
  ------------------
  |  Branch (144:7): [True: 210, False: 11.8M]
  |  Branch (144:18): [True: 1.14k, False: 11.8M]
  ------------------
  145|  11.8M|      !oi->next_option || *oi->next_option == COAP_PAYLOAD_START) {
  ------------------
  |  |   96|  11.8M|#define COAP_PAYLOAD_START 0xFF /* payload marker */
  ------------------
  |  Branch (145:7): [True: 0, False: 11.8M]
  |  Branch (145:27): [True: 215, False: 11.8M]
  ------------------
  146|  1.56k|    oi->bad = 1;
  147|  1.56k|  }
  148|       |
  149|  11.8M|  return oi->bad;
  150|  11.8M|}
coap_option.c:coap_option_filter_op:
  433|  38.3M|                      enum filter_op_t op) {
  434|  38.3M|  size_t lindex = 0;
  435|  38.3M|  coap_opt_filter_t *of = filter;
  436|  38.3M|  uint16_t nr, mask = 0;
  437|       |
  438|  38.3M|  if (is_long_option(number)) {
  ------------------
  |  Branch (438:7): [True: 537k, False: 37.7M]
  ------------------
  439|   537k|    mask = LONG_MASK;
  ------------------
  |  |  398|   537k|#define LONG_MASK ((1 << COAP_OPT_FILTER_LONG) - 1)
  |  |  ------------------
  |  |  |  |  208|   537k|#define COAP_OPT_FILTER_LONG  2
  |  |  ------------------
  ------------------
  440|       |
  441|  1.61M|    for (nr = 1; lindex < COAP_OPT_FILTER_LONG; nr <<= 1, lindex++) {
  ------------------
  |  |  208|  1.61M|#define COAP_OPT_FILTER_LONG  2
  ------------------
  |  Branch (441:18): [True: 1.07M, False: 535k]
  ------------------
  442|       |
  443|  1.07M|      if (((of->mask & nr) > 0) && (of->long_opts[lindex] == number)) {
  ------------------
  |  Branch (443:11): [True: 58.9k, False: 1.01M]
  |  Branch (443:36): [True: 2.39k, False: 56.5k]
  ------------------
  444|  2.39k|        if (op == FILTER_CLEAR) {
  ------------------
  |  Branch (444:13): [True: 0, False: 2.39k]
  ------------------
  445|      0|          of->mask &= ~nr;
  446|      0|        }
  447|       |
  448|  2.39k|        return 1;
  449|  2.39k|      }
  450|  1.07M|    }
  451|  37.7M|  } else {
  452|  37.7M|    mask = SHORT_MASK;
  ------------------
  |  |  400|  37.7M|  (~LONG_MASK & ((1 << (COAP_OPT_FILTER_LONG + COAP_OPT_FILTER_SHORT)) - 1))
  |  |  ------------------
  |  |  |  |  398|  37.7M|#define LONG_MASK ((1 << COAP_OPT_FILTER_LONG) - 1)
  |  |  |  |  ------------------
  |  |  |  |  |  |  208|  37.7M|#define COAP_OPT_FILTER_LONG  2
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                 (~LONG_MASK & ((1 << (COAP_OPT_FILTER_LONG + COAP_OPT_FILTER_SHORT)) - 1))
  |  |  ------------------
  |  |  |  |  208|  37.7M|#define COAP_OPT_FILTER_LONG  2
  |  |  ------------------
  |  |                 (~LONG_MASK & ((1 << (COAP_OPT_FILTER_LONG + COAP_OPT_FILTER_SHORT)) - 1))
  |  |  ------------------
  |  |  |  |  200|  37.7M|#define COAP_OPT_FILTER_SHORT 6
  |  |  ------------------
  ------------------
  453|       |
  454|   249M|    for (nr = 1 << COAP_OPT_FILTER_LONG; lindex < COAP_OPT_FILTER_SHORT;
  ------------------
  |  |  208|  37.7M|#define COAP_OPT_FILTER_LONG  2
  ------------------
                  for (nr = 1 << COAP_OPT_FILTER_LONG; lindex < COAP_OPT_FILTER_SHORT;
  ------------------
  |  |  200|   249M|#define COAP_OPT_FILTER_SHORT 6
  ------------------
  |  Branch (454:42): [True: 224M, False: 24.7M]
  ------------------
  455|   224M|         nr <<= 1, lindex++) {
  456|       |
  457|   224M|      if (((of->mask & nr) > 0) && (of->short_opts[lindex] == (number & 0xff))) {
  ------------------
  |  Branch (457:11): [True: 37.7M, False: 186M]
  |  Branch (457:36): [True: 13.0M, False: 24.7M]
  ------------------
  458|  13.0M|        if (op == FILTER_CLEAR) {
  ------------------
  |  Branch (458:13): [True: 0, False: 13.0M]
  ------------------
  459|      0|          of->mask &= ~nr;
  460|      0|        }
  461|       |
  462|  13.0M|        return 1;
  463|  13.0M|      }
  464|   224M|    }
  465|  37.7M|  }
  466|       |
  467|       |  /* number was not found, so there is nothing to do if op is CLEAR or GET */
  468|  25.2M|  if ((op == FILTER_CLEAR) || (op == FILTER_GET)) {
  ------------------
  |  Branch (468:7): [True: 0, False: 25.2M]
  |  Branch (468:31): [True: 25.2M, False: 38.1k]
  ------------------
  469|  25.2M|    return 0;
  470|  25.2M|  }
  471|       |
  472|       |  /* handle FILTER_SET: */
  473|       |
  474|  38.1k|  lindex = coap_fls(~of->mask & mask);
  475|  38.1k|  if (!lindex) {
  ------------------
  |  Branch (475:7): [True: 29.9k, False: 8.15k]
  ------------------
  476|  29.9k|    return 0;
  477|  29.9k|  }
  478|       |
  479|  8.15k|  if (is_long_option(number)) {
  ------------------
  |  Branch (479:7): [True: 296, False: 7.85k]
  ------------------
  480|    296|    of->long_opts[lindex - 1] = number;
  481|  7.85k|  } else {
  482|  7.85k|    of->short_opts[lindex - COAP_OPT_FILTER_LONG - 1] = (uint8_t)number;
  ------------------
  |  |  208|  7.85k|#define COAP_OPT_FILTER_LONG  2
  ------------------
  483|  7.85k|  }
  484|       |
  485|  8.15k|  of->mask |= 1 << (lindex - 1);
  486|       |
  487|  8.15k|  return 1;
  488|  38.1k|}
coap_option.c:is_long_option:
  404|  38.3M|is_long_option(coap_option_num_t number) {
  405|  38.3M|  return number > 255;
  406|  38.3M|}

coap_pdu_clear:
   47|  3.16k|coap_pdu_clear(coap_pdu_t *pdu, size_t size) {
   48|  3.16k|  assert(pdu);
  ------------------
  |  Branch (48:3): [True: 3.16k, False: 0]
  ------------------
   49|  3.16k|  assert(pdu->token);
  ------------------
  |  Branch (49:3): [True: 3.16k, False: 0]
  ------------------
   50|  3.16k|  assert(pdu->max_hdr_size >= COAP_PDU_MAX_UDP_HEADER_SIZE);
  ------------------
  |  Branch (50:3): [True: 3.16k, False: 0]
  ------------------
   51|  3.16k|  if (pdu->alloc_size > size)
  ------------------
  |  Branch (51:7): [True: 0, False: 3.16k]
  ------------------
   52|      0|    pdu->alloc_size = size;
   53|  3.16k|  pdu->type = 0;
   54|  3.16k|  pdu->code = 0;
   55|  3.16k|  pdu->ref = 0;
   56|  3.16k|  pdu->hdr_size = 0;
   57|  3.16k|  pdu->actual_token.length = 0;
   58|  3.16k|  pdu->e_token_length = 0;
   59|  3.16k|  pdu->crit_opt = 0;
   60|  3.16k|  pdu->mid = 0;
   61|  3.16k|  pdu->max_opt = 0;
   62|  3.16k|  pdu->max_size = size;
   63|  3.16k|  pdu->used_size = 0;
   64|  3.16k|  pdu->data = NULL;
   65|  3.16k|  pdu->body_data = NULL;
   66|  3.16k|  pdu->body_length = 0;
   67|  3.16k|  pdu->body_offset = 0;
   68|  3.16k|  pdu->body_total = 0;
   69|  3.16k|  pdu->lg_xmit = NULL;
   70|  3.16k|  pdu->session = NULL;
   71|       |  pdu->data_free = NULL;
   72|  3.16k|}
coap_pdu_init:
  105|  3.16k|              size_t size) {
  106|  3.16k|  coap_pdu_t *pdu;
  107|       |
  108|  3.16k|#ifndef RIOT_VERSION
  109|  3.16k|  assert(type <= 0x3);
  ------------------
  |  Branch (109:3): [True: 3.16k, False: 0]
  ------------------
  110|  3.16k|  assert(code <= 0xff);
  ------------------
  |  Branch (110:3): [True: 3.16k, False: 0]
  ------------------
  111|  3.16k|  assert(mid >= 0 && mid <= 0xffff);
  ------------------
  |  Branch (111:3): [True: 3.16k, False: 0]
  |  Branch (111:3): [True: 3.16k, False: 0]
  ------------------
  112|  3.16k|#endif /* RIOT_VERSION */
  113|       |
  114|       |#if defined(WITH_LWIP) && MEMP_USE_CUSTOM_POOLS
  115|       |#if MEMP_STATS
  116|       |  /* Reserve 1 PDU for a response packet */
  117|       |  if (memp_pools[MEMP_COAP_PDU]->stats->used + 1 >=
  118|       |      memp_pools[MEMP_COAP_PDU]->stats->avail) {
  119|       |    memp_pools[MEMP_COAP_PDU]->stats->err++;
  120|       |    return NULL;
  121|       |  }
  122|       |#endif /* MEMP_STATS */
  123|       |#endif /* LWIP && MEMP_USE_CUSTOM_POOLS */
  124|  3.16k|  pdu = coap_malloc_type(COAP_PDU, sizeof(coap_pdu_t));
  125|  3.16k|  if (!pdu)
  ------------------
  |  Branch (125:7): [True: 0, False: 3.16k]
  ------------------
  126|      0|    return NULL;
  127|       |
  128|       |#if COAP_DEFAULT_MAX_PDU_RX_SIZE <= COAP_MAX_MESSAGE_SIZE_TCP16
  129|       |  /* on TCP, the CoAP header will also have a maximum length of 4 bytes */
  130|       |  pdu->max_hdr_size = COAP_PDU_MAX_UDP_HEADER_SIZE;
  131|       |#else
  132|  3.16k|  pdu->max_hdr_size = COAP_PDU_MAX_TCP_HEADER_SIZE;
  ------------------
  |  |  108|  3.16k|#define COAP_PDU_MAX_TCP_HEADER_SIZE 6
  ------------------
  133|  3.16k|#endif
  134|  3.16k|  if (size > ((size_t)COAP_DEFAULT_MAX_PDU_RX_SIZE - pdu->max_hdr_size)) {
  ------------------
  |  |   84|  3.16k|#define COAP_DEFAULT_MAX_PDU_RX_SIZE (8UL*1024*1024+256)
  ------------------
  |  Branch (134:7): [True: 0, False: 3.16k]
  ------------------
  135|      0|    coap_free_type(COAP_PDU, pdu);
  136|      0|    return NULL;
  137|      0|  }
  138|       |
  139|  3.16k|  pdu->alloc_size = min(size, COAP_DEFAULT_MTU);
  ------------------
  |  |   37|  3.16k|#define min(a,b) ((a) < (b) ? (a) : (b))
  |  |  ------------------
  |  |  |  Branch (37:19): [True: 2.59k, False: 570]
  |  |  ------------------
  ------------------
  140|       |#ifdef WITH_LWIP
  141|       |  pdu->pbuf = pbuf_alloc(PBUF_TRANSPORT, pdu->alloc_size + pdu->max_hdr_size,
  142|       |                         PBUF_RAM);
  143|       |  if (pdu->pbuf == NULL) {
  144|       |    coap_free_type(COAP_PDU, pdu);
  145|       |    return NULL;
  146|       |  }
  147|       |  pdu->token = (uint8_t *)pdu->pbuf->payload + pdu->max_hdr_size;
  148|       |#else /* ! WITH_LWIP */
  149|  3.16k|  uint8_t *buf;
  150|  3.16k|  buf = coap_malloc_type(COAP_PDU_BUF, pdu->alloc_size + pdu->max_hdr_size);
  151|  3.16k|  if (buf == NULL) {
  ------------------
  |  Branch (151:7): [True: 0, False: 3.16k]
  ------------------
  152|      0|    coap_free_type(COAP_PDU, pdu);
  153|      0|    return NULL;
  154|      0|  }
  155|  3.16k|  pdu->token = buf + pdu->max_hdr_size;
  156|  3.16k|#endif /* ! WITH_LWIP */
  157|  3.16k|  coap_pdu_clear(pdu, size);
  158|  3.16k|  pdu->mid = mid;
  159|  3.16k|  pdu->type = type;
  160|  3.16k|  pdu->code = code;
  161|  3.16k|  return pdu;
  162|  3.16k|}
coap_delete_pdu:
  190|  3.16k|coap_delete_pdu(coap_pdu_t *pdu) {
  191|  3.16k|  coap_lock_lock(return);
  192|  3.16k|  coap_delete_pdu_lkd(pdu);
  193|  3.16k|  coap_lock_unlock();
  194|  3.16k|}
coap_delete_pdu_lkd:
  197|  3.16k|coap_delete_pdu_lkd(coap_pdu_t *pdu) {
  198|  3.16k|  if (pdu != NULL) {
  ------------------
  |  Branch (198:7): [True: 3.16k, False: 0]
  ------------------
  199|  3.16k|    if (pdu->ref) {
  ------------------
  |  Branch (199:9): [True: 0, False: 3.16k]
  ------------------
  200|      0|      pdu->ref--;
  201|      0|      return;
  202|      0|    }
  203|       |#ifdef WITH_LWIP
  204|       |    pbuf_free(pdu->pbuf);
  205|       |#else
  206|  3.16k|    if (pdu->token != NULL)
  ------------------
  |  Branch (206:9): [True: 3.16k, False: 0]
  ------------------
  207|  3.16k|      coap_free_type(COAP_PDU_BUF, pdu->token - pdu->max_hdr_size);
  208|  3.16k|#endif
  209|  3.16k|    coap_delete_binary(pdu->data_free);
  210|  3.16k|    coap_free_type(COAP_PDU, pdu);
  211|  3.16k|  }
  212|  3.16k|}
coap_pdu_resize:
  341|  3.16k|coap_pdu_resize(coap_pdu_t *pdu, size_t new_size) {
  342|  3.16k|  if (new_size > pdu->alloc_size) {
  ------------------
  |  Branch (342:7): [True: 566, False: 2.59k]
  ------------------
  343|       |    /* Expanding the PDU usage */
  344|    566|#if !defined(WITH_LWIP)
  345|    566|    uint8_t *new_hdr;
  346|       |#else /* WITH_LWIP */
  347|       |    struct pbuf *new_hdr;
  348|       |#endif /* WITH_LWIP */
  349|    566|    size_t offset;
  350|       |
  351|    566|    if (pdu->max_size && new_size > pdu->max_size) {
  ------------------
  |  Branch (351:9): [True: 566, False: 0]
  |  Branch (351:26): [True: 0, False: 566]
  ------------------
  352|      0|      coap_log_warn("coap_pdu_resize: pdu too big\n");
  ------------------
  |  |  108|      0|#define coap_log_warn(...) coap_log(COAP_LOG_WARN, __VA_ARGS__)
  |  |  ------------------
  |  |  |  |  290|      0|#define coap_log(level, ...) do { \
  |  |  |  |  291|      0|    if ((level) < (coap_get_log_level() + 1)) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (291:9): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  292|      0|      coap_log_impl((level), __VA_ARGS__); \
  |  |  |  |  293|      0|  } while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (293:11): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  353|      0|      return 0;
  354|      0|    }
  355|    566|    if (pdu->data != NULL) {
  ------------------
  |  Branch (355:9): [True: 0, False: 566]
  ------------------
  356|      0|      assert(pdu->data > pdu->token);
  ------------------
  |  Branch (356:7): [True: 0, False: 0]
  ------------------
  357|      0|      offset = pdu->data - pdu->token;
  358|    566|    } else {
  359|    566|      offset = 0;
  360|    566|    }
  361|    566|#if !defined(WITH_LWIP)
  362|    566|    new_hdr = (uint8_t *)coap_realloc_type(COAP_PDU_BUF,
  363|    566|                                           pdu->token - pdu->max_hdr_size,
  364|    566|                                           new_size + pdu->max_hdr_size);
  365|       |#else /* WITH_LWIP */
  366|       |    new_hdr = pbuf_alloc(PBUF_TRANSPORT, new_size + pdu->max_hdr_size, PBUF_RAM);
  367|       |#endif /* WITH_LWIP */
  368|    566|    if (new_hdr == NULL) {
  ------------------
  |  Branch (368:9): [True: 0, False: 566]
  ------------------
  369|      0|      coap_log_warn("coap_pdu_resize: realloc failed\n");
  ------------------
  |  |  108|      0|#define coap_log_warn(...) coap_log(COAP_LOG_WARN, __VA_ARGS__)
  |  |  ------------------
  |  |  |  |  290|      0|#define coap_log(level, ...) do { \
  |  |  |  |  291|      0|    if ((level) < (coap_get_log_level() + 1)) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (291:9): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  292|      0|      coap_log_impl((level), __VA_ARGS__); \
  |  |  |  |  293|      0|  } while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (293:11): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  370|      0|      return 0;
  371|      0|    }
  372|    566|#if !defined(WITH_LWIP)
  373|    566|    pdu->token = new_hdr + pdu->max_hdr_size;
  374|       |#else /* WITH_LWIP */
  375|       |    memcpy(new_hdr->payload, pdu->pbuf->payload, pdu->pbuf->len);
  376|       |    pbuf_free(pdu->pbuf);
  377|       |    pdu->pbuf = new_hdr;
  378|       |    pdu->token = (uint8_t *)pdu->pbuf->payload + pdu->max_hdr_size;
  379|       |#endif /* WITH_LWIP */
  380|    566|    if (offset > 0)
  ------------------
  |  Branch (380:9): [True: 0, False: 566]
  ------------------
  381|      0|      pdu->data = pdu->token + offset;
  382|    566|    else
  383|    566|      pdu->data = NULL;
  384|    566|    if (pdu->actual_token.length < COAP_TOKEN_EXT_1B_BIAS)
  ------------------
  |  |   56|    566|#define COAP_TOKEN_EXT_1B_BIAS 13
  ------------------
  |  Branch (384:9): [True: 566, False: 0]
  ------------------
  385|    566|      pdu->actual_token.s = &pdu->token[0];
  386|      0|    else if (pdu->actual_token.length < COAP_TOKEN_EXT_2B_BIAS)
  ------------------
  |  |   57|      0|#define COAP_TOKEN_EXT_2B_BIAS 269 /* 13 + 256 */
  ------------------
  |  Branch (386:14): [True: 0, False: 0]
  ------------------
  387|      0|      pdu->actual_token.s = &pdu->token[1];
  388|      0|    else
  389|      0|      pdu->actual_token.s = &pdu->token[2];
  390|    566|    pdu->alloc_size = new_size;
  391|    566|  }
  392|  3.16k|  return 1;
  393|  3.16k|}
coap_pdu_parse_header_size:
 1078|  3.16k|                           const uint8_t *data) {
 1079|  3.16k|  assert(data);
  ------------------
  |  Branch (1079:3): [True: 3.16k, False: 0]
  ------------------
 1080|  3.16k|  size_t header_size = 0;
 1081|       |
 1082|  3.16k|  if (proto == COAP_PROTO_TCP || proto==COAP_PROTO_TLS) {
  ------------------
  |  Branch (1082:7): [True: 0, False: 3.16k]
  |  Branch (1082:34): [True: 0, False: 3.16k]
  ------------------
 1083|      0|    uint8_t len = *data >> 4;
 1084|      0|    if (len < 13)
  ------------------
  |  Branch (1084:9): [True: 0, False: 0]
  ------------------
 1085|      0|      header_size = 2;
 1086|      0|    else if (len==13)
  ------------------
  |  Branch (1086:14): [True: 0, False: 0]
  ------------------
 1087|      0|      header_size = 3;
 1088|      0|    else if (len==14)
  ------------------
  |  Branch (1088:14): [True: 0, False: 0]
  ------------------
 1089|      0|      header_size = 4;
 1090|      0|    else
 1091|      0|      header_size = 6;
 1092|  3.16k|  } else if (proto == COAP_PROTO_WS || proto==COAP_PROTO_WSS) {
  ------------------
  |  Branch (1092:14): [True: 0, False: 3.16k]
  |  Branch (1092:40): [True: 0, False: 3.16k]
  ------------------
 1093|      0|    header_size = 2;
 1094|  3.16k|  } else if (proto == COAP_PROTO_UDP || proto==COAP_PROTO_DTLS) {
  ------------------
  |  Branch (1094:14): [True: 3.16k, False: 0]
  |  Branch (1094:41): [True: 0, False: 0]
  ------------------
 1095|  3.16k|    header_size = 4;
 1096|  3.16k|  }
 1097|       |
 1098|  3.16k|  return header_size;
 1099|  3.16k|}
coap_pdu_parse_header:
 1161|  3.16k|coap_pdu_parse_header(coap_pdu_t *pdu, coap_proto_t proto) {
 1162|  3.16k|  uint8_t *hdr = pdu->token - pdu->hdr_size;
 1163|  3.16k|  uint8_t e_token_length;
 1164|       |
 1165|  3.16k|  if (proto == COAP_PROTO_UDP || proto == COAP_PROTO_DTLS) {
  ------------------
  |  Branch (1165:7): [True: 3.16k, False: 0]
  |  Branch (1165:34): [True: 0, False: 0]
  ------------------
 1166|  3.16k|    assert(pdu->hdr_size == 4);
  ------------------
  |  Branch (1166:5): [True: 3.16k, False: 0]
  ------------------
 1167|  3.16k|    if ((hdr[0] >> 6) != COAP_DEFAULT_VERSION) {
  ------------------
  |  |   35|  3.16k|#define COAP_DEFAULT_VERSION      1 /* version of CoAP supported */
  ------------------
  |  Branch (1167:9): [True: 8, False: 3.15k]
  ------------------
 1168|      8|      coap_log_debug("coap_pdu_parse: UDP version not supported\n");
  ------------------
  |  |  126|      8|#define coap_log_debug(...) coap_log(COAP_LOG_DEBUG, __VA_ARGS__)
  |  |  ------------------
  |  |  |  |  290|      8|#define coap_log(level, ...) do { \
  |  |  |  |  291|      8|    if ((level) < (coap_get_log_level() + 1)) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (291:9): [True: 0, False: 8]
  |  |  |  |  ------------------
  |  |  |  |  292|      8|      coap_log_impl((level), __VA_ARGS__); \
  |  |  |  |  293|      8|  } while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (293:11): [Folded, False: 8]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1169|      8|      return 0;
 1170|      8|    }
 1171|  3.15k|    pdu->type = (hdr[0] >> 4) & 0x03;
 1172|  3.15k|    pdu->code = hdr[1];
 1173|  3.15k|    pdu->mid = (uint16_t)hdr[2] << 8 | hdr[3];
 1174|  3.15k|  } else if (proto == COAP_PROTO_TCP || proto == COAP_PROTO_TLS) {
  ------------------
  |  Branch (1174:14): [True: 0, False: 0]
  |  Branch (1174:41): [True: 0, False: 0]
  ------------------
 1175|      0|    assert(pdu->hdr_size >= 2 && pdu->hdr_size <= 6);
  ------------------
  |  Branch (1175:5): [True: 0, False: 0]
  |  Branch (1175:5): [True: 0, False: 0]
  ------------------
 1176|      0|    pdu->type = COAP_MESSAGE_CON;
 1177|      0|    pdu->code = hdr[pdu->hdr_size-1];
 1178|      0|    pdu->mid = 0;
 1179|      0|  } else if (proto == COAP_PROTO_WS || proto == COAP_PROTO_WSS) {
  ------------------
  |  Branch (1179:14): [True: 0, False: 0]
  |  Branch (1179:40): [True: 0, False: 0]
  ------------------
 1180|      0|    assert(pdu->hdr_size == 2);
  ------------------
  |  Branch (1180:5): [True: 0, False: 0]
  ------------------
 1181|      0|    pdu->type = COAP_MESSAGE_CON;
 1182|      0|    pdu->code = hdr[pdu->hdr_size-1];
 1183|      0|    pdu->mid = 0;
 1184|      0|  } else {
 1185|      0|    coap_log_debug("coap_pdu_parse: unsupported protocol\n");
  ------------------
  |  |  126|      0|#define coap_log_debug(...) coap_log(COAP_LOG_DEBUG, __VA_ARGS__)
  |  |  ------------------
  |  |  |  |  290|      0|#define coap_log(level, ...) do { \
  |  |  |  |  291|      0|    if ((level) < (coap_get_log_level() + 1)) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (291:9): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  292|      0|      coap_log_impl((level), __VA_ARGS__); \
  |  |  |  |  293|      0|  } while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (293:11): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1186|      0|    return 0;
 1187|      0|  }
 1188|       |
 1189|  3.15k|  e_token_length = hdr[0] & 0x0f;
 1190|  3.15k|  if (e_token_length < COAP_TOKEN_EXT_1B_TKL) {
  ------------------
  |  |   54|  3.15k|#define COAP_TOKEN_EXT_1B_TKL 13
  ------------------
  |  Branch (1190:7): [True: 3.04k, False: 114]
  ------------------
 1191|  3.04k|    pdu->e_token_length = e_token_length;
 1192|  3.04k|    pdu->actual_token.length = pdu->e_token_length;
 1193|  3.04k|    pdu->actual_token.s = &pdu->token[0];
 1194|  3.04k|  } else if (e_token_length == COAP_TOKEN_EXT_1B_TKL) {
  ------------------
  |  |   54|    114|#define COAP_TOKEN_EXT_1B_TKL 13
  ------------------
  |  Branch (1194:14): [True: 48, False: 66]
  ------------------
 1195|     48|    if (pdu->used_size < 1)
  ------------------
  |  Branch (1195:9): [True: 1, False: 47]
  ------------------
 1196|      1|      goto bad_ext_token;
 1197|     47|    pdu->e_token_length = pdu->token[0] + COAP_TOKEN_EXT_1B_BIAS + 1;
  ------------------
  |  |   56|     47|#define COAP_TOKEN_EXT_1B_BIAS 13
  ------------------
 1198|     47|    pdu->actual_token.length = pdu->e_token_length - 1;
 1199|     47|    pdu->actual_token.s = &pdu->token[1];
 1200|     66|  } else if (e_token_length == COAP_TOKEN_EXT_2B_TKL) {
  ------------------
  |  |   55|     66|#define COAP_TOKEN_EXT_2B_TKL 14
  ------------------
  |  Branch (1200:14): [True: 65, False: 1]
  ------------------
 1201|     65|    if (pdu->used_size < 2)
  ------------------
  |  Branch (1201:9): [True: 2, False: 63]
  ------------------
 1202|      2|      goto bad_ext_token;
 1203|     63|    pdu->e_token_length = ((uint16_t)pdu->token[0] << 8) + pdu->token[1] +
 1204|     63|                          COAP_TOKEN_EXT_2B_BIAS + 2;
  ------------------
  |  |   57|     63|#define COAP_TOKEN_EXT_2B_BIAS 269 /* 13 + 256 */
  ------------------
 1205|     63|    pdu->actual_token.length = pdu->e_token_length - 2;
 1206|     63|    pdu->actual_token.s = &pdu->token[2];
 1207|     63|  }
 1208|  3.15k|  if (pdu->e_token_length > pdu->alloc_size || e_token_length == 15) {
  ------------------
  |  Branch (1208:7): [True: 31, False: 3.12k]
  |  Branch (1208:48): [True: 1, False: 3.12k]
  ------------------
 1209|     32|    goto bad_ext_token;
 1210|     32|  }
 1211|  3.12k|  return 1;
 1212|       |
 1213|     35|bad_ext_token:
 1214|       |  /* Invalid PDU provided - not wise to assert here though */
 1215|     35|  coap_log_debug("coap_pdu_parse: PDU header extended token size broken\n");
  ------------------
  |  |  126|     35|#define coap_log_debug(...) coap_log(COAP_LOG_DEBUG, __VA_ARGS__)
  |  |  ------------------
  |  |  |  |  290|     35|#define coap_log(level, ...) do { \
  |  |  |  |  291|     35|    if ((level) < (coap_get_log_level() + 1)) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (291:9): [True: 0, False: 35]
  |  |  |  |  ------------------
  |  |  |  |  292|     35|      coap_log_impl((level), __VA_ARGS__); \
  |  |  |  |  293|     35|  } while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (293:11): [Folded, False: 35]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1216|     35|  pdu->e_token_length = 0;
 1217|     35|  pdu->actual_token.length = 0;
 1218|     35|  return 0;
 1219|  3.15k|}
coap_pdu_parse_opt_base:
 1290|  8.82M|coap_pdu_parse_opt_base(coap_option_num_t number, size_t len, const uint8_t *opt_val) {
 1291|  8.82M|  int res = 1;
 1292|       |
 1293|  8.82M|  switch ((coap_code_opt_num_t)number) {
 1294|  87.2k|  case COAP_OPTION_IF_MATCH:
  ------------------
  |  Branch (1294:3): [True: 87.2k, False: 8.73M]
  ------------------
 1295|  87.2k|    if (len > 8)
  ------------------
  |  Branch (1295:9): [True: 1.06k, False: 86.2k]
  ------------------
 1296|  1.06k|      res = 0;
 1297|  87.2k|    break;
 1298|  5.07k|  case COAP_OPTION_URI_HOST:
  ------------------
  |  Branch (1298:3): [True: 5.07k, False: 8.82M]
  ------------------
 1299|  5.07k|    if (len < 1 || len > 255)
  ------------------
  |  Branch (1299:9): [True: 3.12k, False: 1.95k]
  |  Branch (1299:20): [True: 1.29k, False: 657]
  ------------------
 1300|  4.42k|      res = 0;
 1301|  5.07k|    break;
 1302|   117k|  case COAP_OPTION_ETAG:
  ------------------
  |  Branch (1302:3): [True: 117k, False: 8.70M]
  ------------------
 1303|   117k|    if (len < 1 || len > 8)
  ------------------
  |  Branch (1303:9): [True: 116k, False: 1.61k]
  |  Branch (1303:20): [True: 1.17k, False: 435]
  ------------------
 1304|   117k|      res = 0;
 1305|   117k|    break;
 1306|  2.83k|  case COAP_OPTION_IF_NONE_MATCH:
  ------------------
  |  Branch (1306:3): [True: 2.83k, False: 8.82M]
  ------------------
 1307|  2.83k|    if (len != 0)
  ------------------
  |  Branch (1307:9): [True: 1.37k, False: 1.46k]
  ------------------
 1308|  1.37k|      res = 0;
 1309|  2.83k|    break;
 1310|  5.08k|  case COAP_OPTION_OBSERVE:
  ------------------
  |  Branch (1310:3): [True: 5.08k, False: 8.82M]
  ------------------
 1311|  5.08k|    if (len > 3)
  ------------------
  |  Branch (1311:9): [True: 1.09k, False: 3.99k]
  ------------------
 1312|  1.09k|      res = 0;
 1313|  5.08k|    break;
 1314|  12.6k|  case COAP_OPTION_URI_PORT:
  ------------------
  |  Branch (1314:3): [True: 12.6k, False: 8.81M]
  ------------------
 1315|  12.6k|    if (len > 2)
  ------------------
  |  Branch (1315:9): [True: 1.23k, False: 11.4k]
  ------------------
 1316|  1.23k|      res = 0;
 1317|  12.6k|    break;
 1318|  5.18k|  case COAP_OPTION_LOCATION_PATH:
  ------------------
  |  Branch (1318:3): [True: 5.18k, False: 8.82M]
  ------------------
 1319|  5.92M|  case COAP_OPTION_URI_PATH:
  ------------------
  |  Branch (1319:3): [True: 5.92M, False: 2.90M]
  ------------------
 1320|  5.92M|    if (len > 255)
  ------------------
  |  Branch (1320:9): [True: 1.11k, False: 5.92M]
  ------------------
 1321|  1.11k|      res = 0;
 1322|  5.92M|    if (coap_check_dots(opt_val, len)) {
  ------------------
  |  Branch (1322:9): [True: 3.00k, False: 5.92M]
  ------------------
 1323|  3.00k|      res = 0;
 1324|  3.00k|    }
 1325|  5.92M|    break;
 1326|  11.0k|  case COAP_OPTION_OSCORE:
  ------------------
  |  Branch (1326:3): [True: 11.0k, False: 8.81M]
  ------------------
 1327|  11.0k|    if (len > 255)
  ------------------
  |  Branch (1327:9): [True: 990, False: 10.0k]
  ------------------
 1328|    990|      res = 0;
 1329|  11.0k|    break;
 1330|  2.73k|  case COAP_OPTION_CONTENT_FORMAT:
  ------------------
  |  Branch (1330:3): [True: 2.73k, False: 8.82M]
  ------------------
 1331|  2.73k|    if (len > 2)
  ------------------
  |  Branch (1331:9): [True: 1.28k, False: 1.44k]
  ------------------
 1332|  1.28k|      res = 0;
 1333|  2.73k|    break;
 1334|  3.34k|  case COAP_OPTION_URI_PATH_ABB:
  ------------------
  |  Branch (1334:3): [True: 3.34k, False: 8.82M]
  ------------------
 1335|  3.34k|    if (len > 4)
  ------------------
  |  Branch (1335:9): [True: 1.29k, False: 2.05k]
  ------------------
 1336|  1.29k|      res = 0;
 1337|  3.34k|    break;
 1338|  5.17k|  case COAP_OPTION_MAXAGE:
  ------------------
  |  Branch (1338:3): [True: 5.17k, False: 8.82M]
  ------------------
 1339|  5.17k|    if (len > 4)
  ------------------
  |  Branch (1339:9): [True: 1.74k, False: 3.43k]
  ------------------
 1340|  1.74k|      res = 0;
 1341|  5.17k|    break;
 1342|  45.2k|  case COAP_OPTION_URI_QUERY:
  ------------------
  |  Branch (1342:3): [True: 45.2k, False: 8.78M]
  ------------------
 1343|  45.2k|    if (len < 1 || len > 255)
  ------------------
  |  Branch (1343:9): [True: 3.03k, False: 42.2k]
  |  Branch (1343:20): [True: 1.00k, False: 41.2k]
  ------------------
 1344|  4.04k|      res = 0;
 1345|  45.2k|    break;
 1346|   112k|  case COAP_OPTION_HOP_LIMIT:
  ------------------
  |  Branch (1346:3): [True: 112k, False: 8.71M]
  ------------------
 1347|   112k|    if (len != 1)
  ------------------
  |  Branch (1347:9): [True: 111k, False: 253]
  ------------------
 1348|   111k|      res = 0;
 1349|   112k|    break;
 1350|  13.6k|  case COAP_OPTION_ACCEPT:
  ------------------
  |  Branch (1350:3): [True: 13.6k, False: 8.81M]
  ------------------
 1351|  13.6k|    if (len > 2)
  ------------------
  |  Branch (1351:9): [True: 1.25k, False: 12.4k]
  ------------------
 1352|  1.25k|      res = 0;
 1353|  13.6k|    break;
 1354|   539k|  case COAP_OPTION_Q_BLOCK1:
  ------------------
  |  Branch (1354:3): [True: 539k, False: 8.28M]
  ------------------
 1355|   539k|    if (len > 3)
  ------------------
  |  Branch (1355:9): [True: 1.68k, False: 537k]
  ------------------
 1356|  1.68k|      res = 0;
 1357|   539k|    break;
 1358|  2.76k|  case COAP_OPTION_LOCATION_QUERY:
  ------------------
  |  Branch (1358:3): [True: 2.76k, False: 8.82M]
  ------------------
 1359|  2.76k|    if (len > 255)
  ------------------
  |  Branch (1359:9): [True: 975, False: 1.78k]
  ------------------
 1360|    975|      res = 0;
 1361|  2.76k|    break;
 1362|  1.89k|  case COAP_OPTION_EDHOC:
  ------------------
  |  Branch (1362:3): [True: 1.89k, False: 8.82M]
  ------------------
 1363|  1.89k|    if (len != 0)
  ------------------
  |  Branch (1363:9): [True: 1.20k, False: 685]
  ------------------
 1364|  1.20k|      res = 0;
 1365|  1.89k|    break;
 1366|  2.94k|  case COAP_OPTION_BLOCK2:
  ------------------
  |  Branch (1366:3): [True: 2.94k, False: 8.82M]
  ------------------
 1367|  2.94k|    if (len > 3)
  ------------------
  |  Branch (1367:9): [True: 1.78k, False: 1.16k]
  ------------------
 1368|  1.78k|      res = 0;
 1369|  2.94k|    break;
 1370|   534k|  case COAP_OPTION_BLOCK1:
  ------------------
  |  Branch (1370:3): [True: 534k, False: 8.29M]
  ------------------
 1371|   534k|    if (len > 3)
  ------------------
  |  Branch (1371:9): [True: 1.51k, False: 532k]
  ------------------
 1372|  1.51k|      res = 0;
 1373|   534k|    break;
 1374|  9.26k|  case COAP_OPTION_SIZE2:
  ------------------
  |  Branch (1374:3): [True: 9.26k, False: 8.81M]
  ------------------
 1375|  9.26k|    if (len > 4)
  ------------------
  |  Branch (1375:9): [True: 1.35k, False: 7.91k]
  ------------------
 1376|  1.35k|      res = 0;
 1377|  9.26k|    break;
 1378|  4.46k|  case COAP_OPTION_Q_BLOCK2:
  ------------------
  |  Branch (1378:3): [True: 4.46k, False: 8.82M]
  ------------------
 1379|  4.46k|    if (len > 3)
  ------------------
  |  Branch (1379:9): [True: 2.67k, False: 1.79k]
  ------------------
 1380|  2.67k|      res = 0;
 1381|  4.46k|    break;
 1382|  7.40k|  case COAP_OPTION_PROXY_URI:
  ------------------
  |  Branch (1382:3): [True: 7.40k, False: 8.81M]
  ------------------
 1383|  7.40k|    if (len < 1 || len > 1034)
  ------------------
  |  Branch (1383:9): [True: 4.72k, False: 2.68k]
  |  Branch (1383:20): [True: 1.08k, False: 1.59k]
  ------------------
 1384|  5.81k|      res = 0;
 1385|  7.40k|    break;
 1386|  13.1k|  case COAP_OPTION_PROXY_SCHEME:
  ------------------
  |  Branch (1386:3): [True: 13.1k, False: 8.81M]
  ------------------
 1387|  13.1k|    if (len < 1 || len > 255)
  ------------------
  |  Branch (1387:9): [True: 9.49k, False: 3.64k]
  |  Branch (1387:20): [True: 1.01k, False: 2.63k]
  ------------------
 1388|  10.5k|      res = 0;
 1389|  13.1k|    break;
 1390|  2.62k|  case COAP_OPTION_SIZE1:
  ------------------
  |  Branch (1390:3): [True: 2.62k, False: 8.82M]
  ------------------
 1391|  2.62k|    if (len > 4)
  ------------------
  |  Branch (1391:9): [True: 1.26k, False: 1.35k]
  ------------------
 1392|  1.26k|      res = 0;
 1393|  2.62k|    break;
 1394|  2.27k|  case COAP_OPTION_ECHO:
  ------------------
  |  Branch (1394:3): [True: 2.27k, False: 8.82M]
  ------------------
 1395|  2.27k|    if (len > 40)
  ------------------
  |  Branch (1395:9): [True: 1.01k, False: 1.25k]
  ------------------
 1396|  1.01k|      res = 0;
 1397|  2.27k|    break;
 1398|  4.21k|  case COAP_OPTION_NORESPONSE:
  ------------------
  |  Branch (1398:3): [True: 4.21k, False: 8.82M]
  ------------------
 1399|  4.21k|    if (len > 1)
  ------------------
  |  Branch (1399:9): [True: 1.57k, False: 2.63k]
  ------------------
 1400|  1.57k|      res = 0;
 1401|  4.21k|    break;
 1402|  2.27k|  case COAP_OPTION_RTAG:
  ------------------
  |  Branch (1402:3): [True: 2.27k, False: 8.82M]
  ------------------
 1403|  2.27k|    if (len > 8)
  ------------------
  |  Branch (1403:9): [True: 1.20k, False: 1.06k]
  ------------------
 1404|  1.20k|      res = 0;
 1405|  2.27k|    break;
 1406|  1.34M|  default:
  ------------------
  |  Branch (1406:3): [True: 1.34M, False: 7.47M]
  ------------------
 1407|  1.34M|    ;
 1408|  8.82M|  }
 1409|  8.82M|  return res;
 1410|  8.82M|}
coap_pdu_parse_opt:
 1446|  3.12k|coap_pdu_parse_opt(coap_pdu_t *pdu, coap_opt_filter_t *error_opts) {
 1447|  3.12k|  int good = 1;
 1448|       |
 1449|  3.12k|  coap_option_filter_clear(error_opts);
 1450|       |
 1451|       |  /* sanity checks */
 1452|  3.12k|  if (pdu->code == 0) {
  ------------------
  |  Branch (1452:7): [True: 16, False: 3.10k]
  ------------------
 1453|     16|    if (pdu->used_size != 0 || pdu->e_token_length) {
  ------------------
  |  Branch (1453:9): [True: 12, False: 4]
  |  Branch (1453:32): [True: 3, False: 1]
  ------------------
 1454|     15|      coap_log_debug("coap_pdu_parse: empty message is not empty\n");
  ------------------
  |  |  126|     15|#define coap_log_debug(...) coap_log(COAP_LOG_DEBUG, __VA_ARGS__)
  |  |  ------------------
  |  |  |  |  290|     15|#define coap_log(level, ...) do { \
  |  |  |  |  291|     15|    if ((level) < (coap_get_log_level() + 1)) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (291:9): [True: 0, False: 15]
  |  |  |  |  ------------------
  |  |  |  |  292|     15|      coap_log_impl((level), __VA_ARGS__); \
  |  |  |  |  293|     15|  } while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (293:11): [Folded, False: 15]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1455|     15|      return 0;
 1456|     15|    }
 1457|     16|  }
 1458|       |
 1459|  3.10k|  if (pdu->e_token_length > pdu->used_size) {
  ------------------
  |  Branch (1459:7): [True: 8, False: 3.09k]
  ------------------
 1460|      8|    coap_log_debug("coap_pdu_parse: invalid Token\n");
  ------------------
  |  |  126|      8|#define coap_log_debug(...) coap_log(COAP_LOG_DEBUG, __VA_ARGS__)
  |  |  ------------------
  |  |  |  |  290|      8|#define coap_log(level, ...) do { \
  |  |  |  |  291|      8|    if ((level) < (coap_get_log_level() + 1)) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (291:9): [True: 0, False: 8]
  |  |  |  |  ------------------
  |  |  |  |  292|      8|      coap_log_impl((level), __VA_ARGS__); \
  |  |  |  |  293|      8|  } while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (293:11): [Folded, False: 8]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1461|      8|    return 0;
 1462|      8|  }
 1463|       |
 1464|  3.09k|  pdu->max_opt = 0;
 1465|  3.09k|  if (pdu->code == 0) {
  ------------------
  |  Branch (1465:7): [True: 1, False: 3.09k]
  ------------------
 1466|       |    /* empty packet */
 1467|      1|    pdu->used_size = 0;
 1468|      1|    pdu->data = NULL;
 1469|  3.09k|  } else {
 1470|       |    /* skip header + token */
 1471|  3.09k|    coap_opt_t *opt = pdu->token + pdu->e_token_length;
 1472|  3.09k|    size_t length = pdu->used_size - pdu->e_token_length;
 1473|       |
 1474|  9.00M|    while (length > 0 && *opt != COAP_PAYLOAD_START) {
  ------------------
  |  |   96|  8.99M|#define COAP_PAYLOAD_START 0xFF /* payload marker */
  ------------------
  |  Branch (1474:12): [True: 8.99M, False: 2.40k]
  |  Branch (1474:26): [True: 8.99M, False: 213]
  ------------------
 1475|  8.99M|#if (COAP_MAX_LOGGING_LEVEL >= _COAP_LOG_WARN)
 1476|  8.99M|      coap_opt_t *opt_last = opt;
 1477|  8.99M|#endif
 1478|  8.99M|      size_t optsize = next_option_safe(&opt, &length, &pdu->max_opt);
 1479|  8.99M|      uint32_t len;
 1480|  8.99M|      const uint8_t *opt_val;
 1481|       |
 1482|  8.99M|      if (optsize == 0) {
  ------------------
  |  Branch (1482:11): [True: 477, False: 8.99M]
  ------------------
 1483|    477|        coap_log_debug("coap_pdu_parse: %d.%02d: offset %u malformed option\n",
  ------------------
  |  |  126|    477|#define coap_log_debug(...) coap_log(COAP_LOG_DEBUG, __VA_ARGS__)
  |  |  ------------------
  |  |  |  |  290|    477|#define coap_log(level, ...) do { \
  |  |  |  |  291|    477|    if ((level) < (coap_get_log_level() + 1)) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (291:9): [True: 0, False: 477]
  |  |  |  |  ------------------
  |  |  |  |  292|    477|      coap_log_impl((level), __VA_ARGS__); \
  |  |  |  |  293|    477|  } while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (293:11): [Folded, False: 477]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1484|    477|                       pdu->code >> 5, pdu->code & 0x1F,
 1485|    477|                       (int)(opt_last - pdu->token - pdu->e_token_length));
 1486|    477|        coap_option_filter_set(error_opts, pdu->max_opt);
 1487|    477|        good = 0;
 1488|    477|        break;
 1489|    477|      }
 1490|  8.99M|      len = coap_opt_length((const uint8_t *)opt - optsize);
 1491|  8.99M|      opt_val = coap_opt_value((const uint8_t *)opt - optsize);
 1492|  8.99M|      if (COAP_PDU_IS_SIGNALING(pdu) ?
  ------------------
  |  |  102|  8.99M|#define COAP_PDU_IS_SIGNALING(pdu) ((pdu)->code >= 224)
  |  |  ------------------
  |  |  |  Branch (102:36): [True: 1.10M, False: 7.88M]
  |  |  ------------------
  ------------------
  |  Branch (1492:11): [True: 1.18M, False: 7.81M]
  ------------------
 1493|  1.10M|          !coap_pdu_parse_opt_csm(pdu->code, pdu->max_opt, len) :
 1494|  8.99M|          !coap_pdu_parse_opt_base(pdu->max_opt, len, opt_val)) {
 1495|  1.18M|        coap_log_warn("coap_pdu_parse: %d.%02d: offset %u option %u has bad length %" PRIu32 " or value\n",
  ------------------
  |  |  108|  1.18M|#define coap_log_warn(...) coap_log(COAP_LOG_WARN, __VA_ARGS__)
  |  |  ------------------
  |  |  |  |  290|  1.18M|#define coap_log(level, ...) do { \
  |  |  |  |  291|  1.18M|    if ((level) < (coap_get_log_level() + 1)) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (291:9): [True: 0, False: 1.18M]
  |  |  |  |  ------------------
  |  |  |  |  292|  1.18M|      coap_log_impl((level), __VA_ARGS__); \
  |  |  |  |  293|  1.18M|  } while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (293:11): [Folded, False: 1.18M]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1496|  1.18M|                      pdu->code >> 5, pdu->code & 0x1F,
 1497|  1.18M|                      (int)(opt_last - pdu->token - pdu->e_token_length), pdu->max_opt,
 1498|  1.18M|                      len);
 1499|  1.18M|        coap_option_filter_set(error_opts, pdu->max_opt);
 1500|  1.18M|        good = 0;
 1501|  1.18M|      }
 1502|  8.99M|    }
 1503|       |
 1504|  3.09k|    if (!good) {
  ------------------
  |  Branch (1504:9): [True: 1.50k, False: 1.59k]
  ------------------
 1505|       |      /*
 1506|       |       * Dump the options in the PDU for analysis, space separated except
 1507|       |       * error options which are prefixed by *
 1508|       |       * Two rows - hex and ascii (if printable)
 1509|       |       */
 1510|  1.50k|      static char outbuf[COAP_DEBUG_BUF_SIZE];
 1511|  1.50k|      char *obp;
 1512|  1.50k|      size_t tlen;
 1513|  1.50k|      size_t outbuflen;
 1514|  1.50k|      int i;
 1515|  1.50k|      int ok;
 1516|       |
 1517|  4.51k|      for (i = 0; i < 2; i++) {
  ------------------
  |  Branch (1517:19): [True: 3.01k, False: 1.50k]
  ------------------
 1518|  3.01k|        opt = pdu->token + pdu->e_token_length;
 1519|  3.01k|        length = pdu->used_size - pdu->e_token_length;
 1520|  3.01k|        pdu->max_opt = 0;
 1521|       |
 1522|  3.01k|        outbuflen = sizeof(outbuf);
 1523|  3.01k|        obp = outbuf;
 1524|  3.01k|        ok = write_prefix(&obp, &outbuflen, "O: ", 3);
 1525|       |        /*
 1526|       |         * Not safe to check for 'ok' here as a lot of variables may get
 1527|       |         * partially changed due to lack of outbuflen */
 1528|  3.16M|        while (length > 0 && *opt != COAP_PAYLOAD_START) {
  ------------------
  |  |   96|  3.15M|#define COAP_PAYLOAD_START 0xFF /* payload marker */
  ------------------
  |  Branch (1528:16): [True: 3.15M, False: 2.86k]
  |  Branch (1528:30): [True: 3.15M, False: 150]
  ------------------
 1529|  3.15M|          coap_opt_t *opt_last = opt;
 1530|  3.15M|          size_t optsize = next_option_safe(&opt, &length, &pdu->max_opt);
 1531|  3.15M|          const uint32_t len =
 1532|  3.15M|              optsize ? coap_opt_length((const uint8_t *)opt - optsize) : 0;
  ------------------
  |  Branch (1532:15): [True: 3.15M, False: 954]
  ------------------
 1533|  3.15M|          const uint8_t *opt_val =
 1534|  3.15M|              optsize ?  coap_opt_value((const uint8_t *)opt - optsize) : 0;
  ------------------
  |  Branch (1534:15): [True: 3.15M, False: 954]
  ------------------
 1535|       |
 1536|  3.15M|          if (!optsize || (COAP_PDU_IS_SIGNALING(pdu) ?
  ------------------
  |  |  102|  3.15M|#define COAP_PDU_IS_SIGNALING(pdu) ((pdu)->code >= 224)
  |  |  ------------------
  |  |  |  Branch (102:36): [True: 2.21M, False: 939k]
  |  |  ------------------
  ------------------
  |  Branch (1536:15): [True: 954, False: 3.15M]
  |  Branch (1536:27): [True: 2.37M, False: 784k]
  ------------------
 1537|  2.21M|                           !coap_pdu_parse_opt_csm(pdu->code, pdu->max_opt, len) :
 1538|  3.15M|                           !coap_pdu_parse_opt_base(pdu->max_opt, len, opt_val))) {
 1539|  2.37M|            ok = ok && write_prefix(&obp, &outbuflen, "*", 1);
  ------------------
  |  Branch (1539:18): [True: 59.6k, False: 2.31M]
  |  Branch (1539:24): [True: 59.6k, False: 22]
  ------------------
 1540|  2.37M|            if (!optsize) {
  ------------------
  |  Branch (1540:17): [True: 954, False: 2.37M]
  ------------------
 1541|       |              /* Skip to end of options to output all data */
 1542|    954|              opt = pdu->token + pdu->used_size;
 1543|    954|              length = 0;
 1544|    954|            }
 1545|  2.37M|          } else {
 1546|   784k|            ok = ok && write_prefix(&obp, &outbuflen, " ", 1);
  ------------------
  |  Branch (1546:18): [True: 51.5k, False: 732k]
  |  Branch (1546:24): [True: 51.5k, False: 28]
  ------------------
 1547|   784k|          }
 1548|  3.15M|          tlen = opt - opt_last;
 1549|  81.5M|          while (tlen) {
  ------------------
  |  Branch (1549:18): [True: 78.4M, False: 3.15M]
  ------------------
 1550|  78.4M|            tlen--;
 1551|  78.4M|            ok = ok && write_char(&obp, &outbuflen, *opt_last, i);
  ------------------
  |  Branch (1551:18): [True: 1.14M, False: 77.2M]
  |  Branch (1551:24): [True: 1.14M, False: 870]
  ------------------
 1552|  78.4M|            opt_last++;
 1553|  78.4M|          }
 1554|  3.15M|        }
 1555|  3.01k|        if (length && *opt == COAP_PAYLOAD_START) {
  ------------------
  |  |   96|    150|#define COAP_PAYLOAD_START 0xFF /* payload marker */
  ------------------
  |  Branch (1555:13): [True: 150, False: 2.86k]
  |  Branch (1555:23): [True: 150, False: 0]
  ------------------
 1556|    150|          write_char(&obp, &outbuflen, *opt, i);
 1557|    150|        }
 1558|       |        /* write_*() always leaves a spare byte to null terminate */
 1559|  3.01k|        *obp = '\000';
 1560|  3.01k|        coap_log_debug("%s\n", outbuf);
  ------------------
  |  |  126|  3.01k|#define coap_log_debug(...) coap_log(COAP_LOG_DEBUG, __VA_ARGS__)
  |  |  ------------------
  |  |  |  |  290|  3.01k|#define coap_log(level, ...) do { \
  |  |  |  |  291|  3.01k|    if ((level) < (coap_get_log_level() + 1)) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (291:9): [True: 0, False: 3.01k]
  |  |  |  |  ------------------
  |  |  |  |  292|  3.01k|      coap_log_impl((level), __VA_ARGS__); \
  |  |  |  |  293|  3.01k|  } while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (293:11): [Folded, False: 3.01k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1561|  3.01k|      }
 1562|  1.50k|    }
 1563|       |
 1564|  3.09k|    if (length > 0) {
  ------------------
  |  Branch (1564:9): [True: 213, False: 2.88k]
  ------------------
 1565|    213|      assert(*opt == COAP_PAYLOAD_START);
  ------------------
  |  Branch (1565:7): [True: 213, False: 0]
  ------------------
 1566|    213|      opt++;
 1567|    213|      length--;
 1568|       |
 1569|    213|      if (length == 0) {
  ------------------
  |  Branch (1569:11): [True: 18, False: 195]
  ------------------
 1570|     18|        coap_log_debug("coap_pdu_parse: message ending in payload start marker\n");
  ------------------
  |  |  126|     18|#define coap_log_debug(...) coap_log(COAP_LOG_DEBUG, __VA_ARGS__)
  |  |  ------------------
  |  |  |  |  290|     18|#define coap_log(level, ...) do { \
  |  |  |  |  291|     18|    if ((level) < (coap_get_log_level() + 1)) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (291:9): [True: 0, False: 18]
  |  |  |  |  ------------------
  |  |  |  |  292|     18|      coap_log_impl((level), __VA_ARGS__); \
  |  |  |  |  293|     18|  } while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (293:11): [Folded, False: 18]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1571|     18|        return 0;
 1572|     18|      }
 1573|    213|    }
 1574|  3.08k|    if (length > 0)
  ------------------
  |  Branch (1574:9): [True: 195, False: 2.88k]
  ------------------
 1575|    195|      pdu->data = (uint8_t *)opt;
 1576|  2.88k|    else
 1577|  2.88k|      pdu->data = NULL;
 1578|  3.08k|  }
 1579|       |
 1580|  3.08k|  return good;
 1581|  3.09k|}
coap_pdu_parse:
 1587|  3.16k|               coap_pdu_t *pdu) {
 1588|  3.16k|  coap_opt_filter_t error_opts;
 1589|       |
 1590|  3.16k|  return coap_pdu_parse2(proto, data, length, pdu, &error_opts);
 1591|  3.16k|}
coap_pdu_parse2:
 1598|  3.16k|                coap_opt_filter_t *error_opts) {
 1599|  3.16k|  size_t hdr_size;
 1600|       |
 1601|  3.16k|  if (length == 0)
  ------------------
  |  Branch (1601:7): [True: 0, False: 3.16k]
  ------------------
 1602|      0|    return 0;
 1603|  3.16k|  hdr_size = coap_pdu_parse_header_size(proto, data);
 1604|  3.16k|  if (!hdr_size || hdr_size > length)
  ------------------
  |  Branch (1604:7): [True: 0, False: 3.16k]
  |  Branch (1604:20): [True: 3, False: 3.16k]
  ------------------
 1605|      3|    return 0;
 1606|  3.16k|  if (hdr_size > pdu->max_hdr_size)
  ------------------
  |  Branch (1606:7): [True: 0, False: 3.16k]
  ------------------
 1607|      0|    return 0;
 1608|  3.16k|  if (!coap_pdu_resize(pdu, length - hdr_size))
  ------------------
  |  Branch (1608:7): [True: 0, False: 3.16k]
  ------------------
 1609|      0|    return 0;
 1610|  3.16k|  if (pdu->token - hdr_size != data)
  ------------------
  |  Branch (1610:7): [True: 3.16k, False: 0]
  ------------------
 1611|  3.16k|    memcpy(pdu->token - hdr_size, data, length);
 1612|  3.16k|  pdu->hdr_size = (uint8_t)hdr_size;
 1613|  3.16k|  pdu->used_size = length - hdr_size;
 1614|  3.16k|  return coap_pdu_parse_header(pdu, proto) && coap_pdu_parse_opt(pdu, error_opts);
  ------------------
  |  Branch (1614:10): [True: 3.12k, False: 43]
  |  Branch (1614:47): [True: 1.58k, False: 1.53k]
  ------------------
 1615|  3.16k|}
coap_pdu_encode_header:
 1618|  1.58k|coap_pdu_encode_header(coap_pdu_t *pdu, coap_proto_t proto) {
 1619|  1.58k|  uint8_t e_token_length;
 1620|       |
 1621|  1.58k|  if (pdu->actual_token.length < COAP_TOKEN_EXT_1B_BIAS) {
  ------------------
  |  |   56|  1.58k|#define COAP_TOKEN_EXT_1B_BIAS 13
  ------------------
  |  Branch (1621:7): [True: 1.52k, False: 57]
  ------------------
 1622|  1.52k|    e_token_length = (uint8_t)pdu->actual_token.length;
 1623|  1.52k|  } else if (pdu->actual_token.length < COAP_TOKEN_EXT_2B_BIAS) {
  ------------------
  |  |   57|     57|#define COAP_TOKEN_EXT_2B_BIAS 269 /* 13 + 256 */
  ------------------
  |  Branch (1623:14): [True: 24, False: 33]
  ------------------
 1624|     24|    e_token_length = COAP_TOKEN_EXT_1B_TKL;
  ------------------
  |  |   54|     24|#define COAP_TOKEN_EXT_1B_TKL 13
  ------------------
 1625|     33|  } else if (pdu->actual_token.length <= COAP_TOKEN_EXT_MAX) {
  ------------------
  |  |   60|     33|#define COAP_TOKEN_EXT_MAX 65804UL /* 13 + 256 + 65535 */
  ------------------
  |  Branch (1625:14): [True: 33, False: 0]
  ------------------
 1626|     33|    e_token_length = COAP_TOKEN_EXT_2B_TKL;
  ------------------
  |  |   55|     33|#define COAP_TOKEN_EXT_2B_TKL 14
  ------------------
 1627|     33|  } else {
 1628|      0|    coap_log_warn("coap_pdu_encode_header: Token size too large. PDU ignored\n");
  ------------------
  |  |  108|      0|#define coap_log_warn(...) coap_log(COAP_LOG_WARN, __VA_ARGS__)
  |  |  ------------------
  |  |  |  |  290|      0|#define coap_log(level, ...) do { \
  |  |  |  |  291|      0|    if ((level) < (coap_get_log_level() + 1)) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (291:9): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  292|      0|      coap_log_impl((level), __VA_ARGS__); \
  |  |  |  |  293|      0|  } while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (293:11): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1629|      0|    return 0;
 1630|      0|  }
 1631|  1.58k|  if (COAP_PROTO_NOT_RELIABLE(proto)) {
  ------------------
  |  |   41|  1.58k|#define COAP_PROTO_NOT_RELIABLE(p) ((p)==COAP_PROTO_UDP || (p)==COAP_PROTO_DTLS)
  |  |  ------------------
  |  |  |  Branch (41:37): [True: 1.58k, False: 0]
  |  |  |  Branch (41:60): [True: 0, False: 0]
  |  |  ------------------
  ------------------
 1632|  1.58k|    assert(pdu->max_hdr_size >= 4);
  ------------------
  |  Branch (1632:5): [True: 1.58k, False: 0]
  ------------------
 1633|  1.58k|    if (pdu->max_hdr_size < 4) {
  ------------------
  |  Branch (1633:9): [True: 0, False: 1.58k]
  ------------------
 1634|      0|      coap_log_warn("coap_pdu_encode_header: not enough space for UDP-style header\n");
  ------------------
  |  |  108|      0|#define coap_log_warn(...) coap_log(COAP_LOG_WARN, __VA_ARGS__)
  |  |  ------------------
  |  |  |  |  290|      0|#define coap_log(level, ...) do { \
  |  |  |  |  291|      0|    if ((level) < (coap_get_log_level() + 1)) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (291:9): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  292|      0|      coap_log_impl((level), __VA_ARGS__); \
  |  |  |  |  293|      0|  } while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (293:11): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1635|      0|      return 0;
 1636|      0|    }
 1637|  1.58k|    pdu->token[-4] = COAP_DEFAULT_VERSION << 6
  ------------------
  |  |   35|  1.58k|#define COAP_DEFAULT_VERSION      1 /* version of CoAP supported */
  ------------------
 1638|  1.58k|                     | pdu->type << 4
 1639|  1.58k|                     | e_token_length;
 1640|  1.58k|    pdu->token[-3] = pdu->code;
 1641|  1.58k|    pdu->token[-2] = (uint8_t)(pdu->mid >> 8);
 1642|  1.58k|    pdu->token[-1] = (uint8_t)(pdu->mid);
 1643|  1.58k|    pdu->hdr_size = 4;
 1644|  1.58k|#if !COAP_DISABLE_TCP
 1645|  1.58k|  } else if (COAP_PROTO_RELIABLE(proto)) {
  ------------------
  |  |   42|      0|#define COAP_PROTO_RELIABLE(p) ((p)==COAP_PROTO_TCP || (p)==COAP_PROTO_TLS || \
  |  |  ------------------
  |  |  |  Branch (42:33): [True: 0, False: 0]
  |  |  |  Branch (42:56): [True: 0, False: 0]
  |  |  ------------------
  |  |   43|      0|                                (p)==COAP_PROTO_WS || (p)==COAP_PROTO_WSS)
  |  |  ------------------
  |  |  |  Branch (43:33): [True: 0, False: 0]
  |  |  |  Branch (43:55): [True: 0, False: 0]
  |  |  ------------------
  ------------------
 1646|      0|    size_t len;
 1647|      0|    assert(pdu->used_size >= pdu->e_token_length);
  ------------------
  |  Branch (1647:5): [True: 0, False: 0]
  ------------------
 1648|      0|    if (pdu->used_size < pdu->e_token_length) {
  ------------------
  |  Branch (1648:9): [True: 0, False: 0]
  ------------------
 1649|      0|      coap_log_warn("coap_pdu_encode_header: corrupted PDU\n");
  ------------------
  |  |  108|      0|#define coap_log_warn(...) coap_log(COAP_LOG_WARN, __VA_ARGS__)
  |  |  ------------------
  |  |  |  |  290|      0|#define coap_log(level, ...) do { \
  |  |  |  |  291|      0|    if ((level) < (coap_get_log_level() + 1)) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (291:9): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  292|      0|      coap_log_impl((level), __VA_ARGS__); \
  |  |  |  |  293|      0|  } while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (293:11): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1650|      0|      return 0;
 1651|      0|    }
 1652|       |
 1653|       |    /* A lot of the reliable code assumes type is CON */
 1654|      0|    if (pdu->type != COAP_MESSAGE_CON)
  ------------------
  |  Branch (1654:9): [True: 0, False: 0]
  ------------------
 1655|      0|      pdu->type = COAP_MESSAGE_CON;
 1656|       |
 1657|      0|    if (proto == COAP_PROTO_WS || proto == COAP_PROTO_WSS)
  ------------------
  |  Branch (1657:9): [True: 0, False: 0]
  |  Branch (1657:35): [True: 0, False: 0]
  ------------------
 1658|      0|      len = 0;
 1659|      0|    else
 1660|      0|      len = pdu->used_size - pdu->e_token_length;
 1661|      0|    if (len <= COAP_MAX_MESSAGE_SIZE_TCP0) {
  ------------------
  |  |   43|      0|#define COAP_MAX_MESSAGE_SIZE_TCP0 (COAP_MESSAGE_SIZE_OFFSET_TCP8-1) /* 12 */
  |  |  ------------------
  |  |  |  |   38|      0|#define COAP_MESSAGE_SIZE_OFFSET_TCP8 13
  |  |  ------------------
  ------------------
  |  Branch (1661:9): [True: 0, False: 0]
  ------------------
 1662|      0|      assert(pdu->max_hdr_size >= 2);
  ------------------
  |  Branch (1662:7): [True: 0, False: 0]
  ------------------
 1663|      0|      if (pdu->max_hdr_size < 2) {
  ------------------
  |  Branch (1663:11): [True: 0, False: 0]
  ------------------
 1664|      0|        coap_log_warn("coap_pdu_encode_header: not enough space for TCP0 header\n");
  ------------------
  |  |  108|      0|#define coap_log_warn(...) coap_log(COAP_LOG_WARN, __VA_ARGS__)
  |  |  ------------------
  |  |  |  |  290|      0|#define coap_log(level, ...) do { \
  |  |  |  |  291|      0|    if ((level) < (coap_get_log_level() + 1)) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (291:9): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  292|      0|      coap_log_impl((level), __VA_ARGS__); \
  |  |  |  |  293|      0|  } while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (293:11): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1665|      0|        return 0;
 1666|      0|      }
 1667|      0|      pdu->token[-2] = (uint8_t)len << 4
 1668|      0|                       | e_token_length;
 1669|      0|      pdu->token[-1] = pdu->code;
 1670|      0|      pdu->hdr_size = 2;
 1671|      0|    } else if (len <= COAP_MAX_MESSAGE_SIZE_TCP8) {
  ------------------
  |  |   44|      0|#define COAP_MAX_MESSAGE_SIZE_TCP8 (COAP_MESSAGE_SIZE_OFFSET_TCP16-1) /* 268 */
  |  |  ------------------
  |  |  |  |   39|      0|#define COAP_MESSAGE_SIZE_OFFSET_TCP16 269 /* 13 + 256 */
  |  |  ------------------
  ------------------
  |  Branch (1671:16): [True: 0, False: 0]
  ------------------
 1672|      0|      assert(pdu->max_hdr_size >= 3);
  ------------------
  |  Branch (1672:7): [True: 0, False: 0]
  ------------------
 1673|      0|      if (pdu->max_hdr_size < 3) {
  ------------------
  |  Branch (1673:11): [True: 0, False: 0]
  ------------------
 1674|      0|        coap_log_warn("coap_pdu_encode_header: not enough space for TCP8 header\n");
  ------------------
  |  |  108|      0|#define coap_log_warn(...) coap_log(COAP_LOG_WARN, __VA_ARGS__)
  |  |  ------------------
  |  |  |  |  290|      0|#define coap_log(level, ...) do { \
  |  |  |  |  291|      0|    if ((level) < (coap_get_log_level() + 1)) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (291:9): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  292|      0|      coap_log_impl((level), __VA_ARGS__); \
  |  |  |  |  293|      0|  } while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (293:11): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1675|      0|        return 0;
 1676|      0|      }
 1677|      0|      pdu->token[-3] = 13 << 4 | e_token_length;
 1678|      0|      pdu->token[-2] = (uint8_t)(len - COAP_MESSAGE_SIZE_OFFSET_TCP8);
  ------------------
  |  |   38|      0|#define COAP_MESSAGE_SIZE_OFFSET_TCP8 13
  ------------------
 1679|      0|      pdu->token[-1] = pdu->code;
 1680|      0|      pdu->hdr_size = 3;
 1681|      0|    } else if (len <= COAP_MAX_MESSAGE_SIZE_TCP16) {
  ------------------
  |  |   45|      0|#define COAP_MAX_MESSAGE_SIZE_TCP16 (COAP_MESSAGE_SIZE_OFFSET_TCP32-1) /* 65804 */
  |  |  ------------------
  |  |  |  |   40|      0|#define COAP_MESSAGE_SIZE_OFFSET_TCP32 65805 /* 269 + 65536 */
  |  |  ------------------
  ------------------
  |  Branch (1681:16): [True: 0, False: 0]
  ------------------
 1682|      0|      assert(pdu->max_hdr_size >= 4);
  ------------------
  |  Branch (1682:7): [True: 0, False: 0]
  ------------------
 1683|      0|      if (pdu->max_hdr_size < 4) {
  ------------------
  |  Branch (1683:11): [True: 0, False: 0]
  ------------------
 1684|      0|        coap_log_warn("coap_pdu_encode_header: not enough space for TCP16 header\n");
  ------------------
  |  |  108|      0|#define coap_log_warn(...) coap_log(COAP_LOG_WARN, __VA_ARGS__)
  |  |  ------------------
  |  |  |  |  290|      0|#define coap_log(level, ...) do { \
  |  |  |  |  291|      0|    if ((level) < (coap_get_log_level() + 1)) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (291:9): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  292|      0|      coap_log_impl((level), __VA_ARGS__); \
  |  |  |  |  293|      0|  } while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (293:11): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1685|      0|        return 0;
 1686|      0|      }
 1687|      0|      pdu->token[-4] = 14 << 4 | e_token_length;
 1688|      0|      pdu->token[-3] = (uint8_t)((len - COAP_MESSAGE_SIZE_OFFSET_TCP16) >> 8);
  ------------------
  |  |   39|      0|#define COAP_MESSAGE_SIZE_OFFSET_TCP16 269 /* 13 + 256 */
  ------------------
 1689|      0|      pdu->token[-2] = (uint8_t)(len - COAP_MESSAGE_SIZE_OFFSET_TCP16);
  ------------------
  |  |   39|      0|#define COAP_MESSAGE_SIZE_OFFSET_TCP16 269 /* 13 + 256 */
  ------------------
 1690|      0|      pdu->token[-1] = pdu->code;
 1691|      0|      pdu->hdr_size = 4;
 1692|      0|    } else {
 1693|      0|      assert(pdu->max_hdr_size >= 6);
  ------------------
  |  Branch (1693:7): [True: 0, False: 0]
  ------------------
 1694|      0|      if (pdu->max_hdr_size < 6) {
  ------------------
  |  Branch (1694:11): [True: 0, False: 0]
  ------------------
 1695|      0|        coap_log_warn("coap_pdu_encode_header: not enough space for TCP32 header\n");
  ------------------
  |  |  108|      0|#define coap_log_warn(...) coap_log(COAP_LOG_WARN, __VA_ARGS__)
  |  |  ------------------
  |  |  |  |  290|      0|#define coap_log(level, ...) do { \
  |  |  |  |  291|      0|    if ((level) < (coap_get_log_level() + 1)) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (291:9): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  292|      0|      coap_log_impl((level), __VA_ARGS__); \
  |  |  |  |  293|      0|  } while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (293:11): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1696|      0|        return 0;
 1697|      0|      }
 1698|      0|      pdu->token[-6] = 15 << 4 | e_token_length;
 1699|      0|      pdu->token[-5] = (uint8_t)((len - COAP_MESSAGE_SIZE_OFFSET_TCP32) >> 24);
  ------------------
  |  |   40|      0|#define COAP_MESSAGE_SIZE_OFFSET_TCP32 65805 /* 269 + 65536 */
  ------------------
 1700|      0|      pdu->token[-4] = (uint8_t)((len - COAP_MESSAGE_SIZE_OFFSET_TCP32) >> 16);
  ------------------
  |  |   40|      0|#define COAP_MESSAGE_SIZE_OFFSET_TCP32 65805 /* 269 + 65536 */
  ------------------
 1701|      0|      pdu->token[-3] = (uint8_t)((len - COAP_MESSAGE_SIZE_OFFSET_TCP32) >> 8);
  ------------------
  |  |   40|      0|#define COAP_MESSAGE_SIZE_OFFSET_TCP32 65805 /* 269 + 65536 */
  ------------------
 1702|      0|      pdu->token[-2] = (uint8_t)(len - COAP_MESSAGE_SIZE_OFFSET_TCP32);
  ------------------
  |  |   40|      0|#define COAP_MESSAGE_SIZE_OFFSET_TCP32 65805 /* 269 + 65536 */
  ------------------
 1703|      0|      pdu->token[-1] = pdu->code;
 1704|      0|      pdu->hdr_size = 6;
 1705|      0|    }
 1706|      0|#endif /* ! COAP_DISABLE_TCP */
 1707|      0|  } else {
 1708|      0|    coap_log_warn("coap_pdu_encode_header: unsupported protocol\n");
  ------------------
  |  |  108|      0|#define coap_log_warn(...) coap_log(COAP_LOG_WARN, __VA_ARGS__)
  |  |  ------------------
  |  |  |  |  290|      0|#define coap_log(level, ...) do { \
  |  |  |  |  291|      0|    if ((level) < (coap_get_log_level() + 1)) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (291:9): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  292|      0|      coap_log_impl((level), __VA_ARGS__); \
  |  |  |  |  293|      0|  } while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (293:11): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1709|      0|  }
 1710|  1.58k|  return pdu->hdr_size;
 1711|  1.58k|}
coap_pdu.c:coap_pdu_parse_opt_csm:
 1222|  3.32M|coap_pdu_parse_opt_csm(coap_pdu_code_t code, coap_option_num_t option, size_t len) {
 1223|  3.32M|  switch ((coap_pdu_signaling_proto_t)code) {
 1224|  13.7k|  case COAP_SIGNALING_CSM:
  ------------------
  |  Branch (1224:3): [True: 13.7k, False: 3.31M]
  ------------------
 1225|  13.7k|    switch ((coap_sig_csm_opt_t)option) {
 1226|  2.19k|    case COAP_SIG_OPT_MAX_MESSAGE_SIZE:
  ------------------
  |  Branch (1226:5): [True: 2.19k, False: 11.5k]
  ------------------
 1227|  2.19k|      if (len > 4)
  ------------------
  |  Branch (1227:11): [True: 1.20k, False: 992]
  ------------------
 1228|  1.20k|        goto bad;
 1229|    992|      break;
 1230|  1.48k|    case COAP_SIG_OPT_BLOCK_WISE_TRANSFER:
  ------------------
  |  Branch (1230:5): [True: 1.48k, False: 12.2k]
  ------------------
 1231|  1.48k|      if (len > 0)
  ------------------
  |  Branch (1231:11): [True: 1.09k, False: 387]
  ------------------
 1232|  1.09k|        goto bad;
 1233|    387|      break;
 1234|  1.90k|    case COAP_SIG_OPT_EXTENDED_TOKEN_LENGTH:
  ------------------
  |  Branch (1234:5): [True: 1.90k, False: 11.8k]
  ------------------
 1235|  1.90k|      if (len > 3)
  ------------------
  |  Branch (1235:11): [True: 1.02k, False: 879]
  ------------------
 1236|  1.02k|        goto bad;
 1237|    879|      break;
 1238|  8.14k|    default:
  ------------------
  |  Branch (1238:5): [True: 8.14k, False: 5.58k]
  ------------------
 1239|  8.14k|      if (option & 0x01)
  ------------------
  |  Branch (1239:11): [True: 6.74k, False: 1.39k]
  ------------------
 1240|  6.74k|        goto bad; /* Critical */
 1241|  13.7k|    }
 1242|  3.65k|    break;
 1243|  44.7k|  case COAP_SIGNALING_PING:
  ------------------
  |  Branch (1243:3): [True: 44.7k, False: 3.28M]
  ------------------
 1244|  80.4k|  case COAP_SIGNALING_PONG:
  ------------------
  |  Branch (1244:3): [True: 35.7k, False: 3.29M]
  ------------------
 1245|  80.4k|    switch ((coap_sig_ping_opt_t)option) {
 1246|  3.10k|    case COAP_SIG_OPT_CUSTODY:
  ------------------
  |  Branch (1246:5): [True: 3.10k, False: 77.3k]
  ------------------
 1247|  3.10k|      if (len > 0)
  ------------------
  |  Branch (1247:11): [True: 1.86k, False: 1.24k]
  ------------------
 1248|  1.86k|        goto bad;
 1249|  1.24k|      break;
 1250|  77.3k|    default:
  ------------------
  |  Branch (1250:5): [True: 77.3k, False: 3.10k]
  ------------------
 1251|  77.3k|      if (option & 0x01)
  ------------------
  |  Branch (1251:11): [True: 40.5k, False: 36.7k]
  ------------------
 1252|  40.5k|        goto bad; /* Critical */
 1253|  80.4k|    }
 1254|  38.0k|    break;
 1255|  38.0k|  case COAP_SIGNALING_RELEASE:
  ------------------
  |  Branch (1255:3): [True: 21.0k, False: 3.30M]
  ------------------
 1256|  21.0k|    switch ((coap_sig_release_opt_t)option) {
 1257|  7.09k|    case COAP_SIG_OPT_ALTERNATIVE_ADDRESS:
  ------------------
  |  Branch (1257:5): [True: 7.09k, False: 13.9k]
  ------------------
 1258|  7.09k|      if (len < 1 || len > 255)
  ------------------
  |  Branch (1258:11): [True: 4.90k, False: 2.18k]
  |  Branch (1258:22): [True: 1.02k, False: 1.16k]
  ------------------
 1259|  5.93k|        goto bad;
 1260|  1.16k|      break;
 1261|  2.97k|    case COAP_SIG_OPT_HOLD_OFF:
  ------------------
  |  Branch (1261:5): [True: 2.97k, False: 18.0k]
  ------------------
 1262|  2.97k|      if (len > 3)
  ------------------
  |  Branch (1262:11): [True: 1.41k, False: 1.55k]
  ------------------
 1263|  1.41k|        goto bad;
 1264|  1.55k|      break;
 1265|  10.9k|    default:
  ------------------
  |  Branch (1265:5): [True: 10.9k, False: 10.0k]
  ------------------
 1266|  10.9k|      if (option & 0x01)
  ------------------
  |  Branch (1266:11): [True: 6.22k, False: 4.71k]
  ------------------
 1267|  6.22k|        goto bad; /* Critical */
 1268|  21.0k|    }
 1269|  7.42k|    break;
 1270|  12.2k|  case COAP_SIGNALING_ABORT:
  ------------------
  |  Branch (1270:3): [True: 12.2k, False: 3.31M]
  ------------------
 1271|  12.2k|    switch ((coap_sig_abort_opt_t)option) {
 1272|  2.19k|    case COAP_SIG_OPT_BAD_CSM_OPTION:
  ------------------
  |  Branch (1272:5): [True: 2.19k, False: 10.0k]
  ------------------
 1273|  2.19k|      if (len > 2)
  ------------------
  |  Branch (1273:11): [True: 1.19k, False: 1.00k]
  ------------------
 1274|  1.19k|        goto bad;
 1275|  1.00k|      break;
 1276|  10.0k|    default:
  ------------------
  |  Branch (1276:5): [True: 10.0k, False: 2.19k]
  ------------------
 1277|  10.0k|      if (option & 0x01)
  ------------------
  |  Branch (1277:11): [True: 6.15k, False: 3.89k]
  ------------------
 1278|  6.15k|        goto bad; /* Critical */
 1279|  12.2k|    }
 1280|  4.89k|    break;
 1281|  3.19M|  default:
  ------------------
  |  Branch (1281:3): [True: 3.19M, False: 127k]
  ------------------
 1282|  3.19M|    goto bad;
 1283|  3.32M|  }
 1284|  54.0k|  return 1;
 1285|  3.27M|bad:
 1286|  3.27M|  return 0;
 1287|  3.32M|}
coap_pdu.c:next_option_safe:
 1053|  12.1M|next_option_safe(coap_opt_t **optp, size_t *length, uint16_t *max_opt) {
 1054|  12.1M|  coap_option_t option;
 1055|  12.1M|  size_t optsize;
 1056|       |
 1057|  12.1M|  assert(optp);
  ------------------
  |  Branch (1057:3): [True: 12.1M, False: 0]
  ------------------
 1058|  12.1M|  assert(*optp);
  ------------------
  |  Branch (1058:3): [True: 12.1M, False: 0]
  ------------------
 1059|  12.1M|  assert(length);
  ------------------
  |  Branch (1059:3): [True: 12.1M, False: 0]
  ------------------
 1060|       |
 1061|  12.1M|  optsize = coap_opt_parse(*optp, *length, &option);
 1062|  12.1M|  assert(optsize <= *length);
  ------------------
  |  Branch (1062:3): [True: 12.1M, False: 0]
  ------------------
 1063|       |
 1064|       |  /* signal an error if this option would exceed the
 1065|       |   * allowed number space */
 1066|  12.1M|  if ((uint32_t)(*max_opt) + option.delta > COAP_MAX_OPT) {
  ------------------
  |  |  105|  12.1M|#define COAP_MAX_OPT 65535 /**< the highest option number we know */
  ------------------
  |  Branch (1066:7): [True: 30, False: 12.1M]
  ------------------
 1067|     30|    return 0;
 1068|     30|  }
 1069|  12.1M|  *max_opt += option.delta;
 1070|  12.1M|  *optp += optsize;
 1071|  12.1M|  *length -= optsize;
 1072|       |
 1073|  12.1M|  return optsize;
 1074|  12.1M|}
coap_pdu.c:write_prefix:
 1413|   114k|write_prefix(char **obp, size_t *len, const char *prf, size_t prflen) {
 1414|       |  /* Make sure space for null terminating byte */
 1415|   114k|  if (*len < prflen +1) {
  ------------------
  |  Branch (1415:7): [True: 50, False: 114k]
  ------------------
 1416|     50|    return 0;
 1417|     50|  }
 1418|       |
 1419|   114k|  memcpy(*obp, prf, prflen);
 1420|   114k|  *obp += prflen;
 1421|   114k|  *len -= prflen;
 1422|   114k|  return 1;
 1423|   114k|}
coap_pdu.c:write_char:
 1426|  1.14M|write_char(char **obp, size_t *len, int c, int printable) {
 1427|       |  /* Make sure space for null terminating byte */
 1428|  1.14M|  if (*len < 2 +1) {
  ------------------
  |  Branch (1428:7): [True: 970, False: 1.14M]
  ------------------
 1429|    970|    return 0;
 1430|    970|  }
 1431|       |
 1432|  1.14M|  if (!printable) {
  ------------------
  |  Branch (1432:7): [True: 571k, False: 571k]
  ------------------
 1433|   571k|    const uint8_t hex[] = "0123456789abcdef";
 1434|   571k|    (*obp)[0] = hex[(c & 0xf0) >> 4];
 1435|   571k|    (*obp)[1] = hex[c & 0x0f];
 1436|   571k|  } else {
 1437|   571k|    (*obp)[0] = isprint(c) ? c : '.';
  ------------------
  |  Branch (1437:17): [True: 103k, False: 467k]
  ------------------
 1438|   571k|    (*obp)[1] = ' ';
 1439|   571k|  }
 1440|  1.14M|  *obp += 2;
 1441|  1.14M|  *len -= 2;
 1442|  1.14M|  return 1;
 1443|  1.14M|}

coap_prng_init_lkd:
  180|  3.16k|coap_prng_init_lkd(unsigned int seed) {
  181|  3.16k|#ifdef HAVE_GETRANDOM
  182|       |  /* No seed to seed the random source if getrandom() is used */
  183|  3.16k|  (void)seed;
  184|       |#elif defined(HAVE_RANDOM)
  185|       |  srandom(seed);
  186|       |#else /* !HAVE_GETRANDOM  && !HAVE_RANDOM */
  187|       |  srand(seed);
  188|       |#endif /* !HAVE_GETRANDOM */
  189|  3.16k|}
coap_prng_lkd:
  192|  3.16k|coap_prng_lkd(void *buf, size_t len) {
  193|  3.16k|  if (!rand_func) {
  ------------------
  |  Branch (193:7): [True: 0, False: 3.16k]
  ------------------
  194|      0|    return 0;
  195|      0|  }
  196|       |
  197|  3.16k|  return rand_func(buf, len);
  198|  3.16k|}
coap_prng.c:coap_prng_default:
  110|  3.16k|coap_prng_default(void *buf, size_t len) {
  111|       |#if defined(MBEDTLS_ENTROPY_HARDWARE_ALT)
  112|       |  /* mbedtls_hardware_poll() returns 0 on success */
  113|       |  return (mbedtls_hardware_poll(NULL, buf, len, NULL) ? 0 : 1);
  114|       |
  115|       |#elif defined(__ZEPHYR__)
  116|       |  /* Use Zephyr's cryptographically secure random number generator */
  117|       |  if (!buf || len == 0) {
  118|       |    return 0;
  119|       |  }
  120|       |
  121|       |  sys_rand_get(buf, len);
  122|       |  return 1;
  123|       |
  124|       |#elif defined(HAVE_GETRANDOM)
  125|  3.16k|  return (getrandom(buf, len, 0) > 0) ? 1 : 0;
  ------------------
  |  Branch (125:10): [True: 3.16k, False: 0]
  ------------------
  126|       |
  127|       |#elif defined(HAVE_RANDOM)
  128|       |#define RAND_BYTES (RAND_MAX >= 0xffffff ? 3 : (RAND_MAX >= 0xffff ? 2 : 1))
  129|       |  unsigned char *dst = (unsigned char *)buf;
  130|       |
  131|       |  if (len) {
  132|       |    uint8_t byte_counter = RAND_BYTES;
  133|       |    uint32_t r_v = random();
  134|       |
  135|       |    while (1) {
  136|       |      *dst++ = r_v & 0xFF;
  137|       |      if (!--len) {
  138|       |        break;
  139|       |      }
  140|       |      if (--byte_counter) {
  141|       |        r_v >>= 8;
  142|       |      } else {
  143|       |        r_v = random();
  144|       |        byte_counter = RAND_BYTES;
  145|       |      }
  146|       |    }
  147|       |  }
  148|       |  return 1;
  149|       |#elif defined(RIOT_VERSION)
  150|       |#include <random.h>
  151|       |  random_bytes(buf, len);
  152|       |  return 1;
  153|       |
  154|       |#elif defined(WITH_CONTIKI)
  155|       |  return csprng_rand(buf, len);
  156|       |
  157|       |#elif defined(_WIN32)
  158|       |  return coap_prng_impl(buf,len);
  159|       |
  160|       |#else /* !MBEDTLS_ENTROPY_HARDWARE_ALT && !HAVE_GETRANDOM &&
  161|       |         !HAVE_RANDOM && !_WIN32 */
  162|       |#error "CVE-2021-34430: using rand() for crypto randoms is not secure!"
  163|       |#error "Please update you C-library and rerun the auto-configuration."
  164|       |  unsigned char *dst = (unsigned char *)buf;
  165|       |  while (len--)
  166|       |    *dst++ = rand() & 0xFF;
  167|       |  return 1;
  168|       |#endif /* !MBEDTLS_ENTROPY_HARDWARE_ALT && !HAVE_GETRANDOM &&
  169|       |          !HAVE_RANDOM && !_WIN32 */
  170|  3.16k|}

coap_new_string:
   21|  1.43k|coap_new_string(size_t size) {
   22|  1.43k|  coap_string_t *s;
   23|       |#if defined(WITH_LWIP) && MEMP_USE_CUSTOM_POOLS && ! MEM_USE_POOLS
   24|       |  if (size >= MEMP_LEN_COAPSTRING) {
   25|       |    coap_log_crit("coap_new_string: size too large (%" PRIuS " +1 > MEMP_LEN_COAPSTRING)\n",
   26|       |                  size);
   27|       |    return NULL;
   28|       |  }
   29|       |#endif /* WITH_LWIP && MEMP_USE_CUSTOM_POOLS */
   30|       |  /* Check no overflow (including a 8 byte small headroom) */
   31|  1.43k|  if (size > SIZE_MAX - sizeof(coap_str_bin_union_t) - 1 - 8) {
  ------------------
  |  Branch (31:7): [True: 0, False: 1.43k]
  ------------------
   32|      0|    return NULL;
   33|      0|  }
   34|       |
   35|  1.43k|  s = (coap_string_t *)coap_malloc_type(COAP_STRING,
   36|  1.43k|                                        sizeof(coap_str_bin_union_t) + size + 1);
   37|  1.43k|  if (!s) {
  ------------------
  |  Branch (37:7): [True: 0, False: 1.43k]
  ------------------
   38|      0|    coap_log_crit("coap_new_string: malloc: failed\n");
  ------------------
  |  |   96|      0|#define coap_log_crit(...) coap_log(COAP_LOG_CRIT, __VA_ARGS__)
  |  |  ------------------
  |  |  |  |  290|      0|#define coap_log(level, ...) do { \
  |  |  |  |  291|      0|    if ((level) < (coap_get_log_level() + 1)) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (291:9): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  292|      0|      coap_log_impl((level), __VA_ARGS__); \
  |  |  |  |  293|      0|  } while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (293:11): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
   39|      0|    return NULL;
   40|      0|  }
   41|       |
   42|  1.43k|  memset(s, 0, sizeof(coap_str_bin_union_t));
   43|  1.43k|  s->s = ((unsigned char *)s) + sizeof(coap_str_bin_union_t);
   44|  1.43k|  s->s[size] = '\000';
   45|  1.43k|  s->length = size;
   46|  1.43k|  return s;
   47|  1.43k|}
coap_delete_string:
   50|  3.16k|coap_delete_string(coap_string_t *s) {
   51|  3.16k|  coap_free_type(COAP_STRING, s);
   52|  3.16k|}
coap_delete_binary:
  114|  3.16k|coap_delete_binary(coap_binary_t *s) {
  115|  3.16k|  coap_free_type(COAP_STRING, s);
  116|  3.16k|}

coap_tcp_is_supported:
   35|      4|coap_tcp_is_supported(void) {
   36|      4|  return !COAP_DISABLE_TCP;
  ------------------
  |  |   23|      4|#define COAP_DISABLE_TCP 0
  ------------------
   37|      4|}

coap_clock_init:
   68|  3.16k|coap_clock_init(void) {
   69|  3.16k|#ifdef COAP_CLOCK
   70|  3.16k|  struct timespec tv;
   71|  3.16k|  clock_gettime(COAP_CLOCK, &tv);
  ------------------
  |  |   43|  3.16k|#define COAP_CLOCK CLOCK_REALTIME
  ------------------
   72|       |#else /* _POSIX_TIMERS */
   73|       |  struct timeval tv;
   74|       |  gettimeofday(&tv, NULL);
   75|       |#endif /* not _POSIX_TIMERS */
   76|       |
   77|  3.16k|  coap_clock_offset = tv.tv_sec;
   78|  3.16k|}
coap_ticks:
   90|  3.16k|coap_ticks(coap_tick_t *t) {
   91|  3.16k|  coap_tick_t tmp;
   92|       |
   93|  3.16k|#ifdef COAP_CLOCK
   94|  3.16k|  struct timespec tv;
   95|  3.16k|  clock_gettime(COAP_CLOCK, &tv);
  ------------------
  |  |   43|  3.16k|#define COAP_CLOCK CLOCK_REALTIME
  ------------------
   96|       |  /* Possible errors are (see clock_gettime(2)):
   97|       |   *  EFAULT tp points outside the accessible address space.
   98|       |   *  EINVAL The clk_id specified is not supported on this system.
   99|       |   * Both cases should not be possible here.
  100|       |   */
  101|       |
  102|  3.16k|  tmp = SHR_FP(tv.tv_nsec * Q(FRAC, (COAP_TICKS_PER_SECOND/1000000000.0)), FRAC);
  ------------------
  |  |   87|  3.16k|#define SHR_FP(val,frac) (((coap_tick_t)((val) + (1 << ((frac) - 1)))) >> (frac))
  ------------------
  103|       |#else /* _POSIX_TIMERS */
  104|       |  /* Fall back to gettimeofday() */
  105|       |
  106|       |  struct timeval tv;
  107|       |  gettimeofday(&tv, NULL);
  108|       |  /* Possible errors are (see gettimeofday(2)):
  109|       |   *  EFAULT One of tv or tz pointed outside the accessible address space.
  110|       |   *  EINVAL Timezone (or something else) is invalid.
  111|       |   * Both cases should not be possible here.
  112|       |   */
  113|       |
  114|       |  tmp = SHR_FP(tv.tv_usec * Q(FRAC, (COAP_TICKS_PER_SECOND/1000000.0)), FRAC);
  115|       |#endif /* not _POSIX_TIMERS */
  116|       |
  117|       |  /* Finally, convert temporary FP representation to multiple of
  118|       |   * COAP_TICKS_PER_SECOND */
  119|  3.16k|  *t = tmp + (tv.tv_sec - coap_clock_offset) * COAP_TICKS_PER_SECOND;
  ------------------
  |  |  164|  3.16k|#define COAP_TICKS_PER_SECOND ((coap_tick_t)(1000U))
  ------------------
  120|  3.16k|}
coap_ticks_to_rt_us:
  128|  3.16k|coap_ticks_to_rt_us(coap_tick_t t) {
  129|  3.16k|  return (uint64_t)coap_clock_offset * 1000000 + (uint64_t)t * 1000000 / COAP_TICKS_PER_SECOND;
  ------------------
  |  |  164|  3.16k|#define COAP_TICKS_PER_SECOND ((coap_tick_t)(1000U))
  ------------------
  130|  3.16k|}

coap_split_proxy_uri:
  351|    549|coap_split_proxy_uri(const uint8_t *str_var, size_t len, coap_uri_t *uri) {
  352|    549|  return coap_split_uri_sub(str_var, len, uri, COAP_URI_CHECK_PROXY);
  353|    549|}
coap_check_dots:
  668|  5.92M|coap_check_dots(const uint8_t *s, size_t len) {
  669|  5.92M|  uint8_t p;
  670|       |
  671|  5.92M|  if (!len)
  ------------------
  |  Branch (671:7): [True: 5.78M, False: 138k]
  ------------------
  672|  5.78M|    return 0;
  673|       |
  674|   138k|  p = *s;
  675|       |
  676|       |  /* Check 'first' char */
  677|   138k|  if (p == '%' && len >=3) {
  ------------------
  |  Branch (677:7): [True: 3.86k, False: 135k]
  |  Branch (677:19): [True: 3.63k, False: 224]
  ------------------
  678|  3.63k|    if (s[1] == '2' && (s[2] == 'E' || s[2] == 'e')) {
  ------------------
  |  Branch (678:9): [True: 747, False: 2.89k]
  |  Branch (678:25): [True: 219, False: 528]
  |  Branch (678:40): [True: 276, False: 252]
  ------------------
  679|    495|      s += 2;
  680|    495|      len -= 2;
  681|    495|    }
  682|  3.63k|    p = '.';
  683|  3.63k|  }
  684|   138k|  if (p != '.')
  ------------------
  |  Branch (684:7): [True: 134k, False: 4.88k]
  ------------------
  685|   134k|    return 0;
  686|  4.88k|  if (len == 1)
  ------------------
  |  Branch (686:7): [True: 1.23k, False: 3.64k]
  ------------------
  687|  1.23k|    return 1;
  688|       |
  689|       |  /* Check 'second' char, first is '.' */
  690|  3.64k|  s++;
  691|  3.64k|  len--;
  692|  3.64k|  assert(len);
  ------------------
  |  Branch (692:3): [True: 3.64k, False: 0]
  ------------------
  693|  3.64k|  p = *s;
  694|  3.64k|  if (p == '%' && len >=3) {
  ------------------
  |  Branch (694:7): [True: 2.69k, False: 943]
  |  Branch (694:19): [True: 2.41k, False: 284]
  ------------------
  695|  2.41k|    if (s[1] == '2' && (s[2] == 'E' || s[2] == 'e')) {
  ------------------
  |  Branch (695:9): [True: 2.05k, False: 356]
  |  Branch (695:25): [True: 216, False: 1.84k]
  |  Branch (695:40): [True: 1.48k, False: 353]
  ------------------
  696|  1.70k|      len -= 2;
  697|  1.70k|    }
  698|  2.41k|    p = '.';
  699|  2.41k|  }
  700|  3.64k|  if (p != '.')
  ------------------
  |  Branch (700:7): [True: 1.07k, False: 2.56k]
  ------------------
  701|  1.07k|    return 0;
  702|  2.56k|  if (len == 1)
  ------------------
  |  Branch (702:7): [True: 1.76k, False: 803]
  ------------------
  703|  1.76k|    return 2;
  704|       |
  705|    803|  return 0;
  706|  2.56k|}
coap_get_query:
 1103|  1.58k|coap_get_query(const coap_pdu_t *request) {
 1104|  1.58k|  coap_opt_iterator_t opt_iter;
 1105|  1.58k|  coap_opt_filter_t f;
 1106|  1.58k|  coap_opt_t *q;
 1107|  1.58k|  coap_string_t *query = NULL;
 1108|  1.58k|  size_t length = 0;
 1109|  1.58k|  static const uint8_t hex[] = "0123456789ABCDEF";
 1110|       |
 1111|  1.58k|  coap_option_filter_clear(&f);
 1112|  1.58k|  coap_option_filter_set(&f, COAP_OPTION_URI_QUERY);
 1113|  1.58k|  coap_option_iterator_init(request, &opt_iter, &f);
 1114|  41.6k|  while ((q = coap_option_next(&opt_iter))) {
  ------------------
  |  Branch (1114:10): [True: 40.0k, False: 1.58k]
  ------------------
 1115|  40.0k|    uint16_t seg_len = coap_opt_length(q), i;
 1116|  40.0k|    const uint8_t *seg= coap_opt_value(q);
 1117|   151k|    for (i = 0; i < seg_len; i++) {
  ------------------
  |  Branch (1117:17): [True: 111k, False: 40.0k]
  ------------------
 1118|   111k|      if (is_unescaped_in_query(seg[i]))
  ------------------
  |  Branch (1118:11): [True: 5.84k, False: 105k]
  ------------------
 1119|  5.84k|        length += 1;
 1120|   105k|      else
 1121|   105k|        length += 3;
 1122|   111k|    }
 1123|  40.0k|    length += 1;
 1124|  40.0k|  }
 1125|  1.58k|  if (length > 0)
  ------------------
  |  Branch (1125:7): [True: 283, False: 1.30k]
  ------------------
 1126|    283|    length -= 1;
 1127|  1.58k|  if (length > 0) {
  ------------------
  |  Branch (1127:7): [True: 283, False: 1.30k]
  ------------------
 1128|    283|    query = coap_new_string(length);
 1129|    283|    if (query) {
  ------------------
  |  Branch (1129:9): [True: 283, False: 0]
  ------------------
 1130|    283|      query->length = length;
 1131|    283|      unsigned char *s = query->s;
 1132|    283|      coap_option_iterator_init(request, &opt_iter, &f);
 1133|  40.3k|      while ((q = coap_option_next(&opt_iter))) {
  ------------------
  |  Branch (1133:14): [True: 40.0k, False: 283]
  ------------------
 1134|  40.0k|        if (s != query->s)
  ------------------
  |  Branch (1134:13): [True: 39.7k, False: 283]
  ------------------
 1135|  39.7k|          *s++ = '&';
 1136|  40.0k|        uint16_t seg_len = coap_opt_length(q), i;
 1137|  40.0k|        const uint8_t *seg= coap_opt_value(q);
 1138|   151k|        for (i = 0; i < seg_len; i++) {
  ------------------
  |  Branch (1138:21): [True: 111k, False: 40.0k]
  ------------------
 1139|   111k|          if (is_unescaped_in_query(seg[i])) {
  ------------------
  |  Branch (1139:15): [True: 5.84k, False: 105k]
  ------------------
 1140|  5.84k|            *s++ = seg[i];
 1141|   105k|          } else {
 1142|   105k|            *s++ = '%';
 1143|   105k|            *s++ = hex[seg[i]>>4];
 1144|   105k|            *s++ = hex[seg[i]&0x0F];
 1145|   105k|          }
 1146|   111k|        }
 1147|  40.0k|      }
 1148|    283|    }
 1149|    283|  }
 1150|  1.58k|  return query;
 1151|  1.58k|}
coap_map_abbrev_uri_path:
 1154|     15|coap_map_abbrev_uri_path(coap_upa_chain_t *chain, uint32_t value) {
 1155|     15|  while (chain) {
  ------------------
  |  Branch (1155:10): [True: 0, False: 15]
  ------------------
 1156|      0|    coap_upa_chain_t *next = chain->next;
 1157|       |
 1158|      0|    if (chain->upa_value == value) {
  ------------------
  |  Branch (1158:9): [True: 0, False: 0]
  ------------------
 1159|      0|      return chain->upa_path;
 1160|      0|    }
 1161|      0|    chain = next;
 1162|      0|  }
 1163|     15|  return NULL;
 1164|     15|}
coap_get_uri_path:
 1182|  1.58k|coap_get_uri_path(const coap_pdu_t *request) {
 1183|  1.58k|  coap_opt_iterator_t opt_iter;
 1184|  1.58k|  coap_opt_filter_t f;
 1185|  1.58k|  coap_opt_t *q;
 1186|  1.58k|  coap_string_t *uri_path = NULL;
 1187|  1.58k|  size_t length = 0;
 1188|  1.58k|  static const uint8_t hex[] = "0123456789ABCDEF";
 1189|       |
 1190|  1.58k|  q = coap_check_option(request, COAP_OPTION_URI_PATH_ABB, &opt_iter);
 1191|  1.58k|  if (q) {
  ------------------
  |  Branch (1191:7): [True: 31, False: 1.55k]
  ------------------
 1192|     31|    uint32_t value;
 1193|     31|    const char *exp;
 1194|     31|    if (coap_check_option(request, COAP_OPTION_PROXY_URI, &opt_iter) ||
  ------------------
  |  Branch (1194:9): [True: 8, False: 23]
  ------------------
 1195|     23|        coap_check_option(request, COAP_OPTION_URI_PATH, &opt_iter)) {
  ------------------
  |  Branch (1195:9): [True: 8, False: 15]
  ------------------
 1196|     16|      return NULL;
 1197|     16|    }
 1198|     15|    value = coap_decode_var_bytes(coap_opt_value(q), coap_opt_length(q));
 1199|     15|    exp = coap_map_abbrev_uri_path(coap_upa_server_mapping_chain, value);
 1200|     15|    if (exp) {
  ------------------
  |  Branch (1200:9): [True: 0, False: 15]
  ------------------
 1201|      0|      uri_path = coap_new_string(strlen(exp));
 1202|      0|      if (uri_path) {
  ------------------
  |  Branch (1202:11): [True: 0, False: 0]
  ------------------
 1203|      0|        memcpy(uri_path->s, exp, strlen(exp));
 1204|      0|      }
 1205|      0|      return uri_path;
 1206|      0|    }
 1207|     15|    return NULL;
 1208|     15|  }
 1209|  1.55k|  q = coap_check_option(request, COAP_OPTION_PROXY_URI, &opt_iter);
 1210|  1.55k|  if (q) {
  ------------------
  |  Branch (1210:7): [True: 549, False: 1.00k]
  ------------------
 1211|    549|    coap_uri_t uri;
 1212|       |
 1213|    549|    if (coap_split_proxy_uri(coap_opt_value(q),
  ------------------
  |  Branch (1213:9): [True: 396, False: 153]
  ------------------
 1214|    549|                             coap_opt_length(q), &uri) < 0) {
 1215|    396|      return NULL;
 1216|    396|    }
 1217|    153|    uri_path = coap_new_string(uri.path.length);
 1218|    153|    if (uri_path && uri.path.length) {
  ------------------
  |  Branch (1218:9): [True: 153, False: 0]
  |  Branch (1218:21): [True: 36, False: 117]
  ------------------
 1219|     36|      memcpy(uri_path->s, uri.path.s, uri.path.length);
 1220|     36|    }
 1221|    153|    return uri_path;
 1222|    549|  }
 1223|       |
 1224|  1.00k|  coap_option_filter_clear(&f);
 1225|  1.00k|  coap_option_filter_set(&f, COAP_OPTION_URI_PATH);
 1226|  1.00k|  coap_option_iterator_init(request, &opt_iter, &f);
 1227|  5.88M|  while ((q = coap_option_next(&opt_iter))) {
  ------------------
  |  Branch (1227:10): [True: 5.88M, False: 1.00k]
  ------------------
 1228|  5.88M|    uint16_t seg_len = coap_opt_length(q), i;
 1229|  5.88M|    const uint8_t *seg = coap_opt_value(q);
 1230|  7.86M|    for (i = 0; i < seg_len; i++) {
  ------------------
  |  Branch (1230:17): [True: 1.97M, False: 5.88M]
  ------------------
 1231|  1.97M|      if (is_unescaped_in_path(seg[i]))
  ------------------
  |  Branch (1231:11): [True: 46.4k, False: 1.92M]
  ------------------
 1232|  46.4k|        length += 1;
 1233|  1.92M|      else
 1234|  1.92M|        length += 3;
 1235|  1.97M|    }
 1236|       |    /* bump for the leading "/" */
 1237|  5.88M|    length += 1;
 1238|  5.88M|  }
 1239|       |  /* The first entry does not have a leading "/" */
 1240|  1.00k|  if (length > 0)
  ------------------
  |  Branch (1240:7): [True: 378, False: 625]
  ------------------
 1241|    378|    length -= 1;
 1242|       |
 1243|       |  /* if 0, either no URI_PATH Option, or the first one was empty */
 1244|  1.00k|  uri_path = coap_new_string(length);
 1245|  1.00k|  if (uri_path) {
  ------------------
  |  Branch (1245:7): [True: 1.00k, False: 0]
  ------------------
 1246|  1.00k|    uri_path->length = length;
 1247|  1.00k|    unsigned char *s = uri_path->s;
 1248|  1.00k|    int n = 0;
 1249|  1.00k|    coap_option_iterator_init(request, &opt_iter, &f);
 1250|  5.88M|    while ((q = coap_option_next(&opt_iter))) {
  ------------------
  |  Branch (1250:12): [True: 5.88M, False: 1.00k]
  ------------------
 1251|  5.88M|      if (n++) {
  ------------------
  |  Branch (1251:11): [True: 5.88M, False: 378]
  ------------------
 1252|  5.88M|        *s++ = '/';
 1253|  5.88M|      }
 1254|  5.88M|      uint16_t seg_len = coap_opt_length(q), i;
 1255|  5.88M|      const uint8_t *seg= coap_opt_value(q);
 1256|  7.86M|      for (i = 0; i < seg_len; i++) {
  ------------------
  |  Branch (1256:19): [True: 1.97M, False: 5.88M]
  ------------------
 1257|  1.97M|        if (is_unescaped_in_path(seg[i])) {
  ------------------
  |  Branch (1257:13): [True: 46.4k, False: 1.92M]
  ------------------
 1258|  46.4k|          *s++ = seg[i];
 1259|  1.92M|        } else {
 1260|  1.92M|          *s++ = '%';
 1261|  1.92M|          *s++ = hex[seg[i]>>4];
 1262|  1.92M|          *s++ = hex[seg[i]&0x0F];
 1263|  1.92M|        }
 1264|  1.97M|      }
 1265|  5.88M|    }
 1266|  1.00k|  }
 1267|  1.00k|  return uri_path;
 1268|  1.55k|}
coap_delete_upa_chain:
 1271|  6.33k|coap_delete_upa_chain(coap_upa_chain_t *chain) {
 1272|  6.33k|  while (chain) {
  ------------------
  |  Branch (1272:10): [True: 0, False: 6.33k]
  ------------------
 1273|      0|    coap_upa_chain_t *next = chain->next;
 1274|       |
 1275|      0|    coap_free_type(COAP_STRING, chain);
 1276|      0|    chain = next;
 1277|      0|  }
 1278|  6.33k|}
coap_uri.c:coap_split_uri_sub:
   84|    549|                   coap_uri_check_t check_proxy) {
   85|    549|  const uint8_t *p, *q;
   86|    549|  int res = 0;
   87|    549|  size_t i;
   88|    549|  int is_unix_domain = 0;
   89|    549|  int is_llc = 0;
   90|       |
   91|    549|  if (!str_var || !uri || len == 0)
  ------------------
  |  Branch (91:7): [True: 0, False: 549]
  |  Branch (91:19): [True: 0, False: 549]
  |  Branch (91:27): [True: 0, False: 549]
  ------------------
   92|      0|    return -1;
   93|       |
   94|    549|  memset(uri, 0, sizeof(coap_uri_t));
   95|    549|  uri->port = COAP_DEFAULT_PORT;
  ------------------
  |  |   39|    549|#define COAP_DEFAULT_PORT      5683 /* CoAP default UDP/TCP port */
  ------------------
   96|       |
   97|       |  /* search for scheme */
   98|    549|  p = str_var;
   99|    549|  if (*p == '/') {
  ------------------
  |  Branch (99:7): [True: 1, False: 548]
  ------------------
  100|       |    /* no scheme, host or port */
  101|      1|    if (check_proxy == COAP_URI_CHECK_PROXY) {
  ------------------
  |  Branch (101:9): [True: 1, False: 0]
  ------------------
  102|       |      /* Must have ongoing host if proxy definition */
  103|      1|      return -1;
  104|      1|    }
  105|      0|    q = p;
  106|      0|    goto path;
  107|      1|  }
  108|       |
  109|       |  /* find scheme terminating :// */
  110|  14.3k|  while (len >= 3 && !(p[0] == ':' && p[1] == '/' && p[2] == '/')) {
  ------------------
  |  Branch (110:10): [True: 14.2k, False: 51]
  |  Branch (110:24): [True: 1.28k, False: 13.0k]
  |  Branch (110:39): [True: 697, False: 584]
  |  Branch (110:54): [True: 497, False: 200]
  ------------------
  111|  13.7k|    ++p;
  112|  13.7k|    --len;
  113|  13.7k|  }
  114|    548|  if (len < 3) {
  ------------------
  |  Branch (114:7): [True: 51, False: 497]
  ------------------
  115|       |    /* scheme not defined with a :// terminator */
  116|     51|    res = -2;
  117|     51|    goto error;
  118|     51|  }
  119|  2.37k|  for (i = 0; i < COAP_URI_SCHEME_LAST; i++) {
  ------------------
  |  Branch (119:15): [True: 2.27k, False: 101]
  ------------------
  120|  2.27k|    if ((p - str_var) == (int)strlen(coap_uri_scheme[i].name) &&
  ------------------
  |  Branch (120:9): [True: 786, False: 1.48k]
  ------------------
  121|    786|        memcmp(str_var, coap_uri_scheme[i].name, p - str_var) == 0) {
  ------------------
  |  Branch (121:9): [True: 396, False: 390]
  ------------------
  122|    396|      if (check_proxy != COAP_URI_CHECK_PROXY && coap_uri_scheme[i].proxy_only) {
  ------------------
  |  Branch (122:11): [True: 0, False: 396]
  |  Branch (122:50): [True: 0, False: 0]
  ------------------
  123|      0|        coap_log_err("%.*s URI scheme not enabled (not a proxy)\n",
  ------------------
  |  |  102|      0|#define coap_log_err(...) coap_log(COAP_LOG_ERR, __VA_ARGS__)
  |  |  ------------------
  |  |  |  |  290|      0|#define coap_log(level, ...) do { \
  |  |  |  |  291|      0|    if ((level) < (coap_get_log_level() + 1)) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (291:9): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  292|      0|      coap_log_impl((level), __VA_ARGS__); \
  |  |  |  |  293|      0|  } while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (293:11): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  124|      0|                     (int)(p - str_var), str_var);
  125|      0|        return -1;
  126|      0|      }
  127|    396|      uri->scheme = coap_uri_scheme[i].scheme;
  128|    396|      uri->port = coap_uri_scheme[i].port;
  129|    396|      break;
  130|    396|    }
  131|  2.27k|  }
  132|    497|  if (i == COAP_URI_SCHEME_LAST) {
  ------------------
  |  Branch (132:7): [True: 101, False: 396]
  ------------------
  133|       |    /* scheme unknown */
  134|    101|    coap_log_err("%.*s URI scheme unknown\n", (int)(p - str_var), str_var);
  ------------------
  |  |  102|    101|#define coap_log_err(...) coap_log(COAP_LOG_ERR, __VA_ARGS__)
  |  |  ------------------
  |  |  |  |  290|    101|#define coap_log(level, ...) do { \
  |  |  |  |  291|    101|    if ((level) < (coap_get_log_level() + 1)) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (291:9): [True: 0, False: 101]
  |  |  |  |  ------------------
  |  |  |  |  292|    101|      coap_log_impl((level), __VA_ARGS__); \
  |  |  |  |  293|    101|  } while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (293:11): [Folded, False: 101]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  135|    101|    res = -1;
  136|    101|    goto error;
  137|    101|  }
  138|    396|  switch (uri->scheme) {
  139|    126|  case COAP_URI_SCHEME_COAP:
  ------------------
  |  Branch (139:3): [True: 126, False: 270]
  ------------------
  140|    126|    break;
  141|      3|  case COAP_URI_SCHEME_COAPS:
  ------------------
  |  Branch (141:3): [True: 3, False: 393]
  ------------------
  142|      3|    if (!coap_dtls_is_supported()) {
  ------------------
  |  Branch (142:9): [True: 0, False: 3]
  ------------------
  143|      0|      coap_log_err("coaps URI scheme not supported in this version of libcoap\n");
  ------------------
  |  |  102|      0|#define coap_log_err(...) coap_log(COAP_LOG_ERR, __VA_ARGS__)
  |  |  ------------------
  |  |  |  |  290|      0|#define coap_log(level, ...) do { \
  |  |  |  |  291|      0|    if ((level) < (coap_get_log_level() + 1)) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (291:9): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  292|      0|      coap_log_impl((level), __VA_ARGS__); \
  |  |  |  |  293|      0|  } while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (293:11): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  144|      0|      return -1;
  145|      0|    }
  146|      3|    break;
  147|      3|  case COAP_URI_SCHEME_COAP_TCP:
  ------------------
  |  Branch (147:3): [True: 3, False: 393]
  ------------------
  148|      3|    if (!coap_tcp_is_supported()) {
  ------------------
  |  Branch (148:9): [True: 0, False: 3]
  ------------------
  149|      0|      coap_log_err("coap+tcp URI scheme not supported in this version of libcoap\n");
  ------------------
  |  |  102|      0|#define coap_log_err(...) coap_log(COAP_LOG_ERR, __VA_ARGS__)
  |  |  ------------------
  |  |  |  |  290|      0|#define coap_log(level, ...) do { \
  |  |  |  |  291|      0|    if ((level) < (coap_get_log_level() + 1)) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (291:9): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  292|      0|      coap_log_impl((level), __VA_ARGS__); \
  |  |  |  |  293|      0|  } while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (293:11): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  150|      0|      return -1;
  151|      0|    }
  152|      3|    break;
  153|      3|  case COAP_URI_SCHEME_COAPS_TCP:
  ------------------
  |  Branch (153:3): [True: 1, False: 395]
  ------------------
  154|      1|    if (!coap_tls_is_supported()) {
  ------------------
  |  Branch (154:9): [True: 0, False: 1]
  ------------------
  155|      0|      coap_log_err("coaps+tcp URI scheme not supported in this version of libcoap\n");
  ------------------
  |  |  102|      0|#define coap_log_err(...) coap_log(COAP_LOG_ERR, __VA_ARGS__)
  |  |  ------------------
  |  |  |  |  290|      0|#define coap_log(level, ...) do { \
  |  |  |  |  291|      0|    if ((level) < (coap_get_log_level() + 1)) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (291:9): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  292|      0|      coap_log_impl((level), __VA_ARGS__); \
  |  |  |  |  293|      0|  } while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (293:11): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  156|      0|      return -1;
  157|      0|    }
  158|      1|    break;
  159|      1|  case COAP_URI_SCHEME_COAP_WS:
  ------------------
  |  Branch (159:3): [True: 1, False: 395]
  ------------------
  160|      1|    if (!coap_ws_is_supported()) {
  ------------------
  |  Branch (160:9): [True: 0, False: 1]
  ------------------
  161|      0|      coap_log_err("coap+ws URI scheme not supported in this version of libcoap\n");
  ------------------
  |  |  102|      0|#define coap_log_err(...) coap_log(COAP_LOG_ERR, __VA_ARGS__)
  |  |  ------------------
  |  |  |  |  290|      0|#define coap_log(level, ...) do { \
  |  |  |  |  291|      0|    if ((level) < (coap_get_log_level() + 1)) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (291:9): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  292|      0|      coap_log_impl((level), __VA_ARGS__); \
  |  |  |  |  293|      0|  } while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (293:11): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  162|      0|      return -1;
  163|      0|    }
  164|      1|    break;
  165|      1|  case COAP_URI_SCHEME_COAPS_WS:
  ------------------
  |  Branch (165:3): [True: 1, False: 395]
  ------------------
  166|      1|    if (!coap_wss_is_supported()) {
  ------------------
  |  Branch (166:9): [True: 0, False: 1]
  ------------------
  167|      0|      coap_log_err("coaps+ws URI scheme not supported in this version of libcoap\n");
  ------------------
  |  |  102|      0|#define coap_log_err(...) coap_log(COAP_LOG_ERR, __VA_ARGS__)
  |  |  ------------------
  |  |  |  |  290|      0|#define coap_log(level, ...) do { \
  |  |  |  |  291|      0|    if ((level) < (coap_get_log_level() + 1)) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (291:9): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  292|      0|      coap_log_impl((level), __VA_ARGS__); \
  |  |  |  |  293|      0|  } while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (293:11): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  168|      0|      return -1;
  169|      0|    }
  170|      1|    break;
  171|    259|  case COAP_URI_SCHEME_HTTP:
  ------------------
  |  Branch (171:3): [True: 259, False: 137]
  ------------------
  172|    261|  case COAP_URI_SCHEME_HTTPS:
  ------------------
  |  Branch (172:3): [True: 2, False: 394]
  ------------------
  173|       |    /* Not proxy, caught above.  For proxy, assume app is doing CoAP <> HTTP mapping. */
  174|    261|    break;
  175|      0|  case COAP_URI_SCHEME_LAST:
  ------------------
  |  Branch (175:3): [True: 0, False: 396]
  ------------------
  176|      0|  default:
  ------------------
  |  Branch (176:3): [True: 0, False: 396]
  ------------------
  177|      0|    coap_log_warn("Unsupported URI type %d\n", uri->scheme);
  ------------------
  |  |  108|      0|#define coap_log_warn(...) coap_log(COAP_LOG_WARN, __VA_ARGS__)
  |  |  ------------------
  |  |  |  |  290|      0|#define coap_log(level, ...) do { \
  |  |  |  |  291|      0|    if ((level) < (coap_get_log_level() + 1)) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (291:9): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  292|      0|      coap_log_impl((level), __VA_ARGS__); \
  |  |  |  |  293|      0|  } while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (293:11): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  178|      0|    return -1;
  179|    396|  }
  180|       |  /* skip :// */
  181|    396|  p += 3;
  182|    396|  len -= 3;
  183|       |
  184|       |  /* p points to beginning of Uri-Host */
  185|    396|  q = p;
  186|       |
  187|    396|  if (len && *p == '[') {
  ------------------
  |  Branch (187:7): [True: 388, False: 8]
  |  Branch (187:14): [True: 28, False: 360]
  ------------------
  188|       |    /* IPv6 address reference or Unix domain */
  189|     28|    ++p;
  190|     28|    ++q;
  191|     28|    --len;
  192|       |
  193|  3.65k|    while (len && *q != ']') {
  ------------------
  |  Branch (193:12): [True: 3.64k, False: 18]
  |  Branch (193:19): [True: 3.63k, False: 10]
  ------------------
  194|  3.63k|      ++q;
  195|  3.63k|      --len;
  196|  3.63k|    }
  197|       |
  198|     28|    if (!len || *q != ']' || p == q) {
  ------------------
  |  Branch (198:9): [True: 18, False: 10]
  |  Branch (198:17): [True: 0, False: 10]
  |  Branch (198:30): [True: 1, False: 9]
  ------------------
  199|     19|      res = -3;
  200|     19|      goto error;
  201|     19|    }
  202|       |
  203|      9|    COAP_SET_STR(&uri->host, q - p, p);
  ------------------
  |  |   52|      9|#define COAP_SET_STR(st,l,v) { (st)->length = (l), (st)->s = (v); }
  ------------------
  204|      9|    ++q;
  205|      9|    --len;
  206|      9|#if COAP_AF_LLC_SUPPORT
  207|    368|  } else if ((len >= LLC_HOST_LEN) && strncmp((const char *)p, "llc[", 4) == 0) {
  ------------------
  |  |  169|    368|#define LLC_HOST_LEN (4 + HW_ADDRSTRLEN + 4)
  |  |  ------------------
  |  |  |  |  167|    368|#define HW_ADDRSTRLEN 17
  |  |  ------------------
  ------------------
  |  Branch (207:14): [True: 224, False: 144]
  |  Branch (207:39): [True: 139, False: 85]
  ------------------
  208|    139|    unsigned long sap = 0;
  209|       |
  210|    139|    is_llc = 1;
  211|       |
  212|  5.38k|    while (len && *q != ']') {
  ------------------
  |  Branch (212:12): [True: 5.37k, False: 10]
  |  Branch (212:19): [True: 5.24k, False: 129]
  ------------------
  213|  5.24k|      ++q;
  214|  5.24k|      --len;
  215|  5.24k|    }
  216|       |
  217|    139|    if (!len || *q != ']' || p == q) {
  ------------------
  |  Branch (217:9): [True: 10, False: 129]
  |  Branch (217:17): [True: 0, False: 129]
  |  Branch (217:30): [True: 0, False: 129]
  ------------------
  218|     10|      res = -7;
  219|     10|      goto error;
  220|     10|    }
  221|       |
  222|    129|    ++q;
  223|    129|    --len;
  224|       |
  225|    129|    if (!len || *q != ':') {
  ------------------
  |  Branch (225:9): [True: 2, False: 127]
  |  Branch (225:17): [True: 17, False: 110]
  ------------------
  226|     19|      coap_log_warn("LLC SAP missing in URI\n");
  ------------------
  |  |  108|     19|#define coap_log_warn(...) coap_log(COAP_LOG_WARN, __VA_ARGS__)
  |  |  ------------------
  |  |  |  |  290|     19|#define coap_log(level, ...) do { \
  |  |  |  |  291|     19|    if ((level) < (coap_get_log_level() + 1)) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (291:9): [True: 0, False: 19]
  |  |  |  |  ------------------
  |  |  |  |  292|     19|      coap_log_impl((level), __VA_ARGS__); \
  |  |  |  |  293|     19|  } while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (293:11): [Folded, False: 19]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  227|     19|      res = -7;
  228|     19|      goto error;
  229|     19|    }
  230|       |
  231|    110|    ++q;
  232|    110|    --len;
  233|       |
  234|  1.91k|    while (len && isxdigit(*q)) {
  ------------------
  |  Branch (234:12): [True: 1.89k, False: 29]
  |  Branch (234:19): [True: 1.80k, False: 81]
  ------------------
  235|  1.80k|      if (*q >= 'a' && *q <= 'f')
  ------------------
  |  Branch (235:11): [True: 901, False: 908]
  |  Branch (235:24): [True: 901, False: 0]
  ------------------
  236|    901|        sap = sap * 16 + (*q - 'a' + 10);
  237|    908|      else if (*q >= 'A' && *q <= 'F')
  ------------------
  |  Branch (237:16): [True: 610, False: 298]
  |  Branch (237:29): [True: 610, False: 0]
  ------------------
  238|    610|        sap = sap * 16 + (*q - 'A' + 10);
  239|       |
  240|  1.80k|      ++q;
  241|  1.80k|      --len;
  242|  1.80k|    }
  243|       |
  244|    110|    if (sap > UINT8_MAX) {
  ------------------
  |  Branch (244:9): [True: 94, False: 16]
  ------------------
  245|     94|      coap_log_warn("LLC SAP invalid (%lu > 255)\n", sap);
  ------------------
  |  |  108|     94|#define coap_log_warn(...) coap_log(COAP_LOG_WARN, __VA_ARGS__)
  |  |  ------------------
  |  |  |  |  290|     94|#define coap_log(level, ...) do { \
  |  |  |  |  291|     94|    if ((level) < (coap_get_log_level() + 1)) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (291:9): [True: 0, False: 94]
  |  |  |  |  ------------------
  |  |  |  |  292|     94|      coap_log_impl((level), __VA_ARGS__); \
  |  |  |  |  293|     94|  } while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (293:11): [Folded, False: 94]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  246|     94|      res = -7;
  247|     94|      goto error;
  248|     94|    }
  249|       |
  250|     16|    COAP_SET_STR(&uri->host, q - p, p);
  ------------------
  |  |   52|     16|#define COAP_SET_STR(st,l,v) { (st)->length = (l), (st)->s = (v); }
  ------------------
  251|     16|#endif /* COAP_AF_LLC_SUPPORT */
  252|    229|  } else {
  253|       |    /* IPv4 address, FQDN or Unix domain socket */
  254|    229|    if (len >= 3 && p[0] == '%' && p[1] == '2' &&
  ------------------
  |  Branch (254:9): [True: 199, False: 30]
  |  Branch (254:21): [True: 35, False: 164]
  |  Branch (254:36): [True: 17, False: 18]
  ------------------
  255|     17|        (p[2] == 'F' || p[2] == 'f')) {
  ------------------
  |  Branch (255:10): [True: 1, False: 16]
  |  Branch (255:25): [True: 2, False: 14]
  ------------------
  256|       |      /* Unix domain definition */
  257|      3|      uri->port = 0;
  258|      3|      is_unix_domain = 1;
  259|      3|    }
  260|  6.99k|    while (len && *q != ':' && *q != '/' && *q != '?') {
  ------------------
  |  Branch (260:12): [True: 6.91k, False: 84]
  |  Branch (260:19): [True: 6.80k, False: 108]
  |  Branch (260:32): [True: 6.77k, False: 33]
  |  Branch (260:45): [True: 6.76k, False: 4]
  ------------------
  261|  6.76k|      ++q;
  262|  6.76k|      --len;
  263|  6.76k|    }
  264|       |
  265|    229|    if (p == q) {
  ------------------
  |  Branch (265:9): [True: 10, False: 219]
  ------------------
  266|     10|      res = -3;
  267|     10|      goto error;
  268|     10|    }
  269|       |
  270|    219|    if ((int)(q - p) > 255) {
  ------------------
  |  Branch (270:9): [True: 6, False: 213]
  ------------------
  271|      6|      coap_log_warn("Host name length too long (%d > 255)\n", (int)(q - p));
  ------------------
  |  |  108|      6|#define coap_log_warn(...) coap_log(COAP_LOG_WARN, __VA_ARGS__)
  |  |  ------------------
  |  |  |  |  290|      6|#define coap_log(level, ...) do { \
  |  |  |  |  291|      6|    if ((level) < (coap_get_log_level() + 1)) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (291:9): [True: 0, False: 6]
  |  |  |  |  ------------------
  |  |  |  |  292|      6|      coap_log_impl((level), __VA_ARGS__); \
  |  |  |  |  293|      6|  } while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (293:11): [Folded, False: 6]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  272|      6|      res = -6;
  273|      6|      goto error;
  274|      6|    }
  275|       |
  276|    213|    COAP_SET_STR(&uri->host, q - p, p);
  ------------------
  |  |   52|    213|#define COAP_SET_STR(st,l,v) { (st)->length = (l), (st)->s = (v); }
  ------------------
  277|    213|  }
  278|       |
  279|       |  /* check for Uri-Port (invalid for Unix) */
  280|    238|  if (len && *q == ':') {
  ------------------
  |  Branch (280:7): [True: 161, False: 77]
  |  Branch (280:14): [True: 109, False: 52]
  ------------------
  281|    109|    if (is_unix_domain || is_llc) {
  ------------------
  |  Branch (281:9): [True: 1, False: 108]
  |  Branch (281:27): [True: 2, False: 106]
  ------------------
  282|      3|      res = -5;
  283|      3|      goto error;
  284|      3|    }
  285|    106|    p = ++q;
  286|    106|    --len;
  287|       |
  288|    614|    while (len && isdigit(*q)) {
  ------------------
  |  Branch (288:12): [True: 556, False: 58]
  |  Branch (288:19): [True: 508, False: 48]
  ------------------
  289|    508|      ++q;
  290|    508|      --len;
  291|    508|    }
  292|       |
  293|    106|    if (p < q) {                /* explicit port number given */
  ------------------
  |  Branch (293:9): [True: 66, False: 40]
  ------------------
  294|     66|      long uri_port = 0;
  295|       |
  296|    543|      while ((p < q) && (uri_port <= UINT16_MAX))
  ------------------
  |  Branch (296:14): [True: 485, False: 58]
  |  Branch (296:25): [True: 477, False: 8]
  ------------------
  297|    477|        uri_port = uri_port * 10 + (*p++ - '0');
  298|       |
  299|       |      /* check if port number is in allowed range */
  300|     66|      if (uri_port > UINT16_MAX) {
  ------------------
  |  Branch (300:11): [True: 26, False: 40]
  ------------------
  301|     26|        coap_log_warn("Port number too big (%ld > 65535)\n", uri_port);
  ------------------
  |  |  108|     26|#define coap_log_warn(...) coap_log(COAP_LOG_WARN, __VA_ARGS__)
  |  |  ------------------
  |  |  |  |  290|     26|#define coap_log(level, ...) do { \
  |  |  |  |  291|     26|    if ((level) < (coap_get_log_level() + 1)) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (291:9): [True: 0, False: 26]
  |  |  |  |  ------------------
  |  |  |  |  292|     26|      coap_log_impl((level), __VA_ARGS__); \
  |  |  |  |  293|     26|  } while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (293:11): [Folded, False: 26]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  302|     26|        res = -4;
  303|     26|        goto error;
  304|     26|      }
  305|       |
  306|     40|      uri->port = (uint16_t)uri_port;
  307|     40|    }
  308|    106|  }
  309|       |
  310|    209|path:                 /* at this point, p must point to an absolute path */
  311|       |
  312|    209|  if (!len)
  ------------------
  |  Branch (312:7): [True: 113, False: 96]
  ------------------
  313|    113|    goto end;
  314|       |
  315|     96|  if (*q == '/') {
  ------------------
  |  Branch (315:7): [True: 40, False: 56]
  ------------------
  316|     40|    p = ++q;
  317|     40|    --len;
  318|       |
  319|  9.35k|    while (len && *q != '?') {
  ------------------
  |  Branch (319:12): [True: 9.31k, False: 36]
  |  Branch (319:19): [True: 9.31k, False: 4]
  ------------------
  320|  9.31k|      ++q;
  321|  9.31k|      --len;
  322|  9.31k|    }
  323|       |
  324|     40|    if (p < q) {
  ------------------
  |  Branch (324:9): [True: 36, False: 4]
  ------------------
  325|     36|      COAP_SET_STR(&uri->path, q - p, p);
  ------------------
  |  |   52|     36|#define COAP_SET_STR(st,l,v) { (st)->length = (l), (st)->s = (v); }
  ------------------
  326|     36|      p = q;
  327|     36|    }
  328|     40|  }
  329|       |
  330|       |  /* Uri_Query */
  331|     96|  if (len && *p == '?') {
  ------------------
  |  Branch (331:7): [True: 60, False: 36]
  |  Branch (331:14): [True: 4, False: 56]
  ------------------
  332|      4|    ++p;
  333|      4|    --len;
  334|      4|    COAP_SET_STR(&uri->query, len, p);
  ------------------
  |  |   52|      4|#define COAP_SET_STR(st,l,v) { (st)->length = (l), (st)->s = (v); }
  ------------------
  335|      4|    len = 0;
  336|      4|  }
  337|       |
  338|    209|end:
  339|    209|  return len ? -1 : 0;
  ------------------
  |  Branch (339:10): [True: 56, False: 153]
  ------------------
  340|       |
  341|    339|error:
  342|    339|  return res;
  343|     96|}
coap_uri.c:is_unescaped_in_query:
 1098|   222k|is_unescaped_in_query(const uint8_t c) {
 1099|   222k|  return is_unescaped_in_path(c) || c=='/' || c=='?';
  ------------------
  |  Branch (1099:10): [True: 11.1k, False: 211k]
  |  Branch (1099:37): [True: 558, False: 211k]
  |  Branch (1099:47): [True: 8, False: 211k]
  ------------------
 1100|   222k|}
coap_uri.c:is_unescaped_in_path:
 1089|  4.17M|is_unescaped_in_path(const uint8_t c) {
 1090|  4.17M|  return (c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') ||
  ------------------
  |  Branch (1090:11): [True: 132k, False: 4.04M]
  |  Branch (1090:23): [True: 5.67k, False: 126k]
  |  Branch (1090:37): [True: 109k, False: 4.05M]
  |  Branch (1090:49): [True: 45.1k, False: 64.6k]
  ------------------
 1091|  4.12M|         (c >= '0' && c <= '9') || c == '-' || c == '.' || c == '_' ||
  ------------------
  |  Branch (1091:11): [True: 109k, False: 4.01M]
  |  Branch (1091:23): [True: 9.64k, False: 99.8k]
  |  Branch (1091:36): [True: 6.24k, False: 4.10M]
  |  Branch (1091:48): [True: 1.69k, False: 4.10M]
  |  Branch (1091:60): [True: 1.08k, False: 4.10M]
  ------------------
 1092|  4.10M|         c == '~' || c == '!' || c == '$' || c == '\'' || c == '(' ||
  ------------------
  |  Branch (1092:10): [True: 2.65k, False: 4.10M]
  |  Branch (1092:22): [True: 2.42k, False: 4.10M]
  |  Branch (1092:34): [True: 1.23k, False: 4.09M]
  |  Branch (1092:46): [True: 1.31k, False: 4.09M]
  |  Branch (1092:59): [True: 1.27k, False: 4.09M]
  ------------------
 1093|  4.09M|         c == ')' || c == '*' || c == '+' || c == ',' || c == ';' ||
  ------------------
  |  Branch (1093:10): [True: 1.13k, False: 4.09M]
  |  Branch (1093:22): [True: 2.21k, False: 4.09M]
  |  Branch (1093:34): [True: 2.67k, False: 4.09M]
  |  Branch (1093:46): [True: 1.60k, False: 4.08M]
  |  Branch (1093:58): [True: 870, False: 4.08M]
  ------------------
 1094|  4.08M|         c=='=' || c==':' || c=='@' || c == '&';
  ------------------
  |  Branch (1094:10): [True: 2.03k, False: 4.08M]
  |  Branch (1094:20): [True: 12.5k, False: 4.07M]
  |  Branch (1094:30): [True: 2.36k, False: 4.07M]
  |  Branch (1094:40): [True: 202, False: 4.07M]
  ------------------
 1095|  4.17M|}

coap_ws_is_supported:
   38|      1|coap_ws_is_supported(void) {
   39|      1|  return coap_tcp_is_supported();
   40|      1|}
coap_wss_is_supported:
   43|      1|coap_wss_is_supported(void) {
   44|      1|  return coap_tls_is_supported();
   45|      1|}

LLVMFuzzerTestOneInput:
    4|  3.16k|LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
    5|  3.16k|  coap_pdu_t *pdu;
    6|       |
    7|  3.16k|  coap_startup();
    8|  3.16k|  pdu = coap_pdu_init(0, 0, 0, size);
    9|  3.16k|  if (pdu) {
  ------------------
  |  Branch (9:7): [True: 3.16k, False: 0]
  ------------------
   10|  3.16k|    coap_set_log_level(COAP_LOG_EMERG);
   11|  3.16k|    if (coap_pdu_parse(COAP_PROTO_UDP, data, size, pdu)) {
  ------------------
  |  Branch (11:9): [True: 1.58k, False: 1.58k]
  ------------------
   12|  1.58k|      coap_string_t *query = coap_get_query(pdu);
   13|  1.58k|      coap_string_t *uri_path = coap_get_uri_path(pdu);
   14|  1.58k|      coap_show_pdu(COAP_LOG_ERR, pdu);
   15|  1.58k|      coap_pdu_encode_header(pdu, COAP_PROTO_UDP);
   16|       |
   17|  1.58k|      coap_delete_string(query);
   18|  1.58k|      coap_delete_string(uri_path);
   19|  1.58k|    }
   20|  3.16k|    coap_delete_pdu(pdu);
   21|  3.16k|  }
   22|  3.16k|  coap_cleanup();
   23|  3.16k|  return 0;
   24|  3.16k|}

