coap_get_log_level:
  103|  1.72M|coap_get_log_level(void) {
  104|  1.72M|  return maxlog;
  105|  1.72M|}
coap_set_log_level:
  108|  3.20k|coap_set_log_level(coap_log_t level) {
  109|  3.20k|  if (level > COAP_MAX_LOGGING_LEVEL)
  ------------------
  |  |   48|  3.20k|#define COAP_MAX_LOGGING_LEVEL 8
  ------------------
  |  Branch (109:7): [True: 0, False: 3.20k]
  ------------------
  110|      0|    level = COAP_MAX_LOGGING_LEVEL;
  ------------------
  |  |   48|      0|#define COAP_MAX_LOGGING_LEVEL 8
  ------------------
  111|  3.20k|  maxlog = level;
  112|  3.20k|}
coap_show_pdu:
  812|  1.62k|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.62k|  unsigned char buf[USE_BUF_SIZE];
  821|  1.62k|  char outbuf[COAP_DEBUG_BUF_SIZE];
  822|  1.62k|#endif /* ! COAP_CONSTRAINED_STACK */
  823|  1.62k|  size_t buf_len = 0; /* takes the number of bytes written to buf */
  824|  1.62k|  int have_options = 0;
  825|  1.62k|  uint32_t i;
  826|  1.62k|  coap_opt_iterator_t opt_iter;
  827|  1.62k|  coap_opt_t *option;
  828|  1.62k|  int content_format = -1;
  829|  1.62k|  size_t data_len;
  830|  1.62k|  const uint8_t *data;
  831|  1.62k|  uint32_t opt_len;
  832|  1.62k|  const uint8_t *opt_val;
  833|  1.62k|  size_t outbuflen = 0;
  834|  1.62k|  int is_oscore_payload = 0;
  835|  1.62k|  const char *exp;
  836|  1.62k|  uint32_t value;
  837|       |
  838|       |  /* Save time if not needed */
  839|  1.62k|  if (level > coap_get_log_level())
  ------------------
  |  Branch (839:7): [True: 1.62k, False: 0]
  ------------------
  840|  1.62k|    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:
 1566|  3.20k|coap_debug_reset(void) {
 1567|       |  log_handler = NULL;
 1568|  3.20k|  maxlog = COAP_LOG_WARN;
 1569|  3.20k|  use_fprintf_for_show_pdu = 1;
 1570|  3.20k|  memset(&packet_loss_intervals, 0, sizeof(packet_loss_intervals));
 1571|  3.20k|  num_packet_loss_intervals = 0;
 1572|  3.20k|  packet_loss_level = 0;
 1573|  3.20k|  num_packet_fail_intervals = 0;
 1574|  3.20k|  packet_fail_level = 0;
 1575|  3.20k|  send_packet_count = 0;
 1576|  3.20k|}

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

coap_memory_init:
  554|  3.20k|coap_memory_init(void) {
  555|  3.20k|}
coap_malloc_type:
  558|  7.87k|coap_malloc_type(coap_memory_tag_t type, size_t size) {
  559|  7.87k|  void *ptr;
  560|       |
  561|  7.87k|  (void)type;
  562|  7.87k|  ptr = malloc(size);
  563|       |#if COAP_MEMORY_TYPE_TRACK
  564|       |  assert(type < COAP_MEM_TAG_LAST);
  565|       |  if (ptr) {
  566|       |    track_counts[type]++;
  567|       |    if (track_counts[type] > peak_counts[type])
  568|       |      peak_counts[type] = track_counts[type];
  569|       |  } else {
  570|       |    fail_counts[type]++;
  571|       |  }
  572|       |#endif /* COAP_MEMORY_TYPE_TRACK */
  573|  7.87k|  return ptr;
  574|  7.87k|}
coap_realloc_type:
  577|    576|coap_realloc_type(coap_memory_tag_t type, void *p, size_t size) {
  578|    576|  void *ptr;
  579|       |
  580|    576|  (void)type;
  581|    576|  ptr = realloc(p, size);
  582|       |#if COAP_MEMORY_TYPE_TRACK
  583|       |  if (ptr) {
  584|       |    assert(type < COAP_MEM_TAG_LAST);
  585|       |    if (!p)
  586|       |      track_counts[type]++;
  587|       |    if (track_counts[type] > peak_counts[type])
  588|       |      peak_counts[type] = track_counts[type];
  589|       |  } else {
  590|       |    fail_counts[type]++;
  591|       |  }
  592|       |#endif /* COAP_MEMORY_TYPE_TRACK */
  593|    576|  return ptr;
  594|    576|}
coap_free_type:
  597|  12.8k|coap_free_type(coap_memory_tag_t type, void *p) {
  598|  12.8k|  (void)type;
  599|       |#if COAP_MEMORY_TYPE_TRACK
  600|       |  assert(type < COAP_MEM_TAG_LAST);
  601|       |  if (p)
  602|       |    track_counts[type]--;
  603|       |#endif /* COAP_MEMORY_TYPE_TRACK */
  604|  12.8k|  free(p);
  605|  12.8k|}

coap_startup:
 5374|  3.20k|coap_startup(void) {
 5375|  3.20k|  coap_tick_t now;
 5376|  3.20k|#ifndef WITH_CONTIKI
 5377|  3.20k|  uint64_t us;
 5378|  3.20k|#endif /* !WITH_CONTIKI */
 5379|       |
 5380|  3.20k|  if (coap_started)
  ------------------
  |  Branch (5380:7): [True: 0, False: 3.20k]
  ------------------
 5381|      0|    return;
 5382|  3.20k|  coap_started = 1;
 5383|       |
 5384|       |#if COAP_THREAD_SAFE
 5385|       |  coap_lock_init(&global_lock);
 5386|       |  coap_mutex_init(&m_show_pdu);
 5387|       |  coap_mutex_init(&m_log_impl);
 5388|       |  coap_mutex_init(&m_io_threads);
 5389|       |#endif /* COAP_THREAD_SAFE */
 5390|       |
 5391|       |#if defined(HAVE_WINSOCK2_H)
 5392|       |  WORD wVersionRequested = MAKEWORD(2, 2);
 5393|       |  WSADATA wsaData;
 5394|       |  WSAStartup(wVersionRequested, &wsaData);
 5395|       |#endif
 5396|  3.20k|  coap_clock_init();
 5397|  3.20k|  coap_ticks(&now);
 5398|  3.20k|#ifndef WITH_CONTIKI
 5399|  3.20k|  us = coap_ticks_to_rt_us(now);
 5400|       |  /* Be accurate to the nearest (approx) us */
 5401|  3.20k|  coap_prng_init_lkd((unsigned int)us);
 5402|       |#else /* WITH_CONTIKI */
 5403|       |  coap_start_io_process();
 5404|       |#endif /* WITH_CONTIKI */
 5405|  3.20k|  coap_memory_init();
 5406|  3.20k|  coap_dtls_startup();
 5407|       |#ifdef WITH_LWIP
 5408|       |  coap_io_lwip_init();
 5409|       |#endif /* WITH_LWIP */
 5410|  3.20k|#if COAP_SERVER_SUPPORT
 5411|  3.20k|  static coap_str_const_t well_known = { sizeof(".well-known/core")-1,
 5412|  3.20k|                                         (const uint8_t *)".well-known/core"
 5413|  3.20k|                                       };
 5414|  3.20k|  memset(&resource_uri_wellknown, 0, sizeof(resource_uri_wellknown));
 5415|  3.20k|  resource_uri_wellknown.ref = 1;
 5416|  3.20k|  resource_uri_wellknown.handler[COAP_REQUEST_GET-1] = hnd_get_wellknown_lkd;
 5417|  3.20k|  resource_uri_wellknown.flags = COAP_RESOURCE_FLAGS_HAS_MCAST_SUPPORT;
  ------------------
  |  |   89|  3.20k|#define COAP_RESOURCE_FLAGS_HAS_MCAST_SUPPORT 0x8
  ------------------
 5418|  3.20k|  resource_uri_wellknown.uri_path = &well_known;
 5419|  3.20k|#endif /* COAP_SERVER_SUPPORT */
 5420|  3.20k|  send_recv_terminate = 0;
 5421|  3.20k|  coap_prng_lkd(&coap_unique_id, sizeof(coap_unique_id));
 5422|  3.20k|}
coap_cleanup:
 5425|  3.20k|coap_cleanup(void) {
 5426|  3.20k|  if (!coap_started)
  ------------------
  |  Branch (5426:7): [True: 0, False: 3.20k]
  ------------------
 5427|      0|    return;
 5428|  3.20k|  coap_started = 0;
 5429|       |#if defined(HAVE_WINSOCK2_H)
 5430|       |  WSACleanup();
 5431|       |#elif defined(WITH_CONTIKI)
 5432|       |  coap_stop_io_process();
 5433|       |#endif
 5434|       |#ifdef WITH_LWIP
 5435|       |  coap_io_lwip_cleanup();
 5436|       |#endif /* WITH_LWIP */
 5437|  3.20k|  coap_dtls_shutdown();
 5438|       |
 5439|  3.20k|  coap_delete_upa_chain(coap_upa_client_fallback_chain);
 5440|  3.20k|  coap_upa_client_fallback_chain = NULL;
 5441|  3.20k|  coap_delete_upa_chain(coap_upa_server_mapping_chain);
 5442|  3.20k|  coap_upa_server_mapping_chain = NULL;
 5443|       |#if COAP_THREAD_SAFE
 5444|       |  coap_mutex_destroy(&m_show_pdu);
 5445|       |  coap_mutex_destroy(&m_log_impl);
 5446|       |  coap_mutex_destroy(&m_io_threads);
 5447|       |#endif /* COAP_THREAD_SAFE */
 5448|       |
 5449|  3.20k|  coap_debug_reset();
 5450|  3.20k|}

coap_dtls_is_supported:
  191|      1|coap_dtls_is_supported(void) {
  192|      1|  if (SSLeay() < 0x10100000L) {
  ------------------
  |  Branch (192:7): [True: 0, False: 1]
  ------------------
  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|      1|#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|      1|  if (SSLeay() < 0x10101000L) {
  ------------------
  |  Branch (204:7): [True: 0, False: 1]
  ------------------
  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|      1|#endif /* OPENSSL_VERSION_NUMBER >= 0x10101000L */
  209|      1|  return 1;
  210|      1|}
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.20k|coap_dtls_startup(void) {
  305|  3.20k|  SSL_load_error_strings();
  306|  3.20k|  SSL_library_init();
  307|  3.20k|#if OPENSSL_VERSION_NUMBER < 0x40000000L
  308|       |  ENGINE_load_dynamic();
  309|  3.20k|#endif /* OPENSSL_VERSION_NUMBER < 0x40000000L */
  310|  3.20k|}
coap_dtls_shutdown:
  313|  3.20k|coap_dtls_shutdown(void) {
  314|  3.20k|#if OPENSSL_VERSION_NUMBER < 0x30000000L
  315|  3.20k|  if (pkcs11_engine) {
  ------------------
  |  Branch (315:7): [True: 0, False: 3.20k]
  ------------------
  316|       |    /* Release the functional reference from ENGINE_init() */
  317|      0|    ENGINE_finish(pkcs11_engine);
  318|      0|    pkcs11_engine = NULL;
  319|      0|  }
  320|  3.20k|  if (defined_engine) {
  ------------------
  |  Branch (320:7): [True: 0, False: 3.20k]
  ------------------
  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.20k]
  ------------------
  330|  3.20k|  coap_dtls_set_log_level(COAP_LOG_EMERG);
  331|  3.20k|}
coap_dtls_set_log_level:
  590|  3.20k|coap_dtls_set_log_level(coap_log_t level) {
  591|  3.20k|  dtls_log_level = level;
  592|  3.20k|}

coap_opt_parse:
   41|  60.2M|coap_opt_parse(const coap_opt_t *opt, size_t length, coap_option_t *result) {
   42|       |
   43|  60.2M|  const coap_opt_t *opt_start = opt; /* store where parsing starts  */
   44|       |
   45|  60.2M|  assert(opt);
  ------------------
  |  Branch (45:3): [True: 60.2M, False: 0]
  ------------------
   46|  60.2M|  assert(result);
  ------------------
  |  Branch (46:3): [True: 60.2M, False: 0]
  ------------------
   47|       |
   48|  60.2M|  if (length < 1)
  ------------------
  |  Branch (48:7): [True: 4.76k, False: 60.2M]
  ------------------
   49|  4.76k|    return 0;
   50|       |
   51|  60.2M|  result->delta = (*opt & 0xf0) >> 4;
   52|  60.2M|  result->length = *opt & 0x0f;
   53|       |
   54|  60.2M|  switch (result->delta) {
   55|    469|  case 15:
  ------------------
  |  Branch (55:3): [True: 469, False: 60.2M]
  ------------------
   56|    469|    if (*opt != COAP_PAYLOAD_START) {
  ------------------
  |  |   96|    469|#define COAP_PAYLOAD_START 0xFF /* payload marker */
  ------------------
  |  Branch (56:9): [True: 147, False: 322]
  ------------------
   57|    147|      coap_log_debug("ignored reserved option delta 15\n");
  ------------------
  |  |  126|    147|#define coap_log_debug(...) coap_log(COAP_LOG_DEBUG, __VA_ARGS__)
  |  |  ------------------
  |  |  |  |  290|    147|#define coap_log(level, ...) do { \
  |  |  |  |  291|    147|    if ((level) < (coap_get_log_level() + 1)) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (291:9): [True: 0, False: 147]
  |  |  |  |  ------------------
  |  |  |  |  292|    147|      coap_log_impl((level), __VA_ARGS__); \
  |  |  |  |  293|    147|  } while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (293:11): [Folded, False: 147]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
   58|    147|    }
   59|    469|    return 0;
   60|  1.24k|  case 14:
  ------------------
  |  Branch (60:3): [True: 1.24k, False: 60.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.24k|    ADVANCE_OPT_CHECK(opt,length,1);
  ------------------
  |  |   34|  1.24k|#define ADVANCE_OPT_CHECK(o,e,step) do { \
  |  |   35|  1.24k|    ADVANCE_OPT(o,e,step);               \
  |  |  ------------------
  |  |  |  |   22|  1.24k|#define ADVANCE_OPT(o,e,step) if ((e) < step) {           \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (22:35): [True: 0, False: 1.24k]
  |  |  |  |  ------------------
  |  |  |  |   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.24k|  } else {                                                \
  |  |  |  |   26|  1.24k|    (e) -= step;                                          \
  |  |  |  |   27|  1.24k|    (o) = ((o)) + step;                                   \
  |  |  |  |   28|  1.24k|  }
  |  |  ------------------
  |  |   36|  1.24k|    if ((e) < 1)                         \
  |  |  ------------------
  |  |  |  Branch (36:9): [True: 39, False: 1.20k]
  |  |  ------------------
  |  |   37|  1.24k|      return 0;                          \
  |  |   38|  1.24k|  } while (0)
  |  |  ------------------
  |  |  |  Branch (38:12): [Folded, False: 1.20k]
  |  |  ------------------
  ------------------
   65|  1.20k|    result->delta = ((*opt & 0xff) << 8) + 269;
   66|  1.20k|    if (result->delta < 269) {
  ------------------
  |  Branch (66:9): [True: 3, False: 1.19k]
  ------------------
   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.32k|  case 13:
  ------------------
  |  Branch (71:3): [True: 4.12k, False: 60.2M]
  ------------------
   72|  5.32k|    ADVANCE_OPT_CHECK(opt,length,1);
  ------------------
  |  |   34|  5.32k|#define ADVANCE_OPT_CHECK(o,e,step) do { \
  |  |   35|  5.32k|    ADVANCE_OPT(o,e,step);               \
  |  |  ------------------
  |  |  |  |   22|  5.32k|#define ADVANCE_OPT(o,e,step) if ((e) < step) {           \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (22:35): [True: 0, False: 5.32k]
  |  |  |  |  ------------------
  |  |  |  |   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.32k|  } else {                                                \
  |  |  |  |   26|  5.32k|    (e) -= step;                                          \
  |  |  |  |   27|  5.32k|    (o) = ((o)) + step;                                   \
  |  |  |  |   28|  5.32k|  }
  |  |  ------------------
  |  |   36|  5.32k|    if ((e) < 1)                         \
  |  |  ------------------
  |  |  |  Branch (36:9): [True: 87, False: 5.23k]
  |  |  ------------------
  |  |   37|  5.32k|      return 0;                          \
  |  |   38|  5.32k|  } while (0)
  |  |  ------------------
  |  |  |  Branch (38:12): [Folded, False: 5.23k]
  |  |  ------------------
  ------------------
   73|  5.23k|    result->delta += *opt & 0xff;
   74|  5.23k|    break;
   75|       |
   76|  60.2M|  default:
  ------------------
  |  Branch (76:3): [True: 60.2M, False: 5.83k]
  ------------------
   77|  60.2M|    ;
   78|  60.2M|  }
   79|       |
   80|  60.2M|  switch (result->length) {
   81|     93|  case 15:
  ------------------
  |  Branch (81:3): [True: 93, False: 60.2M]
  ------------------
   82|     93|    coap_log_debug("found reserved option length 15\n");
  ------------------
  |  |  126|     93|#define coap_log_debug(...) coap_log(COAP_LOG_DEBUG, __VA_ARGS__)
  |  |  ------------------
  |  |  |  |  290|     93|#define coap_log(level, ...) do { \
  |  |  |  |  291|     93|    if ((level) < (coap_get_log_level() + 1)) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (291:9): [True: 0, False: 93]
  |  |  |  |  ------------------
  |  |  |  |  292|     93|      coap_log_impl((level), __VA_ARGS__); \
  |  |  |  |  293|     93|  } while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (293:11): [Folded, False: 93]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
   83|     93|    return 0;
   84|  8.90k|  case 14:
  ------------------
  |  Branch (84:3): [True: 8.90k, False: 60.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|  8.90k|    ADVANCE_OPT_CHECK(opt,length,1);
  ------------------
  |  |   34|  8.90k|#define ADVANCE_OPT_CHECK(o,e,step) do { \
  |  |   35|  8.90k|    ADVANCE_OPT(o,e,step);               \
  |  |  ------------------
  |  |  |  |   22|  8.90k|#define ADVANCE_OPT(o,e,step) if ((e) < step) {           \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (22:35): [True: 0, False: 8.90k]
  |  |  |  |  ------------------
  |  |  |  |   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|  8.90k|  } else {                                                \
  |  |  |  |   26|  8.90k|    (e) -= step;                                          \
  |  |  |  |   27|  8.90k|    (o) = ((o)) + step;                                   \
  |  |  |  |   28|  8.90k|  }
  |  |  ------------------
  |  |   36|  8.90k|    if ((e) < 1)                         \
  |  |  ------------------
  |  |  |  Branch (36:9): [True: 45, False: 8.85k]
  |  |  ------------------
  |  |   37|  8.90k|      return 0;                          \
  |  |   38|  8.90k|  } while (0)
  |  |  ------------------
  |  |  |  Branch (38:12): [Folded, False: 8.85k]
  |  |  ------------------
  ------------------
   89|  8.85k|    result->length = ((*opt & 0xff) << 8) + 269;
   90|       |  /* fall through */
   91|   156k|  case 13:
  ------------------
  |  Branch (91:3): [True: 147k, False: 60.1M]
  ------------------
   92|   156k|    ADVANCE_OPT_CHECK(opt,length,1);
  ------------------
  |  |   34|   156k|#define ADVANCE_OPT_CHECK(o,e,step) do { \
  |  |   35|   156k|    ADVANCE_OPT(o,e,step);               \
  |  |  ------------------
  |  |  |  |   22|   156k|#define ADVANCE_OPT(o,e,step) if ((e) < step) {           \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (22:35): [True: 0, False: 156k]
  |  |  |  |  ------------------
  |  |  |  |   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|   156k|  } else {                                                \
  |  |  |  |   26|   156k|    (e) -= step;                                          \
  |  |  |  |   27|   156k|    (o) = ((o)) + step;                                   \
  |  |  |  |   28|   156k|  }
  |  |  ------------------
  |  |   36|   156k|    if ((e) < 1)                         \
  |  |  ------------------
  |  |  |  Branch (36:9): [True: 54, False: 156k]
  |  |  ------------------
  |  |   37|   156k|      return 0;                          \
  |  |   38|   156k|  } while (0)
  |  |  ------------------
  |  |  |  Branch (38:12): [Folded, False: 156k]
  |  |  ------------------
  ------------------
   93|   156k|    result->length += *opt & 0xff;
   94|   156k|    break;
   95|       |
   96|  60.1M|  default:
  ------------------
  |  Branch (96:3): [True: 60.1M, False: 156k]
  ------------------
   97|  60.1M|    ;
   98|  60.2M|  }
   99|       |
  100|       |  /* ADVANCE_OPT() is correct here */
  101|  60.2M|  ADVANCE_OPT(opt,length,1);
  ------------------
  |  |   22|  60.2M|#define ADVANCE_OPT(o,e,step) if ((e) < step) {           \
  |  |  ------------------
  |  |  |  Branch (22:35): [True: 0, False: 60.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|  60.2M|  } else {                                                \
  |  |   26|  60.2M|    (e) -= step;                                          \
  |  |   27|  60.2M|    (o) = ((o)) + step;                                   \
  |  |   28|  60.2M|  }
  ------------------
  102|       |  /* opt now points to value, if present */
  103|       |
  104|  60.2M|  result->value = opt;
  105|  60.2M|  if (length < result->length) {
  ------------------
  |  Branch (105:7): [True: 882, False: 60.2M]
  ------------------
  106|    882|    coap_log_debug("invalid option length\n");
  ------------------
  |  |  126|    882|#define coap_log_debug(...) coap_log(COAP_LOG_DEBUG, __VA_ARGS__)
  |  |  ------------------
  |  |  |  |  290|    882|#define coap_log(level, ...) do { \
  |  |  |  |  291|    882|    if ((level) < (coap_get_log_level() + 1)) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (291:9): [True: 0, False: 882]
  |  |  |  |  ------------------
  |  |  |  |  292|    882|      coap_log_impl((level), __VA_ARGS__); \
  |  |  |  |  293|    882|  } while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (293:11): [Folded, False: 882]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  107|    882|    return 0;
  108|    882|  }
  109|       |
  110|  60.2M|#undef ADVANCE_OPT
  111|  60.2M|#undef ADVANCE_OPT_CHECK
  112|       |
  113|  60.2M|  return (opt + result->length) - opt_start;
  114|  60.2M|}
