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

coap_fls:
   21|  16.3k|coap_fls(unsigned int i) {
   22|  16.3k|  return coap_flsll(i);
   23|  16.3k|}
coap_flsll:
   28|  16.3k|coap_flsll(long long j) {
   29|  16.3k|  unsigned long long i = (unsigned long long)j;
   30|  16.3k|  int n;
   31|  79.2k|  for (n = 0; i; n++)
  ------------------
  |  Branch (31:15): [True: 62.8k, False: 16.3k]
  ------------------
   32|  62.8k|    i >>= 1;
   33|  16.3k|  return n;
   34|  16.3k|}
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|     26|  for (i = 0; i < len; ++i)
  ------------------
  |  Branch (40:15): [True: 13, False: 13]
  ------------------
   41|     13|    n = (n << 8) + buf[i];
   42|       |
   43|     13|  return n;
   44|     13|}

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

coap_startup:
 5654|  3.16k|coap_startup(void) {
 5655|  3.16k|  coap_tick_t now;
 5656|  3.16k|#ifndef WITH_CONTIKI
 5657|  3.16k|  uint64_t us;
 5658|  3.16k|#endif /* !WITH_CONTIKI */
 5659|       |
 5660|  3.16k|  if (coap_started)
  ------------------
  |  Branch (5660:7): [True: 0, False: 3.16k]
  ------------------
 5661|      0|    return;
 5662|  3.16k|  coap_started = 1;
 5663|       |
 5664|       |#if COAP_THREAD_SAFE
 5665|       |  coap_lock_init(&global_lock);
 5666|       |  coap_mutex_init(&m_show_pdu);
 5667|       |  coap_mutex_init(&m_log_impl);
 5668|       |  coap_mutex_init(&m_io_threads);
 5669|       |#endif /* COAP_THREAD_SAFE */
 5670|       |
 5671|       |#if defined(HAVE_WINSOCK2_H)
 5672|       |  WORD wVersionRequested = MAKEWORD(2, 2);
 5673|       |  WSADATA wsaData;
 5674|       |  WSAStartup(wVersionRequested, &wsaData);
 5675|       |#endif
 5676|  3.16k|  coap_clock_init();
 5677|  3.16k|  coap_ticks(&now);
 5678|  3.16k|#ifndef WITH_CONTIKI
 5679|  3.16k|  us = coap_ticks_to_rt_us(now);
 5680|       |  /* Be accurate to the nearest (approx) us */
 5681|  3.16k|  coap_prng_init_lkd((unsigned int)us);
 5682|       |#else /* WITH_CONTIKI */
 5683|       |  coap_start_io_process();
 5684|       |#endif /* WITH_CONTIKI */
 5685|  3.16k|  coap_memory_init();
 5686|  3.16k|  coap_dtls_startup();
 5687|       |#ifdef WITH_LWIP
 5688|       |  coap_io_lwip_init();
 5689|       |#endif /* WITH_LWIP */
 5690|  3.16k|#if COAP_SERVER_SUPPORT
 5691|  3.16k|  static coap_str_const_t well_known = { sizeof(".well-known/core")-1,
 5692|  3.16k|                                         (const uint8_t *)".well-known/core"
 5693|  3.16k|                                       };
 5694|  3.16k|  memset(&resource_uri_wellknown, 0, sizeof(resource_uri_wellknown));
 5695|  3.16k|  resource_uri_wellknown.ref = 1;
 5696|  3.16k|  resource_uri_wellknown.handler[COAP_REQUEST_GET-1] = hnd_get_wellknown_lkd;
 5697|  3.16k|  resource_uri_wellknown.flags = COAP_RESOURCE_FLAGS_HAS_MCAST_SUPPORT;
  ------------------
  |  |   89|  3.16k|#define COAP_RESOURCE_FLAGS_HAS_MCAST_SUPPORT 0x8
  ------------------
 5698|  3.16k|  resource_uri_wellknown.uri_path = &well_known;
 5699|  3.16k|#endif /* COAP_SERVER_SUPPORT */
 5700|  3.16k|  send_recv_terminate = 0;
 5701|  3.16k|  coap_prng_lkd(&coap_unique_id, sizeof(coap_unique_id));
 5702|  3.16k|}
coap_cleanup:
 5705|  3.16k|coap_cleanup(void) {
 5706|  3.16k|  if (!coap_started)
  ------------------
  |  Branch (5706:7): [True: 0, False: 3.16k]
  ------------------
 5707|      0|    return;
 5708|  3.16k|  coap_started = 0;
 5709|       |#if defined(HAVE_WINSOCK2_H)
 5710|       |  WSACleanup();
 5711|       |#elif defined(WITH_CONTIKI)
 5712|       |  coap_stop_io_process();
 5713|       |#endif
 5714|       |#ifdef WITH_LWIP
 5715|       |  coap_io_lwip_cleanup();
 5716|       |#endif /* WITH_LWIP */
 5717|  3.16k|  coap_dtls_shutdown();
 5718|       |
 5719|  3.16k|  coap_delete_upa_chain(coap_upa_client_fallback_chain);
 5720|  3.16k|  coap_upa_client_fallback_chain = NULL;
 5721|  3.16k|  coap_delete_upa_chain(coap_upa_server_mapping_chain);
 5722|  3.16k|  coap_upa_server_mapping_chain = NULL;
 5723|       |#if COAP_THREAD_SAFE
 5724|       |  coap_mutex_destroy(&m_show_pdu);
 5725|       |  coap_mutex_destroy(&m_log_impl);
 5726|       |  coap_mutex_destroy(&m_io_threads);
 5727|       |#endif /* COAP_THREAD_SAFE */
 5728|       |
 5729|  3.16k|  coap_debug_reset();
 5730|  3.16k|}

coap_dtls_is_supported:
  191|      2|coap_dtls_is_supported(void) {
  192|      2|  if (SSLeay() < 0x10100000L) {
  ------------------
  |  Branch (192:7): [True: 0, False: 2]
  ------------------
  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|      2|#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|      2|  if (SSLeay() < 0x10101000L) {
  ------------------
  |  Branch (204:7): [True: 0, False: 2]
  ------------------
  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|      2|#endif /* OPENSSL_VERSION_NUMBER >= 0x10101000L */
  209|      2|  return 1;
  210|      2|}
coap_tls_is_supported:
  213|      2|coap_tls_is_supported(void) {
  214|      2|#if !COAP_DISABLE_TCP
  215|      2|  if (SSLeay() < 0x10100000L) {
  ------------------
  |  Branch (215:7): [True: 0, False: 2]
  ------------------
  216|      0|    coap_log_warn("OpenSSL version 1.1.0 or later is required\n");
  ------------------
  |  |  108|      0|#define coap_log_warn(...) coap_log(COAP_LOG_WARN, __VA_ARGS__)
  |  |  ------------------
  |  |  |  |  290|      0|#define coap_log(level, ...) do { \
  |  |  |  |  291|      0|    if ((level) < (coap_get_log_level() + 1)) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (291:9): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  292|      0|      coap_log_impl((level), __VA_ARGS__); \
  |  |  |  |  293|      0|  } while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (293:11): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  217|      0|    return 0;
  218|      0|  }
  219|      2|#if OPENSSL_VERSION_NUMBER >= 0x10101000L
  220|      2|  if (SSLeay() < 0x10101000L) {
  ------------------
  |  Branch (220:7): [True: 0, False: 2]
  ------------------
  221|      0|    coap_log_warn("OpenSSL version 1.1.1 or later is required\n");
  ------------------
  |  |  108|      0|#define coap_log_warn(...) coap_log(COAP_LOG_WARN, __VA_ARGS__)
  |  |  ------------------
  |  |  |  |  290|      0|#define coap_log(level, ...) do { \
  |  |  |  |  291|      0|    if ((level) < (coap_get_log_level() + 1)) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (291:9): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  292|      0|      coap_log_impl((level), __VA_ARGS__); \
  |  |  |  |  293|      0|  } while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (293:11): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  222|      0|    return 0;
  223|      0|  }
  224|      2|#endif /* OPENSSL_VERSION_NUMBER >= 0x10101000L */
  225|      2|  return 1;
  226|       |#else /* COAP_DISABLE_TCP */
  227|       |  return 0;
  228|       |#endif /* COAP_DISABLE_TCP */
  229|      2|}
coap_dtls_startup:
  304|  3.16k|coap_dtls_startup(void) {
  305|  3.16k|  SSL_load_error_strings();
  306|  3.16k|  SSL_library_init();
  307|  3.16k|#if OPENSSL_VERSION_NUMBER < 0x40000000L
  308|       |  ENGINE_load_dynamic();
  309|  3.16k|#endif /* OPENSSL_VERSION_NUMBER < 0x40000000L */
  310|  3.16k|}
coap_dtls_shutdown:
  313|  3.16k|coap_dtls_shutdown(void) {
  314|  3.16k|#if OPENSSL_VERSION_NUMBER < 0x30000000L
  315|  3.16k|  if (pkcs11_engine) {
  ------------------
  |  Branch (315:7): [True: 0, False: 3.16k]
  ------------------
  316|       |    /* Release the functional reference from ENGINE_init() */
  317|      0|    ENGINE_finish(pkcs11_engine);
  318|      0|    pkcs11_engine = NULL;
  319|      0|  }
  320|  3.16k|  if (defined_engine) {
  ------------------
  |  Branch (320:7): [True: 0, False: 3.16k]
  ------------------
  321|       |    /* Release the functional reference from ENGINE_init() */
  322|      0|    ENGINE_finish(defined_engine);
  323|      0|    defined_engine = NULL;
  324|      0|  }
  325|       |#elif OPENSSL_VERSION_NUMBER < 0x40000000L
  326|       |  pkcs11_engine = NULL;
  327|       |  defined_engine = NULL;
  328|       |#endif /* OPENSSL_VERSION_NUMBER >= 0x30000000L && < 0x40000000L */
  329|       |  ERR_free_strings();
  ------------------
  |  Branch (329:3): [Folded, False: 3.16k]
  ------------------
  330|  3.16k|  coap_dtls_set_log_level(COAP_LOG_EMERG);
  331|  3.16k|}
coap_dtls_set_log_level:
  590|  3.16k|coap_dtls_set_log_level(coap_log_t level) {
  591|  3.16k|  dtls_log_level = level;
  592|  3.16k|}

coap_opt_parse:
   41|  63.4M|coap_opt_parse(const coap_opt_t *opt, size_t length, coap_option_t *result) {
   42|       |
   43|  63.4M|  const coap_opt_t *opt_start = opt; /* store where parsing starts  */
   44|  63.4M|  uint32_t delta; /* wider than result->delta to detect overflow */
   45|       |
   46|  63.4M|  assert(opt);
  ------------------
  |  Branch (46:3): [True: 63.4M, False: 0]
  ------------------
   47|  63.4M|  assert(result);
  ------------------
  |  Branch (47:3): [True: 63.4M, False: 0]
  ------------------
   48|       |
   49|  63.4M|  if (length < 1)
  ------------------
  |  Branch (49:7): [True: 4.67k, False: 63.4M]
  ------------------
   50|  4.67k|    return 0;
   51|       |
   52|  63.4M|  result->delta = (*opt & 0xf0) >> 4;
   53|  63.4M|  result->length = *opt & 0x0f;
   54|  63.4M|  delta = result->delta;
   55|       |
   56|  63.4M|  switch (result->delta) {
   57|    618|  case 15:
  ------------------
  |  Branch (57:3): [True: 618, False: 63.4M]
  ------------------
   58|    618|    if (*opt != COAP_PAYLOAD_START) {
  ------------------
  |  |   96|    618|#define COAP_PAYLOAD_START 0xFF /* payload marker */
  ------------------
  |  Branch (58:9): [True: 141, False: 477]
  ------------------
   59|    141|      coap_log_debug("ignored reserved option delta 15\n");
  ------------------
  |  |  126|    141|#define coap_log_debug(...) coap_log(COAP_LOG_DEBUG, __VA_ARGS__)
  |  |  ------------------
  |  |  |  |  290|    141|#define coap_log(level, ...) do { \
  |  |  |  |  291|    141|    if ((level) < (coap_get_log_level() + 1)) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (291:9): [True: 0, False: 141]
  |  |  |  |  ------------------
  |  |  |  |  292|    141|      coap_log_impl((level), __VA_ARGS__); \
  |  |  |  |  293|    141|  } while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (293:11): [Folded, False: 141]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
   60|    141|    }
   61|    618|    return 0;
   62|  1.19k|  case 14:
  ------------------
  |  Branch (62:3): [True: 1.19k, False: 63.4M]
  ------------------
   63|       |    /* Handle two-byte value: First, the MSB + 269 is stored as delta value.
   64|       |     * After that, the option pointer is advanced to the LSB which is handled
   65|       |     * just like case delta == 13. */
   66|  1.19k|    ADVANCE_OPT_CHECK(opt,length,1);
  ------------------
  |  |   34|  1.19k|#define ADVANCE_OPT_CHECK(o,e,step) do { \
  |  |   35|  1.19k|    ADVANCE_OPT(o,e,step);               \
  |  |  ------------------
  |  |  |  |   22|  1.19k|#define ADVANCE_OPT(o,e,step) if ((e) < step) {           \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (22:35): [True: 0, False: 1.19k]
  |  |  |  |  ------------------
  |  |  |  |   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.19k|  } else {                                                \
  |  |  |  |   26|  1.19k|    (e) -= step;                                          \
  |  |  |  |   27|  1.19k|    (o) = ((o)) + step;                                   \
  |  |  |  |   28|  1.19k|  }
  |  |  ------------------
  |  |   36|  1.19k|    if ((e) < 1)                         \
  |  |  ------------------
  |  |  |  Branch (36:9): [True: 39, False: 1.15k]
  |  |  ------------------
  |  |   37|  1.19k|      return 0;                          \
  |  |   38|  1.19k|  } while (0)
  |  |  ------------------
  |  |  |  Branch (38:12): [Folded, False: 1.15k]
  |  |  ------------------
  ------------------
   67|  1.15k|    delta = ((*opt & 0xff) << 8) + 269;
   68|       |  /* fall through */
   69|  5.51k|  case 13:
  ------------------
  |  Branch (69:3): [True: 4.35k, False: 63.3M]
  ------------------
   70|  5.51k|    ADVANCE_OPT_CHECK(opt,length,1);
  ------------------
  |  |   34|  5.51k|#define ADVANCE_OPT_CHECK(o,e,step) do { \
  |  |   35|  5.51k|    ADVANCE_OPT(o,e,step);               \
  |  |  ------------------
  |  |  |  |   22|  5.51k|#define ADVANCE_OPT(o,e,step) if ((e) < step) {           \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (22:35): [True: 0, False: 5.51k]
  |  |  |  |  ------------------
  |  |  |  |   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.51k|  } else {                                                \
  |  |  |  |   26|  5.51k|    (e) -= step;                                          \
  |  |  |  |   27|  5.51k|    (o) = ((o)) + step;                                   \
  |  |  |  |   28|  5.51k|  }
  |  |  ------------------
  |  |   36|  5.51k|    if ((e) < 1)                         \
  |  |  ------------------
  |  |  |  Branch (36:9): [True: 51, False: 5.45k]
  |  |  ------------------
  |  |   37|  5.51k|      return 0;                          \
  |  |   38|  5.51k|  } while (0)
  |  |  ------------------
  |  |  |  Branch (38:12): [Folded, False: 5.45k]
  |  |  ------------------
  ------------------
   71|  5.45k|    delta += *opt & 0xff;
   72|  5.45k|    if (delta > 0xffff) {
  ------------------
  |  Branch (72:9): [True: 12, False: 5.44k]
  ------------------
   73|     12|      coap_log_debug("delta too large\n");
  ------------------
  |  |  126|     12|#define coap_log_debug(...) coap_log(COAP_LOG_DEBUG, __VA_ARGS__)
  |  |  ------------------
  |  |  |  |  290|     12|#define coap_log(level, ...) do { \
  |  |  |  |  291|     12|    if ((level) < (coap_get_log_level() + 1)) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (291:9): [True: 0, False: 12]
  |  |  |  |  ------------------
  |  |  |  |  292|     12|      coap_log_impl((level), __VA_ARGS__); \
  |  |  |  |  293|     12|  } while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (293:11): [Folded, False: 12]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
   74|     12|      return 0;
   75|     12|    }
   76|  5.44k|    result->delta = (uint16_t)delta;
   77|  5.44k|    break;
   78|       |
   79|  63.3M|  default:
  ------------------
  |  Branch (79:3): [True: 63.3M, False: 6.16k]
  ------------------
   80|  63.3M|    ;
   81|  63.4M|  }
   82|       |
   83|  63.4M|  switch (result->length) {
   84|     72|  case 15:
  ------------------
  |  Branch (84:3): [True: 72, False: 63.4M]
  ------------------
   85|     72|    coap_log_debug("found reserved option length 15\n");
  ------------------
  |  |  126|     72|#define coap_log_debug(...) coap_log(COAP_LOG_DEBUG, __VA_ARGS__)
  |  |  ------------------
  |  |  |  |  290|     72|#define coap_log(level, ...) do { \
  |  |  |  |  291|     72|    if ((level) < (coap_get_log_level() + 1)) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (291:9): [True: 0, False: 72]
  |  |  |  |  ------------------
  |  |  |  |  292|     72|      coap_log_impl((level), __VA_ARGS__); \
  |  |  |  |  293|     72|  } while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (293:11): [Folded, False: 72]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
   86|     72|    return 0;
   87|  5.99k|  case 14:
  ------------------
  |  Branch (87:3): [True: 5.99k, False: 63.3M]
  ------------------
   88|       |    /* Handle two-byte value: First, the MSB + 269 is stored as delta value.
   89|       |     * After that, the option pointer is advanced to the LSB which is handled
   90|       |     * just like case delta == 13. */
   91|  5.99k|    ADVANCE_OPT_CHECK(opt,length,1);
  ------------------
  |  |   34|  5.99k|#define ADVANCE_OPT_CHECK(o,e,step) do { \
  |  |   35|  5.99k|    ADVANCE_OPT(o,e,step);               \
  |  |  ------------------
  |  |  |  |   22|  5.99k|#define ADVANCE_OPT(o,e,step) if ((e) < step) {           \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (22:35): [True: 0, False: 5.99k]
  |  |  |  |  ------------------
  |  |  |  |   23|      0|    coap_log_debug("cannot advance opt past end\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |  126|      0|#define coap_log_debug(...) coap_log(COAP_LOG_DEBUG, __VA_ARGS__)
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  290|      0|#define coap_log(level, ...) do { \
  |  |  |  |  |  |  |  |  291|      0|    if ((level) < (coap_get_log_level() + 1)) \
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  Branch (291:9): [True: 0, False: 0]
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  292|      0|      coap_log_impl((level), __VA_ARGS__); \
  |  |  |  |  |  |  |  |  293|      0|  } while(0)
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  Branch (293:11): [Folded, False: 0]
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  |  |   24|      0|    return 0;                                             \
  |  |  |  |   25|  5.99k|  } else {                                                \
  |  |  |  |   26|  5.99k|    (e) -= step;                                          \
  |  |  |  |   27|  5.99k|    (o) = ((o)) + step;                                   \
  |  |  |  |   28|  5.99k|  }
  |  |  ------------------
  |  |   36|  5.99k|    if ((e) < 1)                         \
  |  |  ------------------
  |  |  |  Branch (36:9): [True: 57, False: 5.93k]
  |  |  ------------------
  |  |   37|  5.99k|      return 0;                          \
  |  |   38|  5.99k|  } while (0)
  |  |  ------------------
  |  |  |  Branch (38:12): [Folded, False: 5.93k]
  |  |  ------------------
  ------------------
   92|  5.93k|    result->length = ((*opt & 0xff) << 8) + 269;
   93|       |  /* fall through */
   94|  1.23M|  case 13:
  ------------------
  |  Branch (94:3): [True: 1.23M, False: 62.1M]
  ------------------
   95|  1.23M|    ADVANCE_OPT_CHECK(opt,length,1);
  ------------------
  |  |   34|  1.23M|#define ADVANCE_OPT_CHECK(o,e,step) do { \
  |  |   35|  1.23M|    ADVANCE_OPT(o,e,step);               \
  |  |  ------------------
  |  |  |  |   22|  1.23M|#define ADVANCE_OPT(o,e,step) if ((e) < step) {           \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (22:35): [True: 0, False: 1.23M]
  |  |  |  |  ------------------
  |  |  |  |   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.23M|  } else {                                                \
  |  |  |  |   26|  1.23M|    (e) -= step;                                          \
  |  |  |  |   27|  1.23M|    (o) = ((o)) + step;                                   \
  |  |  |  |   28|  1.23M|  }
  |  |  ------------------
  |  |   36|  1.23M|    if ((e) < 1)                         \
  |  |  ------------------
  |  |  |  Branch (36:9): [True: 72, False: 1.23M]
  |  |  ------------------
  |  |   37|  1.23M|      return 0;                          \
  |  |   38|  1.23M|  } while (0)
  |  |  ------------------
  |  |  |  Branch (38:12): [Folded, False: 1.23M]
  |  |  ------------------
  ------------------
   96|  1.23M|    result->length += *opt & 0xff;
   97|  1.23M|    break;
   98|       |
   99|  62.1M|  default:
  ------------------
  |  Branch (99:3): [True: 62.1M, False: 1.23M]
  ------------------
  100|  62.1M|    ;
  101|  63.4M|  }
  102|       |
  103|       |  /* ADVANCE_OPT() is correct here */
  104|  63.4M|  ADVANCE_OPT(opt,length,1);
  ------------------
  |  |   22|  63.4M|#define ADVANCE_OPT(o,e,step) if ((e) < step) {           \
  |  |  ------------------
  |  |  |  Branch (22:35): [True: 0, False: 63.4M]
  |  |  ------------------
  |  |   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|  63.4M|  } else {                                                \
  |  |   26|  63.4M|    (e) -= step;                                          \
  |  |   27|  63.4M|    (o) = ((o)) + step;                                   \
  |  |   28|  63.4M|  }
  ------------------
  105|       |  /* opt now points to value, if present */
  106|       |
  107|  63.4M|  result->value = opt;
  108|  63.4M|  if (length < result->length) {
  ------------------
  |  Branch (108:7): [True: 873, False: 63.4M]
  ------------------
  109|    873|    coap_log_debug("invalid option length\n");
  ------------------
  |  |  126|    873|#define coap_log_debug(...) coap_log(COAP_LOG_DEBUG, __VA_ARGS__)
  |  |  ------------------
  |  |  |  |  290|    873|#define coap_log(level, ...) do { \
  |  |  |  |  291|    873|    if ((level) < (coap_get_log_level() + 1)) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (291:9): [True: 0, False: 873]
  |  |  |  |  ------------------
  |  |  |  |  292|    873|      coap_log_impl((level), __VA_ARGS__); \
  |  |  |  |  293|    873|  } while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (293:11): [Folded, False: 873]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  110|    873|    return 0;
  111|    873|  }
  112|       |
  113|  63.4M|#undef ADVANCE_OPT
  114|  63.4M|#undef ADVANCE_OPT_CHECK
  115|       |
  116|  63.4M|  return (opt + result->length) - opt_start;
  117|  63.4M|}
