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

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

coap_memory_init:
  623|  3.09k|coap_memory_init(void) {
  624|  3.09k|}
coap_malloc_type:
  627|  7.69k|coap_malloc_type(coap_memory_tag_t type, size_t size) {
  628|  7.69k|  void *ptr;
  629|       |
  630|  7.69k|  (void)type;
  631|  7.69k|  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.69k|  return ptr;
  643|  7.69k|}
coap_realloc_type:
  646|    562|coap_realloc_type(coap_memory_tag_t type, void *p, size_t size) {
  647|    562|  void *ptr;
  648|       |
  649|    562|  (void)type;
  650|    562|  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|    562|  return ptr;
  663|    562|}
coap_free_type:
  666|  12.5k|coap_free_type(coap_memory_tag_t type, void *p) {
  667|  12.5k|  (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.5k|  free(p);
  674|  12.5k|}

coap_startup:
 5720|  3.09k|coap_startup(void) {
 5721|  3.09k|  coap_tick_t now;
 5722|  3.09k|#ifndef WITH_CONTIKI
 5723|  3.09k|  uint64_t us;
 5724|  3.09k|#endif /* !WITH_CONTIKI */
 5725|       |
 5726|  3.09k|  if (coap_started)
  ------------------
  |  Branch (5726:7): [True: 0, False: 3.09k]
  ------------------
 5727|      0|    return;
 5728|  3.09k|  coap_started = 1;
 5729|       |
 5730|       |#if COAP_THREAD_SAFE
 5731|       |  coap_lock_init(&global_lock);
 5732|       |  coap_mutex_init(&m_show_pdu);
 5733|       |  coap_mutex_init(&m_log_impl);
 5734|       |  coap_mutex_init(&m_io_threads);
 5735|       |#endif /* COAP_THREAD_SAFE */
 5736|       |
 5737|       |#if defined(HAVE_WINSOCK2_H)
 5738|       |  WORD wVersionRequested = MAKEWORD(2, 2);
 5739|       |  WSADATA wsaData;
 5740|       |  WSAStartup(wVersionRequested, &wsaData);
 5741|       |#endif
 5742|  3.09k|  coap_clock_init();
 5743|  3.09k|  coap_ticks(&now);
 5744|  3.09k|#ifndef WITH_CONTIKI
 5745|  3.09k|  us = coap_ticks_to_rt_us(now);
 5746|       |  /* Be accurate to the nearest (approx) us */
 5747|  3.09k|  coap_prng_init_lkd((unsigned int)us);
 5748|       |#else /* WITH_CONTIKI */
 5749|       |  coap_start_io_process();
 5750|       |#endif /* WITH_CONTIKI */
 5751|  3.09k|  coap_memory_init();
 5752|  3.09k|  coap_dtls_startup();
 5753|       |#ifdef WITH_LWIP
 5754|       |  coap_io_lwip_init();
 5755|       |#endif /* WITH_LWIP */
 5756|  3.09k|#if COAP_SERVER_SUPPORT
 5757|  3.09k|  static coap_str_const_t well_known = { sizeof(".well-known/core")-1,
 5758|  3.09k|                                         (const uint8_t *)".well-known/core"
 5759|  3.09k|                                       };
 5760|  3.09k|  memset(&resource_uri_wellknown, 0, sizeof(resource_uri_wellknown));
 5761|  3.09k|  resource_uri_wellknown.ref = 1;
 5762|  3.09k|  resource_uri_wellknown.handler[COAP_REQUEST_GET-1] = hnd_get_wellknown_lkd;
 5763|  3.09k|  resource_uri_wellknown.flags = COAP_RESOURCE_FLAGS_HAS_MCAST_SUPPORT;
  ------------------
  |  |   89|  3.09k|#define COAP_RESOURCE_FLAGS_HAS_MCAST_SUPPORT 0x8
  ------------------
 5764|  3.09k|  resource_uri_wellknown.uri_path = &well_known;
 5765|  3.09k|#endif /* COAP_SERVER_SUPPORT */
 5766|  3.09k|  send_recv_terminate = 0;
 5767|  3.09k|  coap_prng_lkd(&coap_unique_id, sizeof(coap_unique_id));
 5768|  3.09k|}
coap_cleanup:
 5771|  3.09k|coap_cleanup(void) {
 5772|  3.09k|  if (!coap_started)
  ------------------
  |  Branch (5772:7): [True: 0, False: 3.09k]
  ------------------
 5773|      0|    return;
 5774|  3.09k|  coap_started = 0;
 5775|       |#if defined(HAVE_WINSOCK2_H)
 5776|       |  WSACleanup();
 5777|       |#elif defined(WITH_CONTIKI)
 5778|       |  coap_stop_io_process();
 5779|       |#endif
 5780|       |#ifdef WITH_LWIP
 5781|       |  coap_io_lwip_cleanup();
 5782|       |#endif /* WITH_LWIP */
 5783|  3.09k|  coap_dtls_shutdown();
 5784|       |
 5785|  3.09k|  coap_delete_upa_chain(coap_upa_client_fallback_chain);
 5786|  3.09k|  coap_upa_client_fallback_chain = NULL;
 5787|  3.09k|  coap_delete_upa_chain(coap_upa_server_mapping_chain);
 5788|  3.09k|  coap_upa_server_mapping_chain = NULL;
 5789|       |#if COAP_THREAD_SAFE
 5790|       |  coap_mutex_destroy(&m_show_pdu);
 5791|       |  coap_mutex_destroy(&m_log_impl);
 5792|       |  coap_mutex_destroy(&m_io_threads);
 5793|       |#endif /* COAP_THREAD_SAFE */
 5794|       |
 5795|  3.09k|  coap_debug_reset();
 5796|  3.09k|}

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

coap_opt_parse:
   41|  50.7M|coap_opt_parse(const coap_opt_t *opt, size_t length, coap_option_t *result) {
   42|       |
   43|  50.7M|  const coap_opt_t *opt_start = opt; /* store where parsing starts  */
   44|  50.7M|  uint32_t delta; /* wider than result->delta to detect overflow */
   45|       |
   46|  50.7M|  assert(opt);
  ------------------
  |  Branch (46:3): [True: 50.7M, False: 0]
  ------------------
   47|  50.7M|  assert(result);
  ------------------
  |  Branch (47:3): [True: 50.7M, False: 0]
  ------------------
   48|       |
   49|  50.7M|  if (length < 1)
  ------------------
  |  Branch (49:7): [True: 4.62k, False: 50.7M]
  ------------------
   50|  4.62k|    return 0;
   51|       |
   52|  50.7M|  result->delta = (*opt & 0xf0) >> 4;
   53|  50.7M|  result->length = *opt & 0x0f;
   54|  50.7M|  delta = result->delta;
   55|       |
   56|  50.7M|  switch (result->delta) {
   57|    595|  case 15:
  ------------------
  |  Branch (57:3): [True: 595, False: 50.7M]
  ------------------
   58|    595|    if (*opt != COAP_PAYLOAD_START) {
  ------------------
  |  |   96|    595|#define COAP_PAYLOAD_START 0xFF /* payload marker */
  ------------------
  |  Branch (58:9): [True: 159, False: 436]
  ------------------
   59|    159|      coap_log_debug("ignored reserved option delta 15\n");
  ------------------
  |  |  126|    159|#define coap_log_debug(...) coap_log(COAP_LOG_DEBUG, __VA_ARGS__)
  |  |  ------------------
  |  |  |  |  290|    159|#define coap_log(level, ...) do { \
  |  |  |  |  291|    159|    if ((level) < (coap_get_log_level() + 1)) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (291:9): [True: 0, False: 159]
  |  |  |  |  ------------------
  |  |  |  |  292|    159|      coap_log_impl((level), __VA_ARGS__); \
  |  |  |  |  293|    159|  } while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (293:11): [Folded, False: 159]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
   60|    159|    }
   61|    595|    return 0;
   62|  1.17k|  case 14:
  ------------------
  |  Branch (62:3): [True: 1.17k, False: 50.7M]
  ------------------
   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.17k|    ADVANCE_OPT_CHECK(opt,length,1);
  ------------------
  |  |   34|  1.17k|#define ADVANCE_OPT_CHECK(o,e,step) do { \
  |  |   35|  1.17k|    ADVANCE_OPT(o,e,step);               \
  |  |  ------------------
  |  |  |  |   22|  1.17k|#define ADVANCE_OPT(o,e,step) if ((e) < step) {           \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (22:35): [True: 0, False: 1.17k]
  |  |  |  |  ------------------
  |  |  |  |   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.17k|  } else {                                                \
  |  |  |  |   26|  1.17k|    (e) -= step;                                          \
  |  |  |  |   27|  1.17k|    (o) = ((o)) + step;                                   \
  |  |  |  |   28|  1.17k|  }
  |  |  ------------------
  |  |   36|  1.17k|    if ((e) < 1)                         \
  |  |  ------------------
  |  |  |  Branch (36:9): [True: 27, False: 1.15k]
  |  |  ------------------
  |  |   37|  1.17k|      return 0;                          \
  |  |   38|  1.17k|  } while (0)
  |  |  ------------------
  |  |  |  Branch (38:12): [Folded, False: 1.15k]
  |  |  ------------------
  ------------------
   67|  1.15k|    delta = ((*opt & 0xff) << 8) + 269;
   68|       |  /* fall through */
   69|  5.17k|  case 13:
  ------------------
  |  Branch (69:3): [True: 4.02k, False: 50.7M]
  ------------------
   70|  5.17k|    ADVANCE_OPT_CHECK(opt,length,1);
  ------------------
  |  |   34|  5.17k|#define ADVANCE_OPT_CHECK(o,e,step) do { \
  |  |   35|  5.17k|    ADVANCE_OPT(o,e,step);               \
  |  |  ------------------
  |  |  |  |   22|  5.17k|#define ADVANCE_OPT(o,e,step) if ((e) < step) {           \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (22:35): [True: 0, False: 5.17k]
  |  |  |  |  ------------------
  |  |  |  |   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.17k|  } else {                                                \
  |  |  |  |   26|  5.17k|    (e) -= step;                                          \
  |  |  |  |   27|  5.17k|    (o) = ((o)) + step;                                   \
  |  |  |  |   28|  5.17k|  }
  |  |  ------------------
  |  |   36|  5.17k|    if ((e) < 1)                         \
  |  |  ------------------
  |  |  |  Branch (36:9): [True: 39, False: 5.13k]
  |  |  ------------------
  |  |   37|  5.17k|      return 0;                          \
  |  |   38|  5.17k|  } while (0)
  |  |  ------------------
  |  |  |  Branch (38:12): [Folded, False: 5.13k]
  |  |  ------------------
  ------------------
   71|  5.13k|    delta += *opt & 0xff;
   72|  5.13k|    if (delta > 0xffff) {
  ------------------
  |  Branch (72:9): [True: 15, False: 5.11k]
  ------------------
   73|     15|      coap_log_debug("delta too large\n");
  ------------------
  |  |  126|     15|#define coap_log_debug(...) coap_log(COAP_LOG_DEBUG, __VA_ARGS__)
  |  |  ------------------
  |  |  |  |  290|     15|#define coap_log(level, ...) do { \
  |  |  |  |  291|     15|    if ((level) < (coap_get_log_level() + 1)) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (291:9): [True: 0, False: 15]
  |  |  |  |  ------------------
  |  |  |  |  292|     15|      coap_log_impl((level), __VA_ARGS__); \
  |  |  |  |  293|     15|  } while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (293:11): [Folded, False: 15]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
   74|     15|      return 0;
   75|     15|    }
   76|  5.11k|    result->delta = (uint16_t)delta;
   77|  5.11k|    break;
   78|       |
   79|  50.7M|  default:
  ------------------
  |  Branch (79:3): [True: 50.7M, False: 5.79k]
  ------------------
   80|  50.7M|    ;
   81|  50.7M|  }
   82|       |
   83|  50.7M|  switch (result->length) {
   84|    105|  case 15:
  ------------------
  |  Branch (84:3): [True: 105, False: 50.7M]
  ------------------
   85|    105|    coap_log_debug("found reserved option length 15\n");
  ------------------
  |  |  126|    105|#define coap_log_debug(...) coap_log(COAP_LOG_DEBUG, __VA_ARGS__)
  |  |  ------------------
  |  |  |  |  290|    105|#define coap_log(level, ...) do { \
  |  |  |  |  291|    105|    if ((level) < (coap_get_log_level() + 1)) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (291:9): [True: 0, False: 105]
  |  |  |  |  ------------------
  |  |  |  |  292|    105|      coap_log_impl((level), __VA_ARGS__); \
  |  |  |  |  293|    105|  } while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (293:11): [Folded, False: 105]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
   86|    105|    return 0;
   87|  5.22k|  case 14:
  ------------------
  |  Branch (87:3): [True: 5.22k, False: 50.7M]
  ------------------
   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.22k|    ADVANCE_OPT_CHECK(opt,length,1);
  ------------------
  |  |   34|  5.22k|#define ADVANCE_OPT_CHECK(o,e,step) do { \
  |  |   35|  5.22k|    ADVANCE_OPT(o,e,step);               \
  |  |  ------------------
  |  |  |  |   22|  5.22k|#define ADVANCE_OPT(o,e,step) if ((e) < step) {           \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (22:35): [True: 0, False: 5.22k]
  |  |  |  |  ------------------
  |  |  |  |   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.22k|  } else {                                                \
  |  |  |  |   26|  5.22k|    (e) -= step;                                          \
  |  |  |  |   27|  5.22k|    (o) = ((o)) + step;                                   \
  |  |  |  |   28|  5.22k|  }
  |  |  ------------------
  |  |   36|  5.22k|    if ((e) < 1)                         \
  |  |  ------------------
  |  |  |  Branch (36:9): [True: 69, False: 5.15k]
  |  |  ------------------
  |  |   37|  5.22k|      return 0;                          \
  |  |   38|  5.22k|  } while (0)
  |  |  ------------------
  |  |  |  Branch (38:12): [Folded, False: 5.15k]
  |  |  ------------------
  ------------------
   92|  5.15k|    result->length = ((*opt & 0xff) << 8) + 269;
   93|       |  /* fall through */
   94|  17.8k|  case 13:
  ------------------
  |  Branch (94:3): [True: 12.7k, False: 50.7M]
  ------------------
   95|  17.8k|    ADVANCE_OPT_CHECK(opt,length,1);
  ------------------
  |  |   34|  17.8k|#define ADVANCE_OPT_CHECK(o,e,step) do { \
  |  |   35|  17.8k|    ADVANCE_OPT(o,e,step);               \
  |  |  ------------------
  |  |  |  |   22|  17.8k|#define ADVANCE_OPT(o,e,step) if ((e) < step) {           \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (22:35): [True: 0, False: 17.8k]
  |  |  |  |  ------------------
  |  |  |  |   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|  17.8k|  } else {                                                \
  |  |  |  |   26|  17.8k|    (e) -= step;                                          \
  |  |  |  |   27|  17.8k|    (o) = ((o)) + step;                                   \
  |  |  |  |   28|  17.8k|  }
  |  |  ------------------
  |  |   36|  17.8k|    if ((e) < 1)                         \
  |  |  ------------------
  |  |  |  Branch (36:9): [True: 48, False: 17.8k]
  |  |  ------------------
  |  |   37|  17.8k|      return 0;                          \
  |  |   38|  17.8k|  } while (0)
  |  |  ------------------
  |  |  |  Branch (38:12): [Folded, False: 17.8k]
  |  |  ------------------
  ------------------
   96|  17.8k|    result->length += *opt & 0xff;
   97|  17.8k|    break;
   98|       |
   99|  50.7M|  default:
  ------------------
  |  Branch (99:3): [True: 50.7M, False: 18.0k]
  ------------------
  100|  50.7M|    ;
  101|  50.7M|  }
  102|       |
  103|       |  /* ADVANCE_OPT() is correct here */
  104|  50.7M|  ADVANCE_OPT(opt,length,1);
  ------------------
  |  |   22|  50.7M|#define ADVANCE_OPT(o,e,step) if ((e) < step) {           \
  |  |  ------------------
  |  |  |  Branch (22:35): [True: 0, False: 50.7M]
  |  |  ------------------
  |  |   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|  50.7M|  } else {                                                \
  |  |   26|  50.7M|    (e) -= step;                                          \
  |  |   27|  50.7M|    (o) = ((o)) + step;                                   \
  |  |   28|  50.7M|  }
  ------------------
  105|       |  /* opt now points to value, if present */
  106|       |
  107|  50.7M|  result->value = opt;
  108|  50.7M|  if (length < result->length) {
  ------------------
  |  Branch (108:7): [True: 816, False: 50.7M]
  ------------------
  109|    816|    coap_log_debug("invalid option length\n");
  ------------------
  |  |  126|    816|#define coap_log_debug(...) coap_log(COAP_LOG_DEBUG, __VA_ARGS__)
  |  |  ------------------
  |  |  |  |  290|    816|#define coap_log(level, ...) do { \
  |  |  |  |  291|    816|    if ((level) < (coap_get_log_level() + 1)) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (291:9): [True: 0, False: 816]
  |  |  |  |  ------------------
  |  |  |  |  292|    816|      coap_log_impl((level), __VA_ARGS__); \
  |  |  |  |  293|    816|  } while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (293:11): [Folded, False: 816]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  110|    816|    return 0;
  111|    816|  }
  112|       |
  113|  50.7M|#undef ADVANCE_OPT
  114|  50.7M|#undef ADVANCE_OPT_CHECK
  115|       |
  116|  50.7M|  return (opt + result->length) - opt_start;
  117|  50.7M|}