coap_option_iterator_init:
  118|  7.25k|                          const coap_opt_filter_t *filter) {
  119|  7.25k|  assert(pdu);
  ------------------
  |  Branch (119:3): [True: 7.25k, False: 0]
  ------------------
  120|  7.25k|  assert(pdu->token);
  ------------------
  |  Branch (120:3): [True: 7.25k, False: 0]
  ------------------
  121|  7.25k|  assert(oi);
  ------------------
  |  Branch (121:3): [True: 7.25k, False: 0]
  ------------------
  122|       |
  123|  7.25k|  memset(oi, 0, sizeof(coap_opt_iterator_t));
  124|       |
  125|  7.25k|  oi->next_option = pdu->token + pdu->e_token_length;
  126|  7.25k|  if (pdu->token + pdu->used_size <= oi->next_option) {
  ------------------
  |  Branch (126:7): [True: 190, False: 7.06k]
  ------------------
  127|    190|    oi->bad = 1;
  128|    190|    return NULL;
  129|    190|  }
  130|       |
  131|  7.06k|  oi->length = pdu->used_size - pdu->e_token_length;
  132|       |
  133|  7.06k|  if (filter) {
  ------------------
  |  Branch (133:7): [True: 7.06k, False: 0]
  ------------------
  134|  7.06k|    memcpy(&oi->filter, filter, sizeof(coap_opt_filter_t));
  135|  7.06k|    oi->filtered = 1;
  136|  7.06k|  }
  137|  7.06k|  return oi;
  138|  7.25k|}
coap_option_next:
  153|  15.3M|coap_option_next(coap_opt_iterator_t *oi) {
  154|  15.3M|  coap_option_t option;
  155|  15.3M|  coap_opt_t *current_opt = NULL;
  156|  15.3M|  size_t optsize;
  157|       |
  158|  15.3M|  assert(oi);
  ------------------
  |  Branch (158:3): [True: 15.3M, False: 0]
  ------------------
  159|       |
  160|  15.3M|  if (opt_finished(oi))
  ------------------
  |  Branch (160:7): [True: 1.58k, False: 15.3M]
  ------------------
  161|  1.58k|    return NULL;
  162|       |
  163|  44.3M|  while (1) {
  ------------------
  |  Branch (163:10): [True: 44.3M, 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|  44.3M|    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|  44.3M|    optsize = coap_opt_parse(oi->next_option, oi->length, &option);
  174|  44.3M|    if (optsize) {
  ------------------
  |  Branch (174:9): [True: 44.3M, False: 5.08k]
  ------------------
  175|  44.3M|      assert(optsize <= oi->length);
  ------------------
  |  Branch (175:7): [True: 44.3M, False: 0]
  ------------------
  176|       |
  177|  44.3M|      oi->next_option += optsize;
  178|  44.3M|      oi->length -= optsize;
  179|       |
  180|  44.3M|      oi->number += option.delta;
  181|  44.3M|    } else {                        /* current option is malformed */
  182|  5.08k|      oi->bad = 1;
  183|  5.08k|      return NULL;
  184|  5.08k|    }
  185|       |
  186|       |    /* Exit the while loop when:
  187|       |     *   - no filtering is done at all
  188|       |     *   - the filter matches for the current option
  189|       |     */
  190|  44.3M|    if (!oi->filtered ||
  ------------------
  |  Branch (190:9): [True: 0, False: 44.3M]
  ------------------
  191|  44.3M|        coap_option_filter_get(&oi->filter, oi->number) > 0)
  ------------------
  |  Branch (191:9): [True: 15.3M, False: 29.0M]
  ------------------
  192|  15.3M|      break;
  193|  44.3M|  }
  194|       |
  195|  15.3M|  return current_opt;
  196|  15.3M|}
coap_check_option:
  200|  3.26k|                  coap_opt_iterator_t *oi) {
  201|  3.26k|  coap_opt_filter_t f;
  202|       |
  203|  3.26k|  coap_option_filter_clear(&f);
  204|  3.26k|  coap_option_filter_set(&f, number);
  205|       |
  206|  3.26k|  coap_option_iterator_init(pdu, oi, &f);
  207|       |
  208|  3.26k|  return coap_option_next(oi);
  209|  3.26k|}
coap_opt_length:
  212|  31.2M|coap_opt_length(const coap_opt_t *opt) {
  213|  31.2M|  uint32_t length;
  214|       |
  215|  31.2M|  length = *opt & 0x0f;
  216|  31.2M|  switch (*opt & 0xf0) {
  217|      0|  case 0xf0:
  ------------------
  |  Branch (217:3): [True: 0, False: 31.2M]
  ------------------
  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|    657|  case 0xe0:
  ------------------
  |  Branch (220:3): [True: 657, False: 31.2M]
  ------------------
  221|    657|    ++opt;
  222|       |  /* fall through */
  223|       |  /* to skip another byte */
  224|  3.43k|  case 0xd0:
  ------------------
  |  Branch (224:3): [True: 2.78k, False: 31.2M]
  ------------------
  225|  3.43k|    ++opt;
  226|       |  /* fall through */
  227|       |  /* to skip another byte */
  228|  31.2M|  default:
  ------------------
  |  Branch (228:3): [True: 31.2M, False: 3.43k]
  ------------------
  229|  31.2M|    ++opt;
  230|  31.2M|  }
  231|       |
  232|  31.2M|  switch (length) {
  233|      0|  case 0x0f:
  ------------------
  |  Branch (233:3): [True: 0, False: 31.2M]
  ------------------
  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|  8.19k|  case 0x0e:
  ------------------
  |  Branch (236:3): [True: 8.19k, False: 31.2M]
  ------------------
  237|  8.19k|    length = (*opt++ << 8) + 269;
  238|       |  /* fall through */
  239|  86.0k|  case 0x0d:
  ------------------
  |  Branch (239:3): [True: 77.9k, False: 31.1M]
  ------------------
  240|  86.0k|    length += *opt++;
  241|  86.0k|    break;
  242|  31.1M|  default:
  ------------------
  |  Branch (242:3): [True: 31.1M, False: 86.0k]
  ------------------
  243|  31.1M|    ;
  244|  31.2M|  }
  245|  31.2M|  return length;
  246|  31.2M|}
coap_opt_value:
  249|  31.2M|coap_opt_value(const coap_opt_t *opt) {
  250|  31.2M|  size_t ofs = 1;
  251|       |
  252|  31.2M|  switch (*opt & 0xf0) {
  253|      0|  case 0xf0:
  ------------------
  |  Branch (253:3): [True: 0, False: 31.2M]
  ------------------
  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|    657|  case 0xe0:
  ------------------
  |  Branch (256:3): [True: 657, False: 31.2M]
  ------------------
  257|    657|    ++ofs;
  258|       |  /* fall through */
  259|  3.43k|  case 0xd0:
  ------------------
  |  Branch (259:3): [True: 2.78k, False: 31.2M]
  ------------------
  260|  3.43k|    ++ofs;
  261|  3.43k|    break;
  262|  31.2M|  default:
  ------------------
  |  Branch (262:3): [True: 31.2M, False: 3.43k]
  ------------------
  263|  31.2M|    ;
  264|  31.2M|  }
  265|       |
  266|  31.2M|  switch (*opt & 0x0f) {
  267|      0|  case 0x0f:
  ------------------
  |  Branch (267:3): [True: 0, False: 31.2M]
  ------------------
  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|  8.19k|  case 0x0e:
  ------------------
  |  Branch (270:3): [True: 8.19k, False: 31.2M]
  ------------------
  271|  8.19k|    ++ofs;
  272|       |  /* fall through */
  273|  86.0k|  case 0x0d:
  ------------------
  |  Branch (273:3): [True: 77.9k, False: 31.1M]
  ------------------
  274|  86.0k|    ++ofs;
  275|  86.0k|    break;
  276|  31.1M|  default:
  ------------------
  |  Branch (276:3): [True: 31.1M, False: 86.0k]
  ------------------
  277|  31.1M|    ;
  278|  31.2M|  }
  279|       |
  280|  31.2M|  return (const uint8_t *)opt + ofs;
  281|  31.2M|}
coap_option_filter_clear:
  491|  9.09k|coap_option_filter_clear(coap_opt_filter_t *filter) {
  492|  9.09k|  memset(filter, 0, sizeof(coap_opt_filter_t));
  493|  9.09k|}
coap_option_filter_set:
  496|  1.72M|coap_option_filter_set(coap_opt_filter_t *filter, coap_option_num_t option) {
  497|  1.72M|  return coap_option_filter_op(filter, option, FILTER_SET);
  498|  1.72M|}
coap_option_filter_get:
  506|  44.3M|coap_option_filter_get(coap_opt_filter_t *filter, coap_option_num_t option) {
  507|  44.3M|  return coap_option_filter_op(filter, option, FILTER_GET);
  508|  44.3M|}
coap_option.c:opt_finished:
  141|  15.3M|opt_finished(coap_opt_iterator_t *oi) {
  142|  15.3M|  assert(oi);
  ------------------
  |  Branch (142:3): [True: 15.3M, False: 0]
  ------------------
  143|       |
  144|  15.3M|  if (oi->bad || oi->length == 0 ||
  ------------------
  |  Branch (144:7): [True: 190, False: 15.3M]
  |  Branch (144:18): [True: 1.14k, False: 15.3M]
  ------------------
  145|  15.3M|      !oi->next_option || *oi->next_option == COAP_PAYLOAD_START) {
  ------------------
  |  |   96|  15.3M|#define COAP_PAYLOAD_START 0xFF /* payload marker */
  ------------------
  |  Branch (145:7): [True: 0, False: 15.3M]
  |  Branch (145:27): [True: 243, False: 15.3M]
  ------------------
  146|  1.58k|    oi->bad = 1;
  147|  1.58k|  }
  148|       |
  149|  15.3M|  return oi->bad;
  150|  15.3M|}