coap_option_iterator_init:
  121|  7.42k|                          const coap_opt_filter_t *filter) {
  122|  7.42k|  assert(pdu);
  ------------------
  |  Branch (122:3): [True: 7.42k, False: 0]
  ------------------
  123|  7.42k|  assert(pdu->token);
  ------------------
  |  Branch (123:3): [True: 7.42k, False: 0]
  ------------------
  124|  7.42k|  assert(oi);
  ------------------
  |  Branch (124:3): [True: 7.42k, False: 0]
  ------------------
  125|       |
  126|  7.42k|  memset(oi, 0, sizeof(coap_opt_iterator_t));
  127|       |
  128|  7.42k|  oi->next_option = pdu->token + pdu->e_token_length;
  129|  7.42k|  if (pdu->token + pdu->used_size <= oi->next_option) {
  ------------------
  |  Branch (129:7): [True: 235, False: 7.19k]
  ------------------
  130|    235|    oi->bad = 1;
  131|    235|    return NULL;
  132|    235|  }
  133|       |
  134|  7.19k|  oi->length = pdu->used_size - pdu->e_token_length;
  135|       |
  136|  7.19k|  if (filter) {
  ------------------
  |  Branch (136:7): [True: 7.19k, False: 0]
  ------------------
  137|  7.19k|    memcpy(&oi->filter, filter, sizeof(coap_opt_filter_t));
  138|  7.19k|    oi->filtered = 1;
  139|  7.19k|  }
  140|  7.19k|  return oi;
  141|  7.42k|}
coap_option_next:
  156|  16.3M|coap_option_next(coap_opt_iterator_t *oi) {
  157|  16.3M|  coap_option_t option;
  158|  16.3M|  coap_opt_t *current_opt = NULL;
  159|  16.3M|  size_t optsize;
  160|       |
  161|  16.3M|  assert(oi);
  ------------------
  |  Branch (161:3): [True: 16.3M, False: 0]
  ------------------
  162|       |
  163|  16.3M|  if (opt_finished(oi))
  ------------------
  |  Branch (163:7): [True: 1.67k, False: 16.3M]
  ------------------
  164|  1.67k|    return NULL;
  165|       |
  166|  48.0M|  while (1) {
  ------------------
  |  Branch (166:10): [True: 48.0M, Folded]
  ------------------
  167|       |    /* oi->next_option always points to the next option to deliver; as
  168|       |     * opt_finished() filters out any bad conditions, we can assume that
  169|       |     * oi->next_option is valid. */
  170|  48.0M|    current_opt = oi->next_option;
  171|       |
  172|       |    /*
  173|       |     * Advance internal pointer to next option.
  174|       |     * optsize will be 0 when no more options
  175|       |     */
  176|  48.0M|    optsize = coap_opt_parse(oi->next_option, oi->length, &option);
  177|  48.0M|    if (optsize) {
  ------------------
  |  Branch (177:9): [True: 48.0M, False: 5.15k]
  ------------------
  178|  48.0M|      assert(optsize <= oi->length);
  ------------------
  |  Branch (178:7): [True: 48.0M, False: 0]
  ------------------
  179|       |
  180|  48.0M|      oi->next_option += optsize;
  181|  48.0M|      oi->length -= optsize;
  182|       |
  183|  48.0M|      oi->number += option.delta;
  184|  48.0M|    } else {                        /* current option is malformed */
  185|  5.15k|      oi->bad = 1;
  186|  5.15k|      return NULL;
  187|  5.15k|    }
  188|       |
  189|       |    /* Exit the while loop when:
  190|       |     *   - no filtering is done at all
  191|       |     *   - the filter matches for the current option
  192|       |     */
  193|  48.0M|    if (!oi->filtered ||
  ------------------
  |  Branch (193:9): [True: 0, False: 48.0M]
  ------------------
  194|  48.0M|        coap_option_filter_get(&oi->filter, oi->number) > 0)
  ------------------
  |  Branch (194:9): [True: 16.3M, False: 31.6M]
  ------------------
  195|  16.3M|      break;
  196|  48.0M|  }
  197|       |
  198|  16.3M|  return current_opt;
  199|  16.3M|}
coap_check_option:
  203|  3.32k|                  coap_opt_iterator_t *oi) {
  204|  3.32k|  coap_opt_filter_t f;
  205|       |
  206|  3.32k|  coap_option_filter_clear(&f);
  207|  3.32k|  coap_option_filter_set(&f, number);
  208|       |
  209|  3.32k|  coap_option_iterator_init(pdu, oi, &f);
  210|       |
  211|  3.32k|  return coap_option_next(oi);
  212|  3.32k|}
coap_opt_length:
  215|  31.7M|coap_opt_length(const coap_opt_t *opt) {
  216|  31.7M|  uint32_t length;
  217|       |
  218|  31.7M|  length = *opt & 0x0f;
  219|  31.7M|  switch (*opt & 0xf0) {
  220|      0|  case 0xf0:
  ------------------
  |  Branch (220:3): [True: 0, False: 31.7M]
  ------------------
  221|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  222|      0|    return 0;
  223|    607|  case 0xe0:
  ------------------
  |  Branch (223:3): [True: 607, False: 31.7M]
  ------------------
  224|    607|    ++opt;
  225|       |  /* fall through */
  226|       |  /* to skip another byte */
  227|  3.07k|  case 0xd0:
  ------------------
  |  Branch (227:3): [True: 2.47k, False: 31.7M]
  ------------------
  228|  3.07k|    ++opt;
  229|       |  /* fall through */
  230|       |  /* to skip another byte */
  231|  31.7M|  default:
  ------------------
  |  Branch (231:3): [True: 31.7M, False: 3.07k]
  ------------------
  232|  31.7M|    ++opt;
  233|  31.7M|  }
  234|       |
  235|  31.7M|  switch (length) {
  236|      0|  case 0x0f:
  ------------------
  |  Branch (236:3): [True: 0, False: 31.7M]
  ------------------
  237|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  238|      0|    return 0;
  239|  5.12k|  case 0x0e:
  ------------------
  |  Branch (239:3): [True: 5.12k, False: 31.7M]
  ------------------
  240|  5.12k|    length = (*opt++ << 8) + 269;
  241|       |  /* fall through */
  242|   631k|  case 0x0d:
  ------------------
  |  Branch (242:3): [True: 626k, False: 31.0M]
  ------------------
  243|   631k|    length += *opt++;
  244|   631k|    break;
  245|  31.0M|  default:
  ------------------
  |  Branch (245:3): [True: 31.0M, False: 631k]
  ------------------
  246|  31.0M|    ;
  247|  31.7M|  }
  248|  31.7M|  return length;
  249|  31.7M|}
coap_opt_value:
  252|  31.7M|coap_opt_value(const coap_opt_t *opt) {
  253|  31.7M|  size_t ofs = 1;
  254|       |
  255|  31.7M|  switch (*opt & 0xf0) {
  256|      0|  case 0xf0:
  ------------------
  |  Branch (256:3): [True: 0, False: 31.7M]
  ------------------
  257|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  258|      0|    return 0;
  259|    607|  case 0xe0:
  ------------------
  |  Branch (259:3): [True: 607, False: 31.7M]
  ------------------
  260|    607|    ++ofs;
  261|       |  /* fall through */
  262|  3.07k|  case 0xd0:
  ------------------
  |  Branch (262:3): [True: 2.47k, False: 31.7M]
  ------------------
  263|  3.07k|    ++ofs;
  264|  3.07k|    break;
  265|  31.7M|  default:
  ------------------
  |  Branch (265:3): [True: 31.7M, False: 3.07k]
  ------------------
  266|  31.7M|    ;
  267|  31.7M|  }
  268|       |
  269|  31.7M|  switch (*opt & 0x0f) {
  270|      0|  case 0x0f:
  ------------------
  |  Branch (270:3): [True: 0, False: 31.7M]
  ------------------
  271|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  272|      0|    return 0;
  273|  5.12k|  case 0x0e:
  ------------------
  |  Branch (273:3): [True: 5.12k, False: 31.7M]
  ------------------
  274|  5.12k|    ++ofs;
  275|       |  /* fall through */
  276|   631k|  case 0x0d:
  ------------------
  |  Branch (276:3): [True: 626k, False: 31.0M]
  ------------------
  277|   631k|    ++ofs;
  278|   631k|    break;
  279|  31.0M|  default:
  ------------------
  |  Branch (279:3): [True: 31.0M, False: 631k]
  ------------------
  280|  31.0M|    ;
  281|  31.7M|  }
  282|       |
  283|  31.7M|  return (const uint8_t *)opt + ofs;
  284|  31.7M|}
coap_option_filter_clear:
  494|  9.16k|coap_option_filter_clear(coap_opt_filter_t *filter) {
  495|  9.16k|  memset(filter, 0, sizeof(coap_opt_filter_t));
  496|  9.16k|}
coap_option_filter_set:
  499|  1.39M|coap_option_filter_set(coap_opt_filter_t *filter, coap_option_num_t option) {
  500|  1.39M|  return coap_option_filter_op(filter, option, FILTER_SET);
  501|  1.39M|}
coap_option_filter_get:
  509|  48.0M|coap_option_filter_get(coap_opt_filter_t *filter, coap_option_num_t option) {
  510|  48.0M|  return coap_option_filter_op(filter, option, FILTER_GET);
  511|  48.0M|}
coap_option.c:opt_finished:
  144|  16.3M|opt_finished(coap_opt_iterator_t *oi) {
  145|  16.3M|  assert(oi);
  ------------------
  |  Branch (145:3): [True: 16.3M, False: 0]
  ------------------
  146|       |
  147|  16.3M|  if (oi->bad || oi->length == 0 ||
  ------------------
  |  Branch (147:7): [True: 235, False: 16.3M]
  |  Branch (147:18): [True: 1.17k, False: 16.3M]
  ------------------
  148|  16.3M|      !oi->next_option || *oi->next_option == COAP_PAYLOAD_START) {
  ------------------
  |  |   96|  16.3M|#define COAP_PAYLOAD_START 0xFF /* payload marker */
  ------------------
  |  Branch (148:7): [True: 0, False: 16.3M]
  |  Branch (148:27): [True: 270, False: 16.3M]
  ------------------
  149|  1.67k|    oi->bad = 1;
  150|  1.67k|  }
  151|       |
  152|  16.3M|  return oi->bad;
  153|  16.3M|}