coap_option_iterator_init:
  121|  7.29k|                          const coap_opt_filter_t *filter) {
  122|  7.29k|  assert(pdu);
  ------------------
  |  Branch (122:3): [True: 7.29k, False: 0]
  ------------------
  123|  7.29k|  assert(pdu->token);
  ------------------
  |  Branch (123:3): [True: 7.29k, False: 0]
  ------------------
  124|  7.29k|  assert(oi);
  ------------------
  |  Branch (124:3): [True: 7.29k, False: 0]
  ------------------
  125|       |
  126|  7.29k|  memset(oi, 0, sizeof(coap_opt_iterator_t));
  127|       |
  128|  7.29k|  oi->next_option = pdu->token + pdu->e_token_length;
  129|  7.29k|  if (pdu->token + pdu->used_size <= oi->next_option) {
  ------------------
  |  Branch (129:7): [True: 215, False: 7.08k]
  ------------------
  130|    215|    oi->bad = 1;
  131|    215|    return NULL;
  132|    215|  }
  133|       |
  134|  7.08k|  oi->length = pdu->used_size - pdu->e_token_length;
  135|       |
  136|  7.08k|  if (filter) {
  ------------------
  |  Branch (136:7): [True: 7.08k, False: 0]
  ------------------
  137|  7.08k|    memcpy(&oi->filter, filter, sizeof(coap_opt_filter_t));
  138|  7.08k|    oi->filtered = 1;
  139|  7.08k|  }
  140|  7.08k|  return oi;
  141|  7.29k|}
coap_option_next:
  156|  13.2M|coap_option_next(coap_opt_iterator_t *oi) {
  157|  13.2M|  coap_option_t option;
  158|  13.2M|  coap_opt_t *current_opt = NULL;
  159|  13.2M|  size_t optsize;
  160|       |
  161|  13.2M|  assert(oi);
  ------------------
  |  Branch (161:3): [True: 13.2M, False: 0]
  ------------------
  162|       |
  163|  13.2M|  if (opt_finished(oi))
  ------------------
  |  Branch (163:7): [True: 1.65k, False: 13.2M]
  ------------------
  164|  1.65k|    return NULL;
  165|       |
  166|  38.5M|  while (1) {
  ------------------
  |  Branch (166:10): [True: 38.5M, 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|  38.5M|    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|  38.5M|    optsize = coap_opt_parse(oi->next_option, oi->length, &option);
  177|  38.5M|    if (optsize) {
  ------------------
  |  Branch (177:9): [True: 38.5M, False: 5.06k]
  ------------------
  178|  38.5M|      assert(optsize <= oi->length);
  ------------------
  |  Branch (178:7): [True: 38.5M, False: 0]
  ------------------
  179|       |
  180|  38.5M|      oi->next_option += optsize;
  181|  38.5M|      oi->length -= optsize;
  182|       |
  183|  38.5M|      oi->number += option.delta;
  184|  38.5M|    } else {                        /* current option is malformed */
  185|  5.06k|      oi->bad = 1;
  186|  5.06k|      return NULL;
  187|  5.06k|    }
  188|       |
  189|       |    /* Exit the while loop when:
  190|       |     *   - no filtering is done at all
  191|       |     *   - the filter matches for the current option
  192|       |     */
  193|  38.5M|    if (!oi->filtered ||
  ------------------
  |  Branch (193:9): [True: 0, False: 38.5M]
  ------------------
  194|  38.5M|        coap_option_filter_get(&oi->filter, oi->number) > 0)
  ------------------
  |  Branch (194:9): [True: 13.1M, False: 25.3M]
  ------------------
  195|  13.1M|      break;
  196|  38.5M|  }
  197|       |
  198|  13.1M|  return current_opt;
  199|  13.2M|}
coap_check_option:
  203|  3.25k|                  coap_opt_iterator_t *oi) {
  204|  3.25k|  coap_opt_filter_t f;
  205|       |
  206|  3.25k|  coap_option_filter_clear(&f);
  207|  3.25k|  coap_option_filter_set(&f, number);
  208|       |
  209|  3.25k|  coap_option_iterator_init(pdu, oi, &f);
  210|       |
  211|  3.25k|  return coap_option_next(oi);
  212|  3.25k|}
coap_opt_length:
  215|  25.4M|coap_opt_length(const coap_opt_t *opt) {
  216|  25.4M|  uint32_t length;
  217|       |
  218|  25.4M|  length = *opt & 0x0f;
  219|  25.4M|  switch (*opt & 0xf0) {
  220|      0|  case 0xf0:
  ------------------
  |  Branch (220:3): [True: 0, False: 25.4M]
  ------------------
  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|    547|  case 0xe0:
  ------------------
  |  Branch (223:3): [True: 547, False: 25.4M]
  ------------------
  224|    547|    ++opt;
  225|       |  /* fall through */
  226|       |  /* to skip another byte */
  227|  2.76k|  case 0xd0:
  ------------------
  |  Branch (227:3): [True: 2.21k, False: 25.4M]
  ------------------
  228|  2.76k|    ++opt;
  229|       |  /* fall through */
  230|       |  /* to skip another byte */
  231|  25.4M|  default:
  ------------------
  |  Branch (231:3): [True: 25.4M, False: 2.76k]
  ------------------
  232|  25.4M|    ++opt;
  233|  25.4M|  }
  234|       |
  235|  25.4M|  switch (length) {
  236|      0|  case 0x0f:
  ------------------
  |  Branch (236:3): [True: 0, False: 25.4M]
  ------------------
  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|  4.13k|  case 0x0e:
  ------------------
  |  Branch (239:3): [True: 4.13k, False: 25.4M]
  ------------------
  240|  4.13k|    length = (*opt++ << 8) + 269;
  241|       |  /* fall through */
  242|  14.7k|  case 0x0d:
  ------------------
  |  Branch (242:3): [True: 10.6k, False: 25.4M]
  ------------------
  243|  14.7k|    length += *opt++;
  244|  14.7k|    break;
  245|  25.4M|  default:
  ------------------
  |  Branch (245:3): [True: 25.4M, False: 14.7k]
  ------------------
  246|  25.4M|    ;
  247|  25.4M|  }
  248|  25.4M|  return length;
  249|  25.4M|}
coap_opt_value:
  252|  25.4M|coap_opt_value(const coap_opt_t *opt) {
  253|  25.4M|  size_t ofs = 1;
  254|       |
  255|  25.4M|  switch (*opt & 0xf0) {
  256|      0|  case 0xf0:
  ------------------
  |  Branch (256:3): [True: 0, False: 25.4M]
  ------------------
  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|    547|  case 0xe0:
  ------------------
  |  Branch (259:3): [True: 547, False: 25.4M]
  ------------------
  260|    547|    ++ofs;
  261|       |  /* fall through */
  262|  2.76k|  case 0xd0:
  ------------------
  |  Branch (262:3): [True: 2.21k, False: 25.4M]
  ------------------
  263|  2.76k|    ++ofs;
  264|  2.76k|    break;
  265|  25.4M|  default:
  ------------------
  |  Branch (265:3): [True: 25.4M, False: 2.76k]
  ------------------
  266|  25.4M|    ;
  267|  25.4M|  }
  268|       |
  269|  25.4M|  switch (*opt & 0x0f) {
  270|      0|  case 0x0f:
  ------------------
  |  Branch (270:3): [True: 0, False: 25.4M]
  ------------------
  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|  4.13k|  case 0x0e:
  ------------------
  |  Branch (273:3): [True: 4.13k, False: 25.4M]
  ------------------
  274|  4.13k|    ++ofs;
  275|       |  /* fall through */
  276|  14.7k|  case 0x0d:
  ------------------
  |  Branch (276:3): [True: 10.6k, False: 25.4M]
  ------------------
  277|  14.7k|    ++ofs;
  278|  14.7k|    break;
  279|  25.4M|  default:
  ------------------
  |  Branch (279:3): [True: 25.4M, False: 14.7k]
  ------------------
  280|  25.4M|    ;
  281|  25.4M|  }
  282|       |
  283|  25.4M|  return (const uint8_t *)opt + ofs;
  284|  25.4M|}
coap_option_filter_clear:
  494|  8.97k|coap_option_filter_clear(coap_opt_filter_t *filter) {
  495|  8.97k|  memset(filter, 0, sizeof(coap_opt_filter_t));
  496|  8.97k|}
coap_option_filter_set:
  499|  66.6k|coap_option_filter_set(coap_opt_filter_t *filter, coap_option_num_t option) {
  500|  66.6k|  return coap_option_filter_op(filter, option, FILTER_SET);
  501|  66.6k|}
coap_option_filter_get:
  509|  38.5M|coap_option_filter_get(coap_opt_filter_t *filter, coap_option_num_t option) {
  510|  38.5M|  return coap_option_filter_op(filter, option, FILTER_GET);
  511|  38.5M|}
coap_option.c:opt_finished:
  144|  13.2M|opt_finished(coap_opt_iterator_t *oi) {
  145|  13.2M|  assert(oi);
  ------------------
  |  Branch (145:3): [True: 13.2M, False: 0]
  ------------------
  146|       |
  147|  13.2M|  if (oi->bad || oi->length == 0 ||
  ------------------
  |  Branch (147:7): [True: 215, False: 13.2M]
  |  Branch (147:18): [True: 1.12k, False: 13.2M]
  ------------------
  148|  13.2M|      !oi->next_option || *oi->next_option == COAP_PAYLOAD_START) {
  ------------------
  |  |   96|  13.2M|#define COAP_PAYLOAD_START 0xFF /* payload marker */
  ------------------
  |  Branch (148:7): [True: 0, False: 13.2M]
  |  Branch (148:27): [True: 320, False: 13.2M]
  ------------------
  149|  1.65k|    oi->bad = 1;
  150|  1.65k|  }
  151|       |
  152|  13.2M|  return oi->bad;
  153|  13.2M|}
coap_option.c:coap_option_filter_op:
  436|  38.5M|                      enum filter_op_t op) {
  437|  38.5M|  size_t lindex = 0;
  438|  38.5M|  coap_opt_filter_t *of = filter;
  439|  38.5M|  uint16_t nr, mask = 0;
  440|       |
  441|  38.5M|  if (is_long_option(number)) {
  ------------------
  |  Branch (441:7): [True: 51.1k, False: 38.5M]
  ------------------
  442|  51.1k|    mask = LONG_MASK;
  ------------------
  |  |  401|  51.1k|#define LONG_MASK ((1 << COAP_OPT_FILTER_LONG) - 1)
  |  |  ------------------
  |  |  |  |  208|  51.1k|#define COAP_OPT_FILTER_LONG  2
  |  |  ------------------
  ------------------
  443|       |
  444|   152k|    for (nr = 1; lindex < COAP_OPT_FILTER_LONG; nr <<= 1, lindex++) {
  ------------------
  |  |  208|   152k|#define COAP_OPT_FILTER_LONG  2
  ------------------
  |  Branch (444:18): [True: 102k, False: 49.8k]
  ------------------
  445|       |
  446|   102k|      if (((of->mask & nr) > 0) && (of->long_opts[lindex] == number)) {
  ------------------
  |  Branch (446:11): [True: 7.93k, False: 94.4k]
  |  Branch (446:36): [True: 1.32k, False: 6.61k]
  ------------------
  447|  1.32k|        if (op == FILTER_CLEAR) {
  ------------------
  |  Branch (447:13): [True: 0, False: 1.32k]
  ------------------
  448|      0|          of->mask &= ~nr;
  449|      0|        }
  450|       |
  451|  1.32k|        return 1;
  452|  1.32k|      }
  453|   102k|    }
  454|  38.5M|  } else {
  455|  38.5M|    mask = SHORT_MASK;
  ------------------
  |  |  403|  38.5M|  (~LONG_MASK & ((1 << (COAP_OPT_FILTER_LONG + COAP_OPT_FILTER_SHORT)) - 1))
  |  |  ------------------
  |  |  |  |  401|  38.5M|#define LONG_MASK ((1 << COAP_OPT_FILTER_LONG) - 1)
  |  |  |  |  ------------------
  |  |  |  |  |  |  208|  38.5M|#define COAP_OPT_FILTER_LONG  2
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                 (~LONG_MASK & ((1 << (COAP_OPT_FILTER_LONG + COAP_OPT_FILTER_SHORT)) - 1))
  |  |  ------------------
  |  |  |  |  208|  38.5M|#define COAP_OPT_FILTER_LONG  2
  |  |  ------------------
  |  |                 (~LONG_MASK & ((1 << (COAP_OPT_FILTER_LONG + COAP_OPT_FILTER_SHORT)) - 1))
  |  |  ------------------
  |  |  |  |  200|  38.5M|#define COAP_OPT_FILTER_SHORT 6
  |  |  ------------------
  ------------------
  456|       |
  457|   256M|    for (nr = 1 << COAP_OPT_FILTER_LONG; lindex < COAP_OPT_FILTER_SHORT;
  ------------------
  |  |  208|  38.5M|#define COAP_OPT_FILTER_LONG  2
  ------------------
                  for (nr = 1 << COAP_OPT_FILTER_LONG; lindex < COAP_OPT_FILTER_SHORT;
  ------------------
  |  |  200|   256M|#define COAP_OPT_FILTER_SHORT 6
  ------------------
  |  Branch (457:42): [True: 231M, False: 25.2M]
  ------------------
  458|   231M|         nr <<= 1, lindex++) {
  459|       |
  460|   231M|      if (((of->mask & nr) > 0) && (of->short_opts[lindex] == (number & 0xff))) {
  ------------------
  |  Branch (460:11): [True: 38.5M, False: 192M]
  |  Branch (460:36): [True: 13.2M, False: 25.2M]
  ------------------
  461|  13.2M|        if (op == FILTER_CLEAR) {
  ------------------
  |  Branch (461:13): [True: 0, False: 13.2M]
  ------------------
  462|      0|          of->mask &= ~nr;
  463|      0|        }
  464|       |
  465|  13.2M|        return 1;
  466|  13.2M|      }
  467|   231M|    }
  468|  38.5M|  }
  469|       |
  470|       |  /* number was not found, so there is nothing to do if op is CLEAR or GET */
  471|  25.3M|  if ((op == FILTER_CLEAR) || (op == FILTER_GET)) {
  ------------------
  |  Branch (471:7): [True: 0, False: 25.3M]
  |  Branch (471:31): [True: 25.3M, False: 12.3k]
  ------------------
  472|  25.3M|    return 0;
  473|  25.3M|  }
  474|       |
  475|       |  /* handle FILTER_SET: */
  476|       |
  477|  12.3k|  lindex = coap_fls(~of->mask & mask);
  478|  12.3k|  if (!lindex) {
  ------------------
  |  Branch (478:7): [True: 4.36k, False: 7.99k]
  ------------------
  479|  4.36k|    return 0;
  480|  4.36k|  }
  481|       |
  482|  7.99k|  if (is_long_option(number)) {
  ------------------
  |  Branch (482:7): [True: 229, False: 7.76k]
  ------------------
  483|    229|    of->long_opts[lindex - 1] = number;
  484|  7.76k|  } else {
  485|  7.76k|    of->short_opts[lindex - COAP_OPT_FILTER_LONG - 1] = (uint8_t)number;
  ------------------
  |  |  208|  7.76k|#define COAP_OPT_FILTER_LONG  2
  ------------------
  486|  7.76k|  }
  487|       |
  488|  7.99k|  of->mask |= 1 << (lindex - 1);
  489|       |
  490|  7.99k|  return 1;
  491|  12.3k|}
coap_option.c:is_long_option:
  407|  38.5M|is_long_option(coap_option_num_t number) {
  408|  38.5M|  return number > 255;
  409|  38.5M|}

coap_pdu_clear:
   47|  3.09k|coap_pdu_clear(coap_pdu_t *pdu, size_t size) {
   48|  3.09k|  assert(pdu);
  ------------------
  |  Branch (48:3): [True: 3.09k, False: 0]
  ------------------
   49|  3.09k|  assert(pdu->token);
  ------------------
  |  Branch (49:3): [True: 3.09k, False: 0]
  ------------------
   50|  3.09k|  assert(pdu->max_hdr_size >= COAP_PDU_MAX_UDP_HEADER_SIZE);
  ------------------
  |  Branch (50:3): [True: 3.09k, False: 0]
  ------------------
   51|  3.09k|  if (pdu->alloc_size > size)
  ------------------
  |  Branch (51:7): [True: 0, False: 3.09k]
  ------------------
   52|      0|    pdu->alloc_size = size;
   53|  3.09k|  pdu->type = 0;
   54|  3.09k|  pdu->code = 0;
   55|  3.09k|  pdu->ref = 0;
   56|  3.09k|  pdu->hdr_size = 0;
   57|  3.09k|  pdu->actual_token.length = 0;
   58|  3.09k|  pdu->e_token_length = 0;
   59|  3.09k|  pdu->crit_opt = 0;
   60|  3.09k|  pdu->mid = 0;
   61|  3.09k|  pdu->max_opt = 0;
   62|  3.09k|  pdu->max_size = size;
   63|  3.09k|  pdu->used_size = 0;
   64|  3.09k|  pdu->data = NULL;
   65|  3.09k|  pdu->body_data = NULL;
   66|  3.09k|  pdu->body_length = 0;
   67|  3.09k|  pdu->body_offset = 0;
   68|  3.09k|  pdu->body_total = 0;
   69|  3.09k|  pdu->lg_xmit = NULL;
   70|  3.09k|  pdu->session = NULL;
   71|       |  pdu->data_free = NULL;
   72|  3.09k|}
coap_pdu_init:
  105|  3.09k|              size_t size) {
  106|  3.09k|  coap_pdu_t *pdu;
  107|       |
  108|  3.09k|#ifndef RIOT_VERSION
  109|  3.09k|  assert(type <= 0x3);
  ------------------
  |  Branch (109:3): [True: 3.09k, False: 0]
  ------------------
  110|  3.09k|  assert(code <= 0xff);
  ------------------
  |  Branch (110:3): [True: 3.09k, False: 0]
  ------------------
  111|  3.09k|  assert(mid >= 0 && mid <= 0xffff);
  ------------------
  |  Branch (111:3): [True: 3.09k, False: 0]
  |  Branch (111:3): [True: 3.09k, False: 0]
  ------------------
  112|  3.09k|#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.09k|  pdu = coap_malloc_type(COAP_PDU, sizeof(coap_pdu_t));
  125|  3.09k|  if (!pdu)
  ------------------
  |  Branch (125:7): [True: 0, False: 3.09k]
  ------------------
  126|      0|    return NULL;
  127|       |
  128|  3.09k|  pdu->max_hdr_size = COAP_PDU_MAX_HEADER_SIZE;
  ------------------
  |  |  115|  3.09k|#define COAP_PDU_MAX_HEADER_SIZE COAP_PDU_MAX_TCP_HEADER_SIZE
  |  |  ------------------
  |  |  |  |  108|  3.09k|#define COAP_PDU_MAX_TCP_HEADER_SIZE 6
  |  |  ------------------
  ------------------
  129|  3.09k|  if (size > ((size_t)COAP_DEFAULT_MAX_PDU_RX_SIZE - pdu->max_hdr_size)) {
  ------------------
  |  |   84|  3.09k|#define COAP_DEFAULT_MAX_PDU_RX_SIZE (8UL*1024*1024+256)
  ------------------
  |  Branch (129:7): [True: 0, False: 3.09k]
  ------------------
  130|      0|    coap_free_type(COAP_PDU, pdu);
  131|      0|    return NULL;
  132|      0|  }
  133|       |
  134|  3.09k|  pdu->alloc_size = min(size, COAP_DEFAULT_MTU);
  ------------------
  |  |   37|  3.09k|#define min(a,b) ((a) < (b) ? (a) : (b))
  |  |  ------------------
  |  |  |  Branch (37:19): [True: 2.52k, False: 564]
  |  |  ------------------
  ------------------
  135|       |#ifdef WITH_LWIP
  136|       |  pdu->pbuf = pbuf_alloc(PBUF_TRANSPORT, pdu->alloc_size + pdu->max_hdr_size,
  137|       |                         PBUF_RAM);
  138|       |  if (pdu->pbuf == NULL) {
  139|       |    coap_free_type(COAP_PDU, pdu);
  140|       |    return NULL;
  141|       |  }
  142|       |  pdu->token = (uint8_t *)pdu->pbuf->payload + pdu->max_hdr_size;
  143|       |#else /* ! WITH_LWIP */
  144|  3.09k|  uint8_t *buf;
  145|  3.09k|  buf = coap_malloc_type(COAP_PDU_BUF, pdu->alloc_size + pdu->max_hdr_size);
  146|  3.09k|  if (buf == NULL) {
  ------------------
  |  Branch (146:7): [True: 0, False: 3.09k]
  ------------------
  147|      0|    coap_free_type(COAP_PDU, pdu);
  148|      0|    return NULL;
  149|      0|  }
  150|  3.09k|  pdu->token = buf + pdu->max_hdr_size;
  151|  3.09k|#endif /* ! WITH_LWIP */
  152|  3.09k|  coap_pdu_clear(pdu, size);
  153|  3.09k|  pdu->mid = mid;
  154|  3.09k|  pdu->type = type;
  155|  3.09k|  pdu->code = code;
  156|  3.09k|  return pdu;
  157|  3.09k|}