coap_option.c:coap_option_filter_op:
  433|  46.1M|                      enum filter_op_t op) {
  434|  46.1M|  size_t lindex = 0;
  435|  46.1M|  coap_opt_filter_t *of = filter;
  436|  46.1M|  uint16_t nr, mask = 0;
  437|       |
  438|  46.1M|  if (is_long_option(number)) {
  ------------------
  |  Branch (438:7): [True: 243k, False: 45.8M]
  ------------------
  439|   243k|    mask = LONG_MASK;
  ------------------
  |  |  398|   243k|#define LONG_MASK ((1 << COAP_OPT_FILTER_LONG) - 1)
  |  |  ------------------
  |  |  |  |  208|   243k|#define COAP_OPT_FILTER_LONG  2
  |  |  ------------------
  ------------------
  440|       |
  441|   727k|    for (nr = 1; lindex < COAP_OPT_FILTER_LONG; nr <<= 1, lindex++) {
  ------------------
  |  |  208|   727k|#define COAP_OPT_FILTER_LONG  2
  ------------------
  |  Branch (441:18): [True: 486k, False: 241k]
  ------------------
  442|       |
  443|   486k|      if (((of->mask & nr) > 0) && (of->long_opts[lindex] == number)) {
  ------------------
  |  Branch (443:11): [True: 110k, False: 376k]
  |  Branch (443:36): [True: 2.75k, False: 107k]
  ------------------
  444|  2.75k|        if (op == FILTER_CLEAR) {
  ------------------
  |  Branch (444:13): [True: 0, False: 2.75k]
  ------------------
  445|      0|          of->mask &= ~nr;
  446|      0|        }
  447|       |
  448|  2.75k|        return 1;
  449|  2.75k|      }
  450|   486k|    }
  451|  45.8M|  } else {
  452|  45.8M|    mask = SHORT_MASK;
  ------------------
  |  |  400|  45.8M|  (~LONG_MASK & ((1 << (COAP_OPT_FILTER_LONG + COAP_OPT_FILTER_SHORT)) - 1))
  |  |  ------------------
  |  |  |  |  398|  45.8M|#define LONG_MASK ((1 << COAP_OPT_FILTER_LONG) - 1)
  |  |  |  |  ------------------
  |  |  |  |  |  |  208|  45.8M|#define COAP_OPT_FILTER_LONG  2
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                 (~LONG_MASK & ((1 << (COAP_OPT_FILTER_LONG + COAP_OPT_FILTER_SHORT)) - 1))
  |  |  ------------------
  |  |  |  |  208|  45.8M|#define COAP_OPT_FILTER_LONG  2
  |  |  ------------------
  |  |                 (~LONG_MASK & ((1 << (COAP_OPT_FILTER_LONG + COAP_OPT_FILTER_SHORT)) - 1))
  |  |  ------------------
  |  |  |  |  200|  45.8M|#define COAP_OPT_FILTER_SHORT 6
  |  |  ------------------
  ------------------
  453|       |
  454|   301M|    for (nr = 1 << COAP_OPT_FILTER_LONG; lindex < COAP_OPT_FILTER_SHORT;
  ------------------
  |  |  208|  45.8M|#define COAP_OPT_FILTER_LONG  2
  ------------------
                  for (nr = 1 << COAP_OPT_FILTER_LONG; lindex < COAP_OPT_FILTER_SHORT;
  ------------------
  |  |  200|   301M|#define COAP_OPT_FILTER_SHORT 6
  ------------------
  |  Branch (454:42): [True: 272M, False: 28.8M]
  ------------------
  455|   272M|         nr <<= 1, lindex++) {
  456|       |
  457|   272M|      if (((of->mask & nr) > 0) && (of->short_opts[lindex] == (number & 0xff))) {
  ------------------
  |  Branch (457:11): [True: 45.8M, False: 226M]
  |  Branch (457:36): [True: 17.0M, False: 28.8M]
  ------------------
  458|  17.0M|        if (op == FILTER_CLEAR) {
  ------------------
  |  Branch (458:13): [True: 0, False: 17.0M]
  ------------------
  459|      0|          of->mask &= ~nr;
  460|      0|        }
  461|       |
  462|  17.0M|        return 1;
  463|  17.0M|      }
  464|   272M|    }
  465|  45.8M|  }
  466|       |
  467|       |  /* number was not found, so there is nothing to do if op is CLEAR or GET */
  468|  29.0M|  if ((op == FILTER_CLEAR) || (op == FILTER_GET)) {
  ------------------
  |  Branch (468:7): [True: 0, False: 29.0M]
  |  Branch (468:31): [True: 29.0M, False: 65.4k]
  ------------------
  469|  29.0M|    return 0;
  470|  29.0M|  }
  471|       |
  472|       |  /* handle FILTER_SET: */
  473|       |
  474|  65.4k|  lindex = coap_fls(~of->mask & mask);
  475|  65.4k|  if (!lindex) {
  ------------------
  |  Branch (475:7): [True: 57.0k, False: 8.31k]
  ------------------
  476|  57.0k|    return 0;
  477|  57.0k|  }
  478|       |
  479|  8.31k|  if (is_long_option(number)) {
  ------------------
  |  Branch (479:7): [True: 303, False: 8.01k]
  ------------------
  480|    303|    of->long_opts[lindex - 1] = number;
  481|  8.01k|  } else {
  482|  8.01k|    of->short_opts[lindex - COAP_OPT_FILTER_LONG - 1] = (uint8_t)number;
  ------------------
  |  |  208|  8.01k|#define COAP_OPT_FILTER_LONG  2
  ------------------
  483|  8.01k|  }
  484|       |
  485|  8.31k|  of->mask |= 1 << (lindex - 1);
  486|       |
  487|  8.31k|  return 1;
  488|  65.4k|}
coap_option.c:is_long_option:
  404|  46.1M|is_long_option(coap_option_num_t number) {
  405|  46.1M|  return number > 255;
  406|  46.1M|}

coap_pdu_clear:
   47|  3.20k|coap_pdu_clear(coap_pdu_t *pdu, size_t size) {
   48|  3.20k|  assert(pdu);
  ------------------
  |  Branch (48:3): [True: 3.20k, False: 0]
  ------------------
   49|  3.20k|  assert(pdu->token);
  ------------------
  |  Branch (49:3): [True: 3.20k, False: 0]
  ------------------
   50|  3.20k|  assert(pdu->max_hdr_size >= COAP_PDU_MAX_UDP_HEADER_SIZE);
  ------------------
  |  Branch (50:3): [True: 3.20k, False: 0]
  ------------------
   51|  3.20k|  if (pdu->alloc_size > size)
  ------------------
  |  Branch (51:7): [True: 0, False: 3.20k]
  ------------------
   52|      0|    pdu->alloc_size = size;
   53|  3.20k|  pdu->type = 0;
   54|  3.20k|  pdu->code = 0;
   55|  3.20k|  pdu->ref = 0;
   56|  3.20k|  pdu->hdr_size = 0;
   57|  3.20k|  pdu->actual_token.length = 0;
   58|  3.20k|  pdu->e_token_length = 0;
   59|  3.20k|  pdu->crit_opt = 0;
   60|  3.20k|  pdu->mid = 0;
   61|  3.20k|  pdu->max_opt = 0;
   62|  3.20k|  pdu->max_size = size;
   63|  3.20k|  pdu->used_size = 0;
   64|  3.20k|  pdu->data = NULL;
   65|  3.20k|  pdu->body_data = NULL;
   66|  3.20k|  pdu->body_length = 0;
   67|  3.20k|  pdu->body_offset = 0;
   68|  3.20k|  pdu->body_total = 0;
   69|  3.20k|  pdu->lg_xmit = NULL;
   70|  3.20k|  pdu->session = NULL;
   71|       |  pdu->data_free = NULL;
   72|  3.20k|}
coap_pdu_init:
  105|  3.20k|              size_t size) {
  106|  3.20k|  coap_pdu_t *pdu;
  107|       |
  108|  3.20k|#ifndef RIOT_VERSION
  109|  3.20k|  assert(type <= 0x3);
  ------------------
  |  Branch (109:3): [True: 3.20k, False: 0]
  ------------------
  110|  3.20k|  assert(code <= 0xff);
  ------------------
  |  Branch (110:3): [True: 3.20k, False: 0]
  ------------------
  111|  3.20k|  assert(mid >= 0 && mid <= 0xffff);
  ------------------
  |  Branch (111:3): [True: 3.20k, False: 0]
  |  Branch (111:3): [True: 3.20k, False: 0]
  ------------------
  112|  3.20k|#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.20k|  pdu = coap_malloc_type(COAP_PDU, sizeof(coap_pdu_t));
  125|  3.20k|  if (!pdu)
  ------------------
  |  Branch (125:7): [True: 0, False: 3.20k]
  ------------------
  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.20k|  pdu->max_hdr_size = COAP_PDU_MAX_TCP_HEADER_SIZE;
  ------------------
  |  |  108|  3.20k|#define COAP_PDU_MAX_TCP_HEADER_SIZE 6
  ------------------
  133|  3.20k|#endif
  134|  3.20k|  if (size > ((size_t)COAP_DEFAULT_MAX_PDU_RX_SIZE - pdu->max_hdr_size)) {
  ------------------
  |  |   84|  3.20k|#define COAP_DEFAULT_MAX_PDU_RX_SIZE (8UL*1024*1024+256)
  ------------------
  |  Branch (134:7): [True: 0, False: 3.20k]
  ------------------
  135|      0|    coap_free_type(COAP_PDU, pdu);
  136|      0|    return NULL;
  137|      0|  }
  138|       |
  139|  3.20k|  pdu->alloc_size = min(size, COAP_DEFAULT_MTU);
  ------------------
  |  |   37|  3.20k|#define min(a,b) ((a) < (b) ? (a) : (b))
  |  |  ------------------
  |  |  |  Branch (37:19): [True: 2.62k, False: 579]
  |  |  ------------------
  ------------------
  140|       |#ifdef WITH_LWIP
  141|       |  pdu->pbuf = pbuf_alloc(PBUF_TRANSPORT, max(size, COAP_DEFAULT_MTU) + 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.20k|  uint8_t *buf;
  150|  3.20k|  buf = coap_malloc_type(COAP_PDU_BUF, pdu->alloc_size + pdu->max_hdr_size);
  151|  3.20k|  if (buf == NULL) {
  ------------------
  |  Branch (151:7): [True: 0, False: 3.20k]
  ------------------
  152|      0|    coap_free_type(COAP_PDU, pdu);
  153|      0|    return NULL;
  154|      0|  }
  155|  3.20k|  pdu->token = buf + pdu->max_hdr_size;
  156|  3.20k|#endif /* ! WITH_LWIP */
  157|  3.20k|  coap_pdu_clear(pdu, size);
  158|  3.20k|  pdu->mid = mid;
  159|  3.20k|  pdu->type = type;
  160|  3.20k|  pdu->code = code;
  161|  3.20k|  return pdu;
  162|  3.20k|}
coap_delete_pdu:
  190|  3.20k|coap_delete_pdu(coap_pdu_t *pdu) {
  191|  3.20k|  coap_lock_lock(return);
  192|  3.20k|  coap_delete_pdu_lkd(pdu);
  193|  3.20k|  coap_lock_unlock();
  194|  3.20k|}
coap_delete_pdu_lkd:
  197|  3.20k|coap_delete_pdu_lkd(coap_pdu_t *pdu) {
  198|  3.20k|  if (pdu != NULL) {
  ------------------
  |  Branch (198:7): [True: 3.20k, False: 0]
  ------------------
  199|  3.20k|    if (pdu->ref) {
  ------------------
  |  Branch (199:9): [True: 0, False: 3.20k]
  ------------------
  200|      0|      pdu->ref--;
  201|      0|      return;
  202|      0|    }
  203|       |#ifdef WITH_LWIP
  204|       |    pbuf_free(pdu->pbuf);
  205|       |#else
  206|  3.20k|    if (pdu->token != NULL)
  ------------------
  |  Branch (206:9): [True: 3.20k, False: 0]
  ------------------
  207|  3.20k|      coap_free_type(COAP_PDU_BUF, pdu->token - pdu->max_hdr_size);
  208|  3.20k|#endif
  209|  3.20k|    coap_delete_binary(pdu->data_free);
  210|  3.20k|    coap_free_type(COAP_PDU, pdu);
  211|  3.20k|  }
  212|  3.20k|}
coap_pdu_resize:
  341|  3.20k|coap_pdu_resize(coap_pdu_t *pdu, size_t new_size) {
  342|  3.20k|  if (new_size > pdu->alloc_size) {
  ------------------
  |  Branch (342:7): [True: 576, False: 2.62k]
  ------------------
  343|       |    /* Expanding the PDU usage */
  344|    576|#if !defined(WITH_LWIP)
  345|    576|    uint8_t *new_hdr;
  346|       |#else /* WITH_LWIP */
  347|       |    struct pbuf *new_hdr;
  348|       |#endif /* WITH_LWIP */
  349|    576|    size_t offset;
  350|       |
  351|    576|    if (pdu->max_size && new_size > pdu->max_size) {
  ------------------
  |  Branch (351:9): [True: 576, False: 0]
  |  Branch (351:26): [True: 0, False: 576]
  ------------------
  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|    576|    if (pdu->data != NULL) {
  ------------------
  |  Branch (355:9): [True: 0, False: 576]
  ------------------
  356|      0|      assert(pdu->data > pdu->token);
  ------------------
  |  Branch (356:7): [True: 0, False: 0]
  ------------------
  357|      0|      offset = pdu->data - pdu->token;
  358|    576|    } else {
  359|    576|      offset = 0;
  360|    576|    }
  361|    576|#if !defined(WITH_LWIP)
  362|    576|    new_hdr = (uint8_t *)coap_realloc_type(COAP_PDU_BUF,
  363|    576|                                           pdu->token - pdu->max_hdr_size,
  364|    576|                                           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|    576|    if (new_hdr == NULL) {
  ------------------
  |  Branch (368:9): [True: 0, False: 576]
  ------------------
  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|    576|#if !defined(WITH_LWIP)
  373|    576|    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|    576|    if (offset > 0)
  ------------------
  |  Branch (380:9): [True: 0, False: 576]
  ------------------
  381|      0|      pdu->data = pdu->token + offset;
  382|    576|    else
  383|    576|      pdu->data = NULL;
  384|    576|    if (pdu->actual_token.length < COAP_TOKEN_EXT_1B_BIAS)
  ------------------
  |  |   56|    576|#define COAP_TOKEN_EXT_1B_BIAS 13
  ------------------
  |  Branch (384:9): [True: 576, False: 0]
  ------------------
  385|    576|      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|    576|    pdu->alloc_size = new_size;
  391|    576|  }
  392|  3.20k|  return 1;
  393|  3.20k|}
coap_pdu_parse_header_size:
 1063|  3.20k|                           const uint8_t *data) {
 1064|  3.20k|  assert(data);
  ------------------
  |  Branch (1064:3): [True: 3.20k, False: 0]
  ------------------
 1065|  3.20k|  size_t header_size = 0;
 1066|       |
 1067|  3.20k|  if (proto == COAP_PROTO_TCP || proto==COAP_PROTO_TLS) {
  ------------------
  |  Branch (1067:7): [True: 0, False: 3.20k]
  |  Branch (1067:34): [True: 0, False: 3.20k]
  ------------------
 1068|      0|    uint8_t len = *data >> 4;
 1069|      0|    if (len < 13)
  ------------------
  |  Branch (1069:9): [True: 0, False: 0]
  ------------------
 1070|      0|      header_size = 2;
 1071|      0|    else if (len==13)
  ------------------
  |  Branch (1071:14): [True: 0, False: 0]
  ------------------
 1072|      0|      header_size = 3;
 1073|      0|    else if (len==14)
  ------------------
  |  Branch (1073:14): [True: 0, False: 0]
  ------------------
 1074|      0|      header_size = 4;
 1075|      0|    else
 1076|      0|      header_size = 6;
 1077|  3.20k|  } else if (proto == COAP_PROTO_WS || proto==COAP_PROTO_WSS) {
  ------------------
  |  Branch (1077:14): [True: 0, False: 3.20k]
  |  Branch (1077:40): [True: 0, False: 3.20k]
  ------------------
 1078|      0|    header_size = 2;
 1079|  3.20k|  } else if (proto == COAP_PROTO_UDP || proto==COAP_PROTO_DTLS) {
  ------------------
  |  Branch (1079:14): [True: 3.20k, False: 0]
  |  Branch (1079:41): [True: 0, False: 0]
  ------------------
 1080|  3.20k|    header_size = 4;
 1081|  3.20k|  }
 1082|       |
 1083|  3.20k|  return header_size;
 1084|  3.20k|}
coap_pdu_parse_header:
 1146|  3.20k|coap_pdu_parse_header(coap_pdu_t *pdu, coap_proto_t proto) {
 1147|  3.20k|  uint8_t *hdr = pdu->token - pdu->hdr_size;
 1148|  3.20k|  uint8_t e_token_length;
 1149|       |
 1150|  3.20k|  if (proto == COAP_PROTO_UDP || proto == COAP_PROTO_DTLS) {
  ------------------
  |  Branch (1150:7): [True: 3.20k, False: 0]
  |  Branch (1150:34): [True: 0, False: 0]
  ------------------
 1151|  3.20k|    assert(pdu->hdr_size == 4);
  ------------------
  |  Branch (1151:5): [True: 3.20k, False: 0]
  ------------------
 1152|  3.20k|    if ((hdr[0] >> 6) != COAP_DEFAULT_VERSION) {
  ------------------
  |  |   35|  3.20k|#define COAP_DEFAULT_VERSION      1 /* version of CoAP supported */
  ------------------
  |  Branch (1152:9): [True: 7, False: 3.19k]
  ------------------
 1153|      7|      coap_log_debug("coap_pdu_parse: UDP version not supported\n");
  ------------------
  |  |  126|      7|#define coap_log_debug(...) coap_log(COAP_LOG_DEBUG, __VA_ARGS__)
  |  |  ------------------
  |  |  |  |  290|      7|#define coap_log(level, ...) do { \
  |  |  |  |  291|      7|    if ((level) < (coap_get_log_level() + 1)) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (291:9): [True: 0, False: 7]
  |  |  |  |  ------------------
  |  |  |  |  292|      7|      coap_log_impl((level), __VA_ARGS__); \
  |  |  |  |  293|      7|  } while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (293:11): [Folded, False: 7]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1154|      7|      return 0;
 1155|      7|    }
 1156|  3.19k|    pdu->type = (hdr[0] >> 4) & 0x03;
 1157|  3.19k|    pdu->code = hdr[1];
 1158|  3.19k|    pdu->mid = (uint16_t)hdr[2] << 8 | hdr[3];
 1159|  3.19k|  } else if (proto == COAP_PROTO_TCP || proto == COAP_PROTO_TLS) {
  ------------------
  |  Branch (1159:14): [True: 0, False: 0]
  |  Branch (1159:41): [True: 0, False: 0]
  ------------------
 1160|      0|    assert(pdu->hdr_size >= 2 && pdu->hdr_size <= 6);
  ------------------
  |  Branch (1160:5): [True: 0, False: 0]
  |  Branch (1160:5): [True: 0, False: 0]
  ------------------
 1161|      0|    pdu->type = COAP_MESSAGE_CON;
 1162|      0|    pdu->code = hdr[pdu->hdr_size-1];
 1163|      0|    pdu->mid = 0;
 1164|      0|  } else if (proto == COAP_PROTO_WS || proto == COAP_PROTO_WSS) {
  ------------------
  |  Branch (1164:14): [True: 0, False: 0]
  |  Branch (1164:40): [True: 0, False: 0]
  ------------------
 1165|      0|    assert(pdu->hdr_size == 2);
  ------------------
  |  Branch (1165:5): [True: 0, False: 0]
  ------------------
 1166|      0|    pdu->type = COAP_MESSAGE_CON;
 1167|      0|    pdu->code = hdr[pdu->hdr_size-1];
 1168|      0|    pdu->mid = 0;
 1169|      0|  } else {
 1170|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1171|      0|    return 0;
 1172|      0|  }
 1173|       |
 1174|  3.19k|  e_token_length = hdr[0] & 0x0f;
 1175|  3.19k|  if (e_token_length < COAP_TOKEN_EXT_1B_TKL) {
  ------------------
  |  |   54|  3.19k|#define COAP_TOKEN_EXT_1B_TKL 13
  ------------------
  |  Branch (1175:7): [True: 3.07k, False: 115]
  ------------------
 1176|  3.07k|    pdu->e_token_length = e_token_length;
 1177|  3.07k|    pdu->actual_token.length = pdu->e_token_length;
 1178|  3.07k|    pdu->actual_token.s = &pdu->token[0];
 1179|  3.07k|  } else if (e_token_length == COAP_TOKEN_EXT_1B_TKL) {
  ------------------
  |  |   54|    115|#define COAP_TOKEN_EXT_1B_TKL 13
  ------------------
  |  Branch (1179:14): [True: 52, False: 63]
  ------------------
 1180|     52|    if (pdu->used_size < 1)
  ------------------
  |  Branch (1180:9): [True: 1, False: 51]
  ------------------
 1181|      1|      goto bad_ext_token;
 1182|     51|    pdu->e_token_length = pdu->token[0] + COAP_TOKEN_EXT_1B_BIAS + 1;
  ------------------
  |  |   56|     51|#define COAP_TOKEN_EXT_1B_BIAS 13
  ------------------
 1183|     51|    pdu->actual_token.length = pdu->e_token_length - 1;
 1184|     51|    pdu->actual_token.s = &pdu->token[1];
 1185|     63|  } else if (e_token_length == COAP_TOKEN_EXT_2B_TKL) {
  ------------------
  |  |   55|     63|#define COAP_TOKEN_EXT_2B_TKL 14
  ------------------
  |  Branch (1185:14): [True: 62, False: 1]
  ------------------
 1186|     62|    if (pdu->used_size < 2)
  ------------------
  |  Branch (1186:9): [True: 2, False: 60]
  ------------------
 1187|      2|      goto bad_ext_token;
 1188|     60|    pdu->e_token_length = ((uint16_t)pdu->token[0] << 8) + pdu->token[1] +
 1189|     60|                          COAP_TOKEN_EXT_2B_BIAS + 2;
  ------------------
  |  |   57|     60|#define COAP_TOKEN_EXT_2B_BIAS 269 /* 13 + 256 */
  ------------------
 1190|     60|    pdu->actual_token.length = pdu->e_token_length - 2;
 1191|     60|    pdu->actual_token.s = &pdu->token[2];
 1192|     60|  }
 1193|  3.19k|  if (pdu->e_token_length > pdu->alloc_size || e_token_length == 15) {
  ------------------
  |  Branch (1193:7): [True: 26, False: 3.16k]
  |  Branch (1193:48): [True: 1, False: 3.16k]
  ------------------
 1194|     27|    goto bad_ext_token;
 1195|     27|  }
 1196|  3.16k|  return 1;
 1197|       |
 1198|     30|bad_ext_token:
 1199|       |  /* Invalid PDU provided - not wise to assert here though */
 1200|     30|  coap_log_debug("coap_pdu_parse: PDU header extended token size broken\n");
  ------------------
  |  |  126|     30|#define coap_log_debug(...) coap_log(COAP_LOG_DEBUG, __VA_ARGS__)
  |  |  ------------------
  |  |  |  |  290|     30|#define coap_log(level, ...) do { \
  |  |  |  |  291|     30|    if ((level) < (coap_get_log_level() + 1)) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (291:9): [True: 0, False: 30]
  |  |  |  |  ------------------
  |  |  |  |  292|     30|      coap_log_impl((level), __VA_ARGS__); \
  |  |  |  |  293|     30|  } while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (293:11): [Folded, False: 30]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1201|     30|  pdu->e_token_length = 0;
 1202|     30|  pdu->actual_token.length = 0;
 1203|     30|  return 0;
 1204|  3.19k|}
coap_pdu_parse_opt_base:
 1275|  10.8M|coap_pdu_parse_opt_base(coap_option_num_t number, size_t len, const uint8_t *opt_val) {
 1276|  10.8M|  int res = 1;
 1277|       |
 1278|  10.8M|  switch ((coap_code_opt_num_t)number) {
 1279|  2.66k|  case COAP_OPTION_IF_MATCH:
  ------------------
  |  Branch (1279:3): [True: 2.66k, False: 10.8M]
  ------------------
 1280|  2.66k|    if (len > 8)
  ------------------
  |  Branch (1280:9): [True: 1.25k, False: 1.40k]
  ------------------
 1281|  1.25k|      res = 0;
 1282|  2.66k|    break;
 1283|  5.18k|  case COAP_OPTION_URI_HOST:
  ------------------
  |  Branch (1283:3): [True: 5.18k, False: 10.8M]
  ------------------
 1284|  5.18k|    if (len < 1 || len > 255)
  ------------------
  |  Branch (1284:9): [True: 3.24k, False: 1.93k]
  |  Branch (1284:20): [True: 1.29k, False: 647]
  ------------------
 1285|  4.53k|      res = 0;
 1286|  5.18k|    break;
 1287|  20.0k|  case COAP_OPTION_ETAG:
  ------------------
  |  Branch (1287:3): [True: 20.0k, False: 10.8M]
  ------------------
 1288|  20.0k|    if (len < 1 || len > 8)
  ------------------
  |  Branch (1288:9): [True: 18.6k, False: 1.43k]
  |  Branch (1288:20): [True: 1.10k, False: 337]
  ------------------
 1289|  19.7k|      res = 0;
 1290|  20.0k|    break;
 1291|  84.7k|  case COAP_OPTION_IF_NONE_MATCH:
  ------------------
  |  Branch (1291:3): [True: 84.7k, False: 10.8M]
  ------------------
 1292|  84.7k|    if (len != 0)
  ------------------
  |  Branch (1292:9): [True: 1.16k, False: 83.6k]
  ------------------
 1293|  1.16k|      res = 0;
 1294|  84.7k|    break;
 1295|  2.12k|  case COAP_OPTION_OBSERVE:
  ------------------
  |  Branch (1295:3): [True: 2.12k, False: 10.8M]
  ------------------
 1296|  2.12k|    if (len > 3)
  ------------------
  |  Branch (1296:9): [True: 1.09k, False: 1.02k]
  ------------------
 1297|  1.09k|      res = 0;
 1298|  2.12k|    break;
 1299|  11.7k|  case COAP_OPTION_URI_PORT:
  ------------------
  |  Branch (1299:3): [True: 11.7k, False: 10.8M]
  ------------------
 1300|  11.7k|    if (len > 2)
  ------------------
  |  Branch (1300:9): [True: 1.11k, False: 10.6k]
  ------------------
 1301|  1.11k|      res = 0;
 1302|  11.7k|    break;
 1303|   129k|  case COAP_OPTION_LOCATION_PATH:
  ------------------
  |  Branch (1303:3): [True: 129k, False: 10.7M]
  ------------------
 1304|  7.82M|  case COAP_OPTION_URI_PATH:
  ------------------
  |  Branch (1304:3): [True: 7.69M, False: 3.19M]
  ------------------
 1305|  7.82M|    if (len > 255)
  ------------------
  |  Branch (1305:9): [True: 1.11k, False: 7.82M]
  ------------------
 1306|  1.11k|      res = 0;
 1307|  7.82M|    if (coap_check_dots(opt_val, len)) {
  ------------------
  |  Branch (1307:9): [True: 2.43k, False: 7.82M]
  ------------------
 1308|  2.43k|      res = 0;
 1309|  2.43k|    }
 1310|  7.82M|    break;
 1311|  2.57k|  case COAP_OPTION_OSCORE:
  ------------------
  |  Branch (1311:3): [True: 2.57k, False: 10.8M]
  ------------------
 1312|  2.57k|    if (len > 255)
  ------------------
  |  Branch (1312:9): [True: 993, False: 1.58k]
  ------------------
 1313|    993|      res = 0;
 1314|  2.57k|    break;
 1315|  4.88k|  case COAP_OPTION_CONTENT_FORMAT:
  ------------------
  |  Branch (1315:3): [True: 4.88k, False: 10.8M]
  ------------------
 1316|  4.88k|    if (len > 2)
  ------------------
  |  Branch (1316:9): [True: 1.14k, False: 3.73k]
  ------------------
 1317|  1.14k|      res = 0;
 1318|  4.88k|    break;
 1319|  2.77k|  case COAP_OPTION_URI_PATH_ABB:
  ------------------
  |  Branch (1319:3): [True: 2.77k, False: 10.8M]
  ------------------
 1320|  2.77k|    if (len > 4)
  ------------------
  |  Branch (1320:9): [True: 1.37k, False: 1.39k]
  ------------------
 1321|  1.37k|      res = 0;
 1322|  2.77k|    break;
 1323|  14.9k|  case COAP_OPTION_MAXAGE:
  ------------------
  |  Branch (1323:3): [True: 14.9k, False: 10.8M]
  ------------------
 1324|  14.9k|    if (len > 4)
  ------------------
  |  Branch (1324:9): [True: 1.12k, False: 13.8k]
  ------------------
 1325|  1.12k|      res = 0;
 1326|  14.9k|    break;
 1327|   172k|  case COAP_OPTION_URI_QUERY:
  ------------------
  |  Branch (1327:3): [True: 172k, False: 10.7M]
  ------------------
 1328|   172k|    if (len < 1 || len > 255)
  ------------------
  |  Branch (1328:9): [True: 159k, False: 12.1k]
  |  Branch (1328:20): [True: 1.05k, False: 11.0k]
  ------------------
 1329|   160k|      res = 0;
 1330|   172k|    break;
 1331|  3.28k|  case COAP_OPTION_HOP_LIMIT:
  ------------------
  |  Branch (1331:3): [True: 3.28k, False: 10.8M]
  ------------------
 1332|  3.28k|    if (len != 1)
  ------------------
  |  Branch (1332:9): [True: 3.05k, False: 233]
  ------------------
 1333|  3.05k|      res = 0;
 1334|  3.28k|    break;
 1335|  12.7k|  case COAP_OPTION_ACCEPT:
  ------------------
  |  Branch (1335:3): [True: 12.7k, False: 10.8M]
  ------------------
 1336|  12.7k|    if (len > 2)
  ------------------
  |  Branch (1336:9): [True: 1.58k, False: 11.2k]
  ------------------
 1337|  1.58k|      res = 0;
 1338|  12.7k|    break;
 1339|   539k|  case COAP_OPTION_Q_BLOCK1:
  ------------------
  |  Branch (1339:3): [True: 539k, False: 10.3M]
  ------------------
 1340|   539k|    if (len > 3)
  ------------------
  |  Branch (1340:9): [True: 1.41k, False: 537k]
  ------------------
 1341|  1.41k|      res = 0;
 1342|   539k|    break;
 1343|   110k|  case COAP_OPTION_LOCATION_QUERY:
  ------------------
  |  Branch (1343:3): [True: 110k, False: 10.7M]
  ------------------
 1344|   110k|    if (len > 255)
  ------------------
  |  Branch (1344:9): [True: 975, False: 109k]
  ------------------
 1345|    975|      res = 0;
 1346|   110k|    break;
 1347|  5.22k|  case COAP_OPTION_EDHOC:
  ------------------
  |  Branch (1347:3): [True: 5.22k, False: 10.8M]
  ------------------
 1348|  5.22k|    if (len != 0)
  ------------------
  |  Branch (1348:9): [True: 1.18k, False: 4.04k]
  ------------------
 1349|  1.18k|      res = 0;
 1350|  5.22k|    break;
 1351|  2.69k|  case COAP_OPTION_BLOCK2:
  ------------------
  |  Branch (1351:3): [True: 2.69k, False: 10.8M]
  ------------------
 1352|  2.69k|    if (len > 3)
  ------------------
  |  Branch (1352:9): [True: 1.05k, False: 1.64k]
  ------------------
 1353|  1.05k|      res = 0;
 1354|  2.69k|    break;
 1355|   531k|  case COAP_OPTION_BLOCK1:
  ------------------
  |  Branch (1355:3): [True: 531k, False: 10.3M]
  ------------------
 1356|   531k|    if (len > 3)
  ------------------
  |  Branch (1356:9): [True: 1.04k, False: 530k]
  ------------------
 1357|  1.04k|      res = 0;
 1358|   531k|    break;
 1359|  40.4k|  case COAP_OPTION_SIZE2:
  ------------------
  |  Branch (1359:3): [True: 40.4k, False: 10.8M]
  ------------------
 1360|  40.4k|    if (len > 4)
  ------------------
  |  Branch (1360:9): [True: 1.27k, False: 39.1k]
  ------------------
 1361|  1.27k|      res = 0;
 1362|  40.4k|    break;
 1363|  1.46k|  case COAP_OPTION_Q_BLOCK2:
  ------------------
  |  Branch (1363:3): [True: 1.46k, False: 10.8M]
  ------------------
 1364|  1.46k|    if (len > 3)
  ------------------
  |  Branch (1364:9): [True: 1.04k, False: 416]
  ------------------
 1365|  1.04k|      res = 0;
 1366|  1.46k|    break;
 1367|  6.94k|  case COAP_OPTION_PROXY_URI:
  ------------------
  |  Branch (1367:3): [True: 6.94k, False: 10.8M]
  ------------------
 1368|  6.94k|    if (len < 1 || len > 1034)
  ------------------
  |  Branch (1368:9): [True: 4.53k, False: 2.41k]
  |  Branch (1368:20): [True: 999, False: 1.41k]
  ------------------
 1369|  5.52k|      res = 0;
 1370|  6.94k|    break;
 1371|  5.87k|  case COAP_OPTION_PROXY_SCHEME:
  ------------------
  |  Branch (1371:3): [True: 5.87k, False: 10.8M]
  ------------------
 1372|  5.87k|    if (len < 1 || len > 255)
  ------------------
  |  Branch (1372:9): [True: 4.58k, False: 1.29k]
  |  Branch (1372:20): [True: 1.00k, False: 291]
  ------------------
 1373|  5.58k|      res = 0;
 1374|  5.87k|    break;
 1375|  2.10k|  case COAP_OPTION_SIZE1:
  ------------------
  |  Branch (1375:3): [True: 2.10k, False: 10.8M]
  ------------------
 1376|  2.10k|    if (len > 4)
  ------------------
  |  Branch (1376:9): [True: 1.06k, False: 1.04k]
  ------------------
 1377|  1.06k|      res = 0;
 1378|  2.10k|    break;
 1379|  2.64k|  case COAP_OPTION_ECHO:
  ------------------
  |  Branch (1379:3): [True: 2.64k, False: 10.8M]
  ------------------
 1380|  2.64k|    if (len > 40)
  ------------------
  |  Branch (1380:9): [True: 1.14k, False: 1.49k]
  ------------------
 1381|  1.14k|      res = 0;
 1382|  2.64k|    break;
 1383|  2.46k|  case COAP_OPTION_NORESPONSE:
  ------------------
  |  Branch (1383:3): [True: 2.46k, False: 10.8M]
  ------------------
 1384|  2.46k|    if (len > 1)
  ------------------
  |  Branch (1384:9): [True: 1.06k, False: 1.39k]
  ------------------
 1385|  1.06k|      res = 0;
 1386|  2.46k|    break;
 1387|  1.52k|  case COAP_OPTION_RTAG:
  ------------------
  |  Branch (1387:3): [True: 1.52k, False: 10.8M]
  ------------------
 1388|  1.52k|    if (len > 8)
  ------------------
  |  Branch (1388:9): [True: 1.02k, False: 499]
  ------------------
 1389|  1.02k|      res = 0;
 1390|  1.52k|    break;
 1391|  1.46M|  default:
  ------------------
  |  Branch (1391:3): [True: 1.46M, False: 9.41M]
  ------------------
 1392|  1.46M|    ;
 1393|  10.8M|  }
 1394|  10.8M|  return res;
 1395|  10.8M|}
coap_pdu_parse_opt:
 1431|  3.16k|coap_pdu_parse_opt(coap_pdu_t *pdu, coap_opt_filter_t *error_opts) {
 1432|  3.16k|  int good = 1;
 1433|       |
 1434|  3.16k|  coap_option_filter_clear(error_opts);
 1435|       |
 1436|       |  /* sanity checks */
 1437|  3.16k|  if (pdu->code == 0) {
  ------------------
  |  Branch (1437:7): [True: 24, False: 3.13k]
  ------------------
 1438|     24|    if (pdu->used_size != 0 || pdu->e_token_length) {
  ------------------
  |  Branch (1438:9): [True: 21, False: 3]
  |  Branch (1438:32): [True: 2, False: 1]
  ------------------
 1439|     23|      coap_log_debug("coap_pdu_parse: empty message is not empty\n");
  ------------------
  |  |  126|     23|#define coap_log_debug(...) coap_log(COAP_LOG_DEBUG, __VA_ARGS__)
  |  |  ------------------
  |  |  |  |  290|     23|#define coap_log(level, ...) do { \
  |  |  |  |  291|     23|    if ((level) < (coap_get_log_level() + 1)) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (291:9): [True: 0, False: 23]
  |  |  |  |  ------------------
  |  |  |  |  292|     23|      coap_log_impl((level), __VA_ARGS__); \
  |  |  |  |  293|     23|  } while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (293:11): [Folded, False: 23]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1440|     23|      return 0;
 1441|     23|    }
 1442|     24|  }
 1443|       |
 1444|  3.14k|  if (pdu->e_token_length > pdu->used_size) {
  ------------------
  |  Branch (1444:7): [True: 5, False: 3.13k]
  ------------------
 1445|      5|    coap_log_debug("coap_pdu_parse: invalid Token\n");
  ------------------
  |  |  126|      5|#define coap_log_debug(...) coap_log(COAP_LOG_DEBUG, __VA_ARGS__)
  |  |  ------------------
  |  |  |  |  290|      5|#define coap_log(level, ...) do { \
  |  |  |  |  291|      5|    if ((level) < (coap_get_log_level() + 1)) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (291:9): [True: 0, False: 5]
  |  |  |  |  ------------------
  |  |  |  |  292|      5|      coap_log_impl((level), __VA_ARGS__); \
  |  |  |  |  293|      5|  } while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (293:11): [Folded, False: 5]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1446|      5|    return 0;
 1447|      5|  }
 1448|       |
 1449|  3.13k|  pdu->max_opt = 0;
 1450|  3.13k|  if (pdu->code == 0) {
  ------------------
  |  Branch (1450:7): [True: 1, False: 3.13k]
  ------------------
 1451|       |    /* empty packet */
 1452|      1|    pdu->used_size = 0;
 1453|      1|    pdu->data = NULL;
 1454|  3.13k|  } else {
 1455|       |    /* skip header + token */
 1456|  3.13k|    coap_opt_t *opt = pdu->token + pdu->e_token_length;
 1457|  3.13k|    size_t length = pdu->used_size - pdu->e_token_length;
 1458|       |
 1459|  11.2M|    while (length > 0 && *opt != COAP_PAYLOAD_START) {
  ------------------
  |  |   96|  11.2M|#define COAP_PAYLOAD_START 0xFF /* payload marker */
  ------------------
  |  Branch (1459:12): [True: 11.2M, False: 2.46k]
  |  Branch (1459:26): [True: 11.2M, False: 209]
  ------------------
 1460|  11.2M|#if (COAP_MAX_LOGGING_LEVEL >= _COAP_LOG_WARN)
 1461|  11.2M|      coap_opt_t *opt_last = opt;
 1462|  11.2M|#endif
 1463|  11.2M|      size_t optsize = next_option_safe(&opt, &length, &pdu->max_opt);
 1464|  11.2M|      uint32_t len;
 1465|  11.2M|      const uint8_t *opt_val;
 1466|       |
 1467|  11.2M|      if (optsize == 0) {
  ------------------
  |  Branch (1467:11): [True: 460, False: 11.2M]
  ------------------
 1468|    460|        coap_log_debug("coap_pdu_parse: %d.%02d: offset %u malformed option\n",
  ------------------
  |  |  126|    460|#define coap_log_debug(...) coap_log(COAP_LOG_DEBUG, __VA_ARGS__)
  |  |  ------------------
  |  |  |  |  290|    460|#define coap_log(level, ...) do { \
  |  |  |  |  291|    460|    if ((level) < (coap_get_log_level() + 1)) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (291:9): [True: 0, False: 460]
  |  |  |  |  ------------------
  |  |  |  |  292|    460|      coap_log_impl((level), __VA_ARGS__); \
  |  |  |  |  293|    460|  } while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (293:11): [Folded, False: 460]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1469|    460|                       pdu->code >> 5, pdu->code & 0x1F,
 1470|    460|                       (int)(opt_last - pdu->token - pdu->e_token_length));
 1471|    460|        coap_option_filter_set(error_opts, pdu->max_opt);
 1472|    460|        good = 0;
 1473|    460|        break;
 1474|    460|      }
 1475|  11.2M|      len = coap_opt_length((const uint8_t *)opt - optsize);
 1476|  11.2M|      opt_val = coap_opt_value((const uint8_t *)opt - optsize);
 1477|  11.2M|      if (COAP_PDU_IS_SIGNALING(pdu) ?
  ------------------
  |  |  102|  11.2M|#define COAP_PDU_IS_SIGNALING(pdu) ((pdu)->code >= 224)
  |  |  ------------------
  |  |  |  Branch (102:36): [True: 1.66M, False: 9.54M]
  |  |  ------------------
  ------------------
  |  Branch (1477:11): [True: 1.72M, False: 9.49M]
  ------------------
 1478|  1.66M|          !coap_pdu_parse_opt_csm(pdu->code, pdu->max_opt, len) :
 1479|  11.2M|          !coap_pdu_parse_opt_base(pdu->max_opt, len, opt_val)) {
 1480|  1.72M|        coap_log_warn("coap_pdu_parse: %d.%02d: offset %u option %u has bad length %" PRIu32 " or value\n",
  ------------------
  |  |  108|  1.72M|#define coap_log_warn(...) coap_log(COAP_LOG_WARN, __VA_ARGS__)
  |  |  ------------------
  |  |  |  |  290|  1.72M|#define coap_log(level, ...) do { \
  |  |  |  |  291|  1.72M|    if ((level) < (coap_get_log_level() + 1)) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (291:9): [True: 0, False: 1.72M]
  |  |  |  |  ------------------
  |  |  |  |  292|  1.72M|      coap_log_impl((level), __VA_ARGS__); \
  |  |  |  |  293|  1.72M|  } while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (293:11): [Folded, False: 1.72M]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1481|  1.72M|                      pdu->code >> 5, pdu->code & 0x1F,
 1482|  1.72M|                      (int)(opt_last - pdu->token - pdu->e_token_length), pdu->max_opt,
 1483|  1.72M|                      len);
 1484|  1.72M|        coap_option_filter_set(error_opts, pdu->max_opt);
 1485|  1.72M|        good = 0;
 1486|  1.72M|      }
 1487|  11.2M|    }
 1488|       |
 1489|  3.13k|    if (!good) {
  ------------------
  |  Branch (1489:9): [True: 1.50k, False: 1.63k]
  ------------------
 1490|       |      /*
 1491|       |       * Dump the options in the PDU for analysis, space separated except
 1492|       |       * error options which are prefixed by *
 1493|       |       * Two rows - hex and ascii (if printable)
 1494|       |       */
 1495|  1.50k|      static char outbuf[COAP_DEBUG_BUF_SIZE];
 1496|  1.50k|      char *obp;
 1497|  1.50k|      size_t tlen;
 1498|  1.50k|      size_t outbuflen;
 1499|  1.50k|      int i;
 1500|  1.50k|      int ok;
 1501|       |
 1502|  4.51k|      for (i = 0; i < 2; i++) {
  ------------------
  |  Branch (1502:19): [True: 3.00k, False: 1.50k]
  ------------------
 1503|  3.00k|        opt = pdu->token + pdu->e_token_length;
 1504|  3.00k|        length = pdu->used_size - pdu->e_token_length;
 1505|  3.00k|        pdu->max_opt = 0;
 1506|       |
 1507|  3.00k|        outbuflen = sizeof(outbuf);
 1508|  3.00k|        obp = outbuf;
 1509|  3.00k|        ok = write_prefix(&obp, &outbuflen, "O: ", 3);
 1510|       |        /*
 1511|       |         * Not safe to check for 'ok' here as a lot of variables may get
 1512|       |         * partially changed due to lack of outbuflen */
 1513|  4.68M|        while (length > 0 && *opt != COAP_PAYLOAD_START) {
  ------------------
  |  |   96|  4.67M|#define COAP_PAYLOAD_START 0xFF /* payload marker */
  ------------------
  |  Branch (1513:16): [True: 4.67M, False: 2.84k]
  |  Branch (1513:30): [True: 4.67M, False: 164]
  ------------------
 1514|  4.67M|          coap_opt_t *opt_last = opt;
 1515|  4.67M|          size_t optsize = next_option_safe(&opt, &length, &pdu->max_opt);
 1516|  4.67M|          const uint32_t len =
 1517|  4.67M|              optsize ? coap_opt_length((const uint8_t *)opt - optsize) : 0;
  ------------------
  |  Branch (1517:15): [True: 4.67M, False: 920]
  ------------------
 1518|  4.67M|          const uint8_t *opt_val =
 1519|  4.67M|              optsize ?  coap_opt_value((const uint8_t *)opt - optsize) : 0;
  ------------------
  |  Branch (1519:15): [True: 4.67M, False: 920]
  ------------------
 1520|       |
 1521|  4.67M|          if (!optsize || (COAP_PDU_IS_SIGNALING(pdu) ?
  ------------------
  |  |  102|  4.67M|#define COAP_PDU_IS_SIGNALING(pdu) ((pdu)->code >= 224)
  |  |  ------------------
  |  |  |  Branch (102:36): [True: 3.33M, False: 1.33M]
  |  |  ------------------
  ------------------
  |  Branch (1521:15): [True: 920, False: 4.67M]
  |  Branch (1521:27): [True: 3.44M, False: 1.23M]
  ------------------
 1522|  3.33M|                           !coap_pdu_parse_opt_csm(pdu->code, pdu->max_opt, len) :
 1523|  4.67M|                           !coap_pdu_parse_opt_base(pdu->max_opt, len, opt_val))) {
 1524|  3.44M|            ok = ok && write_prefix(&obp, &outbuflen, "*", 1);
  ------------------
  |  Branch (1524:18): [True: 63.1k, False: 3.37M]
  |  Branch (1524:24): [True: 63.1k, False: 18]
  ------------------
 1525|  3.44M|            if (!optsize) {
  ------------------
  |  Branch (1525:17): [True: 920, False: 3.44M]
  ------------------
 1526|       |              /* Skip to end of options to output all data */
 1527|    920|              opt = pdu->token + pdu->used_size;
 1528|    920|              length = 0;
 1529|    920|            }
 1530|  3.44M|          } else {
 1531|  1.23M|            ok = ok && write_prefix(&obp, &outbuflen, " ", 1);
  ------------------
  |  Branch (1531:18): [True: 56.5k, False: 1.17M]
  |  Branch (1531:24): [True: 56.5k, False: 32]
  ------------------
 1532|  1.23M|          }
 1533|  4.67M|          tlen = opt - opt_last;
 1534|  88.5M|          while (tlen) {
  ------------------
  |  Branch (1534:18): [True: 83.8M, False: 4.67M]
  ------------------
 1535|  83.8M|            tlen--;
 1536|  83.8M|            ok = ok && write_char(&obp, &outbuflen, *opt_last, i);
  ------------------
  |  Branch (1536:18): [True: 1.15M, False: 82.6M]
  |  Branch (1536:24): [True: 1.15M, False: 876]
  ------------------
 1537|  83.8M|            opt_last++;
 1538|  83.8M|          }
 1539|  4.67M|        }
 1540|  3.00k|        if (length && *opt == COAP_PAYLOAD_START) {
  ------------------
  |  |   96|    164|#define COAP_PAYLOAD_START 0xFF /* payload marker */
  ------------------
  |  Branch (1540:13): [True: 164, False: 2.84k]
  |  Branch (1540:23): [True: 164, False: 0]
  ------------------
 1541|    164|          write_char(&obp, &outbuflen, *opt, i);
 1542|    164|        }
 1543|       |        /* write_*() always leaves a spare byte to null terminate */
 1544|  3.00k|        *obp = '\000';
 1545|  3.00k|        coap_log_debug("%s\n", outbuf);
  ------------------
  |  |  126|  3.00k|#define coap_log_debug(...) coap_log(COAP_LOG_DEBUG, __VA_ARGS__)
  |  |  ------------------
  |  |  |  |  290|  3.00k|#define coap_log(level, ...) do { \
  |  |  |  |  291|  3.00k|    if ((level) < (coap_get_log_level() + 1)) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (291:9): [True: 0, False: 3.00k]
  |  |  |  |  ------------------
  |  |  |  |  292|  3.00k|      coap_log_impl((level), __VA_ARGS__); \
  |  |  |  |  293|  3.00k|  } while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (293:11): [Folded, False: 3.00k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1546|  3.00k|      }
 1547|  1.50k|    }
 1548|       |
 1549|  3.13k|    if (length > 0) {
  ------------------
  |  Branch (1549:9): [True: 209, False: 2.92k]
  ------------------
 1550|    209|      assert(*opt == COAP_PAYLOAD_START);
  ------------------
  |  Branch (1550:7): [True: 209, False: 0]
  ------------------
 1551|    209|      opt++;
 1552|    209|      length--;
 1553|       |
 1554|    209|      if (length == 0) {
  ------------------
  |  Branch (1554:11): [True: 19, False: 190]
  ------------------
 1555|     19|        coap_log_debug("coap_pdu_parse: message ending in payload start marker\n");
  ------------------
  |  |  126|     19|#define coap_log_debug(...) coap_log(COAP_LOG_DEBUG, __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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1556|     19|        return 0;
 1557|     19|      }
 1558|    209|    }
 1559|  3.11k|    if (length > 0)
  ------------------
  |  Branch (1559:9): [True: 190, False: 2.92k]
  ------------------
 1560|    190|      pdu->data = (uint8_t *)opt;
 1561|  2.92k|    else
 1562|  2.92k|      pdu->data = NULL;
 1563|  3.11k|  }
 1564|       |
 1565|  3.11k|  return good;
 1566|  3.13k|}