coap_option.c:coap_option_filter_op:
  436|  49.4M|                      enum filter_op_t op) {
  437|  49.4M|  size_t lindex = 0;
  438|  49.4M|  coap_opt_filter_t *of = filter;
  439|  49.4M|  uint16_t nr, mask = 0;
  440|       |
  441|  49.4M|  if (is_long_option(number)) {
  ------------------
  |  Branch (441:7): [True: 237k, False: 49.1M]
  ------------------
  442|   237k|    mask = LONG_MASK;
  ------------------
  |  |  401|   237k|#define LONG_MASK ((1 << COAP_OPT_FILTER_LONG) - 1)
  |  |  ------------------
  |  |  |  |  208|   237k|#define COAP_OPT_FILTER_LONG  2
  |  |  ------------------
  ------------------
  443|       |
  444|   709k|    for (nr = 1; lindex < COAP_OPT_FILTER_LONG; nr <<= 1, lindex++) {
  ------------------
  |  |  208|   709k|#define COAP_OPT_FILTER_LONG  2
  ------------------
  |  Branch (444:18): [True: 474k, False: 234k]
  ------------------
  445|       |
  446|   474k|      if (((of->mask & nr) > 0) && (of->long_opts[lindex] == number)) {
  ------------------
  |  Branch (446:11): [True: 16.7k, False: 458k]
  |  Branch (446:36): [True: 2.90k, False: 13.8k]
  ------------------
  447|  2.90k|        if (op == FILTER_CLEAR) {
  ------------------
  |  Branch (447:13): [True: 0, False: 2.90k]
  ------------------
  448|      0|          of->mask &= ~nr;
  449|      0|        }
  450|       |
  451|  2.90k|        return 1;
  452|  2.90k|      }
  453|   474k|    }
  454|  49.1M|  } else {
  455|  49.1M|    mask = SHORT_MASK;
  ------------------
  |  |  403|  49.1M|  (~LONG_MASK & ((1 << (COAP_OPT_FILTER_LONG + COAP_OPT_FILTER_SHORT)) - 1))
  |  |  ------------------
  |  |  |  |  401|  49.1M|#define LONG_MASK ((1 << COAP_OPT_FILTER_LONG) - 1)
  |  |  |  |  ------------------
  |  |  |  |  |  |  208|  49.1M|#define COAP_OPT_FILTER_LONG  2
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                 (~LONG_MASK & ((1 << (COAP_OPT_FILTER_LONG + COAP_OPT_FILTER_SHORT)) - 1))
  |  |  ------------------
  |  |  |  |  208|  49.1M|#define COAP_OPT_FILTER_LONG  2
  |  |  ------------------
  |  |                 (~LONG_MASK & ((1 << (COAP_OPT_FILTER_LONG + COAP_OPT_FILTER_SHORT)) - 1))
  |  |  ------------------
  |  |  |  |  200|  49.1M|#define COAP_OPT_FILTER_SHORT 6
  |  |  ------------------
  ------------------
  456|       |
  457|   323M|    for (nr = 1 << COAP_OPT_FILTER_LONG; lindex < COAP_OPT_FILTER_SHORT;
  ------------------
  |  |  208|  49.1M|#define COAP_OPT_FILTER_LONG  2
  ------------------
                  for (nr = 1 << COAP_OPT_FILTER_LONG; lindex < COAP_OPT_FILTER_SHORT;
  ------------------
  |  |  200|   323M|#define COAP_OPT_FILTER_SHORT 6
  ------------------
  |  Branch (457:42): [True: 292M, False: 31.4M]
  ------------------
  458|   292M|         nr <<= 1, lindex++) {
  459|       |
  460|   292M|      if (((of->mask & nr) > 0) && (of->short_opts[lindex] == (number & 0xff))) {
  ------------------
  |  Branch (460:11): [True: 49.1M, False: 243M]
  |  Branch (460:36): [True: 17.7M, False: 31.4M]
  ------------------
  461|  17.7M|        if (op == FILTER_CLEAR) {
  ------------------
  |  Branch (461:13): [True: 0, False: 17.7M]
  ------------------
  462|      0|          of->mask &= ~nr;
  463|      0|        }
  464|       |
  465|  17.7M|        return 1;
  466|  17.7M|      }
  467|   292M|    }
  468|  49.1M|  }
  469|       |
  470|       |  /* number was not found, so there is nothing to do if op is CLEAR or GET */
  471|  31.6M|  if ((op == FILTER_CLEAR) || (op == FILTER_GET)) {
  ------------------
  |  Branch (471:7): [True: 0, False: 31.6M]
  |  Branch (471:31): [True: 31.6M, False: 16.3k]
  ------------------
  472|  31.6M|    return 0;
  473|  31.6M|  }
  474|       |
  475|       |  /* handle FILTER_SET: */
  476|       |
  477|  16.3k|  lindex = coap_fls(~of->mask & mask);
  478|  16.3k|  if (!lindex) {
  ------------------
  |  Branch (478:7): [True: 8.14k, False: 8.21k]
  ------------------
  479|  8.14k|    return 0;
  480|  8.14k|  }
  481|       |
  482|  8.21k|  if (is_long_option(number)) {
  ------------------
  |  Branch (482:7): [True: 261, False: 7.95k]
  ------------------
  483|    261|    of->long_opts[lindex - 1] = number;
  484|  7.95k|  } else {
  485|  7.95k|    of->short_opts[lindex - COAP_OPT_FILTER_LONG - 1] = (uint8_t)number;
  ------------------
  |  |  208|  7.95k|#define COAP_OPT_FILTER_LONG  2
  ------------------
  486|  7.95k|  }
  487|       |
  488|  8.21k|  of->mask |= 1 << (lindex - 1);
  489|       |
  490|  8.21k|  return 1;
  491|  16.3k|}
coap_option.c:is_long_option:
  407|  49.4M|is_long_option(coap_option_num_t number) {
  408|  49.4M|  return number > 255;
  409|  49.4M|}

coap_pdu_clear:
   47|  3.16k|coap_pdu_clear(coap_pdu_t *pdu, size_t size) {
   48|  3.16k|  assert(pdu);
  ------------------
  |  Branch (48:3): [True: 3.16k, False: 0]
  ------------------
   49|  3.16k|  assert(pdu->token);
  ------------------
  |  Branch (49:3): [True: 3.16k, False: 0]
  ------------------
   50|  3.16k|  assert(pdu->max_hdr_size >= COAP_PDU_MAX_UDP_HEADER_SIZE);
  ------------------
  |  Branch (50:3): [True: 3.16k, False: 0]
  ------------------
   51|  3.16k|  if (pdu->alloc_size > size)
  ------------------
  |  Branch (51:7): [True: 0, False: 3.16k]
  ------------------
   52|      0|    pdu->alloc_size = size;
   53|  3.16k|  pdu->type = 0;
   54|  3.16k|  pdu->code = 0;
   55|  3.16k|  pdu->ref = 0;
   56|  3.16k|  pdu->hdr_size = 0;
   57|  3.16k|  pdu->actual_token.length = 0;
   58|  3.16k|  pdu->e_token_length = 0;
   59|  3.16k|  pdu->crit_opt = 0;
   60|  3.16k|  pdu->mid = 0;
   61|  3.16k|  pdu->max_opt = 0;
   62|  3.16k|  pdu->max_size = size;
   63|  3.16k|  pdu->used_size = 0;
   64|  3.16k|  pdu->data = NULL;
   65|  3.16k|  pdu->body_data = NULL;
   66|  3.16k|  pdu->body_length = 0;
   67|  3.16k|  pdu->body_offset = 0;
   68|  3.16k|  pdu->body_total = 0;
   69|  3.16k|  pdu->lg_xmit = NULL;
   70|  3.16k|  pdu->session = NULL;
   71|       |  pdu->data_free = NULL;
   72|  3.16k|}
coap_pdu_init:
  105|  3.16k|              size_t size) {
  106|  3.16k|  coap_pdu_t *pdu;
  107|       |
  108|  3.16k|#ifndef RIOT_VERSION
  109|  3.16k|  assert(type <= 0x3);
  ------------------
  |  Branch (109:3): [True: 3.16k, False: 0]
  ------------------
  110|  3.16k|  assert(code <= 0xff);
  ------------------
  |  Branch (110:3): [True: 3.16k, False: 0]
  ------------------
  111|  3.16k|  assert(mid >= 0 && mid <= 0xffff);
  ------------------
  |  Branch (111:3): [True: 3.16k, False: 0]
  |  Branch (111:3): [True: 3.16k, False: 0]
  ------------------
  112|  3.16k|#endif /* RIOT_VERSION */
  113|       |
  114|       |#if defined(WITH_LWIP) && MEMP_USE_CUSTOM_POOLS
  115|       |#if MEMP_STATS
  116|       |  /* Reserve 1 PDU for a response packet */
  117|       |  if (memp_pools[MEMP_COAP_PDU]->stats->used + 1 >=
  118|       |      memp_pools[MEMP_COAP_PDU]->stats->avail) {
  119|       |    memp_pools[MEMP_COAP_PDU]->stats->err++;
  120|       |    return NULL;
  121|       |  }
  122|       |#endif /* MEMP_STATS */
  123|       |#endif /* LWIP && MEMP_USE_CUSTOM_POOLS */
  124|  3.16k|  pdu = coap_malloc_type(COAP_PDU, sizeof(coap_pdu_t));
  125|  3.16k|  if (!pdu)
  ------------------
  |  Branch (125:7): [True: 0, False: 3.16k]
  ------------------
  126|      0|    return NULL;
  127|       |
  128|       |#if COAP_DEFAULT_MAX_PDU_RX_SIZE <= COAP_MAX_MESSAGE_SIZE_TCP16
  129|       |  /* on TCP, the CoAP header will also have a maximum length of 4 bytes */
  130|       |  pdu->max_hdr_size = COAP_PDU_MAX_UDP_HEADER_SIZE;
  131|       |#else
  132|  3.16k|  pdu->max_hdr_size = COAP_PDU_MAX_TCP_HEADER_SIZE;
  ------------------
  |  |  108|  3.16k|#define COAP_PDU_MAX_TCP_HEADER_SIZE 6
  ------------------
  133|  3.16k|#endif
  134|  3.16k|  if (size > ((size_t)COAP_DEFAULT_MAX_PDU_RX_SIZE - pdu->max_hdr_size)) {
  ------------------
  |  |   84|  3.16k|#define COAP_DEFAULT_MAX_PDU_RX_SIZE (8UL*1024*1024+256)
  ------------------
  |  Branch (134:7): [True: 0, False: 3.16k]
  ------------------
  135|      0|    coap_free_type(COAP_PDU, pdu);
  136|      0|    return NULL;
  137|      0|  }
  138|       |
  139|  3.16k|  pdu->alloc_size = min(size, COAP_DEFAULT_MTU);
  ------------------
  |  |   37|  3.16k|#define min(a,b) ((a) < (b) ? (a) : (b))
  |  |  ------------------
  |  |  |  Branch (37:19): [True: 2.60k, False: 553]
  |  |  ------------------
  ------------------
  140|       |#ifdef WITH_LWIP
  141|       |  pdu->pbuf = pbuf_alloc(PBUF_TRANSPORT, pdu->alloc_size + pdu->max_hdr_size,
  142|       |                         PBUF_RAM);
  143|       |  if (pdu->pbuf == NULL) {
  144|       |    coap_free_type(COAP_PDU, pdu);
  145|       |    return NULL;
  146|       |  }
  147|       |  pdu->token = (uint8_t *)pdu->pbuf->payload + pdu->max_hdr_size;
  148|       |#else /* ! WITH_LWIP */
  149|  3.16k|  uint8_t *buf;
  150|  3.16k|  buf = coap_malloc_type(COAP_PDU_BUF, pdu->alloc_size + pdu->max_hdr_size);
  151|  3.16k|  if (buf == NULL) {
  ------------------
  |  Branch (151:7): [True: 0, False: 3.16k]
  ------------------
  152|      0|    coap_free_type(COAP_PDU, pdu);
  153|      0|    return NULL;
  154|      0|  }
  155|  3.16k|  pdu->token = buf + pdu->max_hdr_size;
  156|  3.16k|#endif /* ! WITH_LWIP */
  157|  3.16k|  coap_pdu_clear(pdu, size);
  158|  3.16k|  pdu->mid = mid;
  159|  3.16k|  pdu->type = type;
  160|  3.16k|  pdu->code = code;
  161|  3.16k|  return pdu;
  162|  3.16k|}
coap_delete_pdu:
  190|  3.16k|coap_delete_pdu(coap_pdu_t *pdu) {
  191|  3.16k|  coap_lock_lock(return);
  192|  3.16k|  coap_delete_pdu_lkd(pdu);
  193|  3.16k|  coap_lock_unlock();
  194|  3.16k|}
coap_delete_pdu_lkd:
  197|  3.16k|coap_delete_pdu_lkd(coap_pdu_t *pdu) {
  198|  3.16k|  if (pdu != NULL) {
  ------------------
  |  Branch (198:7): [True: 3.16k, False: 0]
  ------------------
  199|  3.16k|    if (pdu->ref) {
  ------------------
  |  Branch (199:9): [True: 0, False: 3.16k]
  ------------------
  200|      0|      pdu->ref--;
  201|      0|      return;
  202|      0|    }
  203|       |#ifdef WITH_LWIP
  204|       |    pbuf_free(pdu->pbuf);
  205|       |#else
  206|  3.16k|    if (pdu->token != NULL)
  ------------------
  |  Branch (206:9): [True: 3.16k, False: 0]
  ------------------
  207|  3.16k|      coap_free_type(COAP_PDU_BUF, pdu->token - pdu->max_hdr_size);
  208|  3.16k|#endif
  209|  3.16k|    coap_delete_binary(pdu->data_free);
  210|  3.16k|    coap_free_type(COAP_PDU, pdu);
  211|  3.16k|  }
  212|  3.16k|}
coap_pdu_resize:
  340|  3.15k|coap_pdu_resize(coap_pdu_t *pdu, size_t new_size) {
  341|  3.15k|  if (new_size > pdu->alloc_size) {
  ------------------
  |  Branch (341:7): [True: 550, False: 2.60k]
  ------------------
  342|       |    /* Expanding the PDU usage */
  343|    550|#if !defined(WITH_LWIP)
  344|    550|    uint8_t *new_hdr;
  345|       |#else /* WITH_LWIP */
  346|       |    struct pbuf *new_hdr;
  347|       |#endif /* WITH_LWIP */
  348|    550|    size_t offset;
  349|       |
  350|    550|    if (pdu->max_size && new_size > pdu->max_size) {
  ------------------
  |  Branch (350:9): [True: 550, False: 0]
  |  Branch (350:26): [True: 0, False: 550]
  ------------------
  351|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  352|      0|      return 0;
  353|      0|    }
  354|    550|    if (pdu->data != NULL) {
  ------------------
  |  Branch (354:9): [True: 0, False: 550]
  ------------------
  355|      0|      assert(pdu->data > pdu->token);
  ------------------
  |  Branch (355:7): [True: 0, False: 0]
  ------------------
  356|      0|      offset = pdu->data - pdu->token;
  357|    550|    } else {
  358|    550|      offset = 0;
  359|    550|    }
  360|    550|#if !defined(WITH_LWIP)
  361|    550|    new_hdr = (uint8_t *)coap_realloc_type(COAP_PDU_BUF,
  362|    550|                                           pdu->token - pdu->max_hdr_size,
  363|    550|                                           new_size + pdu->max_hdr_size);
  364|       |#else /* WITH_LWIP */
  365|       |    new_hdr = pbuf_alloc(PBUF_TRANSPORT, new_size + pdu->max_hdr_size, PBUF_RAM);
  366|       |#endif /* WITH_LWIP */
  367|    550|    if (new_hdr == NULL) {
  ------------------
  |  Branch (367:9): [True: 0, False: 550]
  ------------------
  368|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  369|      0|      return 0;
  370|      0|    }
  371|    550|#if !defined(WITH_LWIP)
  372|    550|    pdu->token = new_hdr + pdu->max_hdr_size;
  373|       |#else /* WITH_LWIP */
  374|       |    memcpy(new_hdr->payload, pdu->pbuf->payload, pdu->pbuf->len);
  375|       |    pbuf_free(pdu->pbuf);
  376|       |    pdu->pbuf = new_hdr;
  377|       |    pdu->token = (uint8_t *)pdu->pbuf->payload + pdu->max_hdr_size;
  378|       |#endif /* WITH_LWIP */
  379|    550|    if (offset > 0)
  ------------------
  |  Branch (379:9): [True: 0, False: 550]
  ------------------
  380|      0|      pdu->data = pdu->token + offset;
  381|    550|    else
  382|    550|      pdu->data = NULL;
  383|    550|    if (pdu->actual_token.length < COAP_TOKEN_EXT_1B_BIAS)
  ------------------
  |  |   56|    550|#define COAP_TOKEN_EXT_1B_BIAS 13
  ------------------
  |  Branch (383:9): [True: 550, False: 0]
  ------------------
  384|    550|      pdu->actual_token.s = &pdu->token[0];
  385|      0|    else if (pdu->actual_token.length < COAP_TOKEN_EXT_2B_BIAS)
  ------------------
  |  |   57|      0|#define COAP_TOKEN_EXT_2B_BIAS 269 /* 13 + 256 */
  ------------------
  |  Branch (385:14): [True: 0, False: 0]
  ------------------
  386|      0|      pdu->actual_token.s = &pdu->token[1];
  387|      0|    else
  388|      0|      pdu->actual_token.s = &pdu->token[2];
  389|    550|    pdu->alloc_size = new_size;
  390|    550|  }
  391|  3.15k|  return 1;
  392|  3.15k|}
coap_pdu_parse_header_size:
 1082|  3.16k|                           const uint8_t *data) {
 1083|  3.16k|  assert(data);
  ------------------
  |  Branch (1083:3): [True: 3.16k, False: 0]
  ------------------
 1084|  3.16k|  size_t header_size = 0;
 1085|       |
 1086|  3.16k|  if (proto == COAP_PROTO_TCP || proto==COAP_PROTO_TLS) {
  ------------------
  |  Branch (1086:7): [True: 0, False: 3.16k]
  |  Branch (1086:34): [True: 0, False: 3.16k]
  ------------------
 1087|      0|    uint8_t len = *data >> 4;
 1088|      0|    if (len < 13)
  ------------------
  |  Branch (1088:9): [True: 0, False: 0]
  ------------------
 1089|      0|      header_size = 2;
 1090|      0|    else if (len==13)
  ------------------
  |  Branch (1090:14): [True: 0, False: 0]
  ------------------
 1091|      0|      header_size = 3;
 1092|      0|    else if (len==14)
  ------------------
  |  Branch (1092:14): [True: 0, False: 0]
  ------------------
 1093|      0|      header_size = 4;
 1094|      0|    else
 1095|      0|      header_size = 6;
 1096|  3.16k|  } else if (proto == COAP_PROTO_WS || proto==COAP_PROTO_WSS) {
  ------------------
  |  Branch (1096:14): [True: 0, False: 3.16k]
  |  Branch (1096:40): [True: 0, False: 3.16k]
  ------------------
 1097|      0|    header_size = 2;
 1098|  3.16k|  } else if (proto == COAP_PROTO_UDP || proto==COAP_PROTO_DTLS) {
  ------------------
  |  Branch (1098:14): [True: 3.16k, False: 0]
  |  Branch (1098:41): [True: 0, False: 0]
  ------------------
 1099|  3.16k|    header_size = 4;
 1100|  3.16k|  }
 1101|       |
 1102|  3.16k|  return header_size;
 1103|  3.16k|}