coap_delete_pdu:
  185|  3.09k|coap_delete_pdu(coap_pdu_t *pdu) {
  186|  3.09k|  coap_lock_lock(return);
  187|  3.09k|  coap_delete_pdu_lkd(pdu);
  188|  3.09k|  coap_lock_unlock();
  189|  3.09k|}
coap_delete_pdu_lkd:
  192|  3.09k|coap_delete_pdu_lkd(coap_pdu_t *pdu) {
  193|  3.09k|  if (pdu != NULL) {
  ------------------
  |  Branch (193:7): [True: 3.09k, False: 0]
  ------------------
  194|  3.09k|    if (pdu->ref) {
  ------------------
  |  Branch (194:9): [True: 0, False: 3.09k]
  ------------------
  195|      0|      pdu->ref--;
  196|      0|      return;
  197|      0|    }
  198|       |#ifdef WITH_LWIP
  199|       |    pbuf_free(pdu->pbuf);
  200|       |#else
  201|  3.09k|    if (pdu->token != NULL)
  ------------------
  |  Branch (201:9): [True: 3.09k, False: 0]
  ------------------
  202|  3.09k|      coap_free_type(COAP_PDU_BUF, pdu->token - pdu->max_hdr_size);
  203|  3.09k|#endif
  204|  3.09k|    coap_delete_binary(pdu->data_free);
  205|  3.09k|    coap_free_type(COAP_PDU, pdu);
  206|  3.09k|  }
  207|  3.09k|}
coap_pdu_resize:
  335|  3.07k|coap_pdu_resize(coap_pdu_t *pdu, size_t new_size) {
  336|  3.07k|  if (new_size > pdu->alloc_size) {
  ------------------
  |  Branch (336:7): [True: 562, False: 2.51k]
  ------------------
  337|       |    /* Expanding the PDU usage */
  338|    562|#if !defined(WITH_LWIP)
  339|    562|    uint8_t *new_hdr;
  340|       |#else /* WITH_LWIP */
  341|       |    struct pbuf *new_hdr;
  342|       |#endif /* WITH_LWIP */
  343|    562|    size_t offset;
  344|       |
  345|    562|    if (pdu->max_size && new_size > pdu->max_size) {
  ------------------
  |  Branch (345:9): [True: 562, False: 0]
  |  Branch (345:26): [True: 0, False: 562]
  ------------------
  346|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  347|      0|      return 0;
  348|      0|    }
  349|    562|    if (pdu->data != NULL) {
  ------------------
  |  Branch (349:9): [True: 0, False: 562]
  ------------------
  350|      0|      assert(pdu->data > pdu->token);
  ------------------
  |  Branch (350:7): [True: 0, False: 0]
  ------------------
  351|      0|      offset = pdu->data - pdu->token;
  352|    562|    } else {
  353|    562|      offset = 0;
  354|    562|    }
  355|    562|#if !defined(WITH_LWIP)
  356|    562|    new_hdr = (uint8_t *)coap_realloc_type(COAP_PDU_BUF,
  357|    562|                                           pdu->token - pdu->max_hdr_size,
  358|    562|                                           new_size + pdu->max_hdr_size);
  359|       |#else /* WITH_LWIP */
  360|       |    new_hdr = pbuf_alloc(PBUF_TRANSPORT, new_size + pdu->max_hdr_size, PBUF_RAM);
  361|       |#endif /* WITH_LWIP */
  362|    562|    if (new_hdr == NULL) {
  ------------------
  |  Branch (362:9): [True: 0, False: 562]
  ------------------
  363|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  364|      0|      return 0;
  365|      0|    }
  366|    562|#if !defined(WITH_LWIP)
  367|    562|    pdu->token = new_hdr + pdu->max_hdr_size;
  368|       |#else /* WITH_LWIP */
  369|       |    memcpy(new_hdr->payload, pdu->pbuf->payload, pdu->pbuf->len);
  370|       |    pbuf_free(pdu->pbuf);
  371|       |    pdu->pbuf = new_hdr;
  372|       |    pdu->token = (uint8_t *)pdu->pbuf->payload + pdu->max_hdr_size;
  373|       |#endif /* WITH_LWIP */
  374|    562|    if (offset > 0)
  ------------------
  |  Branch (374:9): [True: 0, False: 562]
  ------------------
  375|      0|      pdu->data = pdu->token + offset;
  376|    562|    else
  377|    562|      pdu->data = NULL;
  378|    562|    if (pdu->actual_token.length < COAP_TOKEN_EXT_1B_BIAS)
  ------------------
  |  |   56|    562|#define COAP_TOKEN_EXT_1B_BIAS 13
  ------------------
  |  Branch (378:9): [True: 562, False: 0]
  ------------------
  379|    562|      pdu->actual_token.s = &pdu->token[0];
  380|      0|    else if (pdu->actual_token.length < COAP_TOKEN_EXT_2B_BIAS)
  ------------------
  |  |   57|      0|#define COAP_TOKEN_EXT_2B_BIAS 269 /* 13 + 256 */
  ------------------
  |  Branch (380:14): [True: 0, False: 0]
  ------------------
  381|      0|      pdu->actual_token.s = &pdu->token[1];
  382|      0|    else
  383|      0|      pdu->actual_token.s = &pdu->token[2];
  384|    562|    pdu->alloc_size = new_size;
  385|    562|  }
  386|  3.07k|  return 1;
  387|  3.07k|}
coap_pdu_parse_header_size:
 1077|  3.09k|                           const uint8_t *data) {
 1078|  3.09k|  assert(data);
  ------------------
  |  Branch (1078:3): [True: 3.09k, False: 0]
  ------------------
 1079|  3.09k|  size_t header_size = 0;
 1080|       |
 1081|  3.09k|  if (proto == COAP_PROTO_TCP || proto==COAP_PROTO_TLS) {
  ------------------
  |  Branch (1081:7): [True: 3.09k, False: 0]
  |  Branch (1081:34): [True: 0, False: 0]
  ------------------
 1082|  3.09k|    uint8_t len = *data >> 4;
 1083|  3.09k|    if (len < 13)
  ------------------
  |  Branch (1083:9): [True: 3.03k, False: 56]
  ------------------
 1084|  3.03k|      header_size = 2;
 1085|     56|    else if (len==13)
  ------------------
  |  Branch (1085:14): [True: 27, False: 29]
  ------------------
 1086|     27|      header_size = 3;
 1087|     29|    else if (len==14)
  ------------------
  |  Branch (1087:14): [True: 19, False: 10]
  ------------------
 1088|     19|      header_size = 4;
 1089|     10|    else
 1090|     10|      header_size = 6;
 1091|  3.09k|  } else if (proto == COAP_PROTO_WS || proto==COAP_PROTO_WSS) {
  ------------------
  |  Branch (1091:14): [True: 0, False: 0]
  |  Branch (1091:40): [True: 0, False: 0]
  ------------------
 1092|      0|    header_size = COAP_PDU_WS_HEADER_SIZE;
  ------------------
  |  |  109|      0|#define COAP_PDU_WS_HEADER_SIZE 2
  ------------------
 1093|      0|  } else if (proto == COAP_PROTO_UDP || proto==COAP_PROTO_DTLS) {
  ------------------
  |  Branch (1093:14): [True: 0, False: 0]
  |  Branch (1093:41): [True: 0, False: 0]
  ------------------
 1094|      0|    header_size = 4;
 1095|      0|  }
 1096|       |
 1097|  3.09k|  return header_size;
 1098|  3.09k|}