coap_pdu_parse:
 1572|  3.20k|               coap_pdu_t *pdu) {
 1573|  3.20k|  coap_opt_filter_t error_opts;
 1574|       |
 1575|  3.20k|  return coap_pdu_parse2(proto, data, length, pdu, &error_opts);
 1576|  3.20k|}
coap_pdu_parse2:
 1583|  3.20k|                coap_opt_filter_t *error_opts) {
 1584|  3.20k|  size_t hdr_size;
 1585|       |
 1586|  3.20k|  if (length == 0)
  ------------------
  |  Branch (1586:7): [True: 0, False: 3.20k]
  ------------------
 1587|      0|    return 0;
 1588|  3.20k|  hdr_size = coap_pdu_parse_header_size(proto, data);
 1589|  3.20k|  if (!hdr_size || hdr_size > length)
  ------------------
  |  Branch (1589:7): [True: 0, False: 3.20k]
  |  Branch (1589:20): [True: 3, False: 3.20k]
  ------------------
 1590|      3|    return 0;
 1591|  3.20k|  if (hdr_size > pdu->max_hdr_size)
  ------------------
  |  Branch (1591:7): [True: 0, False: 3.20k]
  ------------------
 1592|      0|    return 0;
 1593|  3.20k|  if (!coap_pdu_resize(pdu, length - hdr_size))
  ------------------
  |  Branch (1593:7): [True: 0, False: 3.20k]
  ------------------
 1594|      0|    return 0;
 1595|  3.20k|  if (pdu->token - hdr_size != data)
  ------------------
  |  Branch (1595:7): [True: 3.20k, False: 0]
  ------------------
 1596|  3.20k|    memcpy(pdu->token - hdr_size, data, length);
 1597|  3.20k|  pdu->hdr_size = (uint8_t)hdr_size;
 1598|  3.20k|  pdu->used_size = length - hdr_size;
 1599|  3.20k|  return coap_pdu_parse_header(pdu, proto) && coap_pdu_parse_opt(pdu, error_opts);
  ------------------
  |  Branch (1599:10): [True: 3.16k, False: 37]
  |  Branch (1599:47): [True: 1.62k, False: 1.54k]
  ------------------
 1600|  3.20k|}