coap_pdu_parse_header:
 1178|  3.15k|coap_pdu_parse_header(coap_pdu_t *pdu, coap_proto_t proto) {
 1179|  3.15k|  uint8_t *hdr = pdu->token - pdu->hdr_size;
 1180|  3.15k|  uint8_t e_token_length;
 1181|       |
 1182|  3.15k|  if (proto == COAP_PROTO_UDP || proto == COAP_PROTO_DTLS) {
  ------------------
  |  Branch (1182:7): [True: 3.15k, False: 0]
  |  Branch (1182:34): [True: 0, False: 0]
  ------------------
 1183|  3.15k|    assert(pdu->hdr_size == 4);
  ------------------
  |  Branch (1183:5): [True: 3.15k, False: 0]
  ------------------
 1184|  3.15k|    if ((hdr[0] >> 6) != COAP_DEFAULT_VERSION) {
  ------------------
  |  |   35|  3.15k|#define COAP_DEFAULT_VERSION      1 /* version of CoAP supported */
  ------------------
  |  Branch (1184:9): [True: 9, False: 3.14k]
  ------------------
 1185|      9|      coap_log_debug("coap_pdu_parse: UDP version not supported\n");
  ------------------
  |  |  126|      9|#define coap_log_debug(...) coap_log(COAP_LOG_DEBUG, __VA_ARGS__)
  |  |  ------------------
  |  |  |  |  290|      9|#define coap_log(level, ...) do { \
  |  |  |  |  291|      9|    if ((level) < (coap_get_log_level() + 1)) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (291:9): [True: 0, False: 9]
  |  |  |  |  ------------------
  |  |  |  |  292|      9|      coap_log_impl((level), __VA_ARGS__); \
  |  |  |  |  293|      9|  } while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (293:11): [Folded, False: 9]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1186|      9|      return 0;
 1187|      9|    }
 1188|  3.14k|    pdu->type = (hdr[0] >> 4) & 0x03;
 1189|  3.14k|    pdu->code = hdr[1];
 1190|  3.14k|    pdu->mid = (uint16_t)hdr[2] << 8 | hdr[3];
 1191|  3.14k|  } else if (proto == COAP_PROTO_TCP || proto == COAP_PROTO_TLS) {
  ------------------
  |  Branch (1191:14): [True: 0, False: 0]
  |  Branch (1191:41): [True: 0, False: 0]
  ------------------
 1192|      0|    assert(pdu->hdr_size >= 2 && pdu->hdr_size <= 6);
  ------------------
  |  Branch (1192:5): [True: 0, False: 0]
  |  Branch (1192:5): [True: 0, False: 0]
  ------------------
 1193|      0|    pdu->type = COAP_MESSAGE_CON;
 1194|      0|    pdu->code = hdr[pdu->hdr_size-1];
 1195|      0|    pdu->mid = 0;
 1196|      0|  } else if (proto == COAP_PROTO_WS || proto == COAP_PROTO_WSS) {
  ------------------
  |  Branch (1196:14): [True: 0, False: 0]
  |  Branch (1196:40): [True: 0, False: 0]
  ------------------
 1197|      0|    assert(pdu->hdr_size == 2);
  ------------------
  |  Branch (1197:5): [True: 0, False: 0]
  ------------------
 1198|      0|    pdu->type = COAP_MESSAGE_CON;
 1199|      0|    pdu->code = hdr[pdu->hdr_size-1];
 1200|      0|    pdu->mid = 0;
 1201|      0|  } else {
 1202|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1203|      0|    return 0;
 1204|      0|  }
 1205|       |
 1206|  3.14k|  e_token_length = hdr[0] & 0x0f;
 1207|  3.14k|  if (e_token_length < COAP_TOKEN_EXT_1B_TKL) {
  ------------------
  |  |   54|  3.14k|#define COAP_TOKEN_EXT_1B_TKL 13
  ------------------
  |  Branch (1207:7): [True: 3.02k, False: 121]
  ------------------
 1208|  3.02k|    pdu->e_token_length = e_token_length;
 1209|  3.02k|    pdu->actual_token.length = pdu->e_token_length;
 1210|  3.02k|    pdu->actual_token.s = &pdu->token[0];
 1211|  3.02k|  } else if (e_token_length == COAP_TOKEN_EXT_1B_TKL) {
  ------------------
  |  |   54|    121|#define COAP_TOKEN_EXT_1B_TKL 13
  ------------------
  |  Branch (1211:14): [True: 53, False: 68]
  ------------------
 1212|     53|    if (pdu->used_size < 1)
  ------------------
  |  Branch (1212:9): [True: 1, False: 52]
  ------------------
 1213|      1|      goto bad_ext_token;
 1214|     52|    pdu->e_token_length = pdu->token[0] + COAP_TOKEN_EXT_1B_BIAS + 1;
  ------------------
  |  |   56|     52|#define COAP_TOKEN_EXT_1B_BIAS 13
  ------------------
 1215|     52|    pdu->actual_token.length = pdu->e_token_length - 1;
 1216|     52|    pdu->actual_token.s = &pdu->token[1];
 1217|     68|  } else if (e_token_length == COAP_TOKEN_EXT_2B_TKL) {
  ------------------
  |  |   55|     68|#define COAP_TOKEN_EXT_2B_TKL 14
  ------------------
  |  Branch (1217:14): [True: 66, False: 2]
  ------------------
 1218|     66|    if (pdu->used_size < 2)
  ------------------
  |  Branch (1218:9): [True: 2, False: 64]
  ------------------
 1219|      2|      goto bad_ext_token;
 1220|     64|    pdu->e_token_length = ((uint16_t)pdu->token[0] << 8) + pdu->token[1] +
 1221|     64|                          COAP_TOKEN_EXT_2B_BIAS + 2;
  ------------------
  |  |   57|     64|#define COAP_TOKEN_EXT_2B_BIAS 269 /* 13 + 256 */
  ------------------
 1222|     64|    pdu->actual_token.length = pdu->e_token_length - 2;
 1223|     64|    pdu->actual_token.s = &pdu->token[2];
 1224|     64|  }
 1225|  3.14k|  if (pdu->e_token_length > pdu->alloc_size || e_token_length == 15) {
  ------------------
  |  Branch (1225:7): [True: 27, False: 3.11k]
  |  Branch (1225:48): [True: 2, False: 3.11k]
  ------------------
 1226|     29|    goto bad_ext_token;
 1227|     29|  }
 1228|  3.11k|  return 1;
 1229|       |
 1230|     32|bad_ext_token:
 1231|       |  /* Invalid PDU provided - not wise to assert here though */
 1232|     32|  coap_log_warn("coap_pdu_parse: PDU header extended token size broken\n");
  ------------------
  |  |  108|     32|#define coap_log_warn(...) coap_log(COAP_LOG_WARN, __VA_ARGS__)
  |  |  ------------------
  |  |  |  |  290|     32|#define coap_log(level, ...) do { \
  |  |  |  |  291|     32|    if ((level) < (coap_get_log_level() + 1)) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (291:9): [True: 0, False: 32]
  |  |  |  |  ------------------
  |  |  |  |  292|     32|      coap_log_impl((level), __VA_ARGS__); \
  |  |  |  |  293|     32|  } while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (293:11): [Folded, False: 32]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1233|     32|  pdu->e_token_length = 0;
 1234|     32|  pdu->actual_token.length = 0;
 1235|     32|  return 0;
 1236|  3.14k|}
coap_pdu_parse_opt_base:
 1307|  11.3M|coap_pdu_parse_opt_base(coap_option_num_t number, size_t len, const uint8_t *opt_val) {
 1308|  11.3M|  int res = 1;
 1309|       |
 1310|  11.3M|  switch ((coap_code_opt_num_t)number) {
 1311|  1.44k|  case COAP_OPTION_IF_MATCH:
  ------------------
  |  Branch (1311:3): [True: 1.44k, False: 11.3M]
  ------------------
 1312|  1.44k|    if (len > 8)
  ------------------
  |  Branch (1312:9): [True: 1.03k, False: 406]
  ------------------
 1313|  1.03k|      res = 0;
 1314|  1.44k|    break;
 1315|  59.1k|  case COAP_OPTION_URI_HOST:
  ------------------
  |  Branch (1315:3): [True: 59.1k, False: 11.3M]
  ------------------
 1316|  59.1k|    if (len < 1 || len > 255)
  ------------------
  |  Branch (1316:9): [True: 42.5k, False: 16.5k]
  |  Branch (1316:20): [True: 1.20k, False: 15.3k]
  ------------------
 1317|  43.7k|      res = 0;
 1318|  59.1k|    break;
 1319|  24.6k|  case COAP_OPTION_ETAG:
  ------------------
  |  Branch (1319:3): [True: 24.6k, False: 11.3M]
  ------------------
 1320|  24.6k|    if (len < 1 || len > 8)
  ------------------
  |  Branch (1320:9): [True: 21.2k, False: 3.45k]
  |  Branch (1320:20): [True: 2.02k, False: 1.43k]
  ------------------
 1321|  23.2k|      res = 0;
 1322|  24.6k|    break;
 1323|  2.65k|  case COAP_OPTION_IF_NONE_MATCH:
  ------------------
  |  Branch (1323:3): [True: 2.65k, False: 11.3M]
  ------------------
 1324|  2.65k|    if (len != 0)
  ------------------
  |  Branch (1324:9): [True: 1.13k, False: 1.52k]
  ------------------
 1325|  1.13k|      res = 0;
 1326|  2.65k|    break;
 1327|  3.14k|  case COAP_OPTION_OBSERVE:
  ------------------
  |  Branch (1327:3): [True: 3.14k, False: 11.3M]
  ------------------
 1328|  3.14k|    if (len > 3)
  ------------------
  |  Branch (1328:9): [True: 1.33k, False: 1.80k]
  ------------------
 1329|  1.33k|      res = 0;
 1330|  3.14k|    break;
 1331|  10.6k|  case COAP_OPTION_URI_PORT:
  ------------------
  |  Branch (1331:3): [True: 10.6k, False: 11.3M]
  ------------------
 1332|  10.6k|    if (len > 2)
  ------------------
  |  Branch (1332:9): [True: 3.52k, False: 7.08k]
  ------------------
 1333|  3.52k|      res = 0;
 1334|  10.6k|    break;
 1335|  12.9k|  case COAP_OPTION_LOCATION_PATH:
  ------------------
  |  Branch (1335:3): [True: 12.9k, False: 11.3M]
  ------------------
 1336|  7.24M|  case COAP_OPTION_URI_PATH:
  ------------------
  |  Branch (1336:3): [True: 7.23M, False: 4.13M]
  ------------------
 1337|  7.24M|    if (len > 255)
  ------------------
  |  Branch (1337:9): [True: 1.07k, False: 7.24M]
  ------------------
 1338|  1.07k|      res = 0;
 1339|  7.24M|    if (coap_check_dots(opt_val, len)) {
  ------------------
  |  Branch (1339:9): [True: 2.74k, False: 7.24M]
  ------------------
 1340|  2.74k|      res = 0;
 1341|  2.74k|    }
 1342|  7.24M|    break;
 1343|  3.24k|  case COAP_OPTION_OSCORE:
  ------------------
  |  Branch (1343:3): [True: 3.24k, False: 11.3M]
  ------------------
 1344|  3.24k|    if (len > 255)
  ------------------
  |  Branch (1344:9): [True: 996, False: 2.24k]
  ------------------
 1345|    996|      res = 0;
 1346|  3.24k|    break;
 1347|  1.80k|  case COAP_OPTION_CONTENT_FORMAT:
  ------------------
  |  Branch (1347:3): [True: 1.80k, False: 11.3M]
  ------------------
 1348|  1.80k|    if (len > 2)
  ------------------
  |  Branch (1348:9): [True: 1.11k, False: 697]
  ------------------
 1349|  1.11k|      res = 0;
 1350|  1.80k|    break;
 1351|  13.2k|  case COAP_OPTION_URI_PATH_ABB:
  ------------------
  |  Branch (1351:3): [True: 13.2k, False: 11.3M]
  ------------------
 1352|  13.2k|    if (len > 4)
  ------------------
  |  Branch (1352:9): [True: 3.99k, False: 9.28k]
  ------------------
 1353|  3.99k|      res = 0;
 1354|  13.2k|    break;
 1355|  51.8k|  case COAP_OPTION_MAXAGE:
  ------------------
  |  Branch (1355:3): [True: 51.8k, False: 11.3M]
  ------------------
 1356|  51.8k|    if (len > 4)
  ------------------
  |  Branch (1356:9): [True: 13.4k, False: 38.3k]
  ------------------
 1357|  13.4k|      res = 0;
 1358|  51.8k|    break;
 1359|  1.09M|  case COAP_OPTION_URI_QUERY:
  ------------------
  |  Branch (1359:3): [True: 1.09M, False: 10.2M]
  ------------------
 1360|  1.09M|    if (len > 255)
  ------------------
  |  Branch (1360:9): [True: 972, False: 1.08M]
  ------------------
 1361|    972|      res = 0;
 1362|  1.09M|    break;
 1363|  13.8k|  case COAP_OPTION_HOP_LIMIT:
  ------------------
  |  Branch (1363:3): [True: 13.8k, False: 11.3M]
  ------------------
 1364|  13.8k|    if (len != 1)
  ------------------
  |  Branch (1364:9): [True: 13.5k, False: 258]
  ------------------
 1365|  13.5k|      res = 0;
 1366|  13.8k|    break;
 1367|  10.2k|  case COAP_OPTION_ACCEPT:
  ------------------
  |  Branch (1367:3): [True: 10.2k, False: 11.3M]
  ------------------
 1368|  10.2k|    if (len > 2)
  ------------------
  |  Branch (1368:9): [True: 1.06k, False: 9.15k]
  ------------------
 1369|  1.06k|      res = 0;
 1370|  10.2k|    break;
 1371|   559k|  case COAP_OPTION_Q_BLOCK1:
  ------------------
  |  Branch (1371:3): [True: 559k, False: 10.8M]
  ------------------
 1372|   559k|    if (len > 3)
  ------------------
  |  Branch (1372:9): [True: 6.82k, False: 552k]
  ------------------
 1373|  6.82k|      res = 0;
 1374|   559k|    break;
 1375|   239k|  case COAP_OPTION_LOCATION_QUERY:
  ------------------
  |  Branch (1375:3): [True: 239k, False: 11.1M]
  ------------------
 1376|   239k|    if (len > 255)
  ------------------
  |  Branch (1376:9): [True: 1.00k, False: 238k]
  ------------------
 1377|  1.00k|      res = 0;
 1378|   239k|    break;
 1379|  1.58k|  case COAP_OPTION_EDHOC:
  ------------------
  |  Branch (1379:3): [True: 1.58k, False: 11.3M]
  ------------------
 1380|  1.58k|    if (len != 0)
  ------------------
  |  Branch (1380:9): [True: 1.17k, False: 414]
  ------------------
 1381|  1.17k|      res = 0;
 1382|  1.58k|    break;
 1383|  1.57k|  case COAP_OPTION_BLOCK2:
  ------------------
  |  Branch (1383:3): [True: 1.57k, False: 11.3M]
  ------------------
 1384|  1.57k|    if (len > 3)
  ------------------
  |  Branch (1384:9): [True: 1.05k, False: 516]
  ------------------
 1385|  1.05k|      res = 0;
 1386|  1.57k|    break;
 1387|   580k|  case COAP_OPTION_BLOCK1:
  ------------------
  |  Branch (1387:3): [True: 580k, False: 10.7M]
  ------------------
 1388|   580k|    if (len > 3)
  ------------------
  |  Branch (1388:9): [True: 13.3k, False: 566k]
  ------------------
 1389|  13.3k|      res = 0;
 1390|   580k|    break;
 1391|  12.3k|  case COAP_OPTION_SIZE2:
  ------------------
  |  Branch (1391:3): [True: 12.3k, False: 11.3M]
  ------------------
 1392|  12.3k|    if (len > 4)
  ------------------
  |  Branch (1392:9): [True: 2.00k, False: 10.3k]
  ------------------
 1393|  2.00k|      res = 0;
 1394|  12.3k|    break;
 1395|  20.5k|  case COAP_OPTION_Q_BLOCK2:
  ------------------
  |  Branch (1395:3): [True: 20.5k, False: 11.3M]
  ------------------
 1396|  20.5k|    if (len > 3)
  ------------------
  |  Branch (1396:9): [True: 5.92k, False: 14.6k]
  ------------------
 1397|  5.92k|      res = 0;
 1398|  20.5k|    break;
 1399|  13.7k|  case COAP_OPTION_PROXY_URI:
  ------------------
  |  Branch (1399:3): [True: 13.7k, False: 11.3M]
  ------------------
 1400|  13.7k|    if (len < 1 || len > 1034)
  ------------------
  |  Branch (1400:9): [True: 9.81k, False: 3.96k]
  |  Branch (1400:20): [True: 1.04k, False: 2.91k]
  ------------------
 1401|  10.8k|      res = 0;
 1402|  13.7k|    break;
 1403|  23.2k|  case COAP_OPTION_PROXY_SCHEME:
  ------------------
  |  Branch (1403:3): [True: 23.2k, False: 11.3M]
  ------------------
 1404|  23.2k|    if (len < 1 || len > 255)
  ------------------
  |  Branch (1404:9): [True: 16.0k, False: 7.18k]
  |  Branch (1404:20): [True: 996, False: 6.18k]
  ------------------
 1405|  17.0k|      res = 0;
 1406|  23.2k|    break;
 1407|  2.12k|  case COAP_OPTION_SIZE1:
  ------------------
  |  Branch (1407:3): [True: 2.12k, False: 11.3M]
  ------------------
 1408|  2.12k|    if (len > 4)
  ------------------
  |  Branch (1408:9): [True: 1.05k, False: 1.06k]
  ------------------
 1409|  1.05k|      res = 0;
 1410|  2.12k|    break;
 1411|  1.66k|  case COAP_OPTION_ECHO:
  ------------------
  |  Branch (1411:3): [True: 1.66k, False: 11.3M]
  ------------------
 1412|  1.66k|    if (len > 40)
  ------------------
  |  Branch (1412:9): [True: 1.00k, False: 660]
  ------------------
 1413|  1.00k|      res = 0;
 1414|  1.66k|    break;
 1415|  2.22k|  case COAP_OPTION_NORESPONSE:
  ------------------
  |  Branch (1415:3): [True: 2.22k, False: 11.3M]
  ------------------
 1416|  2.22k|    if (len > 1)
  ------------------
  |  Branch (1416:9): [True: 1.11k, False: 1.11k]
  ------------------
 1417|  1.11k|      res = 0;
 1418|  2.22k|    break;
 1419|  3.59k|  case COAP_OPTION_RTAG:
  ------------------
  |  Branch (1419:3): [True: 3.59k, False: 11.3M]
  ------------------
 1420|  3.59k|    if (len > 8)
  ------------------
  |  Branch (1420:9): [True: 1.30k, False: 2.29k]
  ------------------
 1421|  1.30k|      res = 0;
 1422|  3.59k|    break;
 1423|  1.37M|  default:
  ------------------
  |  Branch (1423:3): [True: 1.37M, False: 9.99M]
  ------------------
 1424|  1.37M|    ;
 1425|  11.3M|  }
 1426|  11.3M|  return res;
 1427|  11.3M|}