coap_pdu_parse_header:
 1173|  3.07k|coap_pdu_parse_header(coap_pdu_t *pdu, coap_proto_t proto) {
 1174|  3.07k|  uint8_t *hdr = pdu->token - pdu->hdr_size;
 1175|  3.07k|  uint8_t e_token_length;
 1176|       |
 1177|  3.07k|  if (proto == COAP_PROTO_UDP || proto == COAP_PROTO_DTLS) {
  ------------------
  |  Branch (1177:7): [True: 0, False: 3.07k]
  |  Branch (1177:34): [True: 0, False: 3.07k]
  ------------------
 1178|      0|    assert(pdu->hdr_size == 4);
  ------------------
  |  Branch (1178:5): [True: 0, False: 0]
  ------------------
 1179|      0|    if ((hdr[0] >> 6) != COAP_DEFAULT_VERSION) {
  ------------------
  |  |   35|      0|#define COAP_DEFAULT_VERSION      1 /* version of CoAP supported */
  ------------------
  |  Branch (1179:9): [True: 0, False: 0]
  ------------------
 1180|      0|      coap_log_debug("coap_pdu_parse: UDP version not supported\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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1181|      0|      return 0;
 1182|      0|    }
 1183|      0|    pdu->type = (hdr[0] >> 4) & 0x03;
 1184|      0|    pdu->code = hdr[1];
 1185|      0|    pdu->mid = (uint16_t)hdr[2] << 8 | hdr[3];
 1186|  3.07k|  } else if (proto == COAP_PROTO_TCP || proto == COAP_PROTO_TLS) {
  ------------------
  |  Branch (1186:14): [True: 3.07k, False: 0]
  |  Branch (1186:41): [True: 0, False: 0]
  ------------------
 1187|  3.07k|    assert(pdu->hdr_size >= 2 && pdu->hdr_size <= 6);
  ------------------
  |  Branch (1187:5): [True: 3.07k, False: 0]
  |  Branch (1187:5): [True: 3.07k, False: 0]
  ------------------
 1188|  3.07k|    pdu->type = COAP_MESSAGE_CON;
 1189|  3.07k|    pdu->code = hdr[pdu->hdr_size-1];
 1190|  3.07k|    pdu->mid = 0;
 1191|  3.07k|  } else if (proto == COAP_PROTO_WS || proto == COAP_PROTO_WSS) {
  ------------------
  |  Branch (1191:14): [True: 0, False: 0]
  |  Branch (1191:40): [True: 0, False: 0]
  ------------------
 1192|      0|    assert(pdu->hdr_size == 2);
  ------------------
  |  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 {
 1197|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1198|      0|    return 0;
 1199|      0|  }
 1200|       |
 1201|  3.07k|  e_token_length = hdr[0] & 0x0f;
 1202|  3.07k|  if (e_token_length < COAP_TOKEN_EXT_1B_TKL) {
  ------------------
  |  |   54|  3.07k|#define COAP_TOKEN_EXT_1B_TKL 13
  ------------------
  |  Branch (1202:7): [True: 2.95k, False: 123]
  ------------------
 1203|  2.95k|    pdu->e_token_length = e_token_length;
 1204|  2.95k|    pdu->actual_token.length = pdu->e_token_length;
 1205|  2.95k|    pdu->actual_token.s = &pdu->token[0];
 1206|  2.95k|  } else if (e_token_length == COAP_TOKEN_EXT_1B_TKL) {
  ------------------
  |  |   54|    123|#define COAP_TOKEN_EXT_1B_TKL 13
  ------------------
  |  Branch (1206:14): [True: 62, False: 61]
  ------------------
 1207|     62|    if (pdu->used_size < 1)
  ------------------
  |  Branch (1207:9): [True: 2, False: 60]
  ------------------
 1208|      2|      goto bad_ext_token;
 1209|     60|    pdu->e_token_length = pdu->token[0] + COAP_TOKEN_EXT_1B_BIAS + 1;
  ------------------
  |  |   56|     60|#define COAP_TOKEN_EXT_1B_BIAS 13
  ------------------
 1210|     60|    pdu->actual_token.length = pdu->e_token_length - 1;
 1211|     60|    pdu->actual_token.s = &pdu->token[1];
 1212|     61|  } else if (e_token_length == COAP_TOKEN_EXT_2B_TKL) {
  ------------------
  |  |   55|     61|#define COAP_TOKEN_EXT_2B_TKL 14
  ------------------
  |  Branch (1212:14): [True: 59, False: 2]
  ------------------
 1213|     59|    if (pdu->used_size < 2)
  ------------------
  |  Branch (1213:9): [True: 2, False: 57]
  ------------------
 1214|      2|      goto bad_ext_token;
 1215|     57|    pdu->e_token_length = ((uint16_t)pdu->token[0] << 8) + pdu->token[1] +
 1216|     57|                          COAP_TOKEN_EXT_2B_BIAS + 2;
  ------------------
  |  |   57|     57|#define COAP_TOKEN_EXT_2B_BIAS 269 /* 13 + 256 */
  ------------------
 1217|     57|    pdu->actual_token.length = pdu->e_token_length - 2;
 1218|     57|    pdu->actual_token.s = &pdu->token[2];
 1219|     57|  }
 1220|  3.07k|  if (pdu->e_token_length > pdu->alloc_size || e_token_length == 15) {
  ------------------
  |  Branch (1220:7): [True: 22, False: 3.05k]
  |  Branch (1220:48): [True: 2, False: 3.04k]
  ------------------
 1221|     24|    goto bad_ext_token;
 1222|     24|  }
 1223|  3.04k|  return 1;
 1224|       |
 1225|     28|bad_ext_token:
 1226|       |  /* Invalid PDU provided - not wise to assert here though */
 1227|     28|  coap_log_warn("coap_pdu_parse: PDU header extended token size broken\n");
  ------------------
  |  |  108|     28|#define coap_log_warn(...) coap_log(COAP_LOG_WARN, __VA_ARGS__)
  |  |  ------------------
  |  |  |  |  290|     28|#define coap_log(level, ...) do { \
  |  |  |  |  291|     28|    if ((level) < (coap_get_log_level() + 1)) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (291:9): [True: 0, False: 28]
  |  |  |  |  ------------------
  |  |  |  |  292|     28|      coap_log_impl((level), __VA_ARGS__); \
  |  |  |  |  293|     28|  } while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (293:11): [Folded, False: 28]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1228|     28|  pdu->e_token_length = 0;
 1229|     28|  pdu->actual_token.length = 0;
 1230|     28|  return 0;
 1231|  3.07k|}
coap_pdu_parse_opt_base:
 1302|  8.95M|coap_pdu_parse_opt_base(coap_option_num_t number, size_t len, const uint8_t *opt_val) {
 1303|  8.95M|  int res = 1;
 1304|       |
 1305|  8.95M|  switch ((coap_code_opt_num_t)number) {
 1306|  1.57k|  case COAP_OPTION_IF_MATCH:
  ------------------
  |  Branch (1306:3): [True: 1.57k, False: 8.94M]
  ------------------
 1307|  1.57k|    if (len > 8)
  ------------------
  |  Branch (1307:9): [True: 1.01k, False: 562]
  ------------------
 1308|  1.01k|      res = 0;
 1309|  1.57k|    break;
 1310|  8.29k|  case COAP_OPTION_URI_HOST:
  ------------------
  |  Branch (1310:3): [True: 8.29k, False: 8.94M]
  ------------------
 1311|  8.29k|    if (len < 1 || len > 255)
  ------------------
  |  Branch (1311:9): [True: 6.66k, False: 1.63k]
  |  Branch (1311:20): [True: 1.03k, False: 602]
  ------------------
 1312|  7.69k|      res = 0;
 1313|  8.29k|    break;
 1314|  4.86k|  case COAP_OPTION_ETAG:
  ------------------
  |  Branch (1314:3): [True: 4.86k, False: 8.94M]
  ------------------
 1315|  4.86k|    if (len < 1 || len > 8)
  ------------------
  |  Branch (1315:9): [True: 3.20k, False: 1.65k]
  |  Branch (1315:20): [True: 1.05k, False: 598]
  ------------------
 1316|  4.26k|      res = 0;
 1317|  4.86k|    break;
 1318|  37.0k|  case COAP_OPTION_IF_NONE_MATCH:
  ------------------
  |  Branch (1318:3): [True: 37.0k, False: 8.91M]
  ------------------
 1319|  37.0k|    if (len != 0)
  ------------------
  |  Branch (1319:9): [True: 1.08k, False: 36.0k]
  ------------------
 1320|  1.08k|      res = 0;
 1321|  37.0k|    break;
 1322|  12.3k|  case COAP_OPTION_OBSERVE:
  ------------------
  |  Branch (1322:3): [True: 12.3k, False: 8.93M]
  ------------------
 1323|  12.3k|    if (len > 3)
  ------------------
  |  Branch (1323:9): [True: 1.41k, False: 10.9k]
  ------------------
 1324|  1.41k|      res = 0;
 1325|  12.3k|    break;
 1326|  9.26k|  case COAP_OPTION_URI_PORT:
  ------------------
  |  Branch (1326:3): [True: 9.26k, False: 8.94M]
  ------------------
 1327|  9.26k|    if (len > 2)
  ------------------
  |  Branch (1327:9): [True: 1.14k, False: 8.11k]
  ------------------
 1328|  1.14k|      res = 0;
 1329|  9.26k|    break;
 1330|  3.46k|  case COAP_OPTION_LOCATION_PATH:
  ------------------
  |  Branch (1330:3): [True: 3.46k, False: 8.94M]
  ------------------
 1331|  6.49M|  case COAP_OPTION_URI_PATH:
  ------------------
  |  Branch (1331:3): [True: 6.48M, False: 2.46M]
  ------------------
 1332|  6.49M|    if (len > 255)
  ------------------
  |  Branch (1332:9): [True: 1.06k, False: 6.49M]
  ------------------
 1333|  1.06k|      res = 0;
 1334|  6.49M|    if (coap_check_dots(opt_val, len)) {
  ------------------
  |  Branch (1334:9): [True: 2.98k, False: 6.49M]
  ------------------
 1335|  2.98k|      res = 0;
 1336|  2.98k|    }
 1337|  6.49M|    break;
 1338|  2.71k|  case COAP_OPTION_OSCORE:
  ------------------
  |  Branch (1338:3): [True: 2.71k, False: 8.94M]
  ------------------
 1339|  2.71k|    if (len > 255)
  ------------------
  |  Branch (1339:9): [True: 990, False: 1.72k]
  ------------------
 1340|    990|      res = 0;
 1341|  2.71k|    break;
 1342|  9.01k|  case COAP_OPTION_CONTENT_FORMAT:
  ------------------
  |  Branch (1342:3): [True: 9.01k, False: 8.94M]
  ------------------
 1343|  9.01k|    if (len > 2)
  ------------------
  |  Branch (1343:9): [True: 1.12k, False: 7.89k]
  ------------------
 1344|  1.12k|      res = 0;
 1345|  9.01k|    break;
 1346|  1.99k|  case COAP_OPTION_URI_PATH_ABB:
  ------------------
  |  Branch (1346:3): [True: 1.99k, False: 8.94M]
  ------------------
 1347|  1.99k|    if (len > 4)
  ------------------
  |  Branch (1347:9): [True: 1.11k, False: 876]
  ------------------
 1348|  1.11k|      res = 0;
 1349|  1.99k|    break;
 1350|  1.78k|  case COAP_OPTION_MAXAGE:
  ------------------
  |  Branch (1350:3): [True: 1.78k, False: 8.94M]
  ------------------
 1351|  1.78k|    if (len > 4)
  ------------------
  |  Branch (1351:9): [True: 1.12k, False: 666]
  ------------------
 1352|  1.12k|      res = 0;
 1353|  1.78k|    break;
 1354|   227k|  case COAP_OPTION_URI_QUERY:
  ------------------
  |  Branch (1354:3): [True: 227k, False: 8.72M]
  ------------------
 1355|   227k|    if (len > 255)
  ------------------
  |  Branch (1355:9): [True: 984, False: 226k]
  ------------------
 1356|    984|      res = 0;
 1357|   227k|    break;
 1358|  25.1k|  case COAP_OPTION_HOP_LIMIT:
  ------------------
  |  Branch (1358:3): [True: 25.1k, False: 8.92M]
  ------------------
 1359|  25.1k|    if (len != 1)
  ------------------
  |  Branch (1359:9): [True: 24.8k, False: 254]
  ------------------
 1360|  24.8k|      res = 0;
 1361|  25.1k|    break;
 1362|  10.6k|  case COAP_OPTION_ACCEPT:
  ------------------
  |  Branch (1362:3): [True: 10.6k, False: 8.94M]
  ------------------
 1363|  10.6k|    if (len > 2)
  ------------------
  |  Branch (1363:9): [True: 1.76k, False: 8.84k]
  ------------------
 1364|  1.76k|      res = 0;
 1365|  10.6k|    break;
 1366|  4.09k|  case COAP_OPTION_Q_BLOCK1:
  ------------------
  |  Branch (1366:3): [True: 4.09k, False: 8.94M]
  ------------------
 1367|  4.09k|    if (len > 3)
  ------------------
  |  Branch (1367:9): [True: 1.55k, False: 2.54k]
  ------------------
 1368|  1.55k|      res = 0;
 1369|  4.09k|    break;
 1370|  2.77k|  case COAP_OPTION_LOCATION_QUERY:
  ------------------
  |  Branch (1370:3): [True: 2.77k, False: 8.94M]
  ------------------
 1371|  2.77k|    if (len > 255)
  ------------------
  |  Branch (1371:9): [True: 984, False: 1.79k]
  ------------------
 1372|    984|      res = 0;
 1373|  2.77k|    break;
 1374|  2.34k|  case COAP_OPTION_EDHOC:
  ------------------
  |  Branch (1374:3): [True: 2.34k, False: 8.94M]
  ------------------
 1375|  2.34k|    if (len != 0)
  ------------------
  |  Branch (1375:9): [True: 1.62k, False: 723]
  ------------------
 1376|  1.62k|      res = 0;
 1377|  2.34k|    break;
 1378|  6.40k|  case COAP_OPTION_BLOCK2:
  ------------------
  |  Branch (1378:3): [True: 6.40k, False: 8.94M]
  ------------------
 1379|  6.40k|    if (len > 3)
  ------------------
  |  Branch (1379:9): [True: 1.86k, False: 4.54k]
  ------------------
 1380|  1.86k|      res = 0;
 1381|  6.40k|    break;
 1382|  2.82k|  case COAP_OPTION_BLOCK1:
  ------------------
  |  Branch (1382:3): [True: 2.82k, False: 8.94M]
  ------------------
 1383|  2.82k|    if (len > 3)
  ------------------
  |  Branch (1383:9): [True: 1.11k, False: 1.71k]
  ------------------
 1384|  1.11k|      res = 0;
 1385|  2.82k|    break;
 1386|  2.48k|  case COAP_OPTION_SIZE2:
  ------------------
  |  Branch (1386:3): [True: 2.48k, False: 8.94M]
  ------------------
 1387|  2.48k|    if (len > 4)
  ------------------
  |  Branch (1387:9): [True: 1.46k, False: 1.02k]
  ------------------
 1388|  1.46k|      res = 0;
 1389|  2.48k|    break;
 1390|  1.46k|  case COAP_OPTION_Q_BLOCK2:
  ------------------
  |  Branch (1390:3): [True: 1.46k, False: 8.94M]
  ------------------
 1391|  1.46k|    if (len > 3)
  ------------------
  |  Branch (1391:9): [True: 1.05k, False: 407]
  ------------------
 1392|  1.05k|      res = 0;
 1393|  1.46k|    break;
 1394|  4.41k|  case COAP_OPTION_PROXY_URI:
  ------------------
  |  Branch (1394:3): [True: 4.41k, False: 8.94M]
  ------------------
 1395|  4.41k|    if (len < 1 || len > 1034)
  ------------------
  |  Branch (1395:9): [True: 2.46k, False: 1.95k]
  |  Branch (1395:20): [True: 999, False: 955]
  ------------------
 1396|  3.45k|      res = 0;
 1397|  4.41k|    break;
 1398|  12.3k|  case COAP_OPTION_PROXY_SCHEME:
  ------------------
  |  Branch (1398:3): [True: 12.3k, False: 8.93M]
  ------------------
 1399|  12.3k|    if (len < 1 || len > 255)
  ------------------
  |  Branch (1399:9): [True: 8.31k, False: 4.05k]
  |  Branch (1399:20): [True: 1.14k, False: 2.91k]
  ------------------
 1400|  9.46k|      res = 0;
 1401|  12.3k|    break;
 1402|  1.37k|  case COAP_OPTION_SIZE1:
  ------------------
  |  Branch (1402:3): [True: 1.37k, False: 8.94M]
  ------------------
 1403|  1.37k|    if (len > 4)
  ------------------
  |  Branch (1403:9): [True: 1.04k, False: 336]
  ------------------
 1404|  1.04k|      res = 0;
 1405|  1.37k|    break;
 1406|  5.92k|  case COAP_OPTION_ECHO:
  ------------------
  |  Branch (1406:3): [True: 5.92k, False: 8.94M]
  ------------------
 1407|  5.92k|    if (len > 40)
  ------------------
  |  Branch (1407:9): [True: 1.05k, False: 4.87k]
  ------------------
 1408|  1.05k|      res = 0;
 1409|  5.92k|    break;
 1410|  1.58k|  case COAP_OPTION_NORESPONSE:
  ------------------
  |  Branch (1410:3): [True: 1.58k, False: 8.94M]
  ------------------
 1411|  1.58k|    if (len > 1)
  ------------------
  |  Branch (1411:9): [True: 1.05k, False: 530]
  ------------------
 1412|  1.05k|      res = 0;
 1413|  1.58k|    break;
 1414|  79.1k|  case COAP_OPTION_RTAG:
  ------------------
  |  Branch (1414:3): [True: 79.1k, False: 8.87M]
  ------------------
 1415|  79.1k|    if (len > 8)
  ------------------
  |  Branch (1415:9): [True: 1.00k, False: 78.1k]
  ------------------
 1416|  1.00k|      res = 0;
 1417|  79.1k|    break;
 1418|  1.97M|  default:
  ------------------
  |  Branch (1418:3): [True: 1.97M, False: 6.97M]
  ------------------
 1419|  1.97M|    ;
 1420|  8.95M|  }
 1421|  8.95M|  return res;
 1422|  8.95M|}
coap_pdu_parse_opt:
 1458|  3.04k|coap_pdu_parse_opt(coap_pdu_t *pdu, coap_opt_filter_t *error_opts) {
 1459|  3.04k|  int good = 1;
 1460|       |
 1461|  3.04k|  coap_option_filter_clear(error_opts);
 1462|       |
 1463|       |  /* sanity checks */
 1464|  3.04k|  if (pdu->code == 0) {
  ------------------
  |  Branch (1464:7): [True: 31, False: 3.01k]
  ------------------
 1465|     31|    if (pdu->used_size != 0 || pdu->e_token_length) {
  ------------------
  |  Branch (1465:9): [True: 27, False: 4]
  |  Branch (1465:32): [True: 3, False: 1]
  ------------------
 1466|     30|      coap_log_debug("coap_pdu_parse: empty message is not empty\n");
  ------------------
  |  |  126|     30|#define coap_log_debug(...) coap_log(COAP_LOG_DEBUG, __VA_ARGS__)
  |  |  ------------------
  |  |  |  |  290|     30|#define coap_log(level, ...) do { \
  |  |  |  |  291|     30|    if ((level) < (coap_get_log_level() + 1)) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (291:9): [True: 0, False: 30]
  |  |  |  |  ------------------
  |  |  |  |  292|     30|      coap_log_impl((level), __VA_ARGS__); \
  |  |  |  |  293|     30|  } while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (293:11): [Folded, False: 30]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1467|     30|      return 0;
 1468|     30|    }
 1469|     31|  }
 1470|       |
 1471|  3.01k|  if (pdu->e_token_length > pdu->used_size) {
  ------------------
  |  Branch (1471:7): [True: 5, False: 3.01k]
  ------------------
 1472|      5|    coap_log_debug("coap_pdu_parse: invalid Token\n");
  ------------------
  |  |  126|      5|#define coap_log_debug(...) coap_log(COAP_LOG_DEBUG, __VA_ARGS__)
  |  |  ------------------
  |  |  |  |  290|      5|#define coap_log(level, ...) do { \
  |  |  |  |  291|      5|    if ((level) < (coap_get_log_level() + 1)) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (291:9): [True: 0, False: 5]
  |  |  |  |  ------------------
  |  |  |  |  292|      5|      coap_log_impl((level), __VA_ARGS__); \
  |  |  |  |  293|      5|  } while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (293:11): [Folded, False: 5]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1473|      5|    return 0;
 1474|      5|  }
 1475|       |
 1476|  3.01k|  pdu->max_opt = 0;
 1477|  3.01k|  if (pdu->code == 0) {
  ------------------
  |  Branch (1477:7): [True: 1, False: 3.01k]
  ------------------
 1478|       |    /* empty packet */
 1479|      1|    pdu->used_size = 0;
 1480|      1|    pdu->data = NULL;
 1481|  3.01k|  } else {
 1482|       |    /* skip header + token */
 1483|  3.01k|    coap_opt_t *opt = pdu->token + pdu->e_token_length;
 1484|  3.01k|    size_t length = pdu->used_size - pdu->e_token_length;
 1485|       |
 1486|  9.19M|    while (length > 0 && *opt != COAP_PAYLOAD_START) {
  ------------------
  |  |   96|  9.19M|#define COAP_PAYLOAD_START 0xFF /* payload marker */
  ------------------
  |  Branch (1486:12): [True: 9.19M, False: 2.34k]
  |  Branch (1486:26): [True: 9.19M, False: 237]
  ------------------
 1487|  9.19M|#if (COAP_MAX_LOGGING_LEVEL >= _COAP_LOG_WARN)
 1488|  9.19M|      coap_opt_t *opt_last = opt;
 1489|  9.19M|#endif
 1490|  9.19M|      size_t optsize = next_option_safe(&opt, &length, &pdu->max_opt);
 1491|  9.19M|      uint32_t len;
 1492|  9.19M|      const uint8_t *opt_val;
 1493|       |
 1494|  9.19M|      if (optsize == 0) {
  ------------------
  |  Branch (1494:11): [True: 434, False: 9.19M]
  ------------------
 1495|    434|        coap_log_debug("coap_pdu_parse: %d.%02d: offset %u malformed option\n",
  ------------------
  |  |  126|    434|#define coap_log_debug(...) coap_log(COAP_LOG_DEBUG, __VA_ARGS__)
  |  |  ------------------
  |  |  |  |  290|    434|#define coap_log(level, ...) do { \
  |  |  |  |  291|    434|    if ((level) < (coap_get_log_level() + 1)) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (291:9): [True: 0, False: 434]
  |  |  |  |  ------------------
  |  |  |  |  292|    434|      coap_log_impl((level), __VA_ARGS__); \
  |  |  |  |  293|    434|  } while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (293:11): [Folded, False: 434]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1496|    434|                       pdu->code >> 5, pdu->code & 0x1F,
 1497|    434|                       (int)(opt_last - pdu->token - pdu->e_token_length));
 1498|    434|        coap_option_filter_set(error_opts, pdu->max_opt);
 1499|    434|        good = 0;
 1500|    434|        break;
 1501|    434|      }
 1502|  9.19M|      len = coap_opt_length((const uint8_t *)opt - optsize);
 1503|  9.19M|      opt_val = coap_opt_value((const uint8_t *)opt - optsize);
 1504|  9.19M|      if (COAP_PDU_IS_SIGNALING(pdu) ?
  ------------------
  |  |  102|  9.19M|#define COAP_PDU_IS_SIGNALING(pdu) ((pdu)->code >= 224)
  |  |  ------------------
  |  |  |  Branch (102:36): [True: 1.09M, False: 8.10M]
  |  |  ------------------
  ------------------
  |  Branch (1504:11): [True: 60.2k, False: 9.13M]
  ------------------
 1505|  1.09M|          !coap_pdu_parse_opt_csm(pdu->code, pdu->max_opt, len) :
 1506|  9.19M|          !coap_pdu_parse_opt_base(pdu->max_opt, len, opt_val)) {
 1507|  60.2k|        coap_log_warn("coap_pdu_parse: %d.%02d: offset %u option %u has bad length %" PRIu32 " or value\n",
  ------------------
  |  |  108|  60.2k|#define coap_log_warn(...) coap_log(COAP_LOG_WARN, __VA_ARGS__)
  |  |  ------------------
  |  |  |  |  290|  60.2k|#define coap_log(level, ...) do { \
  |  |  |  |  291|  60.2k|    if ((level) < (coap_get_log_level() + 1)) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (291:9): [True: 0, False: 60.2k]
  |  |  |  |  ------------------
  |  |  |  |  292|  60.2k|      coap_log_impl((level), __VA_ARGS__); \
  |  |  |  |  293|  60.2k|  } while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (293:11): [Folded, False: 60.2k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1508|  60.2k|                      pdu->code >> 5, pdu->code & 0x1F,
 1509|  60.2k|                      (int)(opt_last - pdu->token - pdu->e_token_length), pdu->max_opt,
 1510|  60.2k|                      len);
 1511|  60.2k|        coap_option_filter_set(error_opts, pdu->max_opt);
 1512|  60.2k|        good = 0;
 1513|  60.2k|      }
 1514|  9.19M|    }
 1515|       |
 1516|  3.01k|    if (!good) {
  ------------------
  |  Branch (1516:9): [True: 1.38k, False: 1.62k]
  ------------------
 1517|       |      /*
 1518|       |       * Dump the options in the PDU for analysis, space separated except
 1519|       |       * error options which are prefixed by *
 1520|       |       * Two rows - hex and ascii (if printable)
 1521|       |       */
 1522|  1.38k|      static char outbuf[COAP_DEBUG_BUF_SIZE];
 1523|  1.38k|      char *obp;
 1524|  1.38k|      size_t tlen;
 1525|  1.38k|      size_t outbuflen;
 1526|  1.38k|      int i;
 1527|  1.38k|      int ok;
 1528|       |
 1529|  4.15k|      for (i = 0; i < 2; i++) {
  ------------------
  |  Branch (1529:19): [True: 2.77k, False: 1.38k]
  ------------------
 1530|  2.77k|        opt = pdu->token + pdu->e_token_length;
 1531|  2.77k|        length = pdu->used_size - pdu->e_token_length;
 1532|  2.77k|        pdu->max_opt = 0;
 1533|       |
 1534|  2.77k|        outbuflen = sizeof(outbuf);
 1535|  2.77k|        obp = outbuf;
 1536|  2.77k|        ok = write_prefix(&obp, &outbuflen, "O: ", 3);
 1537|       |        /*
 1538|       |         * Not safe to check for 'ok' here as a lot of variables may get
 1539|       |         * partially changed due to lack of outbuflen */
 1540|  3.03M|        while (length > 0 && *opt != COAP_PAYLOAD_START) {
  ------------------
  |  |   96|  3.03M|#define COAP_PAYLOAD_START 0xFF /* payload marker */
  ------------------
  |  Branch (1540:16): [True: 3.03M, False: 2.65k]
  |  Branch (1540:30): [True: 3.03M, False: 118]
  ------------------
 1541|  3.03M|          coap_opt_t *opt_last = opt;
 1542|  3.03M|          size_t optsize = next_option_safe(&opt, &length, &pdu->max_opt);
 1543|  3.03M|          const uint32_t len =
 1544|  3.03M|              optsize ? coap_opt_length((const uint8_t *)opt - optsize) : 0;
  ------------------
  |  Branch (1544:15): [True: 3.03M, False: 868]
  ------------------
 1545|  3.03M|          const uint8_t *opt_val =
 1546|  3.03M|              optsize ?  coap_opt_value((const uint8_t *)opt - optsize) : 0;
  ------------------
  |  Branch (1546:15): [True: 3.03M, False: 868]
  ------------------
 1547|       |
 1548|  3.03M|          if (!optsize || (COAP_PDU_IS_SIGNALING(pdu) ?
  ------------------
  |  |  102|  3.03M|#define COAP_PDU_IS_SIGNALING(pdu) ((pdu)->code >= 224)
  |  |  ------------------
  |  |  |  Branch (102:36): [True: 2.18M, False: 848k]
  |  |  ------------------
  ------------------
  |  Branch (1548:15): [True: 868, False: 3.03M]
  |  Branch (1548:27): [True: 120k, False: 2.91M]
  ------------------
 1549|  2.18M|                           !coap_pdu_parse_opt_csm(pdu->code, pdu->max_opt, len) :
 1550|  3.03M|                           !coap_pdu_parse_opt_base(pdu->max_opt, len, opt_val))) {
 1551|   121k|            ok = ok && write_prefix(&obp, &outbuflen, "*", 1);
  ------------------
  |  Branch (1551:18): [True: 58.8k, False: 62.5k]
  |  Branch (1551:24): [True: 58.8k, False: 20]
  ------------------
 1552|   121k|            if (!optsize) {
  ------------------
  |  Branch (1552:17): [True: 868, False: 120k]
  ------------------
 1553|       |              /* Skip to end of options to output all data */
 1554|    868|              opt = pdu->token + pdu->used_size;
 1555|    868|              length = 0;
 1556|    868|            }
 1557|  2.91M|          } else {
 1558|  2.91M|            ok = ok && write_prefix(&obp, &outbuflen, " ", 1);
  ------------------
  |  Branch (1558:18): [True: 42.5k, False: 2.86M]
  |  Branch (1558:24): [True: 42.5k, False: 18]
  ------------------
 1559|  2.91M|          }
 1560|  3.03M|          tlen = opt - opt_last;
 1561|  72.8M|          while (tlen) {
  ------------------
  |  Branch (1561:18): [True: 69.8M, False: 3.03M]
  ------------------
 1562|  69.8M|            tlen--;
 1563|  69.8M|            ok = ok && write_char(&obp, &outbuflen, *opt_last, i);
  ------------------
  |  Branch (1563:18): [True: 1.05M, False: 68.7M]
  |  Branch (1563:24): [True: 1.05M, False: 812]
  ------------------
 1564|  69.8M|            opt_last++;
 1565|  69.8M|          }
 1566|  3.03M|        }
 1567|  2.77k|        if (length && *opt == COAP_PAYLOAD_START) {
  ------------------
  |  |   96|    118|#define COAP_PAYLOAD_START 0xFF /* payload marker */
  ------------------
  |  Branch (1567:13): [True: 118, False: 2.65k]
  |  Branch (1567:23): [True: 118, False: 0]
  ------------------
 1568|    118|          write_char(&obp, &outbuflen, *opt, i);
 1569|    118|        }
 1570|       |        /* write_*() always leaves a spare byte to null terminate */
 1571|  2.77k|        *obp = '\000';
 1572|  2.77k|        coap_log_debug("%s\n", outbuf);
  ------------------
  |  |  126|  2.77k|#define coap_log_debug(...) coap_log(COAP_LOG_DEBUG, __VA_ARGS__)
  |  |  ------------------
  |  |  |  |  290|  2.77k|#define coap_log(level, ...) do { \
  |  |  |  |  291|  2.77k|    if ((level) < (coap_get_log_level() + 1)) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (291:9): [True: 0, False: 2.77k]
  |  |  |  |  ------------------
  |  |  |  |  292|  2.77k|      coap_log_impl((level), __VA_ARGS__); \
  |  |  |  |  293|  2.77k|  } while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (293:11): [Folded, False: 2.77k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1573|  2.77k|      }
 1574|  1.38k|    }
 1575|       |
 1576|  3.01k|    if (length > 0) {
  ------------------
  |  Branch (1576:9): [True: 237, False: 2.77k]
  ------------------
 1577|    237|      assert(*opt == COAP_PAYLOAD_START);
  ------------------
  |  Branch (1577:7): [True: 237, False: 0]
  ------------------
 1578|    237|      opt++;
 1579|    237|      length--;
 1580|       |
 1581|    237|      if (length == 0) {
  ------------------
  |  Branch (1581:11): [True: 17, False: 220]
  ------------------
 1582|     17|        coap_log_debug("coap_pdu_parse: message ending in payload start marker\n");
  ------------------
  |  |  126|     17|#define coap_log_debug(...) coap_log(COAP_LOG_DEBUG, __VA_ARGS__)
  |  |  ------------------
  |  |  |  |  290|     17|#define coap_log(level, ...) do { \
  |  |  |  |  291|     17|    if ((level) < (coap_get_log_level() + 1)) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (291:9): [True: 0, False: 17]
  |  |  |  |  ------------------
  |  |  |  |  292|     17|      coap_log_impl((level), __VA_ARGS__); \
  |  |  |  |  293|     17|  } while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (293:11): [Folded, False: 17]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1583|     17|        return 0;
 1584|     17|      }
 1585|    237|    }
 1586|  2.99k|    if (length > 0)
  ------------------
  |  Branch (1586:9): [True: 220, False: 2.77k]
  ------------------
 1587|    220|      pdu->data = (uint8_t *)opt;
 1588|  2.77k|    else
 1589|  2.77k|      pdu->data = NULL;
 1590|  2.99k|  }
 1591|       |
 1592|  2.99k|  return good;
 1593|  3.01k|}