coap_pdu_encode_header:
 1603|  1.62k|coap_pdu_encode_header(coap_pdu_t *pdu, coap_proto_t proto) {
 1604|  1.62k|  uint8_t e_token_length;
 1605|       |
 1606|  1.62k|  if (pdu->actual_token.length < COAP_TOKEN_EXT_1B_BIAS) {
  ------------------
  |  |   56|  1.62k|#define COAP_TOKEN_EXT_1B_BIAS 13
  ------------------
  |  Branch (1606:7): [True: 1.56k, False: 56]
  ------------------
 1607|  1.56k|    e_token_length = (uint8_t)pdu->actual_token.length;
 1608|  1.56k|  } else if (pdu->actual_token.length < COAP_TOKEN_EXT_2B_BIAS) {
  ------------------
  |  |   57|     56|#define COAP_TOKEN_EXT_2B_BIAS 269 /* 13 + 256 */
  ------------------
  |  Branch (1608:14): [True: 25, False: 31]
  ------------------
 1609|     25|    e_token_length = COAP_TOKEN_EXT_1B_TKL;
  ------------------
  |  |   54|     25|#define COAP_TOKEN_EXT_1B_TKL 13
  ------------------
 1610|     31|  } else if (pdu->actual_token.length <= COAP_TOKEN_EXT_MAX) {
  ------------------
  |  |   60|     31|#define COAP_TOKEN_EXT_MAX 65804UL /* 13 + 256 + 65535 */
  ------------------
  |  Branch (1610:14): [True: 31, False: 0]
  ------------------
 1611|     31|    e_token_length = COAP_TOKEN_EXT_2B_TKL;
  ------------------
  |  |   55|     31|#define COAP_TOKEN_EXT_2B_TKL 14
  ------------------
 1612|     31|  } else {
 1613|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1614|      0|    return 0;
 1615|      0|  }
 1616|  1.62k|  if (COAP_PROTO_NOT_RELIABLE(proto)) {
  ------------------
  |  |   41|  1.62k|#define COAP_PROTO_NOT_RELIABLE(p) ((p)==COAP_PROTO_UDP || (p)==COAP_PROTO_DTLS)
  |  |  ------------------
  |  |  |  Branch (41:37): [True: 1.62k, False: 0]
  |  |  |  Branch (41:60): [True: 0, False: 0]
  |  |  ------------------
  ------------------
 1617|  1.62k|    assert(pdu->max_hdr_size >= 4);
  ------------------
  |  Branch (1617:5): [True: 1.62k, False: 0]
  ------------------
 1618|  1.62k|    if (pdu->max_hdr_size < 4) {
  ------------------
  |  Branch (1618:9): [True: 0, False: 1.62k]
  ------------------
 1619|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1620|      0|      return 0;
 1621|      0|    }
 1622|  1.62k|    pdu->token[-4] = COAP_DEFAULT_VERSION << 6
  ------------------
  |  |   35|  1.62k|#define COAP_DEFAULT_VERSION      1 /* version of CoAP supported */
  ------------------
 1623|  1.62k|                     | pdu->type << 4
 1624|  1.62k|                     | e_token_length;
 1625|  1.62k|    pdu->token[-3] = pdu->code;
 1626|  1.62k|    pdu->token[-2] = (uint8_t)(pdu->mid >> 8);
 1627|  1.62k|    pdu->token[-1] = (uint8_t)(pdu->mid);
 1628|  1.62k|    pdu->hdr_size = 4;
 1629|  1.62k|#if !COAP_DISABLE_TCP
 1630|  1.62k|  } 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]
  |  |  ------------------
  ------------------
 1631|      0|    size_t len;
 1632|      0|    assert(pdu->used_size >= pdu->e_token_length);
  ------------------
  |  Branch (1632:5): [True: 0, False: 0]
  ------------------
 1633|      0|    if (pdu->used_size < pdu->e_token_length) {
  ------------------
  |  Branch (1633:9): [True: 0, False: 0]
  ------------------
 1634|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1635|      0|      return 0;
 1636|      0|    }
 1637|       |
 1638|       |    /* A lot of the reliable code assumes type is CON */
 1639|      0|    if (pdu->type != COAP_MESSAGE_CON)
  ------------------
  |  Branch (1639:9): [True: 0, False: 0]
  ------------------
 1640|      0|      pdu->type = COAP_MESSAGE_CON;
 1641|       |
 1642|      0|    if (proto == COAP_PROTO_WS || proto == COAP_PROTO_WSS)
  ------------------
  |  Branch (1642:9): [True: 0, False: 0]
  |  Branch (1642:35): [True: 0, False: 0]
  ------------------
 1643|      0|      len = 0;
 1644|      0|    else
 1645|      0|      len = pdu->used_size - pdu->e_token_length;
 1646|      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 (1646:9): [True: 0, False: 0]
  ------------------
 1647|      0|      assert(pdu->max_hdr_size >= 2);
  ------------------
  |  Branch (1647:7): [True: 0, False: 0]
  ------------------
 1648|      0|      if (pdu->max_hdr_size < 2) {
  ------------------
  |  Branch (1648:11): [True: 0, False: 0]
  ------------------
 1649|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1650|      0|        return 0;
 1651|      0|      }
 1652|      0|      pdu->token[-2] = (uint8_t)len << 4
 1653|      0|                       | e_token_length;
 1654|      0|      pdu->token[-1] = pdu->code;
 1655|      0|      pdu->hdr_size = 2;
 1656|      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 (1656:16): [True: 0, False: 0]
  ------------------
 1657|      0|      assert(pdu->max_hdr_size >= 3);
  ------------------
  |  Branch (1657:7): [True: 0, False: 0]
  ------------------
 1658|      0|      if (pdu->max_hdr_size < 3) {
  ------------------
  |  Branch (1658:11): [True: 0, False: 0]
  ------------------
 1659|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1660|      0|        return 0;
 1661|      0|      }
 1662|      0|      pdu->token[-3] = 13 << 4 | e_token_length;
 1663|      0|      pdu->token[-2] = (uint8_t)(len - COAP_MESSAGE_SIZE_OFFSET_TCP8);
  ------------------
  |  |   38|      0|#define COAP_MESSAGE_SIZE_OFFSET_TCP8 13
  ------------------
 1664|      0|      pdu->token[-1] = pdu->code;
 1665|      0|      pdu->hdr_size = 3;
 1666|      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 (1666:16): [True: 0, False: 0]
  ------------------
 1667|      0|      assert(pdu->max_hdr_size >= 4);
  ------------------
  |  Branch (1667:7): [True: 0, False: 0]
  ------------------
 1668|      0|      if (pdu->max_hdr_size < 4) {
  ------------------
  |  Branch (1668:11): [True: 0, False: 0]
  ------------------
 1669|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1670|      0|        return 0;
 1671|      0|      }
 1672|      0|      pdu->token[-4] = 14 << 4 | e_token_length;
 1673|      0|      pdu->token[-3] = (uint8_t)((len - COAP_MESSAGE_SIZE_OFFSET_TCP16) >> 8);
  ------------------
  |  |   39|      0|#define COAP_MESSAGE_SIZE_OFFSET_TCP16 269 /* 13 + 256 */
  ------------------
 1674|      0|      pdu->token[-2] = (uint8_t)(len - COAP_MESSAGE_SIZE_OFFSET_TCP16);
  ------------------
  |  |   39|      0|#define COAP_MESSAGE_SIZE_OFFSET_TCP16 269 /* 13 + 256 */
  ------------------
 1675|      0|      pdu->token[-1] = pdu->code;
 1676|      0|      pdu->hdr_size = 4;
 1677|      0|    } else {
 1678|      0|      assert(pdu->max_hdr_size >= 6);
  ------------------
  |  Branch (1678:7): [True: 0, False: 0]
  ------------------
 1679|      0|      if (pdu->max_hdr_size < 6) {
  ------------------
  |  Branch (1679:11): [True: 0, False: 0]
  ------------------
 1680|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1681|      0|        return 0;
 1682|      0|      }
 1683|      0|      pdu->token[-6] = 15 << 4 | e_token_length;
 1684|      0|      pdu->token[-5] = (uint8_t)((len - COAP_MESSAGE_SIZE_OFFSET_TCP32) >> 24);
  ------------------
  |  |   40|      0|#define COAP_MESSAGE_SIZE_OFFSET_TCP32 65805 /* 269 + 65536 */
  ------------------
 1685|      0|      pdu->token[-4] = (uint8_t)((len - COAP_MESSAGE_SIZE_OFFSET_TCP32) >> 16);
  ------------------
  |  |   40|      0|#define COAP_MESSAGE_SIZE_OFFSET_TCP32 65805 /* 269 + 65536 */
  ------------------
 1686|      0|      pdu->token[-3] = (uint8_t)((len - COAP_MESSAGE_SIZE_OFFSET_TCP32) >> 8);
  ------------------
  |  |   40|      0|#define COAP_MESSAGE_SIZE_OFFSET_TCP32 65805 /* 269 + 65536 */
  ------------------
 1687|      0|      pdu->token[-2] = (uint8_t)(len - COAP_MESSAGE_SIZE_OFFSET_TCP32);
  ------------------
  |  |   40|      0|#define COAP_MESSAGE_SIZE_OFFSET_TCP32 65805 /* 269 + 65536 */
  ------------------
 1688|      0|      pdu->token[-1] = pdu->code;
 1689|      0|      pdu->hdr_size = 6;
 1690|      0|    }
 1691|      0|#endif /* ! COAP_DISABLE_TCP */
 1692|      0|  } else {
 1693|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1694|      0|  }
 1695|  1.62k|  return pdu->hdr_size;
 1696|  1.62k|}