coap_pdu_parse_opt:
 1463|  3.11k|coap_pdu_parse_opt(coap_pdu_t *pdu, coap_opt_filter_t *error_opts) {
 1464|  3.11k|  int good = 1;
 1465|       |
 1466|  3.11k|  coap_option_filter_clear(error_opts);
 1467|       |
 1468|       |  /* sanity checks */
 1469|  3.11k|  if (pdu->code == 0) {
  ------------------
  |  Branch (1469:7): [True: 24, False: 3.09k]
  ------------------
 1470|     24|    if (pdu->used_size != 0 || pdu->e_token_length) {
  ------------------
  |  Branch (1470:9): [True: 21, False: 3]
  |  Branch (1470:32): [True: 2, False: 1]
  ------------------
 1471|     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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1472|     23|      return 0;
 1473|     23|    }
 1474|     24|  }
 1475|       |
 1476|  3.09k|  if (pdu->e_token_length > pdu->used_size) {
  ------------------
  |  Branch (1476:7): [True: 6, False: 3.08k]
  ------------------
 1477|      6|    coap_log_debug("coap_pdu_parse: invalid Token\n");
  ------------------
  |  |  126|      6|#define coap_log_debug(...) coap_log(COAP_LOG_DEBUG, __VA_ARGS__)
  |  |  ------------------
  |  |  |  |  290|      6|#define coap_log(level, ...) do { \
  |  |  |  |  291|      6|    if ((level) < (coap_get_log_level() + 1)) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (291:9): [True: 0, False: 6]
  |  |  |  |  ------------------
  |  |  |  |  292|      6|      coap_log_impl((level), __VA_ARGS__); \
  |  |  |  |  293|      6|  } while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (293:11): [Folded, False: 6]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1478|      6|    return 0;
 1479|      6|  }
 1480|       |
 1481|  3.08k|  pdu->max_opt = 0;
 1482|  3.08k|  if (pdu->code == 0) {
  ------------------
  |  Branch (1482:7): [True: 1, False: 3.08k]
  ------------------
 1483|       |    /* empty packet */
 1484|      1|    pdu->used_size = 0;
 1485|      1|    pdu->data = NULL;
 1486|  3.08k|  } else {
 1487|       |    /* skip header + token */
 1488|  3.08k|    coap_opt_t *opt = pdu->token + pdu->e_token_length;
 1489|  3.08k|    size_t length = pdu->used_size - pdu->e_token_length;
 1490|       |
 1491|  11.3M|    while (length > 0 && *opt != COAP_PAYLOAD_START) {
  ------------------
  |  |   96|  11.3M|#define COAP_PAYLOAD_START 0xFF /* payload marker */
  ------------------
  |  Branch (1491:12): [True: 11.3M, False: 2.39k]
  |  Branch (1491:26): [True: 11.3M, False: 240]
  ------------------
 1492|  11.3M|#if (COAP_MAX_LOGGING_LEVEL >= _COAP_LOG_WARN)
 1493|  11.3M|      coap_opt_t *opt_last = opt;
 1494|  11.3M|#endif
 1495|  11.3M|      size_t optsize = next_option_safe(&opt, &length, &pdu->max_opt);
 1496|  11.3M|      uint32_t len;
 1497|  11.3M|      const uint8_t *opt_val;
 1498|       |
 1499|  11.3M|      if (optsize == 0) {
  ------------------
  |  Branch (1499:11): [True: 449, False: 11.3M]
  ------------------
 1500|    449|        coap_log_debug("coap_pdu_parse: %d.%02d: offset %u malformed option\n",
  ------------------
  |  |  126|    449|#define coap_log_debug(...) coap_log(COAP_LOG_DEBUG, __VA_ARGS__)
  |  |  ------------------
  |  |  |  |  290|    449|#define coap_log(level, ...) do { \
  |  |  |  |  291|    449|    if ((level) < (coap_get_log_level() + 1)) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (291:9): [True: 0, False: 449]
  |  |  |  |  ------------------
  |  |  |  |  292|    449|      coap_log_impl((level), __VA_ARGS__); \
  |  |  |  |  293|    449|  } while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (293:11): [Folded, False: 449]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1501|    449|                       pdu->code >> 5, pdu->code & 0x1F,
 1502|    449|                       (int)(opt_last - pdu->token - pdu->e_token_length));
 1503|    449|        coap_option_filter_set(error_opts, pdu->max_opt);
 1504|    449|        good = 0;
 1505|    449|        break;
 1506|    449|      }
 1507|  11.3M|      len = coap_opt_length((const uint8_t *)opt - optsize);
 1508|  11.3M|      opt_val = coap_opt_value((const uint8_t *)opt - optsize);
 1509|  11.3M|      if (COAP_PDU_IS_SIGNALING(pdu) ?
  ------------------
  |  |  102|  11.3M|#define COAP_PDU_IS_SIGNALING(pdu) ((pdu)->code >= 224)
  |  |  ------------------
  |  |  |  Branch (102:36): [True: 1.33M, False: 10.0M]
  |  |  ------------------
  ------------------
  |  Branch (1509:11): [True: 1.38M, False: 9.99M]
  ------------------
 1510|  1.33M|          !coap_pdu_parse_opt_csm(pdu->code, pdu->max_opt, len) :
 1511|  11.3M|          !coap_pdu_parse_opt_base(pdu->max_opt, len, opt_val)) {
 1512|  1.38M|        coap_log_warn("coap_pdu_parse: %d.%02d: offset %u option %u has bad length %" PRIu32 " or value\n",
  ------------------
  |  |  108|  1.38M|#define coap_log_warn(...) coap_log(COAP_LOG_WARN, __VA_ARGS__)
  |  |  ------------------
  |  |  |  |  290|  1.38M|#define coap_log(level, ...) do { \
  |  |  |  |  291|  1.38M|    if ((level) < (coap_get_log_level() + 1)) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (291:9): [True: 0, False: 1.38M]
  |  |  |  |  ------------------
  |  |  |  |  292|  1.38M|      coap_log_impl((level), __VA_ARGS__); \
  |  |  |  |  293|  1.38M|  } while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (293:11): [Folded, False: 1.38M]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1513|  1.38M|                      pdu->code >> 5, pdu->code & 0x1F,
 1514|  1.38M|                      (int)(opt_last - pdu->token - pdu->e_token_length), pdu->max_opt,
 1515|  1.38M|                      len);
 1516|  1.38M|        coap_option_filter_set(error_opts, pdu->max_opt);
 1517|  1.38M|        good = 0;
 1518|  1.38M|      }
 1519|  11.3M|    }
 1520|       |
 1521|  3.08k|    if (!good) {
  ------------------
  |  Branch (1521:9): [True: 1.42k, False: 1.66k]
  ------------------
 1522|       |      /*
 1523|       |       * Dump the options in the PDU for analysis, space separated except
 1524|       |       * error options which are prefixed by *
 1525|       |       * Two rows - hex and ascii (if printable)
 1526|       |       */
 1527|  1.42k|      static char outbuf[COAP_DEBUG_BUF_SIZE];
 1528|  1.42k|      char *obp;
 1529|  1.42k|      size_t tlen;
 1530|  1.42k|      size_t outbuflen;
 1531|  1.42k|      int i;
 1532|  1.42k|      int ok;
 1533|       |
 1534|  4.27k|      for (i = 0; i < 2; i++) {
  ------------------
  |  Branch (1534:19): [True: 2.85k, False: 1.42k]
  ------------------
 1535|  2.85k|        opt = pdu->token + pdu->e_token_length;
 1536|  2.85k|        length = pdu->used_size - pdu->e_token_length;
 1537|  2.85k|        pdu->max_opt = 0;
 1538|       |
 1539|  2.85k|        outbuflen = sizeof(outbuf);
 1540|  2.85k|        obp = outbuf;
 1541|  2.85k|        ok = write_prefix(&obp, &outbuflen, "O: ", 3);
 1542|       |        /*
 1543|       |         * Not safe to check for 'ok' here as a lot of variables may get
 1544|       |         * partially changed due to lack of outbuflen */
 1545|  4.00M|        while (length > 0 && *opt != COAP_PAYLOAD_START) {
  ------------------
  |  |   96|  3.99M|#define COAP_PAYLOAD_START 0xFF /* payload marker */
  ------------------
  |  Branch (1545:16): [True: 3.99M, False: 2.71k]
  |  Branch (1545:30): [True: 3.99M, False: 132]
  ------------------
 1546|  3.99M|          coap_opt_t *opt_last = opt;
 1547|  3.99M|          size_t optsize = next_option_safe(&opt, &length, &pdu->max_opt);
 1548|  3.99M|          const uint32_t len =
 1549|  3.99M|              optsize ? coap_opt_length((const uint8_t *)opt - optsize) : 0;
  ------------------
  |  Branch (1549:15): [True: 3.99M, False: 898]
  ------------------
 1550|  3.99M|          const uint8_t *opt_val =
 1551|  3.99M|              optsize ?  coap_opt_value((const uint8_t *)opt - optsize) : 0;
  ------------------
  |  Branch (1551:15): [True: 3.99M, False: 898]
  ------------------
 1552|       |
 1553|  3.99M|          if (!optsize || (COAP_PDU_IS_SIGNALING(pdu) ?
  ------------------
  |  |  102|  3.99M|#define COAP_PDU_IS_SIGNALING(pdu) ((pdu)->code >= 224)
  |  |  ------------------
  |  |  |  Branch (102:36): [True: 2.67M, False: 1.32M]
  |  |  ------------------
  ------------------
  |  Branch (1553:15): [True: 898, False: 3.99M]
  |  Branch (1553:27): [True: 2.77M, False: 1.22M]
  ------------------
 1554|  2.67M|                           !coap_pdu_parse_opt_csm(pdu->code, pdu->max_opt, len) :
 1555|  3.99M|                           !coap_pdu_parse_opt_base(pdu->max_opt, len, opt_val))) {
 1556|  2.77M|            ok = ok && write_prefix(&obp, &outbuflen, "*", 1);
  ------------------
  |  Branch (1556:18): [True: 58.8k, False: 2.71M]
  |  Branch (1556:24): [True: 58.8k, False: 16]
  ------------------
 1557|  2.77M|            if (!optsize) {
  ------------------
  |  Branch (1557:17): [True: 898, False: 2.77M]
  ------------------
 1558|       |              /* Skip to end of options to output all data */
 1559|    898|              opt = pdu->token + pdu->used_size;
 1560|    898|              length = 0;
 1561|    898|            }
 1562|  2.77M|          } else {
 1563|  1.22M|            ok = ok && write_prefix(&obp, &outbuflen, " ", 1);
  ------------------
  |  Branch (1563:18): [True: 46.8k, False: 1.17M]
  |  Branch (1563:24): [True: 46.8k, False: 24]
  ------------------
 1564|  1.22M|          }
 1565|  3.99M|          tlen = opt - opt_last;
 1566|  81.1M|          while (tlen) {
  ------------------
  |  Branch (1566:18): [True: 77.1M, False: 3.99M]
  ------------------
 1567|  77.1M|            tlen--;
 1568|  77.1M|            ok = ok && write_char(&obp, &outbuflen, *opt_last, i);
  ------------------
  |  Branch (1568:18): [True: 1.04M, False: 76.1M]
  |  Branch (1568:24): [True: 1.04M, False: 792]
  ------------------
 1569|  77.1M|            opt_last++;
 1570|  77.1M|          }
 1571|  3.99M|        }
 1572|  2.85k|        if (length && *opt == COAP_PAYLOAD_START) {
  ------------------
  |  |   96|    132|#define COAP_PAYLOAD_START 0xFF /* payload marker */
  ------------------
  |  Branch (1572:13): [True: 132, False: 2.71k]
  |  Branch (1572:23): [True: 132, False: 0]
  ------------------
 1573|    132|          write_char(&obp, &outbuflen, *opt, i);
 1574|    132|        }
 1575|       |        /* write_*() always leaves a spare byte to null terminate */
 1576|  2.85k|        *obp = '\000';
 1577|  2.85k|        coap_log_debug("%s\n", outbuf);
  ------------------
  |  |  126|  2.85k|#define coap_log_debug(...) coap_log(COAP_LOG_DEBUG, __VA_ARGS__)
  |  |  ------------------
  |  |  |  |  290|  2.85k|#define coap_log(level, ...) do { \
  |  |  |  |  291|  2.85k|    if ((level) < (coap_get_log_level() + 1)) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (291:9): [True: 0, False: 2.85k]
  |  |  |  |  ------------------
  |  |  |  |  292|  2.85k|      coap_log_impl((level), __VA_ARGS__); \
  |  |  |  |  293|  2.85k|  } while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (293:11): [Folded, False: 2.85k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1578|  2.85k|      }
 1579|  1.42k|    }
 1580|       |
 1581|  3.08k|    if (length > 0) {
  ------------------
  |  Branch (1581:9): [True: 240, False: 2.84k]
  ------------------
 1582|    240|      assert(*opt == COAP_PAYLOAD_START);
  ------------------
  |  Branch (1582:7): [True: 240, False: 0]
  ------------------
 1583|    240|      opt++;
 1584|    240|      length--;
 1585|       |
 1586|    240|      if (length == 0) {
  ------------------
  |  Branch (1586:11): [True: 21, False: 219]
  ------------------
 1587|     21|        coap_log_debug("coap_pdu_parse: message ending in payload start marker\n");
  ------------------
  |  |  126|     21|#define coap_log_debug(...) coap_log(COAP_LOG_DEBUG, __VA_ARGS__)
  |  |  ------------------
  |  |  |  |  290|     21|#define coap_log(level, ...) do { \
  |  |  |  |  291|     21|    if ((level) < (coap_get_log_level() + 1)) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (291:9): [True: 0, False: 21]
  |  |  |  |  ------------------
  |  |  |  |  292|     21|      coap_log_impl((level), __VA_ARGS__); \
  |  |  |  |  293|     21|  } while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (293:11): [Folded, False: 21]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1588|     21|        return 0;
 1589|     21|      }
 1590|    240|    }
 1591|  3.06k|    if (length > 0)
  ------------------
  |  Branch (1591:9): [True: 219, False: 2.84k]
  ------------------
 1592|    219|      pdu->data = (uint8_t *)opt;
 1593|  2.84k|    else
 1594|  2.84k|      pdu->data = NULL;
 1595|  3.06k|  }
 1596|       |
 1597|  3.06k|  return good;
 1598|  3.08k|}
coap_pdu_parse:
 1604|  3.16k|               coap_pdu_t *pdu) {
 1605|  3.16k|  coap_opt_filter_t error_opts;
 1606|       |
 1607|  3.16k|  return coap_pdu_parse2(proto, data, length, pdu, &error_opts);
 1608|  3.16k|}
coap_pdu_parse2:
 1615|  3.16k|                coap_opt_filter_t *error_opts) {
 1616|  3.16k|  size_t hdr_size;
 1617|       |
 1618|  3.16k|  if (length == 0)
  ------------------
  |  Branch (1618:7): [True: 0, False: 3.16k]
  ------------------
 1619|      0|    return 0;
 1620|  3.16k|  hdr_size = coap_pdu_parse_header_size(proto, data);
 1621|  3.16k|  if (!hdr_size || hdr_size > length)
  ------------------
  |  Branch (1621:7): [True: 0, False: 3.16k]
  |  Branch (1621:20): [True: 3, False: 3.15k]
  ------------------
 1622|      3|    return 0;
 1623|  3.15k|  if (hdr_size > pdu->max_hdr_size)
  ------------------
  |  Branch (1623:7): [True: 0, False: 3.15k]
  ------------------
 1624|      0|    return 0;
 1625|  3.15k|  if (!coap_pdu_resize(pdu, length - hdr_size))
  ------------------
  |  Branch (1625:7): [True: 0, False: 3.15k]
  ------------------
 1626|      0|    return 0;
 1627|  3.15k|  if (pdu->token - hdr_size != data)
  ------------------
  |  Branch (1627:7): [True: 3.15k, False: 0]
  ------------------
 1628|  3.15k|    memcpy(pdu->token - hdr_size, data, length);
 1629|  3.15k|  pdu->hdr_size = (uint8_t)hdr_size;
 1630|  3.15k|  pdu->used_size = length - hdr_size;
 1631|  3.15k|  return coap_pdu_parse_header(pdu, proto) && coap_pdu_parse_opt(pdu, error_opts);
  ------------------
  |  Branch (1631:10): [True: 3.11k, False: 41]
  |  Branch (1631:47): [True: 1.65k, False: 1.46k]
  ------------------
 1632|  3.15k|}