coap_pdu_parse:
 1599|  3.09k|               coap_pdu_t *pdu) {
 1600|  3.09k|  coap_opt_filter_t error_opts;
 1601|       |
 1602|  3.09k|  return coap_pdu_parse2(proto, data, length, pdu, &error_opts);
 1603|  3.09k|}
coap_pdu_parse2:
 1610|  3.09k|                coap_opt_filter_t *error_opts) {
 1611|  3.09k|  size_t hdr_size;
 1612|       |
 1613|  3.09k|  if (length == 0)
  ------------------
  |  Branch (1613:7): [True: 0, False: 3.09k]
  ------------------
 1614|      0|    return 0;
 1615|  3.09k|  hdr_size = coap_pdu_parse_header_size(proto, data);
 1616|  3.09k|  if (!hdr_size || hdr_size > length)
  ------------------
  |  Branch (1616:7): [True: 0, False: 3.09k]
  |  Branch (1616:20): [True: 14, False: 3.07k]
  ------------------
 1617|     14|    return 0;
 1618|  3.07k|  if (hdr_size > pdu->max_hdr_size)
  ------------------
  |  Branch (1618:7): [True: 0, False: 3.07k]
  ------------------
 1619|      0|    return 0;
 1620|  3.07k|  if (!coap_pdu_resize(pdu, length - hdr_size))
  ------------------
  |  Branch (1620:7): [True: 0, False: 3.07k]
  ------------------
 1621|      0|    return 0;
 1622|  3.07k|  if (pdu->token - hdr_size != data)
  ------------------
  |  Branch (1622:7): [True: 3.07k, False: 0]
  ------------------
 1623|  3.07k|    memcpy(pdu->token - hdr_size, data, length);
 1624|  3.07k|  pdu->hdr_size = (uint8_t)hdr_size;
 1625|  3.07k|  pdu->used_size = length - hdr_size;
 1626|  3.07k|  return coap_pdu_parse_header(pdu, proto) && coap_pdu_parse_opt(pdu, error_opts);
  ------------------
  |  Branch (1626:10): [True: 3.04k, False: 28]
  |  Branch (1626:47): [True: 1.61k, False: 1.43k]
  ------------------
 1627|  3.07k|}
coap_pdu_encode_header:
 1630|  1.61k|coap_pdu_encode_header(coap_pdu_t *pdu, coap_proto_t proto) {
 1631|  1.61k|  uint8_t e_token_length;
 1632|       |
 1633|  1.61k|  if (pdu->actual_token.length < COAP_TOKEN_EXT_1B_BIAS) {
  ------------------
  |  |   56|  1.61k|#define COAP_TOKEN_EXT_1B_BIAS 13
  ------------------
  |  Branch (1633:7): [True: 1.55k, False: 63]
  ------------------
 1634|  1.55k|    e_token_length = (uint8_t)pdu->actual_token.length;
 1635|  1.55k|  } else if (pdu->actual_token.length < COAP_TOKEN_EXT_2B_BIAS) {
  ------------------
  |  |   57|     63|#define COAP_TOKEN_EXT_2B_BIAS 269 /* 13 + 256 */
  ------------------
  |  Branch (1635:14): [True: 29, False: 34]
  ------------------
 1636|     29|    e_token_length = COAP_TOKEN_EXT_1B_TKL;
  ------------------
  |  |   54|     29|#define COAP_TOKEN_EXT_1B_TKL 13
  ------------------
 1637|     34|  } else if (pdu->actual_token.length <= COAP_TOKEN_EXT_MAX) {
  ------------------
  |  |   60|     34|#define COAP_TOKEN_EXT_MAX 65804UL /* 13 + 256 + 65535 */
  ------------------
  |  Branch (1637:14): [True: 34, False: 0]
  ------------------
 1638|     34|    e_token_length = COAP_TOKEN_EXT_2B_TKL;
  ------------------
  |  |   55|     34|#define COAP_TOKEN_EXT_2B_TKL 14
  ------------------
 1639|     34|  } else {
 1640|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1641|      0|    return 0;
 1642|      0|  }
 1643|  1.61k|  if (COAP_PROTO_NOT_RELIABLE(proto)) {
  ------------------
  |  |   41|  1.61k|#define COAP_PROTO_NOT_RELIABLE(p) ((p)==COAP_PROTO_UDP || (p)==COAP_PROTO_DTLS)
  |  |  ------------------
  |  |  |  Branch (41:37): [True: 0, False: 1.61k]
  |  |  |  Branch (41:60): [True: 0, False: 1.61k]
  |  |  ------------------
  ------------------
 1644|      0|    assert(pdu->max_hdr_size >= 4);
  ------------------
  |  Branch (1644:5): [True: 0, False: 0]
  ------------------
 1645|      0|    if (pdu->max_hdr_size < 4) {
  ------------------
  |  Branch (1645:9): [True: 0, False: 0]
  ------------------
 1646|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1647|      0|      return 0;
 1648|      0|    }
 1649|      0|    pdu->token[-4] = COAP_DEFAULT_VERSION << 6
  ------------------
  |  |   35|      0|#define COAP_DEFAULT_VERSION      1 /* version of CoAP supported */
  ------------------
 1650|      0|                     | pdu->type << 4
 1651|      0|                     | e_token_length;
 1652|      0|    pdu->token[-3] = pdu->code;
 1653|      0|    pdu->token[-2] = (uint8_t)(pdu->mid >> 8);
 1654|      0|    pdu->token[-1] = (uint8_t)(pdu->mid);
 1655|      0|    pdu->hdr_size = 4;
 1656|      0|#if !COAP_DISABLE_TCP
 1657|  1.61k|  } else if (COAP_PROTO_RELIABLE(proto)) {
  ------------------
  |  |   42|  1.61k|#define COAP_PROTO_RELIABLE(p) ((p)==COAP_PROTO_TCP || (p)==COAP_PROTO_TLS || \
  |  |  ------------------
  |  |  |  Branch (42:33): [True: 1.61k, False: 0]
  |  |  |  Branch (42:56): [True: 0, False: 0]
  |  |  ------------------
  |  |   43|  1.61k|                                (p)==COAP_PROTO_WS || (p)==COAP_PROTO_WSS)
  |  |  ------------------
  |  |  |  Branch (43:33): [True: 0, False: 0]
  |  |  |  Branch (43:55): [True: 0, False: 0]
  |  |  ------------------
  ------------------
 1658|  1.61k|    size_t len;
 1659|  1.61k|    assert(pdu->used_size >= pdu->e_token_length);
  ------------------
  |  Branch (1659:5): [True: 1.61k, False: 0]
  ------------------
 1660|  1.61k|    if (pdu->used_size < pdu->e_token_length) {
  ------------------
  |  Branch (1660:9): [True: 0, False: 1.61k]
  ------------------
 1661|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1662|      0|      return 0;
 1663|      0|    }
 1664|       |
 1665|       |    /* A lot of the reliable code assumes type is CON */
 1666|  1.61k|    if (pdu->type != COAP_MESSAGE_CON)
  ------------------
  |  Branch (1666:9): [True: 0, False: 1.61k]
  ------------------
 1667|      0|      pdu->type = COAP_MESSAGE_CON;
 1668|       |
 1669|  1.61k|    if (proto == COAP_PROTO_WS || proto == COAP_PROTO_WSS)
  ------------------
  |  Branch (1669:9): [True: 0, False: 1.61k]
  |  Branch (1669:35): [True: 0, False: 1.61k]
  ------------------
 1670|      0|      len = 0;
 1671|  1.61k|    else
 1672|  1.61k|      len = pdu->used_size - pdu->e_token_length;
 1673|  1.61k|    if (len <= COAP_MAX_MESSAGE_SIZE_TCP0) {
  ------------------
  |  |   43|  1.61k|#define COAP_MAX_MESSAGE_SIZE_TCP0 (COAP_MESSAGE_SIZE_OFFSET_TCP8-1) /* 12 */
  |  |  ------------------
  |  |  |  |   38|  1.61k|#define COAP_MESSAGE_SIZE_OFFSET_TCP8 13
  |  |  ------------------
  ------------------
  |  Branch (1673:9): [True: 804, False: 814]
  ------------------
 1674|    804|      assert(pdu->max_hdr_size >= 2);
  ------------------
  |  Branch (1674:7): [True: 804, False: 0]
  ------------------
 1675|    804|      if (pdu->max_hdr_size < 2) {
  ------------------
  |  Branch (1675:11): [True: 0, False: 804]
  ------------------
 1676|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1677|      0|        return 0;
 1678|      0|      }
 1679|    804|      pdu->token[-2] = (uint8_t)len << 4
 1680|    804|                       | e_token_length;
 1681|    804|      pdu->token[-1] = pdu->code;
 1682|    804|      pdu->hdr_size = 2;
 1683|    814|    } else if (len <= COAP_MAX_MESSAGE_SIZE_TCP8) {
  ------------------
  |  |   44|    814|#define COAP_MAX_MESSAGE_SIZE_TCP8 (COAP_MESSAGE_SIZE_OFFSET_TCP16-1) /* 268 */
  |  |  ------------------
  |  |  |  |   39|    814|#define COAP_MESSAGE_SIZE_OFFSET_TCP16 269 /* 13 + 256 */
  |  |  ------------------
  ------------------
  |  Branch (1683:16): [True: 597, False: 217]
  ------------------
 1684|    597|      assert(pdu->max_hdr_size >= 3);
  ------------------
  |  Branch (1684:7): [True: 597, False: 0]
  ------------------
 1685|    597|      if (pdu->max_hdr_size < 3) {
  ------------------
  |  Branch (1685:11): [True: 0, False: 597]
  ------------------
 1686|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1687|      0|        return 0;
 1688|      0|      }
 1689|    597|      pdu->token[-3] = 13 << 4 | e_token_length;
 1690|    597|      pdu->token[-2] = (uint8_t)(len - COAP_MESSAGE_SIZE_OFFSET_TCP8);
  ------------------
  |  |   38|    597|#define COAP_MESSAGE_SIZE_OFFSET_TCP8 13
  ------------------
 1691|    597|      pdu->token[-1] = pdu->code;
 1692|    597|      pdu->hdr_size = 3;
 1693|    597|    } else if (len <= COAP_MAX_MESSAGE_SIZE_TCP16) {
  ------------------
  |  |   45|    217|#define COAP_MAX_MESSAGE_SIZE_TCP16 (COAP_MESSAGE_SIZE_OFFSET_TCP32-1) /* 65804 */
  |  |  ------------------
  |  |  |  |   40|    217|#define COAP_MESSAGE_SIZE_OFFSET_TCP32 65805 /* 269 + 65536 */
  |  |  ------------------
  ------------------
  |  Branch (1693:16): [True: 157, False: 60]
  ------------------
 1694|    157|      assert(pdu->max_hdr_size >= 4);
  ------------------
  |  Branch (1694:7): [True: 157, False: 0]
  ------------------
 1695|    157|      if (pdu->max_hdr_size < 4) {
  ------------------
  |  Branch (1695:11): [True: 0, False: 157]
  ------------------
 1696|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1697|      0|        return 0;
 1698|      0|      }
 1699|    157|      pdu->token[-4] = 14 << 4 | e_token_length;
 1700|    157|      pdu->token[-3] = (uint8_t)((len - COAP_MESSAGE_SIZE_OFFSET_TCP16) >> 8);
  ------------------
  |  |   39|    157|#define COAP_MESSAGE_SIZE_OFFSET_TCP16 269 /* 13 + 256 */
  ------------------
 1701|    157|      pdu->token[-2] = (uint8_t)(len - COAP_MESSAGE_SIZE_OFFSET_TCP16);
  ------------------
  |  |   39|    157|#define COAP_MESSAGE_SIZE_OFFSET_TCP16 269 /* 13 + 256 */
  ------------------
 1702|    157|      pdu->token[-1] = pdu->code;
 1703|    157|      pdu->hdr_size = 4;
 1704|    157|    } else {
 1705|     60|      assert(pdu->max_hdr_size >= 6);
  ------------------
  |  Branch (1705:7): [True: 60, False: 0]
  ------------------
 1706|     60|      if (pdu->max_hdr_size < 6) {
  ------------------
  |  Branch (1706:11): [True: 0, False: 60]
  ------------------
 1707|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1708|      0|        return 0;
 1709|      0|      }
 1710|     60|      pdu->token[-6] = 15 << 4 | e_token_length;
 1711|     60|      pdu->token[-5] = (uint8_t)((len - COAP_MESSAGE_SIZE_OFFSET_TCP32) >> 24);
  ------------------
  |  |   40|     60|#define COAP_MESSAGE_SIZE_OFFSET_TCP32 65805 /* 269 + 65536 */
  ------------------
 1712|     60|      pdu->token[-4] = (uint8_t)((len - COAP_MESSAGE_SIZE_OFFSET_TCP32) >> 16);
  ------------------
  |  |   40|     60|#define COAP_MESSAGE_SIZE_OFFSET_TCP32 65805 /* 269 + 65536 */
  ------------------
 1713|     60|      pdu->token[-3] = (uint8_t)((len - COAP_MESSAGE_SIZE_OFFSET_TCP32) >> 8);
  ------------------
  |  |   40|     60|#define COAP_MESSAGE_SIZE_OFFSET_TCP32 65805 /* 269 + 65536 */
  ------------------
 1714|     60|      pdu->token[-2] = (uint8_t)(len - COAP_MESSAGE_SIZE_OFFSET_TCP32);
  ------------------
  |  |   40|     60|#define COAP_MESSAGE_SIZE_OFFSET_TCP32 65805 /* 269 + 65536 */
  ------------------
 1715|     60|      pdu->token[-1] = pdu->code;
 1716|     60|      pdu->hdr_size = 6;
 1717|     60|    }
 1718|  1.61k|#endif /* ! COAP_DISABLE_TCP */
 1719|  1.61k|  } else {
 1720|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1721|      0|  }
 1722|  1.61k|  return pdu->hdr_size;
 1723|  1.61k|}