coap_pdu.c:next_option_safe:
 1038|  15.8M|next_option_safe(coap_opt_t **optp, size_t *length, uint16_t *max_opt) {
 1039|  15.8M|  coap_option_t option;
 1040|  15.8M|  size_t optsize;
 1041|       |
 1042|  15.8M|  assert(optp);
  ------------------
  |  Branch (1042:3): [True: 15.8M, False: 0]
  ------------------
 1043|  15.8M|  assert(*optp);
  ------------------
  |  Branch (1043:3): [True: 15.8M, False: 0]
  ------------------
 1044|  15.8M|  assert(length);
  ------------------
  |  Branch (1044:3): [True: 15.8M, False: 0]
  ------------------
 1045|       |
 1046|  15.8M|  optsize = coap_opt_parse(*optp, *length, &option);
 1047|  15.8M|  assert(optsize <= *length);
  ------------------
  |  Branch (1047:3): [True: 15.8M, False: 0]
  ------------------
 1048|       |
 1049|       |  /* signal an error if this option would exceed the
 1050|       |   * allowed number space */
 1051|  15.8M|  if ((uint32_t)(*max_opt) + option.delta > COAP_MAX_OPT) {
  ------------------
  |  |  105|  15.8M|#define COAP_MAX_OPT 65535 /**< the highest option number we know */
  ------------------
  |  Branch (1051:7): [True: 30, False: 15.8M]
  ------------------
 1052|     30|    return 0;
 1053|     30|  }
 1054|  15.8M|  *max_opt += option.delta;
 1055|  15.8M|  *optp += optsize;
 1056|  15.8M|  *length -= optsize;
 1057|       |
 1058|  15.8M|  return optsize;
 1059|  15.8M|}
coap_pdu.c:coap_pdu_parse_opt_csm:
 1207|  5.00M|coap_pdu_parse_opt_csm(coap_pdu_code_t code, coap_option_num_t option, uint16_t len) {
 1208|  5.00M|  switch ((coap_pdu_signaling_proto_t)code) {
 1209|  10.5k|  case COAP_SIGNALING_CSM:
  ------------------
  |  Branch (1209:3): [True: 10.5k, False: 4.99M]
  ------------------
 1210|  10.5k|    switch ((coap_sig_csm_opt_t)option) {
 1211|  1.87k|    case COAP_SIG_OPT_MAX_MESSAGE_SIZE:
  ------------------
  |  Branch (1211:5): [True: 1.87k, False: 8.65k]
  ------------------
 1212|  1.87k|      if (len > 4)
  ------------------
  |  Branch (1212:11): [True: 1.15k, False: 716]
  ------------------
 1213|  1.15k|        goto bad;
 1214|    716|      break;
 1215|  2.04k|    case COAP_SIG_OPT_BLOCK_WISE_TRANSFER:
  ------------------
  |  Branch (1215:5): [True: 2.04k, False: 8.48k]
  ------------------
 1216|  2.04k|      if (len > 0)
  ------------------
  |  Branch (1216:11): [True: 1.50k, False: 540]
  ------------------
 1217|  1.50k|        goto bad;
 1218|    540|      break;
 1219|  1.54k|    case COAP_SIG_OPT_EXTENDED_TOKEN_LENGTH:
  ------------------
  |  Branch (1219:5): [True: 1.54k, False: 8.99k]
  ------------------
 1220|  1.54k|      if (len > 3)
  ------------------
  |  Branch (1220:11): [True: 990, False: 550]
  ------------------
 1221|    990|        goto bad;
 1222|    550|      break;
 1223|  5.07k|    default:
  ------------------
  |  Branch (1223:5): [True: 5.07k, False: 5.46k]
  ------------------
 1224|  5.07k|      if (option & 0x01)
  ------------------
  |  Branch (1224:11): [True: 4.24k, False: 831]
  ------------------
 1225|  4.24k|        goto bad; /* Critical */
 1226|  10.5k|    }
 1227|  2.63k|    break;
 1228|  24.5k|  case COAP_SIGNALING_PING:
  ------------------
  |  Branch (1228:3): [True: 24.5k, False: 4.98M]
  ------------------
 1229|  89.0k|  case COAP_SIGNALING_PONG:
  ------------------
  |  Branch (1229:3): [True: 64.4k, False: 4.94M]
  ------------------
 1230|  89.0k|    switch ((coap_sig_ping_opt_t)option) {
 1231|  2.30k|    case COAP_SIG_OPT_CUSTODY:
  ------------------
  |  Branch (1231:5): [True: 2.30k, False: 86.7k]
  ------------------
 1232|  2.30k|      if (len > 0)
  ------------------
  |  Branch (1232:11): [True: 1.65k, False: 645]
  ------------------
 1233|  1.65k|        goto bad;
 1234|    645|      break;
 1235|  86.7k|    default:
  ------------------
  |  Branch (1235:5): [True: 86.7k, False: 2.30k]
  ------------------
 1236|  86.7k|      if (option & 0x01)
  ------------------
  |  Branch (1236:11): [True: 46.6k, False: 40.0k]
  ------------------
 1237|  46.6k|        goto bad; /* Critical */
 1238|  89.0k|    }
 1239|  40.6k|    break;
 1240|  44.9k|  case COAP_SIGNALING_RELEASE:
  ------------------
  |  Branch (1240:3): [True: 44.9k, False: 4.96M]
  ------------------
 1241|  44.9k|    switch ((coap_sig_release_opt_t)option) {
 1242|  3.19k|    case COAP_SIG_OPT_ALTERNATIVE_ADDRESS:
  ------------------
  |  Branch (1242:5): [True: 3.19k, False: 41.8k]
  ------------------
 1243|  3.19k|      if (len < 1 || len > 255)
  ------------------
  |  Branch (1243:11): [True: 1.48k, False: 1.71k]
  |  Branch (1243:22): [True: 1.21k, False: 504]
  ------------------
 1244|  2.69k|        goto bad;
 1245|    504|      break;
 1246|  18.8k|    case COAP_SIG_OPT_HOLD_OFF:
  ------------------
  |  Branch (1246:5): [True: 18.8k, False: 26.1k]
  ------------------
 1247|  18.8k|      if (len > 3)
  ------------------
  |  Branch (1247:11): [True: 1.03k, False: 17.8k]
  ------------------
 1248|  1.03k|        goto bad;
 1249|  17.8k|      break;
 1250|  22.9k|    default:
  ------------------
  |  Branch (1250:5): [True: 22.9k, False: 22.0k]
  ------------------
 1251|  22.9k|      if (option & 0x01)
  ------------------
  |  Branch (1251:11): [True: 17.7k, False: 5.12k]
  ------------------
 1252|  17.7k|        goto bad; /* Critical */
 1253|  44.9k|    }
 1254|  23.4k|    break;
 1255|  23.4k|  case COAP_SIGNALING_ABORT:
  ------------------
  |  Branch (1255:3): [True: 5.92k, False: 4.99M]
  ------------------
 1256|  5.92k|    switch ((coap_sig_abort_opt_t)option) {
 1257|  1.43k|    case COAP_SIG_OPT_BAD_CSM_OPTION:
  ------------------
  |  Branch (1257:5): [True: 1.43k, False: 4.49k]
  ------------------
 1258|  1.43k|      if (len > 2)
  ------------------
  |  Branch (1258:11): [True: 1.07k, False: 359]
  ------------------
 1259|  1.07k|        goto bad;
 1260|    359|      break;
 1261|  4.49k|    default:
  ------------------
  |  Branch (1261:5): [True: 4.49k, False: 1.43k]
  ------------------
 1262|  4.49k|      if (option & 0x01)
  ------------------
  |  Branch (1262:11): [True: 2.59k, False: 1.89k]
  ------------------
 1263|  2.59k|        goto bad; /* Critical */
 1264|  5.92k|    }
 1265|  2.25k|    break;
 1266|  4.85M|  default:
  ------------------
  |  Branch (1266:3): [True: 4.85M, False: 150k]
  ------------------
 1267|  4.85M|    goto bad;
 1268|  5.00M|  }
 1269|  69.0k|  return 1;
 1270|  4.93M|bad:
 1271|  4.93M|  return 0;
 1272|  5.00M|}
coap_pdu.c:write_prefix:
 1398|   122k|write_prefix(char **obp, size_t *len, const char *prf, size_t prflen) {
 1399|       |  /* Make sure space for null terminating byte */
 1400|   122k|  if (*len < prflen +1) {
  ------------------
  |  Branch (1400:7): [True: 50, False: 122k]
  ------------------
 1401|     50|    return 0;
 1402|     50|  }
 1403|       |
 1404|   122k|  memcpy(*obp, prf, prflen);
 1405|   122k|  *obp += prflen;
 1406|   122k|  *len -= prflen;
 1407|   122k|  return 1;
 1408|   122k|}
coap_pdu.c:write_char:
 1411|  1.15M|write_char(char **obp, size_t *len, int c, int printable) {
 1412|       |  /* Make sure space for null terminating byte */
 1413|  1.15M|  if (*len < 2 +1) {
  ------------------
  |  Branch (1413:7): [True: 994, False: 1.15M]
  ------------------
 1414|    994|    return 0;
 1415|    994|  }
 1416|       |
 1417|  1.15M|  if (!printable) {
  ------------------
  |  Branch (1417:7): [True: 577k, False: 577k]
  ------------------
 1418|   577k|    const uint8_t hex[] = "0123456789abcdef";
 1419|   577k|    (*obp)[0] = hex[(c & 0xf0) >> 4];
 1420|   577k|    (*obp)[1] = hex[c & 0x0f];
 1421|   577k|  } else {
 1422|   577k|    (*obp)[0] = isprint(c) ? c : '.';
  ------------------
  |  Branch (1422:17): [True: 106k, False: 471k]
  ------------------
 1423|   577k|    (*obp)[1] = ' ';
 1424|   577k|  }
 1425|  1.15M|  *obp += 2;
 1426|  1.15M|  *len -= 2;
 1427|  1.15M|  return 1;
 1428|  1.15M|}

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