coap_pdu_encode_header:
 1635|  1.65k|coap_pdu_encode_header(coap_pdu_t *pdu, coap_proto_t proto) {
 1636|  1.65k|  uint8_t e_token_length;
 1637|       |
 1638|  1.65k|  if (pdu->actual_token.length < COAP_TOKEN_EXT_1B_BIAS) {
  ------------------
  |  |   56|  1.65k|#define COAP_TOKEN_EXT_1B_BIAS 13
  ------------------
  |  Branch (1638:7): [True: 1.58k, False: 66]
  ------------------
 1639|  1.58k|    e_token_length = (uint8_t)pdu->actual_token.length;
 1640|  1.58k|  } else if (pdu->actual_token.length < COAP_TOKEN_EXT_2B_BIAS) {
  ------------------
  |  |   57|     66|#define COAP_TOKEN_EXT_2B_BIAS 269 /* 13 + 256 */
  ------------------
  |  Branch (1640:14): [True: 31, False: 35]
  ------------------
 1641|     31|    e_token_length = COAP_TOKEN_EXT_1B_TKL;
  ------------------
  |  |   54|     31|#define COAP_TOKEN_EXT_1B_TKL 13
  ------------------
 1642|     35|  } else if (pdu->actual_token.length <= COAP_TOKEN_EXT_MAX) {
  ------------------
  |  |   60|     35|#define COAP_TOKEN_EXT_MAX 65804UL /* 13 + 256 + 65535 */
  ------------------
  |  Branch (1642:14): [True: 35, False: 0]
  ------------------
 1643|     35|    e_token_length = COAP_TOKEN_EXT_2B_TKL;
  ------------------
  |  |   55|     35|#define COAP_TOKEN_EXT_2B_TKL 14
  ------------------
 1644|     35|  } else {
 1645|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1646|      0|    return 0;
 1647|      0|  }
 1648|  1.65k|  if (COAP_PROTO_NOT_RELIABLE(proto)) {
  ------------------
  |  |   41|  1.65k|#define COAP_PROTO_NOT_RELIABLE(p) ((p)==COAP_PROTO_UDP || (p)==COAP_PROTO_DTLS)
  |  |  ------------------
  |  |  |  Branch (41:37): [True: 1.65k, False: 0]
  |  |  |  Branch (41:60): [True: 0, False: 0]
  |  |  ------------------
  ------------------
 1649|  1.65k|    assert(pdu->max_hdr_size >= 4);
  ------------------
  |  Branch (1649:5): [True: 1.65k, False: 0]
  ------------------
 1650|  1.65k|    if (pdu->max_hdr_size < 4) {
  ------------------
  |  Branch (1650:9): [True: 0, False: 1.65k]
  ------------------
 1651|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1652|      0|      return 0;
 1653|      0|    }
 1654|  1.65k|    pdu->token[-4] = COAP_DEFAULT_VERSION << 6
  ------------------
  |  |   35|  1.65k|#define COAP_DEFAULT_VERSION      1 /* version of CoAP supported */
  ------------------
 1655|  1.65k|                     | pdu->type << 4
 1656|  1.65k|                     | e_token_length;
 1657|  1.65k|    pdu->token[-3] = pdu->code;
 1658|  1.65k|    pdu->token[-2] = (uint8_t)(pdu->mid >> 8);
 1659|  1.65k|    pdu->token[-1] = (uint8_t)(pdu->mid);
 1660|  1.65k|    pdu->hdr_size = 4;
 1661|  1.65k|#if !COAP_DISABLE_TCP
 1662|  1.65k|  } 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]
  |  |  ------------------
  ------------------
 1663|      0|    size_t len;
 1664|      0|    assert(pdu->used_size >= pdu->e_token_length);
  ------------------
  |  Branch (1664:5): [True: 0, False: 0]
  ------------------
 1665|      0|    if (pdu->used_size < pdu->e_token_length) {
  ------------------
  |  Branch (1665:9): [True: 0, False: 0]
  ------------------
 1666|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1667|      0|      return 0;
 1668|      0|    }
 1669|       |
 1670|       |    /* A lot of the reliable code assumes type is CON */
 1671|      0|    if (pdu->type != COAP_MESSAGE_CON)
  ------------------
  |  Branch (1671:9): [True: 0, False: 0]
  ------------------
 1672|      0|      pdu->type = COAP_MESSAGE_CON;
 1673|       |
 1674|      0|    if (proto == COAP_PROTO_WS || proto == COAP_PROTO_WSS)
  ------------------
  |  Branch (1674:9): [True: 0, False: 0]
  |  Branch (1674:35): [True: 0, False: 0]
  ------------------
 1675|      0|      len = 0;
 1676|      0|    else
 1677|      0|      len = pdu->used_size - pdu->e_token_length;
 1678|      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 (1678:9): [True: 0, False: 0]
  ------------------
 1679|      0|      assert(pdu->max_hdr_size >= 2);
  ------------------
  |  Branch (1679:7): [True: 0, False: 0]
  ------------------
 1680|      0|      if (pdu->max_hdr_size < 2) {
  ------------------
  |  Branch (1680:11): [True: 0, False: 0]
  ------------------
 1681|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1682|      0|        return 0;
 1683|      0|      }
 1684|      0|      pdu->token[-2] = (uint8_t)len << 4
 1685|      0|                       | e_token_length;
 1686|      0|      pdu->token[-1] = pdu->code;
 1687|      0|      pdu->hdr_size = 2;
 1688|      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 (1688:16): [True: 0, False: 0]
  ------------------
 1689|      0|      assert(pdu->max_hdr_size >= 3);
  ------------------
  |  Branch (1689:7): [True: 0, False: 0]
  ------------------
 1690|      0|      if (pdu->max_hdr_size < 3) {
  ------------------
  |  Branch (1690:11): [True: 0, False: 0]
  ------------------
 1691|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1692|      0|        return 0;
 1693|      0|      }
 1694|      0|      pdu->token[-3] = 13 << 4 | e_token_length;
 1695|      0|      pdu->token[-2] = (uint8_t)(len - COAP_MESSAGE_SIZE_OFFSET_TCP8);
  ------------------
  |  |   38|      0|#define COAP_MESSAGE_SIZE_OFFSET_TCP8 13
  ------------------
 1696|      0|      pdu->token[-1] = pdu->code;
 1697|      0|      pdu->hdr_size = 3;
 1698|      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 (1698:16): [True: 0, False: 0]
  ------------------
 1699|      0|      assert(pdu->max_hdr_size >= 4);
  ------------------
  |  Branch (1699:7): [True: 0, False: 0]
  ------------------
 1700|      0|      if (pdu->max_hdr_size < 4) {
  ------------------
  |  Branch (1700:11): [True: 0, False: 0]
  ------------------
 1701|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1702|      0|        return 0;
 1703|      0|      }
 1704|      0|      pdu->token[-4] = 14 << 4 | e_token_length;
 1705|      0|      pdu->token[-3] = (uint8_t)((len - COAP_MESSAGE_SIZE_OFFSET_TCP16) >> 8);
  ------------------
  |  |   39|      0|#define COAP_MESSAGE_SIZE_OFFSET_TCP16 269 /* 13 + 256 */
  ------------------
 1706|      0|      pdu->token[-2] = (uint8_t)(len - COAP_MESSAGE_SIZE_OFFSET_TCP16);
  ------------------
  |  |   39|      0|#define COAP_MESSAGE_SIZE_OFFSET_TCP16 269 /* 13 + 256 */
  ------------------
 1707|      0|      pdu->token[-1] = pdu->code;
 1708|      0|      pdu->hdr_size = 4;
 1709|      0|    } else {
 1710|      0|      assert(pdu->max_hdr_size >= 6);
  ------------------
  |  Branch (1710:7): [True: 0, False: 0]
  ------------------
 1711|      0|      if (pdu->max_hdr_size < 6) {
  ------------------
  |  Branch (1711:11): [True: 0, False: 0]
  ------------------
 1712|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1713|      0|        return 0;
 1714|      0|      }
 1715|      0|      pdu->token[-6] = 15 << 4 | e_token_length;
 1716|      0|      pdu->token[-5] = (uint8_t)((len - COAP_MESSAGE_SIZE_OFFSET_TCP32) >> 24);
  ------------------
  |  |   40|      0|#define COAP_MESSAGE_SIZE_OFFSET_TCP32 65805 /* 269 + 65536 */
  ------------------
 1717|      0|      pdu->token[-4] = (uint8_t)((len - COAP_MESSAGE_SIZE_OFFSET_TCP32) >> 16);
  ------------------
  |  |   40|      0|#define COAP_MESSAGE_SIZE_OFFSET_TCP32 65805 /* 269 + 65536 */
  ------------------
 1718|      0|      pdu->token[-3] = (uint8_t)((len - COAP_MESSAGE_SIZE_OFFSET_TCP32) >> 8);
  ------------------
  |  |   40|      0|#define COAP_MESSAGE_SIZE_OFFSET_TCP32 65805 /* 269 + 65536 */
  ------------------
 1719|      0|      pdu->token[-2] = (uint8_t)(len - COAP_MESSAGE_SIZE_OFFSET_TCP32);
  ------------------
  |  |   40|      0|#define COAP_MESSAGE_SIZE_OFFSET_TCP32 65805 /* 269 + 65536 */
  ------------------
 1720|      0|      pdu->token[-1] = pdu->code;
 1721|      0|      pdu->hdr_size = 6;
 1722|      0|    }
 1723|      0|#endif /* ! COAP_DISABLE_TCP */
 1724|      0|  } else {
 1725|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1726|      0|  }
 1727|  1.65k|  return pdu->hdr_size;
 1728|  1.65k|}
coap_pdu.c:coap_pdu_parse_opt_csm:
 1239|  4.01M|coap_pdu_parse_opt_csm(coap_pdu_code_t code, coap_option_num_t option, size_t len) {
 1240|  4.01M|  switch ((coap_pdu_signaling_proto_t)code) {
 1241|  14.6k|  case COAP_SIGNALING_CSM:
  ------------------
  |  Branch (1241:3): [True: 14.6k, False: 3.99M]
  ------------------
 1242|  14.6k|    switch ((coap_sig_csm_opt_t)option) {
 1243|  1.92k|    case COAP_SIG_OPT_MAX_MESSAGE_SIZE:
  ------------------
  |  Branch (1243:5): [True: 1.92k, False: 12.7k]
  ------------------
 1244|  1.92k|      if (len > 4)
  ------------------
  |  Branch (1244:11): [True: 1.26k, False: 659]
  ------------------
 1245|  1.26k|        goto bad;
 1246|    659|      break;
 1247|  1.66k|    case COAP_SIG_OPT_BLOCK_WISE_TRANSFER:
  ------------------
  |  Branch (1247:5): [True: 1.66k, False: 12.9k]
  ------------------
 1248|  1.66k|      if (len > 0)
  ------------------
  |  Branch (1248:11): [True: 1.13k, False: 535]
  ------------------
 1249|  1.13k|        goto bad;
 1250|    535|      break;
 1251|  1.89k|    case COAP_SIG_OPT_EXTENDED_TOKEN_LENGTH:
  ------------------
  |  Branch (1251:5): [True: 1.89k, False: 12.7k]
  ------------------
 1252|  1.89k|      if (len > 3)
  ------------------
  |  Branch (1252:11): [True: 1.19k, False: 702]
  ------------------
 1253|  1.19k|        goto bad;
 1254|    702|      break;
 1255|  9.16k|    default:
  ------------------
  |  Branch (1255:5): [True: 9.16k, False: 5.48k]
  ------------------
 1256|  9.16k|      if (option & 0x01)
  ------------------
  |  Branch (1256:11): [True: 7.11k, False: 2.05k]
  ------------------
 1257|  7.11k|        goto bad; /* Critical */
 1258|  14.6k|    }
 1259|  3.95k|    break;
 1260|  18.7k|  case COAP_SIGNALING_PING:
  ------------------
  |  Branch (1260:3): [True: 18.7k, False: 3.99M]
  ------------------
 1261|  27.2k|  case COAP_SIGNALING_PONG:
  ------------------
  |  Branch (1261:3): [True: 8.54k, False: 4.00M]
  ------------------
 1262|  27.2k|    switch ((coap_sig_ping_opt_t)option) {
 1263|  1.38k|    case COAP_SIG_OPT_CUSTODY:
  ------------------
  |  Branch (1263:5): [True: 1.38k, False: 25.9k]
  ------------------
 1264|  1.38k|      if (len > 0)
  ------------------
  |  Branch (1264:11): [True: 1.05k, False: 336]
  ------------------
 1265|  1.05k|        goto bad;
 1266|    336|      break;
 1267|  25.9k|    default:
  ------------------
  |  Branch (1267:5): [True: 25.9k, False: 1.38k]
  ------------------
 1268|  25.9k|      if (option & 0x01)
  ------------------
  |  Branch (1268:11): [True: 15.1k, False: 10.7k]
  ------------------
 1269|  15.1k|        goto bad; /* Critical */
 1270|  27.2k|    }
 1271|  11.0k|    break;
 1272|  16.3k|  case COAP_SIGNALING_RELEASE:
  ------------------
  |  Branch (1272:3): [True: 16.3k, False: 3.99M]
  ------------------
 1273|  16.3k|    switch ((coap_sig_release_opt_t)option) {
 1274|  2.73k|    case COAP_SIG_OPT_ALTERNATIVE_ADDRESS:
  ------------------
  |  Branch (1274:5): [True: 2.73k, False: 13.5k]
  ------------------
 1275|  2.73k|      if (len < 1 || len > 255)
  ------------------
  |  Branch (1275:11): [True: 1.42k, False: 1.31k]
  |  Branch (1275:22): [True: 1.01k, False: 300]
  ------------------
 1276|  2.43k|        goto bad;
 1277|    300|      break;
 1278|  2.17k|    case COAP_SIG_OPT_HOLD_OFF:
  ------------------
  |  Branch (1278:5): [True: 2.17k, False: 14.1k]
  ------------------
 1279|  2.17k|      if (len > 3)
  ------------------
  |  Branch (1279:11): [True: 1.57k, False: 598]
  ------------------
 1280|  1.57k|        goto bad;
 1281|    598|      break;
 1282|  11.4k|    default:
  ------------------
  |  Branch (1282:5): [True: 11.4k, False: 4.90k]
  ------------------
 1283|  11.4k|      if (option & 0x01)
  ------------------
  |  Branch (1283:11): [True: 7.19k, False: 4.21k]
  ------------------
 1284|  7.19k|        goto bad; /* Critical */
 1285|  16.3k|    }
 1286|  5.11k|    break;
 1287|  16.0k|  case COAP_SIGNALING_ABORT:
  ------------------
  |  Branch (1287:3): [True: 16.0k, False: 3.99M]
  ------------------
 1288|  16.0k|    switch ((coap_sig_abort_opt_t)option) {
 1289|  2.67k|    case COAP_SIG_OPT_BAD_CSM_OPTION:
  ------------------
  |  Branch (1289:5): [True: 2.67k, False: 13.4k]
  ------------------
 1290|  2.67k|      if (len > 2)
  ------------------
  |  Branch (1290:11): [True: 1.11k, False: 1.55k]
  ------------------
 1291|  1.11k|        goto bad;
 1292|  1.55k|      break;
 1293|  13.4k|    default:
  ------------------
  |  Branch (1293:5): [True: 13.4k, False: 2.67k]
  ------------------
 1294|  13.4k|      if (option & 0x01)
  ------------------
  |  Branch (1294:11): [True: 7.68k, False: 5.72k]
  ------------------
 1295|  7.68k|        goto bad; /* Critical */
 1296|  16.0k|    }
 1297|  7.28k|    break;
 1298|  3.93M|  default:
  ------------------
  |  Branch (1298:3): [True: 3.93M, False: 74.3k]
  ------------------
 1299|  3.93M|    goto bad;
 1300|  4.01M|  }
 1301|  27.4k|  return 1;
 1302|  3.98M|bad:
 1303|  3.98M|  return 0;
 1304|  4.01M|}
coap_pdu.c:next_option_safe:
 1057|  15.3M|next_option_safe(coap_opt_t **optp, size_t *length, uint16_t *max_opt) {
 1058|  15.3M|  coap_option_t option;
 1059|  15.3M|  size_t optsize;
 1060|       |
 1061|  15.3M|  assert(optp);
  ------------------
  |  Branch (1061:3): [True: 15.3M, False: 0]
  ------------------
 1062|  15.3M|  assert(*optp);
  ------------------
  |  Branch (1062:3): [True: 15.3M, False: 0]
  ------------------
 1063|  15.3M|  assert(length);
  ------------------
  |  Branch (1063:3): [True: 15.3M, False: 0]
  ------------------
 1064|       |
 1065|  15.3M|  optsize = coap_opt_parse(*optp, *length, &option);
 1066|  15.3M|  assert(optsize <= *length);
  ------------------
  |  Branch (1066:3): [True: 15.3M, False: 0]
  ------------------
 1067|       |
 1068|       |  /* signal an error if this option would exceed the
 1069|       |   * allowed number space */
 1070|  15.3M|  if ((uint32_t)(*max_opt) + option.delta > COAP_MAX_OPT) {
  ------------------
  |  |  105|  15.3M|#define COAP_MAX_OPT 65535 /**< the highest option number we know */
  ------------------
  |  Branch (1070:7): [True: 30, False: 15.3M]
  ------------------
 1071|     30|    return 0;
 1072|     30|  }
 1073|  15.3M|  *max_opt += option.delta;
 1074|  15.3M|  *optp += optsize;
 1075|  15.3M|  *length -= optsize;
 1076|       |
 1077|  15.3M|  return optsize;
 1078|  15.3M|}
coap_pdu.c:write_prefix:
 1430|   108k|write_prefix(char **obp, size_t *len, const char *prf, size_t prflen) {
 1431|       |  /* Make sure space for null terminating byte */
 1432|   108k|  if (*len < prflen +1) {
  ------------------
  |  Branch (1432:7): [True: 40, False: 108k]
  ------------------
 1433|     40|    return 0;
 1434|     40|  }
 1435|       |
 1436|   108k|  memcpy(*obp, prf, prflen);
 1437|   108k|  *obp += prflen;
 1438|   108k|  *len -= prflen;
 1439|   108k|  return 1;
 1440|   108k|}
coap_pdu.c:write_char:
 1443|  1.04M|write_char(char **obp, size_t *len, int c, int printable) {
 1444|       |  /* Make sure space for null terminating byte */
 1445|  1.04M|  if (*len < 2 +1) {
  ------------------
  |  Branch (1445:7): [True: 878, False: 1.04M]
  ------------------
 1446|    878|    return 0;
 1447|    878|  }
 1448|       |
 1449|  1.04M|  if (!printable) {
  ------------------
  |  Branch (1449:7): [True: 522k, False: 522k]
  ------------------
 1450|   522k|    const uint8_t hex[] = "0123456789abcdef";
 1451|   522k|    (*obp)[0] = hex[(c & 0xf0) >> 4];
 1452|   522k|    (*obp)[1] = hex[c & 0x0f];
 1453|   522k|  } else {
 1454|   522k|    (*obp)[0] = isprint(c) ? c : '.';
  ------------------
  |  Branch (1454:17): [True: 94.8k, False: 427k]
  ------------------
 1455|   522k|    (*obp)[1] = ' ';
 1456|   522k|  }
 1457|  1.04M|  *obp += 2;
 1458|  1.04M|  *len -= 2;
 1459|  1.04M|  return 1;
 1460|  1.04M|}

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

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

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

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

coap_split_proxy_uri:
  357|    561|coap_split_proxy_uri(const uint8_t *str_var, size_t len, coap_uri_t *uri) {
  358|    561|  return coap_split_uri_sub(str_var, len, uri, COAP_URI_CHECK_PROXY);
  359|    561|}