coap_pdu.c:coap_pdu_parse_opt_csm:
 1234|  3.27M|coap_pdu_parse_opt_csm(coap_pdu_code_t code, coap_option_num_t option, size_t len) {
 1235|  3.27M|  switch ((coap_pdu_signaling_proto_t)code) {
 1236|  23.0k|  case COAP_SIGNALING_CSM:
  ------------------
  |  Branch (1236:3): [True: 23.0k, False: 3.25M]
  ------------------
 1237|  23.0k|    switch ((coap_sig_csm_opt_t)option) {
 1238|  2.53k|    case COAP_SIG_OPT_MAX_MESSAGE_SIZE:
  ------------------
  |  Branch (1238:5): [True: 2.53k, False: 20.5k]
  ------------------
 1239|  2.53k|      if (len > 4)
  ------------------
  |  Branch (1239:11): [True: 1.33k, False: 1.19k]
  ------------------
 1240|  1.33k|        goto bad;
 1241|  1.19k|      break;
 1242|  6.37k|    case COAP_SIG_OPT_BLOCK_WISE_TRANSFER:
  ------------------
  |  Branch (1242:5): [True: 6.37k, False: 16.6k]
  ------------------
 1243|  6.37k|      if (len > 0)
  ------------------
  |  Branch (1243:11): [True: 1.17k, False: 5.20k]
  ------------------
 1244|  1.17k|        goto bad;
 1245|  5.20k|      break;
 1246|  5.20k|    case COAP_SIG_OPT_EXTENDED_TOKEN_LENGTH:
  ------------------
  |  Branch (1246:5): [True: 3.24k, False: 19.7k]
  ------------------
 1247|  3.24k|      if (len > 3)
  ------------------
  |  Branch (1247:11): [True: 1.68k, False: 1.55k]
  ------------------
 1248|  1.68k|        goto bad;
 1249|  1.55k|      break;
 1250|  10.8k|    default:
  ------------------
  |  Branch (1250:5): [True: 10.8k, False: 12.1k]
  ------------------
 1251|  10.8k|      if (option & 0x01)
  ------------------
  |  Branch (1251:11): [True: 2.74k, False: 8.14k]
  ------------------
 1252|  2.74k|        goto bad; /* Critical */
 1253|  23.0k|    }
 1254|  16.0k|    break;
 1255|  16.0k|  case COAP_SIGNALING_PING:
  ------------------
  |  Branch (1255:3): [True: 5.30k, False: 3.27M]
  ------------------
 1256|  12.1k|  case COAP_SIGNALING_PONG:
  ------------------
  |  Branch (1256:3): [True: 6.87k, False: 3.26M]
  ------------------
 1257|  12.1k|    switch ((coap_sig_ping_opt_t)option) {
 1258|  5.67k|    case COAP_SIG_OPT_CUSTODY:
  ------------------
  |  Branch (1258:5): [True: 5.67k, False: 6.50k]
  ------------------
 1259|  5.67k|      if (len > 0)
  ------------------
  |  Branch (1259:11): [True: 3.33k, False: 2.33k]
  ------------------
 1260|  3.33k|        goto bad;
 1261|  2.33k|      break;
 1262|  6.50k|    default:
  ------------------
  |  Branch (1262:5): [True: 6.50k, False: 5.67k]
  ------------------
 1263|  6.50k|      if (option & 0x01)
  ------------------
  |  Branch (1263:11): [True: 2.58k, False: 3.91k]
  ------------------
 1264|  2.58k|        goto bad; /* Critical */
 1265|  12.1k|    }
 1266|  6.25k|    break;
 1267|  19.6k|  case COAP_SIGNALING_RELEASE:
  ------------------
  |  Branch (1267:3): [True: 19.6k, False: 3.25M]
  ------------------
 1268|  19.6k|    switch ((coap_sig_release_opt_t)option) {
 1269|  3.01k|    case COAP_SIG_OPT_ALTERNATIVE_ADDRESS:
  ------------------
  |  Branch (1269:5): [True: 3.01k, False: 16.6k]
  ------------------
 1270|  3.01k|      if (len < 1 || len > 255)
  ------------------
  |  Branch (1270:11): [True: 1.50k, False: 1.51k]
  |  Branch (1270:22): [True: 1.01k, False: 499]
  ------------------
 1271|  2.51k|        goto bad;
 1272|    499|      break;
 1273|  1.45k|    case COAP_SIG_OPT_HOLD_OFF:
  ------------------
  |  Branch (1273:5): [True: 1.45k, False: 18.1k]
  ------------------
 1274|  1.45k|      if (len > 3)
  ------------------
  |  Branch (1274:11): [True: 1.02k, False: 429]
  ------------------
 1275|  1.02k|        goto bad;
 1276|    429|      break;
 1277|  15.1k|    default:
  ------------------
  |  Branch (1277:5): [True: 15.1k, False: 4.46k]
  ------------------
 1278|  15.1k|      if (option & 0x01)
  ------------------
  |  Branch (1278:11): [True: 12.5k, False: 2.61k]
  ------------------
 1279|  12.5k|        goto bad; /* Critical */
 1280|  19.6k|    }
 1281|  3.54k|    break;
 1282|  3.15M|  case COAP_SIGNALING_ABORT:
  ------------------
  |  Branch (1282:3): [True: 3.15M, False: 124k]
  ------------------
 1283|  3.15M|    switch ((coap_sig_abort_opt_t)option) {
 1284|  2.38M|    case COAP_SIG_OPT_BAD_CSM_OPTION:
  ------------------
  |  Branch (1284:5): [True: 2.38M, False: 771k]
  ------------------
 1285|  2.38M|      if (len > 2)
  ------------------
  |  Branch (1285:11): [True: 1.03k, False: 2.37M]
  ------------------
 1286|  1.03k|        goto bad;
 1287|  2.37M|      break;
 1288|  2.37M|    default:
  ------------------
  |  Branch (1288:5): [True: 771k, False: 2.38M]
  ------------------
 1289|   771k|      if (option & 0x01)
  ------------------
  |  Branch (1289:11): [True: 1.99k, False: 769k]
  ------------------
 1290|  1.99k|        goto bad; /* Critical */
 1291|  3.15M|    }
 1292|  3.14M|    break;
 1293|  3.14M|  default:
  ------------------
  |  Branch (1293:3): [True: 69.4k, False: 3.20M]
  ------------------
 1294|  69.4k|    goto bad;
 1295|  3.27M|  }
 1296|  3.17M|  return 1;
 1297|   101k|bad:
 1298|   101k|  return 0;
 1299|  3.27M|}
coap_pdu.c:next_option_safe:
 1052|  12.2M|next_option_safe(coap_opt_t **optp, size_t *length, uint16_t *max_opt) {
 1053|  12.2M|  coap_option_t option;
 1054|  12.2M|  size_t optsize;
 1055|       |
 1056|  12.2M|  assert(optp);
  ------------------
  |  Branch (1056:3): [True: 12.2M, False: 0]
  ------------------
 1057|  12.2M|  assert(*optp);
  ------------------
  |  Branch (1057:3): [True: 12.2M, False: 0]
  ------------------
 1058|  12.2M|  assert(length);
  ------------------
  |  Branch (1058:3): [True: 12.2M, False: 0]
  ------------------
 1059|       |
 1060|  12.2M|  optsize = coap_opt_parse(*optp, *length, &option);
 1061|  12.2M|  assert(optsize <= *length);
  ------------------
  |  Branch (1061:3): [True: 12.2M, False: 0]
  ------------------
 1062|       |
 1063|       |  /* signal an error if this option would exceed the
 1064|       |   * allowed number space */
 1065|  12.2M|  if ((uint32_t)(*max_opt) + option.delta > COAP_MAX_OPT) {
  ------------------
  |  |  105|  12.2M|#define COAP_MAX_OPT 65535 /**< the highest option number we know */
  ------------------
  |  Branch (1065:7): [True: 30, False: 12.2M]
  ------------------
 1066|     30|    return 0;
 1067|     30|  }
 1068|  12.2M|  *max_opt += option.delta;
 1069|  12.2M|  *optp += optsize;
 1070|  12.2M|  *length -= optsize;
 1071|       |
 1072|  12.2M|  return optsize;
 1073|  12.2M|}
coap_pdu.c:write_prefix:
 1425|   104k|write_prefix(char **obp, size_t *len, const char *prf, size_t prflen) {
 1426|       |  /* Make sure space for null terminating byte */
 1427|   104k|  if (*len < prflen +1) {
  ------------------
  |  Branch (1427:7): [True: 38, False: 104k]
  ------------------
 1428|     38|    return 0;
 1429|     38|  }
 1430|       |
 1431|   104k|  memcpy(*obp, prf, prflen);
 1432|   104k|  *obp += prflen;
 1433|   104k|  *len -= prflen;
 1434|   104k|  return 1;
 1435|   104k|}
coap_pdu.c:write_char:
 1438|  1.05M|write_char(char **obp, size_t *len, int c, int printable) {
 1439|       |  /* Make sure space for null terminating byte */
 1440|  1.05M|  if (*len < 2 +1) {
  ------------------
  |  Branch (1440:7): [True: 902, False: 1.05M]
  ------------------
 1441|    902|    return 0;
 1442|    902|  }
 1443|       |
 1444|  1.05M|  if (!printable) {
  ------------------
  |  Branch (1444:7): [True: 525k, False: 525k]
  ------------------
 1445|   525k|    const uint8_t hex[] = "0123456789abcdef";
 1446|   525k|    (*obp)[0] = hex[(c & 0xf0) >> 4];
 1447|   525k|    (*obp)[1] = hex[c & 0x0f];
 1448|   525k|  } else {
 1449|   525k|    (*obp)[0] = isprint(c) ? c : '.';
  ------------------
  |  Branch (1449:17): [True: 84.6k, False: 440k]
  ------------------
 1450|   525k|    (*obp)[1] = ' ';
 1451|   525k|  }
 1452|  1.05M|  *obp += 2;
 1453|  1.05M|  *len -= 2;
 1454|  1.05M|  return 1;
 1455|  1.05M|}