coap_new_string:
   21|  1.47k|coap_new_string(size_t size) {
   22|  1.47k|  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.47k|  if (size > SIZE_MAX - sizeof(coap_str_bin_union_t) - 1 - 8) {
  ------------------
  |  Branch (31:7): [True: 0, False: 1.47k]
  ------------------
   32|      0|    return NULL;
   33|      0|  }
   34|       |
   35|  1.47k|  s = (coap_string_t *)coap_malloc_type(COAP_STRING,
   36|  1.47k|                                        sizeof(coap_str_bin_union_t) + size + 1);
   37|  1.47k|  if (!s) {
  ------------------
  |  Branch (37:7): [True: 0, False: 1.47k]
  ------------------
   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.47k|  memset(s, 0, sizeof(coap_str_bin_union_t));
   43|  1.47k|  s->s = ((unsigned char *)s) + sizeof(coap_str_bin_union_t);
   44|  1.47k|  s->s[size] = '\000';
   45|  1.47k|  s->length = size;
   46|  1.47k|  return s;
   47|  1.47k|}
coap_delete_string:
   50|  3.24k|coap_delete_string(coap_string_t *s) {
   51|  3.24k|  coap_free_type(COAP_STRING, s);
   52|  3.24k|}
coap_delete_binary:
  114|  3.20k|coap_delete_binary(coap_binary_t *s) {
  115|  3.20k|  coap_free_type(COAP_STRING, s);
  116|  3.20k|}

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

coap_clock_init:
   68|  3.20k|coap_clock_init(void) {
   69|  3.20k|#ifdef COAP_CLOCK
   70|  3.20k|  struct timespec tv;
   71|  3.20k|  clock_gettime(COAP_CLOCK, &tv);
  ------------------
  |  |   43|  3.20k|#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.20k|  coap_clock_offset = tv.tv_sec;
   78|  3.20k|}
coap_ticks:
   90|  3.20k|coap_ticks(coap_tick_t *t) {
   91|  3.20k|  coap_tick_t tmp;
   92|       |
   93|  3.20k|#ifdef COAP_CLOCK
   94|  3.20k|  struct timespec tv;
   95|  3.20k|  clock_gettime(COAP_CLOCK, &tv);
  ------------------
  |  |   43|  3.20k|#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.20k|  tmp = SHR_FP(tv.tv_nsec * Q(FRAC, (COAP_TICKS_PER_SECOND/1000000000.0)), FRAC);
  ------------------
  |  |   87|  3.20k|#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.20k|  *t = tmp + (tv.tv_sec - coap_clock_offset) * COAP_TICKS_PER_SECOND;
  ------------------
  |  |  164|  3.20k|#define COAP_TICKS_PER_SECOND ((coap_tick_t)(1000U))
  ------------------
  120|  3.20k|}
coap_ticks_to_rt_us:
  128|  3.20k|coap_ticks_to_rt_us(coap_tick_t t) {
  129|  3.20k|  return (uint64_t)coap_clock_offset * 1000000 + (uint64_t)t * 1000000 / COAP_TICKS_PER_SECOND;
  ------------------
  |  |  164|  3.20k|#define COAP_TICKS_PER_SECOND ((coap_tick_t)(1000U))
  ------------------
  130|  3.20k|}

coap_split_proxy_uri:
  351|    546|coap_split_proxy_uri(const uint8_t *str_var, size_t len, coap_uri_t *uri) {
  352|    546|  return coap_split_uri_sub(str_var, len, uri, COAP_URI_CHECK_PROXY);
  353|    546|}
coap_check_dots:
  668|  7.82M|coap_check_dots(const uint8_t *s, size_t len) {
  669|  7.82M|  uint8_t p;
  670|       |
  671|  7.82M|  if (!len)
  ------------------
  |  Branch (671:7): [True: 7.76M, False: 59.2k]
  ------------------
  672|  7.76M|    return 0;
  673|       |
  674|  59.2k|  p = *s;
  675|       |
  676|       |  /* Check 'first' char */
  677|  59.2k|  if (p == '%' && len >=3) {
  ------------------
  |  Branch (677:7): [True: 3.30k, False: 55.9k]
  |  Branch (677:19): [True: 3.09k, False: 209]
  ------------------
  678|  3.09k|    if (s[1] == '2' && (s[2] == 'E' || s[2] == 'e')) {
  ------------------
  |  Branch (678:9): [True: 813, False: 2.27k]
  |  Branch (678:25): [True: 210, False: 603]
  |  Branch (678:40): [True: 366, False: 237]
  ------------------
  679|    576|      s += 2;
  680|    576|      len -= 2;
  681|    576|    }
  682|  3.09k|    p = '.';
  683|  3.09k|  }
  684|  59.2k|  if (p != '.')
  ------------------
  |  Branch (684:7): [True: 54.9k, False: 4.29k]
  ------------------
  685|  54.9k|    return 0;
  686|  4.29k|  if (len == 1)
  ------------------
  |  Branch (686:7): [True: 1.16k, False: 3.13k]
  ------------------
  687|  1.16k|    return 1;
  688|       |
  689|       |  /* Check 'second' char, first is '.' */
  690|  3.13k|  s++;
  691|  3.13k|  len--;
  692|  3.13k|  assert(len);
  ------------------
  |  Branch (692:3): [True: 3.13k, False: 0]
  ------------------
  693|  3.13k|  p = *s;
  694|  3.13k|  if (p == '%' && len >=3) {
  ------------------
  |  Branch (694:7): [True: 2.30k, False: 822]
  |  Branch (694:19): [True: 2.03k, False: 278]
  ------------------
  695|  2.03k|    if (s[1] == '2' && (s[2] == 'E' || s[2] == 'e')) {
  ------------------
  |  Branch (695:9): [True: 1.66k, False: 369]
  |  Branch (695:25): [True: 201, False: 1.46k]
  |  Branch (695:40): [True: 1.13k, False: 327]
  ------------------
  696|  1.33k|      len -= 2;
  697|  1.33k|    }
  698|  2.03k|    p = '.';
  699|  2.03k|  }
  700|  3.13k|  if (p != '.')
  ------------------
  |  Branch (700:7): [True: 1.00k, False: 2.12k]
  ------------------
  701|  1.00k|    return 0;
  702|  2.12k|  if (len == 1)
  ------------------
  |  Branch (702:7): [True: 1.26k, False: 860]
  ------------------
  703|  1.26k|    return 2;
  704|       |
  705|    860|  return 0;
  706|  2.12k|}
coap_get_query:
 1103|  1.62k|coap_get_query(const coap_pdu_t *request) {
 1104|  1.62k|  coap_opt_iterator_t opt_iter;
 1105|  1.62k|  coap_opt_filter_t f;
 1106|  1.62k|  coap_opt_t *q;
 1107|  1.62k|  coap_string_t *query = NULL;
 1108|  1.62k|  size_t length = 0;
 1109|  1.62k|  static const uint8_t hex[] = "0123456789ABCDEF";
 1110|       |
 1111|  1.62k|  coap_option_filter_clear(&f);
 1112|  1.62k|  coap_option_filter_set(&f, COAP_OPTION_URI_QUERY);
 1113|  1.62k|  coap_option_iterator_init(request, &opt_iter, &f);
 1114|  12.2k|  while ((q = coap_option_next(&opt_iter))) {
  ------------------
  |  Branch (1114:10): [True: 10.6k, False: 1.62k]
  ------------------
 1115|  10.6k|    uint16_t seg_len = coap_opt_length(q), i;
 1116|  10.6k|    const uint8_t *seg= coap_opt_value(q);
 1117|  43.3k|    for (i = 0; i < seg_len; i++) {
  ------------------
  |  Branch (1117:17): [True: 32.7k, False: 10.6k]
  ------------------
 1118|  32.7k|      if (is_unescaped_in_query(seg[i]))
  ------------------
  |  Branch (1118:11): [True: 5.38k, False: 27.3k]
  ------------------
 1119|  5.38k|        length += 1;
 1120|  27.3k|      else
 1121|  27.3k|        length += 3;
 1122|  32.7k|    }
 1123|  10.6k|    length += 1;
 1124|  10.6k|  }
 1125|  1.62k|  if (length > 0)
  ------------------
  |  Branch (1125:7): [True: 273, False: 1.34k]
  ------------------
 1126|    273|    length -= 1;
 1127|  1.62k|  if (length > 0) {
  ------------------
  |  Branch (1127:7): [True: 273, False: 1.34k]
  ------------------
 1128|    273|    query = coap_new_string(length);
 1129|    273|    if (query) {
  ------------------
  |  Branch (1129:9): [True: 273, False: 0]
  ------------------
 1130|    273|      query->length = length;
 1131|    273|      unsigned char *s = query->s;
 1132|    273|      coap_option_iterator_init(request, &opt_iter, &f);
 1133|  10.8k|      while ((q = coap_option_next(&opt_iter))) {
  ------------------
  |  Branch (1133:14): [True: 10.6k, False: 273]
  ------------------
 1134|  10.6k|        if (s != query->s)
  ------------------
  |  Branch (1134:13): [True: 10.3k, False: 273]
  ------------------
 1135|  10.3k|          *s++ = '&';
 1136|  10.6k|        uint16_t seg_len = coap_opt_length(q), i;
 1137|  10.6k|        const uint8_t *seg= coap_opt_value(q);
 1138|  43.3k|        for (i = 0; i < seg_len; i++) {
  ------------------
  |  Branch (1138:21): [True: 32.7k, False: 10.6k]
  ------------------
 1139|  32.7k|          if (is_unescaped_in_query(seg[i])) {
  ------------------
  |  Branch (1139:15): [True: 5.38k, False: 27.3k]
  ------------------
 1140|  5.38k|            *s++ = seg[i];
 1141|  27.3k|          } else {
 1142|  27.3k|            *s++ = '%';
 1143|  27.3k|            *s++ = hex[seg[i]>>4];
 1144|  27.3k|            *s++ = hex[seg[i]&0x0F];
 1145|  27.3k|          }
 1146|  32.7k|        }
 1147|  10.6k|      }
 1148|    273|    }
 1149|    273|  }
 1150|  1.62k|  return query;
 1151|  1.62k|}
coap_map_abbrev_uri_path:
 1154|     13|coap_map_abbrev_uri_path(coap_upa_chain_t *chain, uint32_t value) {
 1155|     13|  while (chain) {
  ------------------
  |  Branch (1155:10): [True: 0, False: 13]
  ------------------
 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|     13|  return NULL;
 1164|     13|}
coap_get_uri_path:
 1182|  1.62k|coap_get_uri_path(const coap_pdu_t *request) {
 1183|  1.62k|  coap_opt_iterator_t opt_iter;
 1184|  1.62k|  coap_opt_filter_t f;
 1185|  1.62k|  coap_opt_t *q;
 1186|  1.62k|  coap_string_t *uri_path = NULL;
 1187|  1.62k|  size_t length = 0;
 1188|  1.62k|  static const uint8_t hex[] = "0123456789ABCDEF";
 1189|       |
 1190|  1.62k|  q = coap_check_option(request, COAP_OPTION_URI_PATH_ABB, &opt_iter);
 1191|  1.62k|  if (q) {
  ------------------
  |  Branch (1191:7): [True: 28, False: 1.59k]
  ------------------
 1192|     28|    uint32_t value;
 1193|     28|    const char *exp;
 1194|     28|    if (coap_check_option(request, COAP_OPTION_PROXY_URI, &opt_iter) ||
  ------------------
  |  Branch (1194:9): [True: 10, False: 18]
  ------------------
 1195|     18|        coap_check_option(request, COAP_OPTION_URI_PATH, &opt_iter)) {
  ------------------
  |  Branch (1195:9): [True: 5, False: 13]
  ------------------
 1196|     15|      return NULL;
 1197|     15|    }
 1198|     13|    value = coap_decode_var_bytes(coap_opt_value(q), coap_opt_length(q));
 1199|     13|    exp = coap_map_abbrev_uri_path(coap_upa_server_mapping_chain, value);
 1200|     13|    if (exp) {
  ------------------
  |  Branch (1200:9): [True: 0, False: 13]
  ------------------
 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|     13|    return NULL;
 1208|     13|  }
 1209|  1.59k|  q = coap_check_option(request, COAP_OPTION_PROXY_URI, &opt_iter);
 1210|  1.59k|  if (q) {
  ------------------
  |  Branch (1210:7): [True: 546, False: 1.04k]
  ------------------
 1211|    546|    coap_uri_t uri;
 1212|       |
 1213|    546|    if (coap_split_proxy_uri(coap_opt_value(q),
  ------------------
  |  Branch (1213:9): [True: 394, False: 152]
  ------------------
 1214|    546|                             coap_opt_length(q), &uri) < 0) {
 1215|    394|      return NULL;
 1216|    394|    }
 1217|    152|    uri_path = coap_new_string(uri.path.length);
 1218|    152|    if (uri_path && uri.path.length) {
  ------------------
  |  Branch (1218:9): [True: 152, False: 0]
  |  Branch (1218:21): [True: 36, False: 116]
  ------------------
 1219|     36|      memcpy(uri_path->s, uri.path.s, uri.path.length);
 1220|     36|    }
 1221|    152|    return uri_path;
 1222|    546|  }
 1223|       |
 1224|  1.04k|  coap_option_filter_clear(&f);
 1225|  1.04k|  coap_option_filter_set(&f, COAP_OPTION_URI_PATH);
 1226|  1.04k|  coap_option_iterator_init(request, &opt_iter, &f);
 1227|  7.67M|  while ((q = coap_option_next(&opt_iter))) {
  ------------------
  |  Branch (1227:10): [True: 7.67M, False: 1.04k]
  ------------------
 1228|  7.67M|    uint16_t seg_len = coap_opt_length(q), i;
 1229|  7.67M|    const uint8_t *seg = coap_opt_value(q);
 1230|  8.49M|    for (i = 0; i < seg_len; i++) {
  ------------------
  |  Branch (1230:17): [True: 820k, False: 7.67M]
  ------------------
 1231|   820k|      if (is_unescaped_in_path(seg[i]))
  ------------------
  |  Branch (1231:11): [True: 28.0k, False: 792k]
  ------------------
 1232|  28.0k|        length += 1;
 1233|   792k|      else
 1234|   792k|        length += 3;
 1235|   820k|    }
 1236|       |    /* bump for the leading "/" */
 1237|  7.67M|    length += 1;
 1238|  7.67M|  }
 1239|       |  /* The first entry does not have a leading "/" */
 1240|  1.04k|  if (length > 0)
  ------------------
  |  Branch (1240:7): [True: 394, False: 654]
  ------------------
 1241|    394|    length -= 1;
 1242|       |
 1243|       |  /* if 0, either no URI_PATH Option, or the first one was empty */
 1244|  1.04k|  uri_path = coap_new_string(length);
 1245|  1.04k|  if (uri_path) {
  ------------------
  |  Branch (1245:7): [True: 1.04k, False: 0]
  ------------------
 1246|  1.04k|    uri_path->length = length;
 1247|  1.04k|    unsigned char *s = uri_path->s;
 1248|  1.04k|    int n = 0;
 1249|  1.04k|    coap_option_iterator_init(request, &opt_iter, &f);
 1250|  7.67M|    while ((q = coap_option_next(&opt_iter))) {
  ------------------
  |  Branch (1250:12): [True: 7.67M, False: 1.04k]
  ------------------
 1251|  7.67M|      if (n++) {
  ------------------
  |  Branch (1251:11): [True: 7.67M, False: 394]
  ------------------
 1252|  7.67M|        *s++ = '/';
 1253|  7.67M|      }
 1254|  7.67M|      uint16_t seg_len = coap_opt_length(q), i;
 1255|  7.67M|      const uint8_t *seg= coap_opt_value(q);
 1256|  8.49M|      for (i = 0; i < seg_len; i++) {
  ------------------
  |  Branch (1256:19): [True: 820k, False: 7.67M]
  ------------------
 1257|   820k|        if (is_unescaped_in_path(seg[i])) {
  ------------------
  |  Branch (1257:13): [True: 28.0k, False: 792k]
  ------------------
 1258|  28.0k|          *s++ = seg[i];
 1259|   792k|        } else {
 1260|   792k|          *s++ = '%';
 1261|   792k|          *s++ = hex[seg[i]>>4];
 1262|   792k|          *s++ = hex[seg[i]&0x0F];
 1263|   792k|        }
 1264|   820k|      }
 1265|  7.67M|    }
 1266|  1.04k|  }
 1267|  1.04k|  return uri_path;
 1268|  1.59k|}
coap_delete_upa_chain:
 1271|  6.40k|coap_delete_upa_chain(coap_upa_chain_t *chain) {
 1272|  6.40k|  while (chain) {
  ------------------
  |  Branch (1272:10): [True: 0, False: 6.40k]
  ------------------
 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.40k|}
coap_uri.c:coap_split_uri_sub:
   84|    546|                   coap_uri_check_t check_proxy) {
   85|    546|  const uint8_t *p, *q;
   86|    546|  int res = 0;
   87|    546|  size_t i;
   88|    546|  int is_unix_domain = 0;
   89|    546|  int is_llc = 0;
   90|       |
   91|    546|  if (!str_var || !uri || len == 0)
  ------------------
  |  Branch (91:7): [True: 0, False: 546]
  |  Branch (91:19): [True: 0, False: 546]
  |  Branch (91:27): [True: 0, False: 546]
  ------------------
   92|      0|    return -1;
   93|       |
   94|    546|  memset(uri, 0, sizeof(coap_uri_t));
   95|    546|  uri->port = COAP_DEFAULT_PORT;
  ------------------
  |  |   39|    546|#define COAP_DEFAULT_PORT      5683 /* CoAP default UDP/TCP port */
  ------------------
   96|       |
   97|       |  /* search for scheme */
   98|    546|  p = str_var;
   99|    546|  if (*p == '/') {
  ------------------
  |  Branch (99:7): [True: 2, False: 544]
  ------------------
  100|       |    /* no scheme, host or port */
  101|      2|    if (check_proxy == COAP_URI_CHECK_PROXY) {
  ------------------
  |  Branch (101:9): [True: 2, False: 0]
  ------------------
  102|       |      /* Must have ongoing host if proxy definition */
  103|      2|      return -1;
  104|      2|    }
  105|      0|    q = p;
  106|      0|    goto path;
  107|      2|  }
  108|       |
  109|       |  /* find scheme terminating :// */
  110|  9.93k|  while (len >= 3 && !(p[0] == ':' && p[1] == '/' && p[2] == '/')) {
  ------------------
  |  Branch (110:10): [True: 9.87k, False: 60]
  |  Branch (110:24): [True: 1.13k, False: 8.73k]
  |  Branch (110:39): [True: 691, False: 448]
  |  Branch (110:54): [True: 484, False: 207]
  ------------------
  111|  9.39k|    ++p;
  112|  9.39k|    --len;
  113|  9.39k|  }
  114|    544|  if (len < 3) {
  ------------------
  |  Branch (114:7): [True: 60, False: 484]
  ------------------
  115|       |    /* scheme not defined with a :// terminator */
  116|     60|    res = -2;
  117|     60|    goto error;
  118|     60|  }
  119|  2.16k|  for (i = 0; i < COAP_URI_SCHEME_LAST; i++) {
  ------------------
  |  Branch (119:15): [True: 2.06k, False: 93]
  ------------------
  120|  2.06k|    if ((p - str_var) == (int)strlen(coap_uri_scheme[i].name) &&
  ------------------
  |  Branch (120:9): [True: 744, False: 1.32k]
  ------------------
  121|    744|        memcmp(str_var, coap_uri_scheme[i].name, p - str_var) == 0) {
  ------------------
  |  Branch (121:9): [True: 391, False: 353]
  ------------------
  122|    391|      if (check_proxy != COAP_URI_CHECK_PROXY && coap_uri_scheme[i].proxy_only) {
  ------------------
  |  Branch (122:11): [True: 0, False: 391]
  |  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|    391|      uri->scheme = coap_uri_scheme[i].scheme;
  128|    391|      uri->port = coap_uri_scheme[i].port;
  129|    391|      break;
  130|    391|    }
  131|  2.06k|  }
  132|    484|  if (i == COAP_URI_SCHEME_LAST) {
  ------------------
  |  Branch (132:7): [True: 93, False: 391]
  ------------------
  133|       |    /* scheme unknown */
  134|     93|    coap_log_err("%.*s URI scheme unknown\n", (int)(p - str_var), str_var);
  ------------------
  |  |  102|     93|#define coap_log_err(...) coap_log(COAP_LOG_ERR, __VA_ARGS__)
  |  |  ------------------
  |  |  |  |  290|     93|#define coap_log(level, ...) do { \
  |  |  |  |  291|     93|    if ((level) < (coap_get_log_level() + 1)) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (291:9): [True: 0, False: 93]
  |  |  |  |  ------------------
  |  |  |  |  292|     93|      coap_log_impl((level), __VA_ARGS__); \
  |  |  |  |  293|     93|  } while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (293:11): [Folded, False: 93]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  135|     93|    res = -1;
  136|     93|    goto error;
  137|     93|  }
  138|    391|  switch (uri->scheme) {
  139|    158|  case COAP_URI_SCHEME_COAP:
  ------------------
  |  Branch (139:3): [True: 158, False: 233]
  ------------------
  140|    158|    break;
  141|      1|  case COAP_URI_SCHEME_COAPS:
  ------------------
  |  Branch (141:3): [True: 1, False: 390]
  ------------------
  142|      1|    if (!coap_dtls_is_supported()) {
  ------------------
  |  Branch (142:9): [True: 0, False: 1]
  ------------------
  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|      1|    break;
  147|      1|  case COAP_URI_SCHEME_COAP_TCP:
  ------------------
  |  Branch (147:3): [True: 1, False: 390]
  ------------------
  148|      1|    if (!coap_tcp_is_supported()) {
  ------------------
  |  Branch (148:9): [True: 0, False: 1]
  ------------------
  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|      1|    break;
  153|      1|  case COAP_URI_SCHEME_COAPS_TCP:
  ------------------
  |  Branch (153:3): [True: 1, False: 390]
  ------------------
  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: 390]
  ------------------
  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: 390]
  ------------------
  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|    227|  case COAP_URI_SCHEME_HTTP:
  ------------------
  |  Branch (171:3): [True: 227, False: 164]
  ------------------
  172|    228|  case COAP_URI_SCHEME_HTTPS:
  ------------------
  |  Branch (172:3): [True: 1, False: 390]
  ------------------
  173|       |    /* Not proxy, caught above.  For proxy, assume app is doing CoAP <> HTTP mapping. */
  174|    228|    break;
  175|      0|  case COAP_URI_SCHEME_LAST:
  ------------------
  |  Branch (175:3): [True: 0, False: 391]
  ------------------
  176|      0|  default:
  ------------------
  |  Branch (176:3): [True: 0, False: 391]
  ------------------
  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|    391|  }
  180|       |  /* skip :// */
  181|    391|  p += 3;
  182|    391|  len -= 3;
  183|       |
  184|       |  /* p points to beginning of Uri-Host */
  185|    391|  q = p;
  186|       |
  187|    391|  if (len && *p == '[') {
  ------------------
  |  Branch (187:7): [True: 383, False: 8]
  |  Branch (187:14): [True: 35, False: 348]
  ------------------
  188|       |    /* IPv6 address reference or Unix domain */
  189|     35|    ++p;
  190|     35|    ++q;
  191|     35|    --len;
  192|       |
  193|  2.63k|    while (len && *q != ']') {
  ------------------
  |  Branch (193:12): [True: 2.61k, False: 15]
  |  Branch (193:19): [True: 2.59k, False: 20]
  ------------------
  194|  2.59k|      ++q;
  195|  2.59k|      --len;
  196|  2.59k|    }
  197|       |
  198|     35|    if (!len || *q != ']' || p == q) {
  ------------------
  |  Branch (198:9): [True: 15, False: 20]
  |  Branch (198:17): [True: 0, False: 20]
  |  Branch (198:30): [True: 1, False: 19]
  ------------------
  199|     16|      res = -3;
  200|     16|      goto error;
  201|     16|    }
  202|       |
  203|     19|    COAP_SET_STR(&uri->host, q - p, p);
  ------------------
  |  |   52|     19|#define COAP_SET_STR(st,l,v) { (st)->length = (l), (st)->s = (v); }
  ------------------
  204|     19|    ++q;
  205|     19|    --len;
  206|     19|#if COAP_AF_LLC_SUPPORT
  207|    356|  } else if ((len >= LLC_HOST_LEN) && strncmp((const char *)p, "llc[", 4) == 0) {
  ------------------
  |  |  169|    356|#define LLC_HOST_LEN (4 + HW_ADDRSTRLEN + 4)
  |  |  ------------------
  |  |  |  |  167|    356|#define HW_ADDRSTRLEN 17
  |  |  ------------------
  ------------------
  |  Branch (207:14): [True: 214, False: 142]
  |  Branch (207:39): [True: 135, False: 79]
  ------------------
  208|    135|    unsigned long sap = 0;
  209|       |
  210|    135|    is_llc = 1;
  211|       |
  212|  4.51k|    while (len && *q != ']') {
  ------------------
  |  Branch (212:12): [True: 4.51k, False: 7]
  |  Branch (212:19): [True: 4.38k, False: 128]
  ------------------
  213|  4.38k|      ++q;
  214|  4.38k|      --len;
  215|  4.38k|    }
  216|       |
  217|    135|    if (!len || *q != ']' || p == q) {
  ------------------
  |  Branch (217:9): [True: 7, False: 128]
  |  Branch (217:17): [True: 0, False: 128]
  |  Branch (217:30): [True: 0, False: 128]
  ------------------
  218|      7|      res = -7;
  219|      7|      goto error;
  220|      7|    }
  221|       |
  222|    128|    ++q;
  223|    128|    --len;
  224|       |
  225|    128|    if (!len || *q != ':') {
  ------------------
  |  Branch (225:9): [True: 3, False: 125]
  |  Branch (225:17): [True: 19, False: 106]
  ------------------
  226|     22|      coap_log_warn("LLC SAP missing in URI\n");
  ------------------
  |  |  108|     22|#define coap_log_warn(...) coap_log(COAP_LOG_WARN, __VA_ARGS__)
  |  |  ------------------
  |  |  |  |  290|     22|#define coap_log(level, ...) do { \
  |  |  |  |  291|     22|    if ((level) < (coap_get_log_level() + 1)) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (291:9): [True: 0, False: 22]
  |  |  |  |  ------------------
  |  |  |  |  292|     22|      coap_log_impl((level), __VA_ARGS__); \
  |  |  |  |  293|     22|  } while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (293:11): [Folded, False: 22]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  227|     22|      res = -7;
  228|     22|      goto error;
  229|     22|    }
  230|       |
  231|    106|    ++q;
  232|    106|    --len;
  233|       |
  234|  1.86k|    while (len && isxdigit(*q)) {
  ------------------
  |  Branch (234:12): [True: 1.82k, False: 35]
  |  Branch (234:19): [True: 1.75k, False: 71]
  ------------------
  235|  1.75k|      if (*q >= 'a' && *q <= 'f')
  ------------------
  |  Branch (235:11): [True: 465, False: 1.29k]
  |  Branch (235:24): [True: 465, False: 0]
  ------------------
  236|    465|        sap = sap * 16 + (*q - 'a' + 10);
  237|  1.29k|      else if (*q >= 'A' && *q <= 'F')
  ------------------
  |  Branch (237:16): [True: 957, False: 336]
  |  Branch (237:29): [True: 957, False: 0]
  ------------------
  238|    957|        sap = sap * 16 + (*q - 'A' + 10);
  239|       |
  240|  1.75k|      ++q;
  241|  1.75k|      --len;
  242|  1.75k|    }
  243|       |
  244|    106|    if (sap > UINT8_MAX) {
  ------------------
  |  Branch (244:9): [True: 91, False: 15]
  ------------------
  245|     91|      coap_log_warn("LLC SAP invalid (%lu > 255)\n", sap);
  ------------------
  |  |  108|     91|#define coap_log_warn(...) coap_log(COAP_LOG_WARN, __VA_ARGS__)
  |  |  ------------------
  |  |  |  |  290|     91|#define coap_log(level, ...) do { \
  |  |  |  |  291|     91|    if ((level) < (coap_get_log_level() + 1)) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (291:9): [True: 0, False: 91]
  |  |  |  |  ------------------
  |  |  |  |  292|     91|      coap_log_impl((level), __VA_ARGS__); \
  |  |  |  |  293|     91|  } while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (293:11): [Folded, False: 91]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  246|     91|      res = -7;
  247|     91|      goto error;
  248|     91|    }
  249|       |
  250|     15|    COAP_SET_STR(&uri->host, q - p, p);
  ------------------
  |  |   52|     15|#define COAP_SET_STR(st,l,v) { (st)->length = (l), (st)->s = (v); }
  ------------------
  251|     15|#endif /* COAP_AF_LLC_SUPPORT */
  252|    221|  } else {
  253|       |    /* IPv4 address, FQDN or Unix domain socket */
  254|    221|    if (len >= 3 && p[0] == '%' && p[1] == '2' &&
  ------------------
  |  Branch (254:9): [True: 192, False: 29]
  |  Branch (254:21): [True: 43, False: 149]
  |  Branch (254:36): [True: 17, False: 26]
  ------------------
  255|     17|        (p[2] == 'F' || p[2] == 'f')) {
  ------------------
  |  Branch (255:10): [True: 2, False: 15]
  |  Branch (255:25): [True: 1, False: 14]
  ------------------
  256|       |      /* Unix domain definition */
  257|      3|      uri->port = 0;
  258|      3|      is_unix_domain = 1;
  259|      3|    }
  260|  8.84k|    while (len && *q != ':' && *q != '/' && *q != '?') {
  ------------------
  |  Branch (260:12): [True: 8.76k, False: 81]
  |  Branch (260:19): [True: 8.66k, False: 96]
  |  Branch (260:32): [True: 8.63k, False: 38]
  |  Branch (260:45): [True: 8.62k, False: 6]
  ------------------
  261|  8.62k|      ++q;
  262|  8.62k|      --len;
  263|  8.62k|    }
  264|       |
  265|    221|    if (p == q) {
  ------------------
  |  Branch (265:9): [True: 10, False: 211]
  ------------------
  266|     10|      res = -3;
  267|     10|      goto error;
  268|     10|    }
  269|       |
  270|    211|    if ((int)(q - p) > 255) {
  ------------------
  |  Branch (270:9): [True: 8, False: 203]
  ------------------
  271|      8|      coap_log_warn("Host name length too long (%d > 255)\n", (int)(q - p));
  ------------------
  |  |  108|      8|#define coap_log_warn(...) coap_log(COAP_LOG_WARN, __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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  272|      8|      res = -6;
  273|      8|      goto error;
  274|      8|    }
  275|       |
  276|    203|    COAP_SET_STR(&uri->host, q - p, p);
  ------------------
  |  |   52|    203|#define COAP_SET_STR(st,l,v) { (st)->length = (l), (st)->s = (v); }
  ------------------
  277|    203|  }
  278|       |
  279|       |  /* check for Uri-Port (invalid for Unix) */
  280|    237|  if (len && *q == ':') {
  ------------------
  |  Branch (280:7): [True: 159, False: 78]
  |  Branch (280:14): [True: 97, False: 62]
  ------------------
  281|     97|    if (is_unix_domain || is_llc) {
  ------------------
  |  Branch (281:9): [True: 1, False: 96]
  |  Branch (281:27): [True: 1, False: 95]
  ------------------
  282|      2|      res = -5;
  283|      2|      goto error;
  284|      2|    }
  285|     95|    p = ++q;
  286|     95|    --len;
  287|       |
  288|    538|    while (len && isdigit(*q)) {
  ------------------
  |  Branch (288:12): [True: 491, False: 47]
  |  Branch (288:19): [True: 443, False: 48]
  ------------------
  289|    443|      ++q;
  290|    443|      --len;
  291|    443|    }
  292|       |
  293|     95|    if (p < q) {                /* explicit port number given */
  ------------------
  |  Branch (293:9): [True: 65, False: 30]
  ------------------
  294|     65|      long uri_port = 0;
  295|       |
  296|    497|      while ((p < q) && (uri_port <= UINT16_MAX))
  ------------------
  |  Branch (296:14): [True: 435, False: 62]
  |  Branch (296:25): [True: 432, False: 3]
  ------------------
  297|    432|        uri_port = uri_port * 10 + (*p++ - '0');
  298|       |
  299|       |      /* check if port number is in allowed range */
  300|     65|      if (uri_port > UINT16_MAX) {
  ------------------
  |  Branch (300:11): [True: 17, False: 48]
  ------------------
  301|     17|        coap_log_warn("Port number too big (%ld > 65535)\n", uri_port);
  ------------------
  |  |  108|     17|#define coap_log_warn(...) coap_log(COAP_LOG_WARN, __VA_ARGS__)
  |  |  ------------------
  |  |  |  |  290|     17|#define coap_log(level, ...) do { \
  |  |  |  |  291|     17|    if ((level) < (coap_get_log_level() + 1)) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (291:9): [True: 0, False: 17]
  |  |  |  |  ------------------
  |  |  |  |  292|     17|      coap_log_impl((level), __VA_ARGS__); \
  |  |  |  |  293|     17|  } while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (293:11): [Folded, False: 17]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  302|     17|        res = -4;
  303|     17|        goto error;
  304|     17|      }
  305|       |
  306|     48|      uri->port = (uint16_t)uri_port;
  307|     48|    }
  308|     95|  }
  309|       |
  310|    218|path:                 /* at this point, p must point to an absolute path */
  311|       |
  312|    218|  if (!len)
  ------------------
  |  Branch (312:7): [True: 110, False: 108]
  ------------------
  313|    110|    goto end;
  314|       |
  315|    108|  if (*q == '/') {
  ------------------
  |  Branch (315:7): [True: 41, False: 67]
  ------------------
  316|     41|    p = ++q;
  317|     41|    --len;
  318|       |
  319|  4.02k|    while (len && *q != '?') {
  ------------------
  |  Branch (319:12): [True: 3.99k, False: 39]
  |  Branch (319:19): [True: 3.98k, False: 2]
  ------------------
  320|  3.98k|      ++q;
  321|  3.98k|      --len;
  322|  3.98k|    }
  323|       |
  324|     41|    if (p < q) {
  ------------------
  |  Branch (324:9): [True: 36, False: 5]
  ------------------
  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|     41|  }
  329|       |
  330|       |  /* Uri_Query */
  331|    108|  if (len && *p == '?') {
  ------------------
  |  Branch (331:7): [True: 69, False: 39]
  |  Branch (331:14): [True: 3, False: 66]
  ------------------
  332|      3|    ++p;
  333|      3|    --len;
  334|      3|    COAP_SET_STR(&uri->query, len, p);
  ------------------
  |  |   52|      3|#define COAP_SET_STR(st,l,v) { (st)->length = (l), (st)->s = (v); }
  ------------------
  335|      3|    len = 0;
  336|      3|  }
  337|       |
  338|    218|end:
  339|    218|  return len ? -1 : 0;
  ------------------
  |  Branch (339:10): [True: 66, False: 152]
  ------------------
  340|       |
  341|    326|error:
  342|    326|  return res;
  343|    108|}
coap_uri.c:is_unescaped_in_query:
 1098|  65.5k|is_unescaped_in_query(const uint8_t c) {
 1099|  65.5k|  return is_unescaped_in_path(c) || c=='/' || c=='?';
  ------------------
  |  Branch (1099:10): [True: 10.3k, False: 55.1k]
  |  Branch (1099:37): [True: 408, False: 54.7k]
  |  Branch (1099:47): [True: 6, False: 54.7k]
  ------------------
 1100|  65.5k|}
coap_uri.c:is_unescaped_in_path:
 1089|  1.70M|is_unescaped_in_path(const uint8_t c) {
 1090|  1.70M|  return (c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') ||
  ------------------
  |  Branch (1090:11): [True: 72.5k, False: 1.63M]
  |  Branch (1090:23): [True: 4.85k, False: 67.6k]
  |  Branch (1090:37): [True: 59.2k, False: 1.64M]
  |  Branch (1090:49): [True: 20.9k, False: 38.2k]
  ------------------
 1091|  1.68M|         (c >= '0' && c <= '9') || c == '-' || c == '.' || c == '_' ||
  ------------------
  |  Branch (1091:11): [True: 63.4k, False: 1.61M]
  |  Branch (1091:23): [True: 6.75k, False: 56.6k]
  |  Branch (1091:36): [True: 6.11k, False: 1.66M]
  |  Branch (1091:48): [True: 1.66k, False: 1.66M]
  |  Branch (1091:60): [True: 1.55k, False: 1.66M]
  ------------------
 1092|  1.66M|         c == '~' || c == '!' || c == '$' || c == '\'' || c == '(' ||
  ------------------
  |  Branch (1092:10): [True: 1.49k, False: 1.66M]
  |  Branch (1092:22): [True: 2.04k, False: 1.66M]
  |  Branch (1092:34): [True: 1.26k, False: 1.65M]
  |  Branch (1092:46): [True: 976, False: 1.65M]
  |  Branch (1092:59): [True: 1.15k, False: 1.65M]
  ------------------
 1093|  1.65M|         c == ')' || c == '*' || c == '+' || c == ',' || c == ';' ||
  ------------------
  |  Branch (1093:10): [True: 1.38k, False: 1.65M]
  |  Branch (1093:22): [True: 2.42k, False: 1.65M]
  |  Branch (1093:34): [True: 2.52k, False: 1.65M]
  |  Branch (1093:46): [True: 1.49k, False: 1.64M]
  |  Branch (1093:58): [True: 816, False: 1.64M]
  ------------------
 1094|  1.64M|         c=='=' || c==':' || c=='@' || c == '&';
  ------------------
  |  Branch (1094:10): [True: 1.20k, False: 1.64M]
  |  Branch (1094:20): [True: 5.26k, False: 1.64M]
  |  Branch (1094:30): [True: 2.29k, False: 1.63M]
  |  Branch (1094:40): [True: 172, False: 1.63M]
  ------------------
 1095|  1.70M|}

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