coap_check_dots:
  676|  7.24M|coap_check_dots(const uint8_t *s, size_t len) {
  677|  7.24M|  uint8_t p;
  678|       |
  679|  7.24M|  if (!len)
  ------------------
  |  Branch (679:7): [True: 7.08M, False: 163k]
  ------------------
  680|  7.08M|    return 0;
  681|       |
  682|   163k|  p = *s;
  683|       |
  684|       |  /* Check 'first' char */
  685|   163k|  if (p == '%' && len >=3) {
  ------------------
  |  Branch (685:7): [True: 2.38k, False: 161k]
  |  Branch (685:19): [True: 2.16k, False: 225]
  ------------------
  686|  2.16k|    if (s[1] == '2' && (s[2] == 'E' || s[2] == 'e')) {
  ------------------
  |  Branch (686:9): [True: 753, False: 1.41k]
  |  Branch (686:25): [True: 220, False: 533]
  |  Branch (686:40): [True: 277, False: 256]
  ------------------
  687|    497|      s += 2;
  688|    497|      len -= 2;
  689|    497|    }
  690|  2.16k|    p = '.';
  691|  2.16k|  }
  692|   163k|  if (p != '.')
  ------------------
  |  Branch (692:7): [True: 159k, False: 4.58k]
  ------------------
  693|   159k|    return 0;
  694|  4.58k|  if (len == 1)
  ------------------
  |  Branch (694:7): [True: 1.38k, False: 3.20k]
  ------------------
  695|  1.38k|    return 1;
  696|       |
  697|       |  /* Check 'second' char, first is '.' */
  698|  3.20k|  s++;
  699|  3.20k|  len--;
  700|  3.20k|  assert(len);
  ------------------
  |  Branch (700:3): [True: 3.20k, False: 0]
  ------------------
  701|  3.20k|  p = *s;
  702|  3.20k|  if (p == '%' && len >=3) {
  ------------------
  |  Branch (702:7): [True: 1.22k, False: 1.97k]
  |  Branch (702:19): [True: 954, False: 273]
  ------------------
  703|    954|    if (s[1] == '2' && (s[2] == 'E' || s[2] == 'e')) {
  ------------------
  |  Branch (703:9): [True: 680, False: 274]
  |  Branch (703:25): [True: 201, False: 479]
  |  Branch (703:40): [True: 202, False: 277]
  ------------------
  704|    403|      len -= 2;
  705|    403|    }
  706|    954|    p = '.';
  707|    954|  }
  708|  3.20k|  if (p != '.')
  ------------------
  |  Branch (708:7): [True: 1.06k, False: 2.14k]
  ------------------
  709|  1.06k|    return 0;
  710|  2.14k|  if (len == 1)
  ------------------
  |  Branch (710:7): [True: 1.36k, False: 777]
  ------------------
  711|  1.36k|    return 2;
  712|       |
  713|    777|  return 0;
  714|  2.14k|}
coap_get_query:
 1111|  1.65k|coap_get_query(const coap_pdu_t *request) {
 1112|  1.65k|  coap_opt_iterator_t opt_iter;
 1113|  1.65k|  coap_opt_filter_t f;
 1114|  1.65k|  coap_opt_t *q;
 1115|  1.65k|  coap_string_t *query = NULL;
 1116|  1.65k|  size_t length = 0;
 1117|  1.65k|  static const uint8_t hex[] = "0123456789ABCDEF";
 1118|       |
 1119|  1.65k|  coap_option_filter_clear(&f);
 1120|  1.65k|  coap_option_filter_set(&f, COAP_OPTION_URI_QUERY);
 1121|  1.65k|  coap_option_iterator_init(request, &opt_iter, &f);
 1122|  1.07M|  while ((q = coap_option_next(&opt_iter))) {
  ------------------
  |  Branch (1122:10): [True: 1.07M, False: 1.65k]
  ------------------
 1123|  1.07M|    uint16_t seg_len = coap_opt_length(q), i;
 1124|  1.07M|    const uint8_t *seg= coap_opt_value(q);
 1125|  5.57M|    for (i = 0; i < seg_len; i++) {
  ------------------
  |  Branch (1125:17): [True: 4.49M, False: 1.07M]
  ------------------
 1126|  4.49M|      if (is_unescaped_in_query(seg[i]))
  ------------------
  |  Branch (1126:11): [True: 82.9k, False: 4.41M]
  ------------------
 1127|  82.9k|        length += 1;
 1128|  4.41M|      else
 1129|  4.41M|        length += 3;
 1130|  4.49M|    }
 1131|  1.07M|    length += 1;
 1132|  1.07M|  }
 1133|  1.65k|  if (length > 0)
  ------------------
  |  Branch (1133:7): [True: 318, False: 1.33k]
  ------------------
 1134|    318|    length -= 1;
 1135|  1.65k|  if (length > 0) {
  ------------------
  |  Branch (1135:7): [True: 310, False: 1.34k]
  ------------------
 1136|    310|    query = coap_new_string(length);
 1137|    310|    if (query) {
  ------------------
  |  Branch (1137:9): [True: 310, False: 0]
  ------------------
 1138|    310|      query->length = length;
 1139|    310|      unsigned char *s = query->s;
 1140|    310|      coap_option_iterator_init(request, &opt_iter, &f);
 1141|  1.07M|      while ((q = coap_option_next(&opt_iter))) {
  ------------------
  |  Branch (1141:14): [True: 1.07M, False: 310]
  ------------------
 1142|  1.07M|        if (s != query->s)
  ------------------
  |  Branch (1142:13): [True: 1.07M, False: 960]
  ------------------
 1143|  1.07M|          *s++ = '&';
 1144|  1.07M|        uint16_t seg_len = coap_opt_length(q), i;
 1145|  1.07M|        const uint8_t *seg= coap_opt_value(q);
 1146|  5.57M|        for (i = 0; i < seg_len; i++) {
  ------------------
  |  Branch (1146:21): [True: 4.49M, False: 1.07M]
  ------------------
 1147|  4.49M|          if (is_unescaped_in_query(seg[i])) {
  ------------------
  |  Branch (1147:15): [True: 82.9k, False: 4.41M]
  ------------------
 1148|  82.9k|            *s++ = seg[i];
 1149|  4.41M|          } else {
 1150|  4.41M|            *s++ = '%';
 1151|  4.41M|            *s++ = hex[seg[i]>>4];
 1152|  4.41M|            *s++ = hex[seg[i]&0x0F];
 1153|  4.41M|          }
 1154|  4.49M|        }
 1155|  1.07M|      }
 1156|    310|    }
 1157|    310|  }
 1158|  1.65k|  return query;
 1159|  1.65k|}
coap_map_abbrev_uri_path:
 1162|     13|coap_map_abbrev_uri_path(coap_upa_chain_t *chain, uint32_t value) {
 1163|     13|  while (chain) {
  ------------------
  |  Branch (1163:10): [True: 0, False: 13]
  ------------------
 1164|      0|    coap_upa_chain_t *next = chain->next;
 1165|       |
 1166|      0|    if (chain->upa_value == value) {
  ------------------
  |  Branch (1166:9): [True: 0, False: 0]
  ------------------
 1167|      0|      return chain->upa_path;
 1168|      0|    }
 1169|      0|    chain = next;
 1170|      0|  }
 1171|     13|  return NULL;
 1172|     13|}
coap_get_uri_path:
 1190|  1.65k|coap_get_uri_path(const coap_pdu_t *request) {
 1191|  1.65k|  coap_opt_iterator_t opt_iter;
 1192|  1.65k|  coap_opt_filter_t f;
 1193|  1.65k|  coap_opt_t *q;
 1194|  1.65k|  coap_string_t *uri_path = NULL;
 1195|  1.65k|  size_t length = 0;
 1196|  1.65k|  static const uint8_t hex[] = "0123456789ABCDEF";
 1197|       |
 1198|  1.65k|  q = coap_check_option(request, COAP_OPTION_URI_PATH_ABB, &opt_iter);
 1199|  1.65k|  if (q) {
  ------------------
  |  Branch (1199:7): [True: 23, False: 1.63k]
  ------------------
 1200|     23|    uint32_t value;
 1201|     23|    const char *exp;
 1202|     23|    if (coap_check_option(request, COAP_OPTION_PROXY_URI, &opt_iter) ||
  ------------------
  |  Branch (1202:9): [True: 5, False: 18]
  ------------------
 1203|     18|        coap_check_option(request, COAP_OPTION_URI_PATH, &opt_iter)) {
  ------------------
  |  Branch (1203:9): [True: 5, False: 13]
  ------------------
 1204|     10|      return NULL;
 1205|     10|    }
 1206|     13|    value = coap_decode_var_bytes(coap_opt_value(q), coap_opt_length(q));
 1207|     13|    exp = coap_map_abbrev_uri_path(coap_upa_server_mapping_chain, value);
 1208|     13|    if (exp) {
  ------------------
  |  Branch (1208:9): [True: 0, False: 13]
  ------------------
 1209|      0|      uri_path = coap_new_string(strlen(exp));
 1210|      0|      if (uri_path) {
  ------------------
  |  Branch (1210:11): [True: 0, False: 0]
  ------------------
 1211|      0|        memcpy(uri_path->s, exp, strlen(exp));
 1212|      0|      }
 1213|      0|      return uri_path;
 1214|      0|    }
 1215|     13|    return NULL;
 1216|     13|  }
 1217|  1.63k|  q = coap_check_option(request, COAP_OPTION_PROXY_URI, &opt_iter);
 1218|  1.63k|  if (q) {
  ------------------
  |  Branch (1218:7): [True: 561, False: 1.06k]
  ------------------
 1219|    561|    coap_uri_t uri;
 1220|       |
 1221|    561|    if (coap_split_proxy_uri(coap_opt_value(q),
  ------------------
  |  Branch (1221:9): [True: 409, False: 152]
  ------------------
 1222|    561|                             coap_opt_length(q), &uri) < 0) {
 1223|    409|      return NULL;
 1224|    409|    }
 1225|    152|    uri_path = coap_new_string(uri.path.length);
 1226|    152|    if (uri_path && uri.path.length) {
  ------------------
  |  Branch (1226:9): [True: 152, False: 0]
  |  Branch (1226:21): [True: 39, False: 113]
  ------------------
 1227|     39|      memcpy(uri_path->s, uri.path.s, uri.path.length);
 1228|     39|    }
 1229|    152|    return uri_path;
 1230|    561|  }
 1231|       |
 1232|  1.06k|  coap_option_filter_clear(&f);
 1233|  1.06k|  coap_option_filter_set(&f, COAP_OPTION_URI_PATH);
 1234|  1.06k|  coap_option_iterator_init(request, &opt_iter, &f);
 1235|  7.09M|  while ((q = coap_option_next(&opt_iter))) {
  ------------------
  |  Branch (1235:10): [True: 7.09M, False: 1.06k]
  ------------------
 1236|  7.09M|    uint16_t seg_len = coap_opt_length(q), i;
 1237|  7.09M|    const uint8_t *seg = coap_opt_value(q);
 1238|  9.03M|    for (i = 0; i < seg_len; i++) {
  ------------------
  |  Branch (1238:17): [True: 1.94M, False: 7.09M]
  ------------------
 1239|  1.94M|      if (is_unescaped_in_path(seg[i]))
  ------------------
  |  Branch (1239:11): [True: 46.8k, False: 1.89M]
  ------------------
 1240|  46.8k|        length += 1;
 1241|  1.89M|      else
 1242|  1.89M|        length += 3;
 1243|  1.94M|    }
 1244|       |    /* bump for the leading "/" */
 1245|  7.09M|    length += 1;
 1246|  7.09M|  }
 1247|       |  /* The first entry does not have a leading "/" */
 1248|  1.06k|  if (length > 0)
  ------------------
  |  Branch (1248:7): [True: 418, False: 651]
  ------------------
 1249|    418|    length -= 1;
 1250|       |
 1251|       |  /* if 0, either no URI_PATH Option, or the first one was empty */
 1252|  1.06k|  uri_path = coap_new_string(length);
 1253|  1.06k|  if (uri_path) {
  ------------------
  |  Branch (1253:7): [True: 1.06k, False: 0]
  ------------------
 1254|  1.06k|    uri_path->length = length;
 1255|  1.06k|    unsigned char *s = uri_path->s;
 1256|  1.06k|    int n = 0;
 1257|  1.06k|    coap_option_iterator_init(request, &opt_iter, &f);
 1258|  7.09M|    while ((q = coap_option_next(&opt_iter))) {
  ------------------
  |  Branch (1258:12): [True: 7.09M, False: 1.06k]
  ------------------
 1259|  7.09M|      if (n++) {
  ------------------
  |  Branch (1259:11): [True: 7.09M, False: 418]
  ------------------
 1260|  7.09M|        *s++ = '/';
 1261|  7.09M|      }
 1262|  7.09M|      uint16_t seg_len = coap_opt_length(q), i;
 1263|  7.09M|      const uint8_t *seg= coap_opt_value(q);
 1264|  9.03M|      for (i = 0; i < seg_len; i++) {
  ------------------
  |  Branch (1264:19): [True: 1.94M, False: 7.09M]
  ------------------
 1265|  1.94M|        if (is_unescaped_in_path(seg[i])) {
  ------------------
  |  Branch (1265:13): [True: 46.8k, False: 1.89M]
  ------------------
 1266|  46.8k|          *s++ = seg[i];
 1267|  1.89M|        } else {
 1268|  1.89M|          *s++ = '%';
 1269|  1.89M|          *s++ = hex[seg[i]>>4];
 1270|  1.89M|          *s++ = hex[seg[i]&0x0F];
 1271|  1.89M|        }
 1272|  1.94M|      }
 1273|  7.09M|    }
 1274|  1.06k|  }
 1275|  1.06k|  return uri_path;
 1276|  1.63k|}
coap_delete_upa_chain:
 1279|  6.32k|coap_delete_upa_chain(coap_upa_chain_t *chain) {
 1280|  6.32k|  while (chain) {
  ------------------
  |  Branch (1280:10): [True: 0, False: 6.32k]
  ------------------
 1281|      0|    coap_upa_chain_t *next = chain->next;
 1282|       |
 1283|      0|    coap_free_type(COAP_STRING, chain);
 1284|      0|    chain = next;
 1285|      0|  }
 1286|  6.32k|}