coap_prng_init_lkd:
  186|  3.09k|coap_prng_init_lkd(unsigned int seed) {
  187|  3.09k|#ifdef HAVE_GETRANDOM
  188|       |  /* No seed to seed the random source if getrandom() is used */
  189|  3.09k|  (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.09k|}
coap_prng_lkd:
  198|  3.09k|coap_prng_lkd(void *buf, size_t len) {
  199|  3.09k|  if (!rand_func) {
  ------------------
  |  Branch (199:7): [True: 0, False: 3.09k]
  ------------------
  200|      0|    return 0;
  201|      0|  }
  202|       |
  203|  3.09k|  return rand_func(buf, len);
  204|  3.09k|}
coap_prng.c:coap_prng_default:
  111|  3.09k|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.09k|  return (getrandom(buf, len, 0) > 0) ? 1 : 0;
  ------------------
  |  Branch (126:10): [True: 3.09k, 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.09k|}

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

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

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

coap_split_proxy_uri:
  356|    536|coap_split_proxy_uri(const uint8_t *str_var, size_t len, coap_uri_t *uri) {
  357|    536|  return coap_split_uri_sub(str_var, len, uri, COAP_URI_CHECK_PROXY);
  358|    536|}
coap_check_dots:
  675|  6.49M|coap_check_dots(const uint8_t *s, size_t len) {
  676|  6.49M|  uint8_t p;
  677|       |
  678|  6.49M|  if (!len)
  ------------------
  |  Branch (678:7): [True: 6.33M, False: 160k]
  ------------------
  679|  6.33M|    return 0;
  680|       |
  681|   160k|  p = *s;
  682|       |
  683|       |  /* Check 'first' char */
  684|   160k|  if (p == '%' && len >=3) {
  ------------------
  |  Branch (684:7): [True: 2.13k, False: 158k]
  |  Branch (684:19): [True: 1.93k, False: 202]
  ------------------
  685|  1.93k|    if (s[1] == '2' && (s[2] == 'E' || s[2] == 'e')) {
  ------------------
  |  Branch (685:9): [True: 620, False: 1.31k]
  |  Branch (685:25): [True: 201, False: 419]
  |  Branch (685:40): [True: 201, False: 218]
  ------------------
  686|    402|      s += 2;
  687|    402|      len -= 2;
  688|    402|    }
  689|  1.93k|    p = '.';
  690|  1.93k|  }
  691|   160k|  if (p != '.')
  ------------------
  |  Branch (691:7): [True: 155k, False: 4.53k]
  ------------------
  692|   155k|    return 0;
  693|  4.53k|  if (len == 1)
  ------------------
  |  Branch (693:7): [True: 1.23k, False: 3.29k]
  ------------------
  694|  1.23k|    return 1;
  695|       |
  696|       |  /* Check 'second' char, first is '.' */
  697|  3.29k|  s++;
  698|  3.29k|  len--;
  699|  3.29k|  assert(len);
  ------------------
  |  Branch (699:3): [True: 3.29k, False: 0]
  ------------------
  700|  3.29k|  p = *s;
  701|  3.29k|  if (p == '%' && len >=3) {
  ------------------
  |  Branch (701:7): [True: 1.35k, False: 1.93k]
  |  Branch (701:19): [True: 886, False: 469]
  ------------------
  702|    886|    if (s[1] == '2' && (s[2] == 'E' || s[2] == 'e')) {
  ------------------
  |  Branch (702:9): [True: 639, False: 247]
  |  Branch (702:25): [True: 202, False: 437]
  |  Branch (702:40): [True: 205, False: 232]
  ------------------
  703|    407|      len -= 2;
  704|    407|    }
  705|    886|    p = '.';
  706|    886|  }
  707|  3.29k|  if (p != '.')
  ------------------
  |  Branch (707:7): [True: 837, False: 2.45k]
  ------------------
  708|    837|    return 0;
  709|  2.45k|  if (len == 1)
  ------------------
  |  Branch (709:7): [True: 1.74k, False: 709]
  ------------------
  710|  1.74k|    return 2;
  711|       |
  712|    709|  return 0;
  713|  2.45k|}
coap_get_query:
 1108|  1.61k|coap_get_query(const coap_pdu_t *request) {
 1109|  1.61k|  coap_opt_iterator_t opt_iter;
 1110|  1.61k|  coap_opt_filter_t f;
 1111|  1.61k|  coap_opt_t *q;
 1112|  1.61k|  coap_string_t *query = NULL;
 1113|  1.61k|  size_t length = 0;
 1114|  1.61k|  int have_query = 0;
 1115|  1.61k|  static const uint8_t hex[] = "0123456789ABCDEF";
 1116|       |
 1117|  1.61k|  coap_option_filter_clear(&f);
 1118|  1.61k|  coap_option_filter_set(&f, COAP_OPTION_URI_QUERY);
 1119|  1.61k|  coap_option_iterator_init(request, &opt_iter, &f);
 1120|   126k|  while ((q = coap_option_next(&opt_iter))) {
  ------------------
  |  Branch (1120:10): [True: 125k, False: 1.61k]
  ------------------
 1121|   125k|    uint16_t seg_len = coap_opt_length(q), i;
 1122|   125k|    const uint8_t *seg= coap_opt_value(q);
 1123|   125k|    have_query = 1;
 1124|   571k|    for (i = 0; i < seg_len; i++) {
  ------------------
  |  Branch (1124:17): [True: 446k, False: 125k]
  ------------------
 1125|   446k|      if (is_unescaped_in_query(seg[i]))
  ------------------
  |  Branch (1125:11): [True: 13.7k, False: 432k]
  ------------------
 1126|  13.7k|        length += 1;
 1127|   432k|      else
 1128|   432k|        length += 3;
 1129|   446k|    }
 1130|   125k|    length += 1;
 1131|   125k|  }
 1132|  1.61k|  if (length > 0)
  ------------------
  |  Branch (1132:7): [True: 308, False: 1.31k]
  ------------------
 1133|    308|    length -= 1;
 1134|       |  /* Allocate and return a string whenever at least one Uri-Query option is
 1135|       |     present, even when every option is empty and the encoded length is zero.
 1136|       |     A single empty Uri-Query then yields an empty string rather than NULL,
 1137|       |     which is reserved for "no Uri-Query option at all". */
 1138|  1.61k|  if (have_query) {
  ------------------
  |  Branch (1138:7): [True: 308, False: 1.31k]
  ------------------
 1139|    308|    query = coap_new_string(length);
 1140|    308|    if (query) {
  ------------------
  |  Branch (1140:9): [True: 308, False: 0]
  ------------------
 1141|    308|      unsigned char *s = query->s;
 1142|    308|      int first = 1;
 1143|    308|      query->length = length;
 1144|    308|      coap_option_iterator_init(request, &opt_iter, &f);
 1145|   125k|      while ((q = coap_option_next(&opt_iter))) {
  ------------------
  |  Branch (1145:14): [True: 125k, False: 308]
  ------------------
 1146|       |        /* Write the '&' separator before every Uri-Query option except the
 1147|       |           first. An empty Uri-Query option is a distinct zero-length segment
 1148|       |           (just as "&&" is not "&"), so the separators around it must still
 1149|       |           be emitted. Keying this off the option index rather than off
 1150|       |           whether any byte has been written yet is what keeps leading empty
 1151|       |           options from being dropped, and keeps the buffer fully written so
 1152|       |           no uninitialised tail is exposed to callers. */
 1153|   125k|        if (!first)
  ------------------
  |  Branch (1153:13): [True: 124k, False: 308]
  ------------------
 1154|   124k|          *s++ = '&';
 1155|   125k|        first = 0;
 1156|   125k|        uint16_t seg_len = coap_opt_length(q), i;
 1157|   125k|        const uint8_t *seg= coap_opt_value(q);
 1158|   571k|        for (i = 0; i < seg_len; i++) {
  ------------------
  |  Branch (1158:21): [True: 446k, False: 125k]
  ------------------
 1159|   446k|          if (is_unescaped_in_query(seg[i])) {
  ------------------
  |  Branch (1159:15): [True: 13.7k, False: 432k]
  ------------------
 1160|  13.7k|            *s++ = seg[i];
 1161|   432k|          } else {
 1162|   432k|            *s++ = '%';
 1163|   432k|            *s++ = hex[seg[i]>>4];
 1164|   432k|            *s++ = hex[seg[i]&0x0F];
 1165|   432k|          }
 1166|   446k|        }
 1167|   125k|      }
 1168|    308|    }
 1169|    308|  }
 1170|  1.61k|  return query;
 1171|  1.61k|}
coap_map_abbrev_uri_path:
 1174|     15|coap_map_abbrev_uri_path(coap_upa_chain_t *chain, uint32_t value) {
 1175|     15|  while (chain) {
  ------------------
  |  Branch (1175:10): [True: 0, False: 15]
  ------------------
 1176|      0|    coap_upa_chain_t *next = chain->next;
 1177|       |
 1178|      0|    if (chain->upa_value == value) {
  ------------------
  |  Branch (1178:9): [True: 0, False: 0]
  ------------------
 1179|      0|      return chain->upa_path;
 1180|      0|    }
 1181|      0|    chain = next;
 1182|      0|  }
 1183|     15|  return NULL;
 1184|     15|}
coap_get_uri_path:
 1202|  1.61k|coap_get_uri_path(const coap_pdu_t *request) {
 1203|  1.61k|  coap_opt_iterator_t opt_iter;
 1204|  1.61k|  coap_opt_filter_t f;
 1205|  1.61k|  coap_opt_t *q;
 1206|  1.61k|  coap_string_t *uri_path = NULL;
 1207|  1.61k|  size_t length = 0;
 1208|  1.61k|  static const uint8_t hex[] = "0123456789ABCDEF";
 1209|       |
 1210|  1.61k|  q = coap_check_option(request, COAP_OPTION_URI_PATH_ABB, &opt_iter);
 1211|  1.61k|  if (q) {
  ------------------
  |  Branch (1211:7): [True: 26, False: 1.59k]
  ------------------
 1212|     26|    uint32_t value;
 1213|     26|    const char *exp;
 1214|     26|    if (coap_check_option(request, COAP_OPTION_PROXY_URI, &opt_iter) ||
  ------------------
  |  Branch (1214:9): [True: 5, False: 21]
  ------------------
 1215|     21|        coap_check_option(request, COAP_OPTION_URI_PATH, &opt_iter)) {
  ------------------
  |  Branch (1215:9): [True: 6, False: 15]
  ------------------
 1216|     11|      return NULL;
 1217|     11|    }
 1218|     15|    value = coap_decode_var_bytes(coap_opt_value(q), coap_opt_length(q));
 1219|     15|    exp = coap_map_abbrev_uri_path(coap_upa_server_mapping_chain, value);
 1220|     15|    if (exp) {
  ------------------
  |  Branch (1220:9): [True: 0, False: 15]
  ------------------
 1221|      0|      uri_path = coap_new_string(strlen(exp));
 1222|      0|      if (uri_path) {
  ------------------
  |  Branch (1222:11): [True: 0, False: 0]
  ------------------
 1223|      0|        memcpy(uri_path->s, exp, strlen(exp));
 1224|      0|      }
 1225|      0|      return uri_path;
 1226|      0|    }
 1227|     15|    return NULL;
 1228|     15|  }
 1229|  1.59k|  q = coap_check_option(request, COAP_OPTION_PROXY_URI, &opt_iter);
 1230|  1.59k|  if (q) {
  ------------------
  |  Branch (1230:7): [True: 536, False: 1.05k]
  ------------------
 1231|    536|    coap_uri_t uri;
 1232|       |
 1233|    536|    if (coap_split_proxy_uri(coap_opt_value(q),
  ------------------
  |  Branch (1233:9): [True: 384, False: 152]
  ------------------
 1234|    536|                             coap_opt_length(q), &uri) < 0) {
 1235|    384|      return NULL;
 1236|    384|    }
 1237|    152|    uri_path = coap_new_string(uri.path.length);
 1238|    152|    if (uri_path && uri.path.length) {
  ------------------
  |  Branch (1238:9): [True: 152, False: 0]
  |  Branch (1238:21): [True: 36, False: 116]
  ------------------
 1239|     36|      memcpy(uri_path->s, uri.path.s, uri.path.length);
 1240|     36|    }
 1241|    152|    return uri_path;
 1242|    536|  }
 1243|       |
 1244|  1.05k|  coap_option_filter_clear(&f);
 1245|  1.05k|  coap_option_filter_set(&f, COAP_OPTION_URI_PATH);
 1246|  1.05k|  coap_option_iterator_init(request, &opt_iter, &f);
 1247|  6.47M|  while ((q = coap_option_next(&opt_iter))) {
  ------------------
  |  Branch (1247:10): [True: 6.47M, False: 1.05k]
  ------------------
 1248|  6.47M|    uint16_t seg_len = coap_opt_length(q), i;
 1249|  6.47M|    const uint8_t *seg = coap_opt_value(q);
 1250|  7.31M|    for (i = 0; i < seg_len; i++) {
  ------------------
  |  Branch (1250:17): [True: 841k, False: 6.47M]
  ------------------
 1251|   841k|      if (is_unescaped_in_path(seg[i]))
  ------------------
  |  Branch (1251:11): [True: 27.9k, False: 814k]
  ------------------
 1252|  27.9k|        length += 1;
 1253|   814k|      else
 1254|   814k|        length += 3;
 1255|   841k|    }
 1256|       |    /* bump for the leading "/" */
 1257|  6.47M|    length += 1;
 1258|  6.47M|  }
 1259|       |  /* The first entry does not have a leading "/" */
 1260|  1.05k|  if (length > 0)
  ------------------
  |  Branch (1260:7): [True: 380, False: 676]
  ------------------
 1261|    380|    length -= 1;
 1262|       |
 1263|       |  /* if 0, either no URI_PATH Option, or the first one was empty */
 1264|  1.05k|  uri_path = coap_new_string(length);
 1265|  1.05k|  if (uri_path) {
  ------------------
  |  Branch (1265:7): [True: 1.05k, False: 0]
  ------------------
 1266|  1.05k|    uri_path->length = length;
 1267|  1.05k|    unsigned char *s = uri_path->s;
 1268|  1.05k|    int n = 0;
 1269|  1.05k|    coap_option_iterator_init(request, &opt_iter, &f);
 1270|  6.47M|    while ((q = coap_option_next(&opt_iter))) {
  ------------------
  |  Branch (1270:12): [True: 6.47M, False: 1.05k]
  ------------------
 1271|  6.47M|      if (n++) {
  ------------------
  |  Branch (1271:11): [True: 6.47M, False: 380]
  ------------------
 1272|  6.47M|        *s++ = '/';
 1273|  6.47M|      }
 1274|  6.47M|      uint16_t seg_len = coap_opt_length(q), i;
 1275|  6.47M|      const uint8_t *seg= coap_opt_value(q);
 1276|  7.31M|      for (i = 0; i < seg_len; i++) {
  ------------------
  |  Branch (1276:19): [True: 841k, False: 6.47M]
  ------------------
 1277|   841k|        if (is_unescaped_in_path(seg[i])) {
  ------------------
  |  Branch (1277:13): [True: 27.9k, False: 814k]
  ------------------
 1278|  27.9k|          *s++ = seg[i];
 1279|   814k|        } else {
 1280|   814k|          *s++ = '%';
 1281|   814k|          *s++ = hex[seg[i]>>4];
 1282|   814k|          *s++ = hex[seg[i]&0x0F];
 1283|   814k|        }
 1284|   841k|      }
 1285|  6.47M|    }
 1286|  1.05k|  }
 1287|  1.05k|  return uri_path;
 1288|  1.59k|}
coap_delete_upa_chain:
 1291|  6.18k|coap_delete_upa_chain(coap_upa_chain_t *chain) {
 1292|  6.18k|  while (chain) {
  ------------------
  |  Branch (1292:10): [True: 0, False: 6.18k]
  ------------------
 1293|      0|    coap_upa_chain_t *next = chain->next;
 1294|       |
 1295|      0|    coap_free_type(COAP_STRING, chain);
 1296|      0|    chain = next;
 1297|      0|  }
 1298|  6.18k|}
coap_uri.c:coap_split_uri_sub:
   84|    536|                   coap_uri_check_t check_proxy) {
   85|    536|  const uint8_t *p, *q;
   86|    536|  int res = 0;
   87|    536|  size_t i;
   88|    536|  int is_unix_domain = 0;
   89|    536|  int is_llc = 0;
   90|       |
   91|    536|  if (!str_var || !uri || len == 0)
  ------------------
  |  Branch (91:7): [True: 0, False: 536]
  |  Branch (91:19): [True: 0, False: 536]
  |  Branch (91:27): [True: 0, False: 536]
  ------------------
   92|      0|    return -1;
   93|       |
   94|    536|  memset(uri, 0, sizeof(coap_uri_t));
   95|    536|  uri->port = COAP_DEFAULT_PORT;
  ------------------
  |  |   39|    536|#define COAP_DEFAULT_PORT      5683 /* CoAP default UDP/TCP port */
  ------------------
   96|       |
   97|       |  /* search for scheme */
   98|    536|  p = str_var;
   99|    536|  if (*p == '/') {
  ------------------
  |  Branch (99:7): [True: 1, False: 535]
  ------------------
  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|  9.85k|  while (len >= 3 && !(p[0] == ':' && p[1] == '/' && p[2] == '/')) {
  ------------------
  |  Branch (110:10): [True: 9.80k, False: 56]
  |  Branch (110:24): [True: 1.44k, False: 8.35k]
  |  Branch (110:39): [True: 743, False: 699]
  |  Branch (110:54): [True: 479, False: 264]
  ------------------
  111|  9.32k|    ++p;
  112|  9.32k|    --len;
  113|  9.32k|  }
  114|    535|  if (len < 3) {
  ------------------
  |  Branch (114:7): [True: 56, False: 479]
  ------------------
  115|       |    /* scheme not defined with a :// terminator */
  116|     56|    res = -2;
  117|     56|    goto error;
  118|     56|  }
  119|  1.72k|  for (i = 0; i < COAP_URI_SCHEME_LAST; i++) {
  ------------------
  |  Branch (119:15): [True: 1.61k, False: 104]
  ------------------
  120|  1.61k|    if ((p - str_var) == (int)strlen(coap_uri_scheme[i].name) &&
  ------------------
  |  Branch (120:9): [True: 605, False: 1.01k]
  ------------------
  121|    605|        strncasecmp((const char *)str_var, coap_uri_scheme[i].name, p - str_var) == 0) {
  ------------------
  |  Branch (121:9): [True: 375, False: 230]
  ------------------
  122|    375|      if (check_proxy != COAP_URI_CHECK_PROXY && coap_uri_scheme[i].proxy_only) {
  ------------------
  |  Branch (122:11): [True: 0, False: 375]
  |  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|    375|      uri->scheme = coap_uri_scheme[i].scheme;
  128|    375|      uri->port = coap_uri_scheme[i].port;
  129|    375|      break;
  130|    375|    }
  131|  1.61k|  }
  132|    479|  if (i == COAP_URI_SCHEME_LAST) {
  ------------------
  |  Branch (132:7): [True: 104, False: 375]
  ------------------
  133|       |    /* scheme unknown */
  134|    104|    coap_log_err("%.*s URI scheme unknown\n", (int)(p - str_var), str_var);
  ------------------
  |  |  102|    104|#define coap_log_err(...) coap_log(COAP_LOG_ERR, __VA_ARGS__)
  |  |  ------------------
  |  |  |  |  290|    104|#define coap_log(level, ...) do { \
  |  |  |  |  291|    104|    if ((level) < (coap_get_log_level() + 1)) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (291:9): [True: 0, False: 104]
  |  |  |  |  ------------------
  |  |  |  |  292|    104|      coap_log_impl((level), __VA_ARGS__); \
  |  |  |  |  293|    104|  } while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (293:11): [Folded, False: 104]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  135|    104|    res = -1;
  136|    104|    goto error;
  137|    104|  }
  138|    375|  switch (uri->scheme) {
  139|    271|  case COAP_URI_SCHEME_COAP:
  ------------------
  |  Branch (139:3): [True: 271, False: 104]
  ------------------
  140|    271|    break;
  141|      1|  case COAP_URI_SCHEME_COAPS:
  ------------------
  |  Branch (141:3): [True: 1, False: 374]
  ------------------
  142|      1|    if (!coap_dtls_is_supported()) {
  ------------------
  |  Branch (142:9): [True: 0, False: 1]
  ------------------
  143|      0|      coap_log_err("coaps URI scheme not supported in this version of libcoap\n");
  ------------------
  |  |  102|      0|#define coap_log_err(...) coap_log(COAP_LOG_ERR, __VA_ARGS__)
  |  |  ------------------
  |  |  |  |  290|      0|#define coap_log(level, ...) do { \
  |  |  |  |  291|      0|    if ((level) < (coap_get_log_level() + 1)) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (291:9): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  292|      0|      coap_log_impl((level), __VA_ARGS__); \
  |  |  |  |  293|      0|  } while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (293:11): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  144|      0|      return -1;
  145|      0|    }
  146|      1|    break;
  147|      2|  case COAP_URI_SCHEME_COAP_TCP:
  ------------------
  |  Branch (147:3): [True: 2, False: 373]
  ------------------
  148|      2|    if (!coap_tcp_is_supported()) {
  ------------------
  |  Branch (148:9): [True: 0, False: 2]
  ------------------
  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|      2|    break;
  153|      5|  case COAP_URI_SCHEME_COAPS_TCP:
  ------------------
  |  Branch (153:3): [True: 5, False: 370]
  ------------------
  154|      5|    if (!coap_tls_is_supported()) {
  ------------------
  |  Branch (154:9): [True: 0, False: 5]
  ------------------
  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|      5|    break;
  159|      5|  case COAP_URI_SCHEME_COAP_WS:
  ------------------
  |  Branch (159:3): [True: 1, False: 374]
  ------------------
  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: 374]
  ------------------
  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|     92|  case COAP_URI_SCHEME_HTTP:
  ------------------
  |  Branch (171:3): [True: 92, False: 283]
  ------------------
  172|     94|  case COAP_URI_SCHEME_HTTPS:
  ------------------
  |  Branch (172:3): [True: 2, False: 373]
  ------------------
  173|       |    /* Not proxy, caught above.  For proxy, assume app is doing CoAP <> HTTP mapping. */
  174|     94|    break;
  175|      0|  case COAP_URI_SCHEME_LAST:
  ------------------
  |  Branch (175:3): [True: 0, False: 375]
  ------------------
  176|      0|  default:
  ------------------
  |  Branch (176:3): [True: 0, False: 375]
  ------------------
  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|    375|  }
  180|       |  /* skip :// */
  181|    375|  p += 3;
  182|    375|  len -= 3;
  183|       |
  184|       |  /* p points to beginning of Uri-Host */
  185|    375|  q = p;
  186|       |
  187|    375|  if (len && *p == '[') {
  ------------------
  |  Branch (187:7): [True: 367, False: 8]
  |  Branch (187:14): [True: 43, False: 324]
  ------------------
  188|       |    /* IPv6 address reference or Unix domain */
  189|     43|    ++p;
  190|     43|    ++q;
  191|     43|    --len;
  192|       |
  193|  7.02k|    while (len && *q != ']') {
  ------------------
  |  Branch (193:12): [True: 7.01k, False: 12]
  |  Branch (193:19): [True: 6.97k, False: 31]
  ------------------
  194|  6.97k|      ++q;
  195|  6.97k|      --len;
  196|  6.97k|    }
  197|       |
  198|     43|    if (!len || *q != ']' || p == q) {
  ------------------
  |  Branch (198:9): [True: 12, False: 31]
  |  Branch (198:17): [True: 0, False: 31]
  |  Branch (198:30): [True: 1, False: 30]
  ------------------
  199|     13|      res = -3;
  200|     13|      goto error;
  201|     13|    }
  202|       |
  203|     30|    if ((int)(q - p) > 255) {
  ------------------
  |  Branch (203:9): [True: 6, False: 24]
  ------------------
  204|      6|      coap_log_warn("Host name length too long (%d > 255)\n", (int)(q - p));
  ------------------
  |  |  108|      6|#define coap_log_warn(...) coap_log(COAP_LOG_WARN, __VA_ARGS__)
  |  |  ------------------
  |  |  |  |  290|      6|#define coap_log(level, ...) do { \
  |  |  |  |  291|      6|    if ((level) < (coap_get_log_level() + 1)) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (291:9): [True: 0, False: 6]
  |  |  |  |  ------------------
  |  |  |  |  292|      6|      coap_log_impl((level), __VA_ARGS__); \
  |  |  |  |  293|      6|  } while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (293:11): [Folded, False: 6]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  205|      6|      res = -6;
  206|      6|      goto error;
  207|      6|    }
  208|       |
  209|     24|    COAP_SET_STR(&uri->host, q - p, p);
  ------------------
  |  |   52|     24|#define COAP_SET_STR(st,l,v) { (st)->length = (l), (st)->s = (v); }
  ------------------
  210|     24|    ++q;
  211|     24|    --len;
  212|     24|#if COAP_AF_LLC_SUPPORT
  213|    332|  } else if ((len >= LLC_HOST_LEN) && strncmp((const char *)p, "llc[", 4) == 0) {
  ------------------
  |  |  178|    332|#define LLC_HOST_LEN (4 + HW_ADDRSTRLEN + 4)
  |  |  ------------------
  |  |  |  |  176|    332|#define HW_ADDRSTRLEN 17
  |  |  ------------------
  ------------------
  |  Branch (213:14): [True: 209, False: 123]
  |  Branch (213:39): [True: 119, False: 90]
  ------------------
  214|    119|    unsigned long sap = 0;
  215|       |
  216|    119|    is_llc = 1;
  217|       |
  218|  4.90k|    while (len && *q != ']') {
  ------------------
  |  Branch (218:12): [True: 4.90k, False: 9]
  |  Branch (218:19): [True: 4.79k, False: 110]
  ------------------
  219|  4.79k|      ++q;
  220|  4.79k|      --len;
  221|  4.79k|    }
  222|       |
  223|    119|    if (!len || *q != ']' || p == q) {
  ------------------
  |  Branch (223:9): [True: 9, False: 110]
  |  Branch (223:17): [True: 0, False: 110]
  |  Branch (223:30): [True: 0, False: 110]
  ------------------
  224|      9|      res = -7;
  225|      9|      goto error;
  226|      9|    }
  227|       |
  228|    110|    ++q;
  229|    110|    --len;
  230|       |
  231|    110|    if (!len || *q != ':') {
  ------------------
  |  Branch (231:9): [True: 2, False: 108]
  |  Branch (231:17): [True: 8, False: 100]
  ------------------
  232|     10|      coap_log_warn("LLC SAP missing in URI\n");
  ------------------
  |  |  108|     10|#define coap_log_warn(...) coap_log(COAP_LOG_WARN, __VA_ARGS__)
  |  |  ------------------
  |  |  |  |  290|     10|#define coap_log(level, ...) do { \
  |  |  |  |  291|     10|    if ((level) < (coap_get_log_level() + 1)) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (291:9): [True: 0, False: 10]
  |  |  |  |  ------------------
  |  |  |  |  292|     10|      coap_log_impl((level), __VA_ARGS__); \
  |  |  |  |  293|     10|  } while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (293:11): [Folded, False: 10]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  233|     10|      res = -7;
  234|     10|      goto error;
  235|     10|    }
  236|       |
  237|    100|    ++q;
  238|    100|    --len;
  239|       |
  240|  1.87k|    while (len && isxdigit(*q)) {
  ------------------
  |  Branch (240:12): [True: 1.83k, False: 43]
  |  Branch (240:19): [True: 1.77k, False: 57]
  ------------------
  241|  1.77k|      if (*q >= 'a' && *q <= 'f')
  ------------------
  |  Branch (241:11): [True: 761, False: 1.01k]
  |  Branch (241:24): [True: 761, False: 0]
  ------------------
  242|    761|        sap = sap * 16 + (*q - 'a' + 10);
  243|  1.01k|      else if (*q >= 'A' && *q <= 'F')
  ------------------
  |  Branch (243:16): [True: 707, False: 311]
  |  Branch (243:29): [True: 707, False: 0]
  ------------------
  244|    707|        sap = sap * 16 + (*q - 'A' + 10);
  245|       |
  246|  1.77k|      ++q;
  247|  1.77k|      --len;
  248|  1.77k|    }
  249|       |
  250|    100|    if (sap > UINT8_MAX) {
  ------------------
  |  Branch (250:9): [True: 88, False: 12]
  ------------------
  251|     88|      coap_log_warn("LLC SAP invalid (%lu > 255)\n", sap);
  ------------------
  |  |  108|     88|#define coap_log_warn(...) coap_log(COAP_LOG_WARN, __VA_ARGS__)
  |  |  ------------------
  |  |  |  |  290|     88|#define coap_log(level, ...) do { \
  |  |  |  |  291|     88|    if ((level) < (coap_get_log_level() + 1)) \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (291:9): [True: 0, False: 88]
  |  |  |  |  ------------------
  |  |  |  |  292|     88|      coap_log_impl((level), __VA_ARGS__); \
  |  |  |  |  293|     88|  } while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (293:11): [Folded, False: 88]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  252|     88|      res = -7;
  253|     88|      goto error;
  254|     88|    }
  255|       |
  256|     12|    COAP_SET_STR(&uri->host, q - p, p);
  ------------------
  |  |   52|     12|#define COAP_SET_STR(st,l,v) { (st)->length = (l), (st)->s = (v); }
  ------------------
  257|     12|#endif /* COAP_AF_LLC_SUPPORT */
  258|    213|  } else {
  259|       |    /* IPv4 address, FQDN or Unix domain socket */
  260|    213|    if (len >= 3 && p[0] == '%' && p[1] == '2' &&
  ------------------
  |  Branch (260:9): [True: 188, False: 25]
  |  Branch (260:21): [True: 30, False: 158]
  |  Branch (260:36): [True: 17, False: 13]
  ------------------
  261|     17|        (p[2] == 'F' || p[2] == 'f')) {
  ------------------
  |  Branch (261:10): [True: 1, False: 16]
  |  Branch (261:25): [True: 2, False: 14]
  ------------------
  262|       |      /* Unix domain definition */
  263|      3|      uri->port = 0;
  264|      3|      is_unix_domain = 1;
  265|      3|    }
  266|  7.78k|    while (len && *q != ':' && *q != '/' && *q != '?') {
  ------------------
  |  Branch (266:12): [True: 7.70k, False: 79]
  |  Branch (266:19): [True: 7.61k, False: 92]
  |  Branch (266:32): [True: 7.57k, False: 32]
  |  Branch (266:45): [True: 7.56k, False: 10]
  ------------------
  267|  7.56k|      ++q;
  268|  7.56k|      --len;
  269|  7.56k|    }
  270|       |
  271|    213|    if (p == q) {
  ------------------
  |  Branch (271:9): [True: 10, False: 203]
  ------------------
  272|     10|      res = -3;
  273|     10|      goto error;
  274|     10|    }
  275|       |
  276|    203|    if ((int)(q - p) > 255) {
  ------------------
  |  Branch (276:9): [True: 7, False: 196]
  ------------------
  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|    196|    COAP_SET_STR(&uri->host, q - p, p);
  ------------------
  |  |   52|    196|#define COAP_SET_STR(st,l,v) { (st)->length = (l), (st)->s = (v); }
  ------------------
  283|    196|  }
  284|       |
  285|       |  /* check for Uri-Port (invalid for Unix) */
  286|    232|  if (len && *q == ':') {
  ------------------
  |  Branch (286:7): [True: 158, False: 74]
  |  Branch (286:14): [True: 97, False: 61]
  ------------------
  287|     97|    if (is_unix_domain || is_llc) {
  ------------------
  |  Branch (287:9): [True: 1, False: 96]
  |  Branch (287:27): [True: 1, False: 95]
  ------------------
  288|      2|      res = -5;
  289|      2|      goto error;
  290|      2|    }
  291|     95|    p = ++q;
  292|     95|    --len;
  293|       |
  294|  1.32k|    while (len && isdigit(*q)) {
  ------------------
  |  Branch (294:12): [True: 1.27k, False: 47]
  |  Branch (294:19): [True: 1.22k, False: 48]
  ------------------
  295|  1.22k|      ++q;
  296|  1.22k|      --len;
  297|  1.22k|    }
  298|       |
  299|     95|    if (p < q) {                /* explicit port number given */
  ------------------
  |  Branch (299:9): [True: 62, False: 33]
  ------------------
  300|     62|      long uri_port = 0;
  301|       |
  302|  1.00k|      while ((p < q) && (uri_port <= UINT16_MAX))
  ------------------
  |  Branch (302:14): [True: 950, False: 54]
  |  Branch (302:25): [True: 942, False: 8]
  ------------------
  303|    942|        uri_port = uri_port * 10 + (*p++ - '0');
  304|       |
  305|       |      /* check if port number is in allowed range */
  306|     62|      if (uri_port > UINT16_MAX) {
  ------------------
  |  Branch (306:11): [True: 23, False: 39]
  ------------------
  307|     23|        coap_log_warn("Port number too big (%ld > 65535)\n", uri_port);
  ------------------
  |  |  108|     23|#define coap_log_warn(...) coap_log(COAP_LOG_WARN, __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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  308|     23|        res = -4;
  309|     23|        goto error;
  310|     23|      }
  311|       |
  312|     39|      uri->port = (uint16_t)uri_port;
  313|     39|    }
  314|     95|  }
  315|       |
  316|    207|path:                 /* q points just past the authority, or to a relative URI's leading '/' */
  317|       |
  318|    207|  if (!len)
  ------------------
  |  Branch (318:7): [True: 104, False: 103]
  ------------------
  319|    104|    goto end;
  320|       |
  321|    103|  if (*q == '/') {
  ------------------
  |  Branch (321:7): [True: 38, False: 65]
  ------------------
  322|     38|    p = ++q;
  323|     38|    --len;
  324|       |
  325|  6.32k|    while (len && *q != '?') {
  ------------------
  |  Branch (325:12): [True: 6.28k, False: 38]
  |  Branch (325:19): [True: 6.28k, False: 0]
  ------------------
  326|  6.28k|      ++q;
  327|  6.28k|      --len;
  328|  6.28k|    }
  329|       |
  330|     38|    if (p < q) {
  ------------------
  |  Branch (330:9): [True: 36, False: 2]
  ------------------
  331|     36|      COAP_SET_STR(&uri->path, q - p, p);
  ------------------
  |  |   52|     36|#define COAP_SET_STR(st,l,v) { (st)->length = (l), (st)->s = (v); }
  ------------------
  332|     36|    }
  333|     38|  }
  334|       |
  335|       |  /* Uri_Query */
  336|    103|  if (len && *q == '?') {
  ------------------
  |  Branch (336:7): [True: 65, False: 38]
  |  Branch (336:14): [True: 10, False: 55]
  ------------------
  337|     10|    ++q;
  338|     10|    --len;
  339|     10|    COAP_SET_STR(&uri->query, len, q);
  ------------------
  |  |   52|     10|#define COAP_SET_STR(st,l,v) { (st)->length = (l), (st)->s = (v); }
  ------------------
  340|     10|    len = 0;
  341|     10|  }
  342|       |
  343|    207|end:
  344|    207|  return len ? -1 : 0;
  ------------------
  |  Branch (344:10): [True: 55, False: 152]
  ------------------
  345|       |
  346|    328|error:
  347|    328|  return res;
  348|    103|}
coap_uri.c:is_unescaped_in_query:
 1103|   892k|is_unescaped_in_query(const uint8_t c) {
 1104|   892k|  return c != '&' && (is_unescaped_in_path(c) || c == '/' || c == '?');
  ------------------
  |  Branch (1104:10): [True: 892k, False: 396]
  |  Branch (1104:23): [True: 26.9k, False: 865k]
  |  Branch (1104:50): [True: 404, False: 864k]
  |  Branch (1104:62): [True: 128, False: 864k]
  ------------------
 1105|   892k|}
coap_uri.c:is_unescaped_in_path:
 1094|  2.57M|is_unescaped_in_path(const uint8_t c) {
 1095|  2.57M|  return (c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') ||
  ------------------
  |  Branch (1095:11): [True: 76.1k, False: 2.50M]
  |  Branch (1095:23): [True: 10.4k, False: 65.6k]
  |  Branch (1095:37): [True: 64.1k, False: 2.50M]
  |  Branch (1095:49): [True: 10.9k, False: 53.2k]
  ------------------
 1096|  2.55M|         (c >= '0' && c <= '9') || c == '-' || c == '.' || c == '_' ||
  ------------------
  |  Branch (1096:11): [True: 68.9k, False: 2.48M]
  |  Branch (1096:23): [True: 3.26k, False: 65.6k]
  |  Branch (1096:36): [True: 966, False: 2.55M]
  |  Branch (1096:48): [True: 1.38k, False: 2.54M]
  |  Branch (1096:60): [True: 804, False: 2.54M]
  ------------------
 1097|  2.54M|         c == '~' || c == '!' || c == '$' || c == '\'' || c == '(' ||
  ------------------
  |  Branch (1097:10): [True: 15.1k, False: 2.53M]
  |  Branch (1097:22): [True: 1.93k, False: 2.53M]
  |  Branch (1097:34): [True: 2.92k, False: 2.52M]
  |  Branch (1097:46): [True: 1.52k, False: 2.52M]
  |  Branch (1097:59): [True: 1.45k, False: 2.52M]
  ------------------
 1098|  2.52M|         c == ')' || c == '*' || c == '+' || c == ',' || c == ';' ||
  ------------------
  |  Branch (1098:10): [True: 1.43k, False: 2.52M]
  |  Branch (1098:22): [True: 5.67k, False: 2.51M]
  |  Branch (1098:34): [True: 11.7k, False: 2.50M]
  |  Branch (1098:46): [True: 1.21k, False: 2.50M]
  |  Branch (1098:58): [True: 1.20k, False: 2.50M]
  ------------------
 1099|  2.50M|         c=='=' || c==':' || c=='@' || c == '&';
  ------------------
  |  Branch (1099:10): [True: 6.09k, False: 2.49M]
  |  Branch (1099:20): [True: 1.58k, False: 2.49M]
  |  Branch (1099:30): [True: 1.86k, False: 2.49M]
  |  Branch (1099:40): [True: 1.23k, False: 2.49M]
  ------------------
 1100|  2.57M|}

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