coap_uri.c:coap_split_uri_sub:
   84|    561|                   coap_uri_check_t check_proxy) {
   85|    561|  const uint8_t *p, *q;
   86|    561|  int res = 0;
   87|    561|  size_t i;
   88|    561|  int is_unix_domain = 0;
   89|    561|  int is_llc = 0;
   90|       |
   91|    561|  if (!str_var || !uri || len == 0)
  ------------------
  |  Branch (91:7): [True: 0, False: 561]
  |  Branch (91:19): [True: 0, False: 561]
  |  Branch (91:27): [True: 0, False: 561]
  ------------------
   92|      0|    return -1;
   93|       |
   94|    561|  memset(uri, 0, sizeof(coap_uri_t));
   95|    561|  uri->port = COAP_DEFAULT_PORT;
  ------------------
  |  |   39|    561|#define COAP_DEFAULT_PORT      5683 /* CoAP default UDP/TCP port */
  ------------------
   96|       |
   97|       |  /* search for scheme */
   98|    561|  p = str_var;
   99|    561|  if (*p == '/') {
  ------------------
  |  Branch (99:7): [True: 1, False: 560]
  ------------------
  100|       |    /* no scheme, host or port */
  101|      1|    if (check_proxy == COAP_URI_CHECK_PROXY) {
  ------------------
  |  Branch (101:9): [True: 1, False: 0]
  ------------------
  102|       |      /* Must have ongoing host if proxy definition */
  103|      1|      return -1;
  104|      1|    }
  105|      0|    q = p;
  106|      0|    goto path;
  107|      1|  }
  108|       |
  109|       |  /* find scheme terminating :// */
  110|  13.1k|  while (len >= 3 && !(p[0] == ':' && p[1] == '/' && p[2] == '/')) {
  ------------------
  |  Branch (110:10): [True: 13.0k, False: 52]
  |  Branch (110:24): [True: 1.22k, False: 11.8k]
  |  Branch (110:39): [True: 721, False: 507]
  |  Branch (110:54): [True: 508, False: 213]
  ------------------
  111|  12.5k|    ++p;
  112|  12.5k|    --len;
  113|  12.5k|  }
  114|    560|  if (len < 3) {
  ------------------
  |  Branch (114:7): [True: 52, False: 508]
  ------------------
  115|       |    /* scheme not defined with a :// terminator */
  116|     52|    res = -2;
  117|     52|    goto error;
  118|     52|  }
  119|  2.45k|  for (i = 0; i < COAP_URI_SCHEME_LAST; i++) {
  ------------------
  |  Branch (119:15): [True: 2.35k, False: 97]
  ------------------
  120|  2.35k|    if ((p - str_var) == (int)strlen(coap_uri_scheme[i].name) &&
  ------------------
  |  Branch (120:9): [True: 830, False: 1.52k]
  ------------------
  121|    830|        memcmp(str_var, coap_uri_scheme[i].name, p - str_var) == 0) {
  ------------------
  |  Branch (121:9): [True: 411, False: 419]
  ------------------
  122|    411|      if (check_proxy != COAP_URI_CHECK_PROXY && coap_uri_scheme[i].proxy_only) {
  ------------------
  |  Branch (122:11): [True: 0, False: 411]
  |  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|    411|      uri->scheme = coap_uri_scheme[i].scheme;
  128|    411|      uri->port = coap_uri_scheme[i].port;
  129|    411|      break;
  130|    411|    }
  131|  2.35k|  }
  132|    508|  if (i == COAP_URI_SCHEME_LAST) {
  ------------------
  |  Branch (132:7): [True: 97, False: 411]
  ------------------
  133|       |    /* scheme unknown */
  134|     97|    coap_log_err("%.*s URI scheme unknown\n", (int)(p - str_var), str_var);
  ------------------
  |  |  102|     97|#define coap_log_err(...) coap_log(COAP_LOG_ERR, __VA_ARGS__)
  |  |  ------------------
  |  |  |  |  290|     97|#define coap_log(level, ...) do { \
  |  |  |  |  291|     97|    if ((level) < (coap_get_log_level() + 1)) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (291:9): [True: 0, False: 97]
  |  |  |  |  ------------------
  |  |  |  |  292|     97|      coap_log_impl((level), __VA_ARGS__); \
  |  |  |  |  293|     97|  } while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (293:11): [Folded, False: 97]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  135|     97|    res = -1;
  136|     97|    goto error;
  137|     97|  }
  138|    411|  switch (uri->scheme) {
  139|    117|  case COAP_URI_SCHEME_COAP:
  ------------------
  |  Branch (139:3): [True: 117, False: 294]
  ------------------
  140|    117|    break;
  141|      2|  case COAP_URI_SCHEME_COAPS:
  ------------------
  |  Branch (141:3): [True: 2, False: 409]
  ------------------
  142|      2|    if (!coap_dtls_is_supported()) {
  ------------------
  |  Branch (142:9): [True: 0, False: 2]
  ------------------
  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|      2|    break;
  147|      3|  case COAP_URI_SCHEME_COAP_TCP:
  ------------------
  |  Branch (147:3): [True: 3, False: 408]
  ------------------
  148|      3|    if (!coap_tcp_is_supported()) {
  ------------------
  |  Branch (148:9): [True: 0, False: 3]
  ------------------
  149|      0|      coap_log_err("coap+tcp URI scheme not supported in this version of libcoap\n");
  ------------------
  |  |  102|      0|#define coap_log_err(...) coap_log(COAP_LOG_ERR, __VA_ARGS__)
  |  |  ------------------
  |  |  |  |  290|      0|#define coap_log(level, ...) do { \
  |  |  |  |  291|      0|    if ((level) < (coap_get_log_level() + 1)) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (291:9): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  292|      0|      coap_log_impl((level), __VA_ARGS__); \
  |  |  |  |  293|      0|  } while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (293:11): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  150|      0|      return -1;
  151|      0|    }
  152|      3|    break;
  153|      3|  case COAP_URI_SCHEME_COAPS_TCP:
  ------------------
  |  Branch (153:3): [True: 1, False: 410]
  ------------------
  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: 410]
  ------------------
  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: 410]
  ------------------
  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|    284|  case COAP_URI_SCHEME_HTTP:
  ------------------
  |  Branch (171:3): [True: 284, False: 127]
  ------------------
  172|    286|  case COAP_URI_SCHEME_HTTPS:
  ------------------
  |  Branch (172:3): [True: 2, False: 409]
  ------------------
  173|       |    /* Not proxy, caught above.  For proxy, assume app is doing CoAP <> HTTP mapping. */
  174|    286|    break;
  175|      0|  case COAP_URI_SCHEME_LAST:
  ------------------
  |  Branch (175:3): [True: 0, False: 411]
  ------------------
  176|      0|  default:
  ------------------
  |  Branch (176:3): [True: 0, False: 411]
  ------------------
  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|    411|  }
  180|       |  /* skip :// */
  181|    411|  p += 3;
  182|    411|  len -= 3;
  183|       |
  184|       |  /* p points to beginning of Uri-Host */
  185|    411|  q = p;
  186|       |
  187|    411|  if (len && *p == '[') {
  ------------------
  |  Branch (187:7): [True: 403, False: 8]
  |  Branch (187:14): [True: 44, False: 359]
  ------------------
  188|       |    /* IPv6 address reference or Unix domain */
  189|     44|    ++p;
  190|     44|    ++q;
  191|     44|    --len;
  192|       |
  193|  8.36k|    while (len && *q != ']') {
  ------------------
  |  Branch (193:12): [True: 8.35k, False: 12]
  |  Branch (193:19): [True: 8.31k, False: 32]
  ------------------
  194|  8.31k|      ++q;
  195|  8.31k|      --len;
  196|  8.31k|    }
  197|       |
  198|     44|    if (!len || *q != ']' || p == q) {
  ------------------
  |  Branch (198:9): [True: 12, False: 32]
  |  Branch (198:17): [True: 0, False: 32]
  |  Branch (198:30): [True: 1, False: 31]
  ------------------
  199|     13|      res = -3;
  200|     13|      goto error;
  201|     13|    }
  202|       |
  203|     31|    if ((int)(q - p) > 255) {
  ------------------
  |  Branch (203:9): [True: 9, False: 22]
  ------------------
  204|      9|      coap_log_warn("Host name length too long (%d > 255)\n", (int)(q - p));
  ------------------
  |  |  108|      9|#define coap_log_warn(...) coap_log(COAP_LOG_WARN, __VA_ARGS__)
  |  |  ------------------
  |  |  |  |  290|      9|#define coap_log(level, ...) do { \
  |  |  |  |  291|      9|    if ((level) < (coap_get_log_level() + 1)) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (291:9): [True: 0, False: 9]
  |  |  |  |  ------------------
  |  |  |  |  292|      9|      coap_log_impl((level), __VA_ARGS__); \
  |  |  |  |  293|      9|  } while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (293:11): [Folded, False: 9]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  205|      9|      res = -6;
  206|      9|      goto error;
  207|      9|    }
  208|       |
  209|     22|    COAP_SET_STR(&uri->host, q - p, p);
  ------------------
  |  |   52|     22|#define COAP_SET_STR(st,l,v) { (st)->length = (l), (st)->s = (v); }
  ------------------
  210|     22|    ++q;
  211|     22|    --len;
  212|     22|#if COAP_AF_LLC_SUPPORT
  213|    367|  } else if ((len >= LLC_HOST_LEN) && strncmp((const char *)p, "llc[", 4) == 0) {
  ------------------
  |  |  178|    367|#define LLC_HOST_LEN (4 + HW_ADDRSTRLEN + 4)
  |  |  ------------------
  |  |  |  |  176|    367|#define HW_ADDRSTRLEN 17
  |  |  ------------------
  ------------------
  |  Branch (213:14): [True: 222, False: 145]
  |  Branch (213:39): [True: 137, False: 85]
  ------------------
  214|    137|    unsigned long sap = 0;
  215|       |
  216|    137|    is_llc = 1;
  217|       |
  218|  7.63k|    while (len && *q != ']') {
  ------------------
  |  Branch (218:12): [True: 7.62k, False: 9]
  |  Branch (218:19): [True: 7.50k, False: 128]
  ------------------
  219|  7.50k|      ++q;
  220|  7.50k|      --len;
  221|  7.50k|    }
  222|       |
  223|    137|    if (!len || *q != ']' || p == q) {
  ------------------
  |  Branch (223:9): [True: 9, False: 128]
  |  Branch (223:17): [True: 0, False: 128]
  |  Branch (223:30): [True: 0, False: 128]
  ------------------
  224|      9|      res = -7;
  225|      9|      goto error;
  226|      9|    }
  227|       |
  228|    128|    ++q;
  229|    128|    --len;
  230|       |
  231|    128|    if (!len || *q != ':') {
  ------------------
  |  Branch (231:9): [True: 1, False: 127]
  |  Branch (231:17): [True: 12, False: 115]
  ------------------
  232|     13|      coap_log_warn("LLC SAP missing in URI\n");
  ------------------
  |  |  108|     13|#define coap_log_warn(...) coap_log(COAP_LOG_WARN, __VA_ARGS__)
  |  |  ------------------
  |  |  |  |  290|     13|#define coap_log(level, ...) do { \
  |  |  |  |  291|     13|    if ((level) < (coap_get_log_level() + 1)) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (291:9): [True: 0, False: 13]
  |  |  |  |  ------------------
  |  |  |  |  292|     13|      coap_log_impl((level), __VA_ARGS__); \
  |  |  |  |  293|     13|  } while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (293:11): [Folded, False: 13]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  233|     13|      res = -7;
  234|     13|      goto error;
  235|     13|    }
  236|       |
  237|    115|    ++q;
  238|    115|    --len;
  239|       |
  240|  2.26k|    while (len && isxdigit(*q)) {
  ------------------
  |  Branch (240:12): [True: 2.23k, False: 31]
  |  Branch (240:19): [True: 2.14k, False: 84]
  ------------------
  241|  2.14k|      if (*q >= 'a' && *q <= 'f')
  ------------------
  |  Branch (241:11): [True: 1.04k, False: 1.10k]
  |  Branch (241:24): [True: 1.04k, False: 0]
  ------------------
  242|  1.04k|        sap = sap * 16 + (*q - 'a' + 10);
  243|  1.10k|      else if (*q >= 'A' && *q <= 'F')
  ------------------
  |  Branch (243:16): [True: 785, False: 320]
  |  Branch (243:29): [True: 785, False: 0]
  ------------------
  244|    785|        sap = sap * 16 + (*q - 'A' + 10);
  245|       |
  246|  2.14k|      ++q;
  247|  2.14k|      --len;
  248|  2.14k|    }
  249|       |
  250|    115|    if (sap > UINT8_MAX) {
  ------------------
  |  Branch (250:9): [True: 96, False: 19]
  ------------------
  251|     96|      coap_log_warn("LLC SAP invalid (%lu > 255)\n", sap);
  ------------------
  |  |  108|     96|#define coap_log_warn(...) coap_log(COAP_LOG_WARN, __VA_ARGS__)
  |  |  ------------------
  |  |  |  |  290|     96|#define coap_log(level, ...) do { \
  |  |  |  |  291|     96|    if ((level) < (coap_get_log_level() + 1)) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (291:9): [True: 0, False: 96]
  |  |  |  |  ------------------
  |  |  |  |  292|     96|      coap_log_impl((level), __VA_ARGS__); \
  |  |  |  |  293|     96|  } while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (293:11): [Folded, False: 96]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  252|     96|      res = -7;
  253|     96|      goto error;
  254|     96|    }
  255|       |
  256|     19|    COAP_SET_STR(&uri->host, q - p, p);
  ------------------
  |  |   52|     19|#define COAP_SET_STR(st,l,v) { (st)->length = (l), (st)->s = (v); }
  ------------------
  257|     19|#endif /* COAP_AF_LLC_SUPPORT */
  258|    230|  } else {
  259|       |    /* IPv4 address, FQDN or Unix domain socket */
  260|    230|    if (len >= 3 && p[0] == '%' && p[1] == '2' &&
  ------------------
  |  Branch (260:9): [True: 206, False: 24]
  |  Branch (260:21): [True: 36, False: 170]
  |  Branch (260:36): [True: 19, False: 17]
  ------------------
  261|     19|        (p[2] == 'F' || p[2] == 'f')) {
  ------------------
  |  Branch (261:10): [True: 1, False: 18]
  |  Branch (261:25): [True: 2, False: 16]
  ------------------
  262|       |      /* Unix domain definition */
  263|      3|      uri->port = 0;
  264|      3|      is_unix_domain = 1;
  265|      3|    }
  266|  8.32k|    while (len && *q != ':' && *q != '/' && *q != '?') {
  ------------------
  |  Branch (266:12): [True: 8.24k, False: 82]
  |  Branch (266:19): [True: 8.13k, False: 102]
  |  Branch (266:32): [True: 8.10k, False: 38]
  |  Branch (266:45): [True: 8.09k, False: 8]
  ------------------
  267|  8.09k|      ++q;
  268|  8.09k|      --len;
  269|  8.09k|    }
  270|       |
  271|    230|    if (p == q) {
  ------------------
  |  Branch (271:9): [True: 11, False: 219]
  ------------------
  272|     11|      res = -3;
  273|     11|      goto error;
  274|     11|    }
  275|       |
  276|    219|    if ((int)(q - p) > 255) {
  ------------------
  |  Branch (276:9): [True: 7, False: 212]
  ------------------
  277|      7|      coap_log_warn("Host name length too long (%d > 255)\n", (int)(q - p));
  ------------------
  |  |  108|      7|#define coap_log_warn(...) coap_log(COAP_LOG_WARN, __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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  278|      7|      res = -6;
  279|      7|      goto error;
  280|      7|    }
  281|       |
  282|    212|    COAP_SET_STR(&uri->host, q - p, p);
  ------------------
  |  |   52|    212|#define COAP_SET_STR(st,l,v) { (st)->length = (l), (st)->s = (v); }
  ------------------
  283|    212|  }
  284|       |
  285|       |  /* check for Uri-Port (invalid for Unix) */
  286|    253|  if (len && *q == ':') {
  ------------------
  |  Branch (286:7): [True: 177, False: 76]
  |  Branch (286:14): [True: 102, False: 75]
  ------------------
  287|    102|    if (is_unix_domain || is_llc) {
  ------------------
  |  Branch (287:9): [True: 1, False: 101]
  |  Branch (287:27): [True: 3, False: 98]
  ------------------
  288|      4|      res = -5;
  289|      4|      goto error;
  290|      4|    }
  291|     98|    p = ++q;
  292|     98|    --len;
  293|       |
  294|  1.15k|    while (len && isdigit(*q)) {
  ------------------
  |  Branch (294:12): [True: 1.10k, False: 55]
  |  Branch (294:19): [True: 1.05k, False: 43]
  ------------------
  295|  1.05k|      ++q;
  296|  1.05k|      --len;
  297|  1.05k|    }
  298|       |
  299|     98|    if (p < q) {                /* explicit port number given */
  ------------------
  |  Branch (299:9): [True: 63, False: 35]
  ------------------
  300|     63|      long uri_port = 0;
  301|       |
  302|  1.11k|      while ((p < q) && (uri_port <= UINT16_MAX))
  ------------------
  |  Branch (302:14): [True: 1.05k, False: 59]
  |  Branch (302:25): [True: 1.05k, False: 4]
  ------------------
  303|  1.05k|        uri_port = uri_port * 10 + (*p++ - '0');
  304|       |
  305|       |      /* check if port number is in allowed range */
  306|     63|      if (uri_port > UINT16_MAX) {
  ------------------
  |  Branch (306:11): [True: 24, False: 39]
  ------------------
  307|     24|        coap_log_warn("Port number too big (%ld > 65535)\n", uri_port);
  ------------------
  |  |  108|     24|#define coap_log_warn(...) coap_log(COAP_LOG_WARN, __VA_ARGS__)
  |  |  ------------------
  |  |  |  |  290|     24|#define coap_log(level, ...) do { \
  |  |  |  |  291|     24|    if ((level) < (coap_get_log_level() + 1)) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (291:9): [True: 0, False: 24]
  |  |  |  |  ------------------
  |  |  |  |  292|     24|      coap_log_impl((level), __VA_ARGS__); \
  |  |  |  |  293|     24|  } while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (293:11): [Folded, False: 24]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  308|     24|        res = -4;
  309|     24|        goto error;
  310|     24|      }
  311|       |
  312|     39|      uri->port = (uint16_t)uri_port;
  313|     39|    }
  314|     98|  }
  315|       |
  316|    225|path:                 /* at this point, p must point to an absolute path */
  317|       |
  318|    225|  if (!len)
  ------------------
  |  Branch (318:7): [True: 108, False: 117]
  ------------------
  319|    108|    goto end;
  320|       |
  321|    117|  if (*q == '/') {
  ------------------
  |  Branch (321:7): [True: 43, False: 74]
  ------------------
  322|     43|    p = ++q;
  323|     43|    --len;
  324|       |
  325|  6.66k|    while (len && *q != '?') {
  ------------------
  |  Branch (325:12): [True: 6.62k, False: 40]
  |  Branch (325:19): [True: 6.61k, False: 3]
  ------------------
  326|  6.61k|      ++q;
  327|  6.61k|      --len;
  328|  6.61k|    }
  329|       |
  330|     43|    if (p < q) {
  ------------------
  |  Branch (330:9): [True: 39, False: 4]
  ------------------
  331|     39|      COAP_SET_STR(&uri->path, q - p, p);
  ------------------
  |  |   52|     39|#define COAP_SET_STR(st,l,v) { (st)->length = (l), (st)->s = (v); }
  ------------------
  332|     39|      p = q;
  333|     39|    }
  334|     43|  }
  335|       |
  336|       |  /* Uri_Query */
  337|    117|  if (len && *p == '?') {
  ------------------
  |  Branch (337:7): [True: 77, False: 40]
  |  Branch (337:14): [True: 4, False: 73]
  ------------------
  338|      4|    ++p;
  339|      4|    --len;
  340|      4|    COAP_SET_STR(&uri->query, len, p);
  ------------------
  |  |   52|      4|#define COAP_SET_STR(st,l,v) { (st)->length = (l), (st)->s = (v); }
  ------------------
  341|      4|    len = 0;
  342|      4|  }
  343|       |
  344|    225|end:
  345|    225|  return len ? -1 : 0;
  ------------------
  |  Branch (345:10): [True: 73, False: 152]
  ------------------
  346|       |
  347|    335|error:
  348|    335|  return res;
  349|    117|}
coap_uri.c:is_unescaped_in_query:
 1106|  8.99M|is_unescaped_in_query(const uint8_t c) {
 1107|  8.99M|  return is_unescaped_in_path(c) || c=='/' || c=='?';
  ------------------
  |  Branch (1107:10): [True: 163k, False: 8.82M]
  |  Branch (1107:37): [True: 1.79k, False: 8.82M]
  |  Branch (1107:47): [True: 94, False: 8.82M]
  ------------------
 1108|  8.99M|}
coap_uri.c:is_unescaped_in_path:
 1097|  12.8M|is_unescaped_in_path(const uint8_t c) {
 1098|  12.8M|  return (c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') ||
  ------------------
  |  Branch (1098:11): [True: 368k, False: 12.5M]
  |  Branch (1098:23): [True: 14.3k, False: 354k]
  |  Branch (1098:37): [True: 302k, False: 12.5M]
  |  Branch (1098:49): [True: 133k, False: 168k]
  ------------------
 1099|  12.7M|         (c >= '0' && c <= '9') || c == '-' || c == '.' || c == '_' ||
  ------------------
  |  Branch (1099:11): [True: 287k, False: 12.4M]
  |  Branch (1099:23): [True: 21.9k, False: 265k]
  |  Branch (1099:36): [True: 11.1k, False: 12.6M]
  |  Branch (1099:48): [True: 2.23k, False: 12.6M]
  |  Branch (1099:60): [True: 1.50k, False: 12.6M]
  ------------------
 1100|  12.6M|         c == '~' || c == '!' || c == '$' || c == '\'' || c == '(' ||
  ------------------
  |  Branch (1100:10): [True: 8.57k, False: 12.6M]
  |  Branch (1100:22): [True: 3.86k, False: 12.6M]
  |  Branch (1100:34): [True: 1.64k, False: 12.6M]
  |  Branch (1100:46): [True: 1.57k, False: 12.6M]
  |  Branch (1100:59): [True: 1.29k, False: 12.6M]
  ------------------
 1101|  12.6M|         c == ')' || c == '*' || c == '+' || c == ',' || c == ';' ||
  ------------------
  |  Branch (1101:10): [True: 1.47k, False: 12.6M]
  |  Branch (1101:22): [True: 3.04k, False: 12.6M]
  |  Branch (1101:34): [True: 4.07k, False: 12.6M]
  |  Branch (1101:46): [True: 2.00k, False: 12.6M]
  |  Branch (1101:58): [True: 1.45k, False: 12.6M]
  ------------------
 1102|  12.6M|         c=='=' || c==':' || c=='@' || c == '&';
  ------------------
  |  Branch (1102:10): [True: 4.00k, False: 12.6M]
  |  Branch (1102:20): [True: 36.3k, False: 12.6M]
  |  Branch (1102:30): [True: 3.29k, False: 12.6M]
  |  Branch (1102:40): [True: 200, False: 12.6M]
  ------------------
 1103|  12.8M|}

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

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

