pack_json_state_fuzzer.c:flb_free:
  126|  1.54k|static inline void flb_free(void *ptr) {
  127|  1.54k|    free(ptr);
  128|  1.54k|}
flb_pack.c:flb_realloc:
  100|    851|{
  101|    851|    return realloc(ptr, size);
  102|    851|}
flb_pack.c:flb_malloc:
   67|  4.12k|void *flb_malloc(const size_t size) {
   68|       |
   69|  4.12k|#ifdef FLB_HAVE_TESTS_OSSFUZZ
   70|       |   // 1% chance of failure
   71|  4.12k|   if (flb_fuzz_get_probability(1)) {
  ------------------
  |  Branch (71:8): [True: 0, False: 4.12k]
  ------------------
   72|      0|     return NULL;
   73|      0|   }
   74|  4.12k|#endif
   75|       |
   76|  4.12k|    if (size == 0) {
  ------------------
  |  Branch (76:9): [True: 0, False: 4.12k]
  ------------------
   77|      0|        return NULL;
   78|      0|    }
   79|       |
   80|  4.12k|    return malloc(size);
   81|  4.12k|}
flb_pack.c:flb_fuzz_get_probability:
   56|  4.12k|static inline int flb_fuzz_get_probability(int val) {
   57|  4.12k|  flb_malloc_p += 1;
   58|  4.12k|  flb_malloc_p = flb_malloc_p % flb_malloc_mod;
   59|  4.12k|  if (val > flb_malloc_p) {
  ------------------
  |  Branch (59:7): [True: 0, False: 4.12k]
  ------------------
   60|      0|    return 1;
   61|      0|  }
   62|  4.12k|  return 0;
   63|  4.12k|}
flb_pack.c:flb_free:
  126|  4.12k|static inline void flb_free(void *ptr) {
  127|  4.12k|    free(ptr);
  128|  4.12k|}

jsmn_parse:
  269|  2.91k|                        jsmntok_t *tokens, const unsigned int num_tokens) {
  270|  2.91k|  int r;
  271|  2.91k|  int i;
  272|  2.91k|  jsmntok_t *token;
  273|  2.91k|  int count = parser->toknext;
  274|       |
  275|   444k|  for (; parser->pos < len && js[parser->pos] != '\0'; parser->pos++) {
  ------------------
  |  Branch (275:10): [True: 442k, False: 1.63k]
  |  Branch (275:31): [True: 442k, False: 2]
  ------------------
  276|   442k|    char c;
  277|   442k|    jsmntype_t type;
  278|       |
  279|   442k|    c = js[parser->pos];
  280|   442k|    switch (c) {
  281|  6.07k|    case '{':
  ------------------
  |  Branch (281:5): [True: 6.07k, False: 436k]
  ------------------
  282|   117k|    case '[':
  ------------------
  |  Branch (282:5): [True: 111k, False: 331k]
  ------------------
  283|   117k|      count++;
  284|   117k|      if (tokens == NULL) {
  ------------------
  |  Branch (284:11): [True: 0, False: 117k]
  ------------------
  285|      0|        break;
  286|      0|      }
  287|   117k|      token = jsmn_alloc_token(parser, tokens, num_tokens);
  288|   117k|      if (token == NULL) {
  ------------------
  |  Branch (288:11): [True: 296, False: 117k]
  ------------------
  289|    296|        return JSMN_ERROR_NOMEM;
  290|    296|      }
  291|   117k|      if (parser->toksuper != -1) {
  ------------------
  |  Branch (291:11): [True: 113k, False: 3.94k]
  ------------------
  292|   113k|        jsmntok_t *t = &tokens[parser->toksuper];
  293|   113k|#ifdef JSMN_STRICT
  294|       |        /* In strict mode an object or array can't become a key */
  295|   113k|        if (t->type == JSMN_OBJECT) {
  ------------------
  |  Branch (295:13): [True: 14, False: 113k]
  ------------------
  296|     14|          return JSMN_ERROR_INVAL;
  297|     14|        }
  298|   113k|#endif
  299|   113k|        t->size++;
  300|   113k|#ifdef JSMN_PARENT_LINKS
  301|   113k|        token->parent = parser->toksuper;
  302|   113k|#endif
  303|   113k|      }
  304|   117k|      token->type = (c == '{' ? JSMN_OBJECT : JSMN_ARRAY);
  ------------------
  |  Branch (304:22): [True: 6.05k, False: 111k]
  ------------------
  305|   117k|      token->start = parser->pos;
  306|   117k|      parser->toksuper = parser->toknext - 1;
  307|   117k|      break;
  308|  6.62k|    case '}':
  ------------------
  |  Branch (308:5): [True: 6.62k, False: 436k]
  ------------------
  309|  22.4k|    case ']':
  ------------------
  |  Branch (309:5): [True: 15.8k, False: 427k]
  ------------------
  310|  22.4k|      if (tokens == NULL) {
  ------------------
  |  Branch (310:11): [True: 0, False: 22.4k]
  ------------------
  311|      0|        break;
  312|      0|      }
  313|  22.4k|      type = (c == '}' ? JSMN_OBJECT : JSMN_ARRAY);
  ------------------
  |  Branch (313:15): [True: 6.62k, False: 15.8k]
  ------------------
  314|  22.4k|#ifdef JSMN_PARENT_LINKS
  315|  22.4k|      if (parser->toknext < 1) {
  ------------------
  |  Branch (315:11): [True: 2, False: 22.4k]
  ------------------
  316|      2|        return JSMN_ERROR_INVAL;
  317|      2|      }
  318|  22.4k|      token = &tokens[parser->toknext - 1];
  319|  55.2k|      for (;;) {
  320|  55.2k|        if (token->start != -1 && token->end == -1) {
  ------------------
  |  Branch (320:13): [True: 55.2k, False: 0]
  |  Branch (320:35): [True: 21.0k, False: 34.1k]
  ------------------
  321|  21.0k|          if (token->type != type) {
  ------------------
  |  Branch (321:15): [True: 4, False: 20.9k]
  ------------------
  322|      4|            return JSMN_ERROR_INVAL;
  323|      4|          }
  324|  20.9k|          token->end = parser->pos + 1;
  325|  20.9k|          parser->toksuper = token->parent;
  326|  20.9k|          break;
  327|  21.0k|        }
  328|  34.1k|        if (token->parent == -1) {
  ------------------
  |  Branch (328:13): [True: 1.43k, False: 32.7k]
  ------------------
  329|  1.43k|          if (token->type != type || parser->toksuper == -1) {
  ------------------
  |  Branch (329:15): [True: 11, False: 1.42k]
  |  Branch (329:38): [True: 8, False: 1.41k]
  ------------------
  330|     19|            return JSMN_ERROR_INVAL;
  331|     19|          }
  332|  1.41k|          break;
  333|  1.43k|        }
  334|  32.7k|        token = &tokens[token->parent];
  335|  32.7k|      }
  336|       |#else
  337|       |      for (i = parser->toknext - 1; i >= 0; i--) {
  338|       |        token = &tokens[i];
  339|       |        if (token->start != -1 && token->end == -1) {
  340|       |          if (token->type != type) {
  341|       |            return JSMN_ERROR_INVAL;
  342|       |          }
  343|       |          parser->toksuper = -1;
  344|       |          token->end = parser->pos + 1;
  345|       |          break;
  346|       |        }
  347|       |      }
  348|       |      /* Error if unmatched closing bracket */
  349|       |      if (i == -1) {
  350|       |        return JSMN_ERROR_INVAL;
  351|       |      }
  352|       |      for (; i >= 0; i--) {
  353|       |        token = &tokens[i];
  354|       |        if (token->start != -1 && token->end == -1) {
  355|       |          parser->toksuper = i;
  356|       |          break;
  357|       |        }
  358|       |      }
  359|       |#endif
  360|  22.4k|      break;
  361|  22.4k|    case '\"':
  ------------------
  |  Branch (361:5): [True: 16.6k, False: 426k]
  ------------------
  362|  16.6k|      r = jsmn_parse_string(parser, js, len, tokens, num_tokens);
  363|  16.6k|      if (r < 0) {
  ------------------
  |  Branch (363:11): [True: 290, False: 16.3k]
  ------------------
  364|    290|        return r;
  365|    290|      }
  366|  16.3k|      count++;
  367|  16.3k|      if (parser->toksuper != -1 && tokens != NULL) {
  ------------------
  |  Branch (367:11): [True: 13.7k, False: 2.61k]
  |  Branch (367:37): [True: 13.7k, False: 0]
  ------------------
  368|  13.7k|        tokens[parser->toksuper].size++;
  369|  13.7k|      }
  370|  16.3k|      break;
  371|  2.79k|    case '\t':
  ------------------
  |  Branch (371:5): [True: 2.79k, False: 440k]
  ------------------
  372|  7.00k|    case '\r':
  ------------------
  |  Branch (372:5): [True: 4.21k, False: 438k]
  ------------------
  373|  7.95k|    case '\n':
  ------------------
  |  Branch (373:5): [True: 950, False: 441k]
  ------------------
  374|   133k|    case ' ':
  ------------------
  |  Branch (374:5): [True: 125k, False: 317k]
  ------------------
  375|   133k|      break;
  376|  1.11k|    case ':':
  ------------------
  |  Branch (376:5): [True: 1.11k, False: 441k]
  ------------------
  377|  1.11k|      parser->toksuper = parser->toknext - 1;
  378|  1.11k|      break;
  379|  4.30k|    case ',':
  ------------------
  |  Branch (379:5): [True: 4.30k, False: 438k]
  ------------------
  380|  4.30k|      if (tokens != NULL && parser->toksuper != -1 &&
  ------------------
  |  Branch (380:11): [True: 4.30k, False: 0]
  |  Branch (380:29): [True: 1.41k, False: 2.89k]
  ------------------
  381|  4.30k|          tokens[parser->toksuper].type != JSMN_ARRAY &&
  ------------------
  |  Branch (381:11): [True: 719, False: 692]
  ------------------
  382|  4.30k|          tokens[parser->toksuper].type != JSMN_OBJECT) {
  ------------------
  |  Branch (382:11): [True: 524, False: 195]
  ------------------
  383|    524|#ifdef JSMN_PARENT_LINKS
  384|    524|        parser->toksuper = tokens[parser->toksuper].parent;
  385|       |#else
  386|       |        for (i = parser->toknext - 1; i >= 0; i--) {
  387|       |          if (tokens[i].type == JSMN_ARRAY || tokens[i].type == JSMN_OBJECT) {
  388|       |            if (tokens[i].start != -1 && tokens[i].end == -1) {
  389|       |              parser->toksuper = i;
  390|       |              break;
  391|       |            }
  392|       |          }
  393|       |        }
  394|       |#endif
  395|    524|      }
  396|  4.30k|      break;
  397|      0|#ifdef JSMN_STRICT
  398|       |    /* In strict mode primitives are: numbers and booleans */
  399|  2.76k|    case '-':
  ------------------
  |  Branch (399:5): [True: 2.76k, False: 440k]
  ------------------
  400|  15.3k|    case '0':
  ------------------
  |  Branch (400:5): [True: 12.5k, False: 430k]
  ------------------
  401|   119k|    case '1':
  ------------------
  |  Branch (401:5): [True: 104k, False: 338k]
  ------------------
  402|   126k|    case '2':
  ------------------
  |  Branch (402:5): [True: 6.86k, False: 436k]
  ------------------
  403|   127k|    case '3':
  ------------------
  |  Branch (403:5): [True: 835, False: 442k]
  ------------------
  404|   129k|    case '4':
  ------------------
  |  Branch (404:5): [True: 1.43k, False: 441k]
  ------------------
  405|   129k|    case '5':
  ------------------
  |  Branch (405:5): [True: 615, False: 442k]
  ------------------
  406|   130k|    case '6':
  ------------------
  |  Branch (406:5): [True: 968, False: 441k]
  ------------------
  407|   131k|    case '7':
  ------------------
  |  Branch (407:5): [True: 1.06k, False: 441k]
  ------------------
  408|   132k|    case '8':
  ------------------
  |  Branch (408:5): [True: 616, False: 442k]
  ------------------
  409|   141k|    case '9':
  ------------------
  |  Branch (409:5): [True: 8.66k, False: 434k]
  ------------------
  410|   142k|    case 't':
  ------------------
  |  Branch (410:5): [True: 1.13k, False: 441k]
  ------------------
  411|   143k|    case 'f':
  ------------------
  |  Branch (411:5): [True: 1.14k, False: 441k]
  ------------------
  412|   147k|    case 'n':
  ------------------
  |  Branch (412:5): [True: 3.79k, False: 439k]
  ------------------
  413|       |      /* And they must not be keys of the object */
  414|   147k|      if (tokens != NULL && parser->toksuper != -1) {
  ------------------
  |  Branch (414:11): [True: 147k, False: 0]
  |  Branch (414:29): [True: 30.1k, False: 116k]
  ------------------
  415|  30.1k|        const jsmntok_t *t = &tokens[parser->toksuper];
  416|  30.1k|        if (t->type == JSMN_OBJECT ||
  ------------------
  |  Branch (416:13): [True: 1, False: 30.1k]
  ------------------
  417|  30.1k|            (t->type == JSMN_STRING && t->size != 0)) {
  ------------------
  |  Branch (417:14): [True: 233, False: 29.9k]
  |  Branch (417:40): [True: 5, False: 228]
  ------------------
  418|      6|          return JSMN_ERROR_INVAL;
  419|      6|        }
  420|  30.1k|      }
  421|       |#else
  422|       |    /* In non-strict mode every unquoted value is a primitive */
  423|       |    default:
  424|       |#endif
  425|   147k|      r = jsmn_parse_primitive(parser, js, len, tokens, num_tokens);
  426|   147k|      if (r < 0) {
  ------------------
  |  Branch (426:11): [True: 645, False: 146k]
  ------------------
  427|    645|        return r;
  428|    645|      }
  429|   146k|      count++;
  430|   146k|      if (parser->toksuper != -1 && tokens != NULL) {
  ------------------
  |  Branch (430:11): [True: 30.0k, False: 116k]
  |  Branch (430:37): [True: 30.0k, False: 0]
  ------------------
  431|  30.0k|        tokens[parser->toksuper].size++;
  432|  30.0k|      }
  433|   146k|      break;
  434|       |
  435|      0|#ifdef JSMN_STRICT
  436|       |    /* Unexpected char in strict mode */
  437|      3|    default:
  ------------------
  |  Branch (437:5): [True: 3, False: 442k]
  ------------------
  438|      3|      return JSMN_ERROR_INVAL;
  439|   442k|#endif
  440|   442k|    }
  441|   442k|  }
  442|       |
  443|  1.63k|  if (tokens != NULL) {
  ------------------
  |  Branch (443:7): [True: 1.63k, False: 0]
  ------------------
  444|   168k|    for (i = parser->toknext - 1; i >= 0; i--) {
  ------------------
  |  Branch (444:35): [True: 167k, False: 1.46k]
  ------------------
  445|       |      /* Unmatched opened object or array */
  446|   167k|      if (tokens[i].start != -1 && tokens[i].end == -1) {
  ------------------
  |  Branch (446:11): [True: 167k, False: 0]
  |  Branch (446:36): [True: 167, False: 167k]
  ------------------
  447|    167|        return JSMN_ERROR_PART;
  448|    167|      }
  449|   167k|    }
  450|  1.63k|  }
  451|       |
  452|  1.46k|  return count;
  453|  1.63k|}
jsmn_init:
  459|  2.06k|JSMN_API void jsmn_init(jsmn_parser *parser) {
  460|  2.06k|  parser->pos = 0;
  461|  2.06k|  parser->toknext = 0;
  462|  2.06k|  parser->toksuper = -1;
  463|  2.06k|}
jsmn.c:jsmn_alloc_token:
  107|   281k|                                   const size_t num_tokens) {
  108|   281k|  jsmntok_t *tok;
  109|   281k|  if (parser->toknext >= num_tokens) {
  ------------------
  |  Branch (109:7): [True: 851, False: 280k]
  ------------------
  110|    851|    return NULL;
  111|    851|  }
  112|   280k|  tok = &tokens[parser->toknext++];
  113|   280k|  tok->start = tok->end = -1;
  114|   280k|  tok->size = 0;
  115|   280k|#ifdef JSMN_PARENT_LINKS
  116|   280k|  tok->parent = -1;
  117|   280k|#endif
  118|   280k|  return tok;
  119|   281k|}
jsmn.c:jsmn_parse_string:
  195|  16.6k|                             const size_t num_tokens) {
  196|  16.6k|  jsmntok_t *token;
  197|       |
  198|  16.6k|  int start = parser->pos;
  199|       |
  200|  16.6k|  parser->pos++;
  201|       |
  202|       |  /* Skip starting quote */
  203|   115k|  for (; parser->pos < len && js[parser->pos] != '\0'; parser->pos++) {
  ------------------
  |  Branch (203:10): [True: 115k, False: 169]
  |  Branch (203:31): [True: 115k, False: 4]
  ------------------
  204|   115k|    char c = js[parser->pos];
  205|       |
  206|       |    /* Quote: end of string */
  207|   115k|    if (c == '\"') {
  ------------------
  |  Branch (207:9): [True: 16.4k, False: 99.2k]
  ------------------
  208|  16.4k|      if (tokens == NULL) {
  ------------------
  |  Branch (208:11): [True: 0, False: 16.4k]
  ------------------
  209|      0|        return 0;
  210|      0|      }
  211|  16.4k|      token = jsmn_alloc_token(parser, tokens, num_tokens);
  212|  16.4k|      if (token == NULL) {
  ------------------
  |  Branch (212:11): [True: 84, False: 16.3k]
  ------------------
  213|     84|        parser->pos = start;
  214|     84|        return JSMN_ERROR_NOMEM;
  215|     84|      }
  216|  16.3k|      jsmn_fill_token(token, JSMN_STRING, start + 1, parser->pos);
  217|  16.3k|#ifdef JSMN_PARENT_LINKS
  218|  16.3k|      token->parent = parser->toksuper;
  219|  16.3k|#endif
  220|  16.3k|      return 0;
  221|  16.4k|    }
  222|       |
  223|       |    /* Backslash: Quoted symbol expected */
  224|  99.2k|    if (c == '\\' && parser->pos + 1 < len) {
  ------------------
  |  Branch (224:9): [True: 8.54k, False: 90.7k]
  |  Branch (224:22): [True: 8.54k, False: 3]
  ------------------
  225|  8.54k|      int i;
  226|  8.54k|      parser->pos++;
  227|  8.54k|      switch (js[parser->pos]) {
  228|       |      /* Allowed escaped symbols */
  229|    735|      case '\"':
  ------------------
  |  Branch (229:7): [True: 735, False: 7.80k]
  ------------------
  230|  2.33k|      case '/':
  ------------------
  |  Branch (230:7): [True: 1.59k, False: 6.94k]
  ------------------
  231|  2.88k|      case '\\':
  ------------------
  |  Branch (231:7): [True: 552, False: 7.99k]
  ------------------
  232|  3.36k|      case 'b':
  ------------------
  |  Branch (232:7): [True: 477, False: 8.06k]
  ------------------
  233|  3.90k|      case 'f':
  ------------------
  |  Branch (233:7): [True: 542, False: 8.00k]
  ------------------
  234|  4.46k|      case 'r':
  ------------------
  |  Branch (234:7): [True: 565, False: 7.97k]
  ------------------
  235|  5.02k|      case 'n':
  ------------------
  |  Branch (235:7): [True: 558, False: 7.98k]
  ------------------
  236|  5.51k|      case 't':
  ------------------
  |  Branch (236:7): [True: 490, False: 8.05k]
  ------------------
  237|  5.51k|        break;
  238|       |      /* Allows escaped symbol \uXXXX */
  239|  3.02k|      case 'u':
  ------------------
  |  Branch (239:7): [True: 3.02k, False: 5.51k]
  ------------------
  240|  3.02k|        parser->pos++;
  241|  14.9k|        for (i = 0; i < 4 && parser->pos < len && js[parser->pos] != '\0';
  ------------------
  |  Branch (241:21): [True: 11.9k, False: 2.96k]
  |  Branch (241:30): [True: 11.9k, False: 33]
  |  Branch (241:51): [True: 11.9k, False: 1]
  ------------------
  242|  11.9k|             i++) {
  243|       |          /* If it isn't a hex character we have an error */
  244|  11.9k|          if (!((js[parser->pos] >= 48 && js[parser->pos] <= 57) ||   /* 0-9 */
  ------------------
  |  Branch (244:18): [True: 11.8k, False: 16]
  |  Branch (244:43): [True: 3.70k, False: 8.18k]
  ------------------
  245|  11.9k|                (js[parser->pos] >= 65 && js[parser->pos] <= 70) ||   /* A-F */
  ------------------
  |  Branch (245:18): [True: 8.18k, False: 21]
  |  Branch (245:43): [True: 4.50k, False: 3.67k]
  ------------------
  246|  11.9k|                (js[parser->pos] >= 97 && js[parser->pos] <= 102))) { /* a-f */
  ------------------
  |  Branch (246:18): [True: 3.67k, False: 27]
  |  Branch (246:43): [True: 3.66k, False: 5]
  ------------------
  247|     32|            parser->pos = start;
  248|     32|            return JSMN_ERROR_INVAL;
  249|     32|          }
  250|  11.8k|          parser->pos++;
  251|  11.8k|        }
  252|  2.99k|        parser->pos--;
  253|  2.99k|        break;
  254|       |      /* Unexpected symbol */
  255|      1|      default:
  ------------------
  |  Branch (255:7): [True: 1, False: 8.54k]
  ------------------
  256|      1|        parser->pos = start;
  257|      1|        return JSMN_ERROR_INVAL;
  258|  8.54k|      }
  259|  8.54k|    }
  260|  99.2k|  }
  261|    173|  parser->pos = start;
  262|    173|  return JSMN_ERROR_PART;
  263|  16.6k|}
jsmn.c:jsmn_fill_token:
  125|   162k|                            const int start, const int end) {
  126|   162k|  token->type = type;
  127|   162k|  token->start = start;
  128|   162k|  token->end = end;
  129|   162k|  token->size = 0;
  130|   162k|}
jsmn.c:jsmn_parse_primitive:
  137|   147k|                                const size_t num_tokens) {
  138|   147k|  jsmntok_t *token;
  139|   147k|  int start;
  140|       |
  141|   147k|  start = parser->pos;
  142|       |
  143|   443k|  for (; parser->pos < len && js[parser->pos] != '\0'; parser->pos++) {
  ------------------
  |  Branch (143:10): [True: 443k, False: 164]
  |  Branch (143:31): [True: 443k, False: 1]
  ------------------
  144|   443k|    switch (js[parser->pos]) {
  145|       |#ifndef JSMN_STRICT
  146|       |    /* In strict mode primitive must be followed by "," or "}" or "]" */
  147|       |    case ':':
  148|       |#endif
  149|  2.52k|    case '\t':
  ------------------
  |  Branch (149:5): [True: 2.52k, False: 441k]
  ------------------
  150|  5.99k|    case '\r':
  ------------------
  |  Branch (150:5): [True: 3.46k, False: 440k]
  ------------------
  151|  6.74k|    case '\n':
  ------------------
  |  Branch (151:5): [True: 755, False: 442k]
  ------------------
  152|   132k|    case ' ':
  ------------------
  |  Branch (152:5): [True: 125k, False: 318k]
  ------------------
  153|   135k|    case ',':
  ------------------
  |  Branch (153:5): [True: 3.22k, False: 440k]
  ------------------
  154|   146k|    case ']':
  ------------------
  |  Branch (154:5): [True: 11.2k, False: 432k]
  ------------------
  155|   146k|    case '}':
  ------------------
  |  Branch (155:5): [True: 268, False: 443k]
  ------------------
  156|   146k|      goto found;
  157|   296k|    default:
  ------------------
  |  Branch (157:5): [True: 296k, False: 146k]
  ------------------
  158|       |                   /* to quiet a warning from gcc*/
  159|   296k|      break;
  160|   443k|    }
  161|   296k|    if (js[parser->pos] < 32 || js[parser->pos] >= 127) {
  ------------------
  |  Branch (161:9): [True: 8, False: 296k]
  |  Branch (161:33): [True: 1, False: 296k]
  ------------------
  162|      9|      parser->pos = start;
  163|      9|      return JSMN_ERROR_INVAL;
  164|      9|    }
  165|   296k|  }
  166|    165|#ifdef JSMN_STRICT
  167|       |  /* In strict mode primitive must be followed by a comma/object/array */
  168|    165|  parser->pos = start;
  169|    165|  return JSMN_ERROR_PART;
  170|      0|#endif
  171|       |
  172|   146k|found:
  173|   146k|  if (tokens == NULL) {
  ------------------
  |  Branch (173:7): [True: 0, False: 146k]
  ------------------
  174|      0|    parser->pos--;
  175|      0|    return 0;
  176|      0|  }
  177|   146k|  token = jsmn_alloc_token(parser, tokens, num_tokens);
  178|   146k|  if (token == NULL) {
  ------------------
  |  Branch (178:7): [True: 471, False: 146k]
  ------------------
  179|    471|    parser->pos = start;
  180|    471|    return JSMN_ERROR_NOMEM;
  181|    471|  }
  182|   146k|  jsmn_fill_token(token, JSMN_PRIMITIVE, start, parser->pos);
  183|   146k|#ifdef JSMN_PARENT_LINKS
  184|   146k|  token->parent = parser->toksuper;
  185|   146k|#endif
  186|   146k|  parser->pos--;
  187|   146k|  return 0;
  188|   146k|}

flb_pack.c:msgpack_packer_init:
  131|  1.54k|{
  132|  1.54k|    pk->data = data;
  133|  1.54k|    pk->callback = callback;
  134|  1.54k|}

flb_pack.c:msgpack_pack_false:
  710|  1.12k|{
  711|  1.12k|    static const unsigned char d = 0xc2;
  712|  1.12k|    msgpack_pack_append_buffer(x, &d, 1);
  ------------------
  |  |  126|  1.12k|    return (*(user)->callback)((user)->data, (const char*)buf, len)
  ------------------
  713|  1.12k|}
flb_pack.c:msgpack_pack_true:
  704|    897|{
  705|    897|    static const unsigned char d = 0xc3;
  706|    897|    msgpack_pack_append_buffer(x, &d, 1);
  ------------------
  |  |  126|    897|    return (*(user)->callback)((user)->data, (const char*)buf, len)
  ------------------
  707|    897|}
flb_pack.c:msgpack_pack_nil:
  693|  3.67k|{
  694|  3.67k|    static const unsigned char d = 0xc0;
  695|  3.67k|    msgpack_pack_append_buffer(x, &d, 1);
  ------------------
  |  |  126|  3.67k|    return (*(user)->callback)((user)->data, (const char*)buf, len)
  ------------------
  696|  3.67k|}
flb_pack.c:msgpack_pack_int64:
  376|  14.7k|{
  377|  14.7k|    msgpack_pack_real_int64(x, d);
  ------------------
  |  |  221|  14.7k|#define msgpack_pack_real_int64(x, d) \
  |  |  222|  14.7k|do { \
  |  |  223|  14.7k|    if(d < -(1LL<<5)) { \
  |  |  ------------------
  |  |  |  Branch (223:8): [True: 1.06k, False: 13.6k]
  |  |  ------------------
  |  |  224|  1.06k|        if(d < -(1LL<<15)) { \
  |  |  ------------------
  |  |  |  Branch (224:12): [True: 631, False: 432]
  |  |  ------------------
  |  |  225|    631|            if(d < -(1LL<<31)) { \
  |  |  ------------------
  |  |  |  Branch (225:16): [True: 328, False: 303]
  |  |  ------------------
  |  |  226|    328|                /* signed 64 */ \
  |  |  227|    328|                unsigned char buf[9]; \
  |  |  228|    328|                buf[0] = 0xd3; _msgpack_store64(&buf[1], d); \
  |  |  ------------------
  |  |  |  |  186|    328|    do { uint64_t val = _msgpack_be64(num); memcpy(to, &val, 8); } while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  |  142|    328|#        define _msgpack_be64(x) bswap_64(x)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (186:74): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  229|    328|                msgpack_pack_append_buffer(x, buf, 9); \
  |  |  ------------------
  |  |  |  |  126|    328|    return (*(user)->callback)((user)->data, (const char*)buf, len)
  |  |  ------------------
  |  |  230|    328|            } else { \
  |  |  231|    303|                /* signed 32 */ \
  |  |  232|    303|                unsigned char buf[5]; \
  |  |  233|    303|                buf[0] = 0xd2; _msgpack_store32(&buf[1], (int32_t)d); \
  |  |  ------------------
  |  |  |  |  184|    303|    do { uint32_t val = _msgpack_be32(num); memcpy(to, &val, 4); } while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  |  124|    303|#       define _msgpack_be32(x) ntohl((uint32_t)x)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (184:74): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  234|    303|                msgpack_pack_append_buffer(x, buf, 5); \
  |  |  ------------------
  |  |  |  |  126|    303|    return (*(user)->callback)((user)->data, (const char*)buf, len)
  |  |  ------------------
  |  |  235|    303|            } \
  |  |  236|    631|        } else { \
  |  |  237|    432|            if(d < -(1<<7)) { \
  |  |  ------------------
  |  |  |  Branch (237:16): [True: 224, False: 208]
  |  |  ------------------
  |  |  238|    224|                /* signed 16 */ \
  |  |  239|    224|                unsigned char buf[3]; \
  |  |  240|    224|                buf[0] = 0xd1; _msgpack_store16(&buf[1], (int16_t)d); \
  |  |  ------------------
  |  |  |  |  182|    224|    do { uint16_t val = _msgpack_be16(num); memcpy(to, &val, 2); } while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  |  110|    224|#       define _msgpack_be16(x) ntohs((uint16_t)x)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (182:74): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  241|    224|                msgpack_pack_append_buffer(x, buf, 3); \
  |  |  ------------------
  |  |  |  |  126|    224|    return (*(user)->callback)((user)->data, (const char*)buf, len)
  |  |  ------------------
  |  |  242|    224|            } else { \
  |  |  243|    208|                /* signed 8 */ \
  |  |  244|    208|                unsigned char buf[2] = {0xd0, TAKE8_64(d)}; \
  |  |  ------------------
  |  |  |  |   22|    208|#define TAKE8_64(d) ((uint8_t*)&d)[0]
  |  |  ------------------
  |  |  245|    208|                msgpack_pack_append_buffer(x, buf, 2); \
  |  |  ------------------
  |  |  |  |  126|    208|    return (*(user)->callback)((user)->data, (const char*)buf, len)
  |  |  ------------------
  |  |  246|    208|            } \
  |  |  247|    432|        } \
  |  |  248|  13.6k|    } else if(d < (1<<7)) { \
  |  |  ------------------
  |  |  |  Branch (248:15): [True: 12.3k, False: 1.34k]
  |  |  ------------------
  |  |  249|  12.3k|        /* fixnum */ \
  |  |  250|  12.3k|        msgpack_pack_append_buffer(x, &TAKE8_64(d), 1); \
  |  |  ------------------
  |  |  |  |  126|  12.3k|    return (*(user)->callback)((user)->data, (const char*)buf, len)
  |  |  ------------------
  |  |  251|  12.3k|    } else { \
  |  |  252|  1.34k|        if(d < (1LL<<16)) { \
  |  |  ------------------
  |  |  |  Branch (252:12): [True: 656, False: 688]
  |  |  ------------------
  |  |  253|    656|            if(d < (1<<8)) { \
  |  |  ------------------
  |  |  |  Branch (253:16): [True: 286, False: 370]
  |  |  ------------------
  |  |  254|    286|                /* unsigned 8 */ \
  |  |  255|    286|                unsigned char buf[2] = {0xcc, TAKE8_64(d)}; \
  |  |  ------------------
  |  |  |  |   22|    286|#define TAKE8_64(d) ((uint8_t*)&d)[0]
  |  |  ------------------
  |  |  256|    286|                msgpack_pack_append_buffer(x, buf, 2); \
  |  |  ------------------
  |  |  |  |  126|    286|    return (*(user)->callback)((user)->data, (const char*)buf, len)
  |  |  ------------------
  |  |  257|    370|            } else { \
  |  |  258|    370|                /* unsigned 16 */ \
  |  |  259|    370|                unsigned char buf[3]; \
  |  |  260|    370|                buf[0] = 0xcd; _msgpack_store16(&buf[1], (uint16_t)d); \
  |  |  ------------------
  |  |  |  |  182|    370|    do { uint16_t val = _msgpack_be16(num); memcpy(to, &val, 2); } while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  |  110|    370|#       define _msgpack_be16(x) ntohs((uint16_t)x)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (182:74): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  261|    370|                msgpack_pack_append_buffer(x, buf, 3); \
  |  |  ------------------
  |  |  |  |  126|    370|    return (*(user)->callback)((user)->data, (const char*)buf, len)
  |  |  ------------------
  |  |  262|    370|            } \
  |  |  263|    688|        } else { \
  |  |  264|    688|            if(d < (1LL<<32)) { \
  |  |  ------------------
  |  |  |  Branch (264:16): [True: 432, False: 256]
  |  |  ------------------
  |  |  265|    432|                /* unsigned 32 */ \
  |  |  266|    432|                unsigned char buf[5]; \
  |  |  267|    432|                buf[0] = 0xce; _msgpack_store32(&buf[1], (uint32_t)d); \
  |  |  ------------------
  |  |  |  |  184|    432|    do { uint32_t val = _msgpack_be32(num); memcpy(to, &val, 4); } while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  |  124|    432|#       define _msgpack_be32(x) ntohl((uint32_t)x)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (184:74): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  268|    432|                msgpack_pack_append_buffer(x, buf, 5); \
  |  |  ------------------
  |  |  |  |  126|    432|    return (*(user)->callback)((user)->data, (const char*)buf, len)
  |  |  ------------------
  |  |  269|    432|            } else { \
  |  |  270|    256|                /* unsigned 64 */ \
  |  |  271|    256|                unsigned char buf[9]; \
  |  |  272|    256|                buf[0] = 0xcf; _msgpack_store64(&buf[1], d); \
  |  |  ------------------
  |  |  |  |  186|    256|    do { uint64_t val = _msgpack_be64(num); memcpy(to, &val, 8); } while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  |  142|    256|#        define _msgpack_be64(x) bswap_64(x)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (186:74): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  273|    256|                msgpack_pack_append_buffer(x, buf, 9); \
  |  |  ------------------
  |  |  |  |  126|    256|    return (*(user)->callback)((user)->data, (const char*)buf, len)
  |  |  ------------------
  |  |  274|    256|            } \
  |  |  275|    688|        } \
  |  |  276|  1.34k|    } \
  |  |  277|  14.7k|} while(0)
  |  |  ------------------
  |  |  |  Branch (277:9): [Folded - Ignored]
  |  |  ------------------
  ------------------
  378|  14.7k|}
flb_pack.c:msgpack_pack_array:
  721|  14.0k|{
  722|  14.0k|    if(n < 16) {
  ------------------
  |  Branch (722:8): [True: 13.4k, False: 622]
  ------------------
  723|  13.4k|        unsigned char d = 0x90 | (uint8_t)n;
  724|  13.4k|        msgpack_pack_append_buffer(x, &d, 1);
  ------------------
  |  |  126|  13.4k|    return (*(user)->callback)((user)->data, (const char*)buf, len)
  ------------------
  725|  13.4k|    } else if(n < 65536) {
  ------------------
  |  Branch (725:15): [True: 622, False: 0]
  ------------------
  726|    622|        unsigned char buf[3];
  727|    622|        buf[0] = 0xdc; _msgpack_store16(&buf[1], (uint16_t)n);
  ------------------
  |  |  182|    622|    do { uint16_t val = _msgpack_be16(num); memcpy(to, &val, 2); } while(0)
  |  |  ------------------
  |  |  |  |  110|    622|#       define _msgpack_be16(x) ntohs((uint16_t)x)
  |  |  ------------------
  |  |  |  Branch (182:74): [Folded - Ignored]
  |  |  ------------------
  ------------------
  728|    622|        msgpack_pack_append_buffer(x, buf, 3);
  ------------------
  |  |  126|    622|    return (*(user)->callback)((user)->data, (const char*)buf, len)
  ------------------
  729|    622|    } else {
  730|      0|        unsigned char buf[5];
  731|      0|        buf[0] = 0xdd; _msgpack_store32(&buf[1], (uint32_t)n);
  ------------------
  |  |  184|      0|    do { uint32_t val = _msgpack_be32(num); memcpy(to, &val, 4); } while(0)
  |  |  ------------------
  |  |  |  |  124|      0|#       define _msgpack_be32(x) ntohl((uint32_t)x)
  |  |  ------------------
  |  |  |  Branch (184:74): [Folded - Ignored]
  |  |  ------------------
  ------------------
  732|      0|        msgpack_pack_append_buffer(x, buf, 5);
  ------------------
  |  |  126|      0|    return (*(user)->callback)((user)->data, (const char*)buf, len)
  ------------------
  733|      0|    }
  734|  14.0k|}
flb_pack.c:msgpack_pack_map:
  742|  4.81k|{
  743|  4.81k|    if(n < 16) {
  ------------------
  |  Branch (743:8): [True: 4.70k, False: 112]
  ------------------
  744|  4.70k|        unsigned char d = 0x80 | (uint8_t)n;
  745|  4.70k|        msgpack_pack_append_buffer(x, &TAKE8_8(d), 1);
  ------------------
  |  |  126|  4.70k|    return (*(user)->callback)((user)->data, (const char*)buf, len)
  ------------------
  746|  4.70k|    } else if(n < 65536) {
  ------------------
  |  Branch (746:15): [True: 112, False: 0]
  ------------------
  747|    112|        unsigned char buf[3];
  748|    112|        buf[0] = 0xde; _msgpack_store16(&buf[1], (uint16_t)n);
  ------------------
  |  |  182|    112|    do { uint16_t val = _msgpack_be16(num); memcpy(to, &val, 2); } while(0)
  |  |  ------------------
  |  |  |  |  110|    112|#       define _msgpack_be16(x) ntohs((uint16_t)x)
  |  |  ------------------
  |  |  |  Branch (182:74): [Folded - Ignored]
  |  |  ------------------
  ------------------
  749|    112|        msgpack_pack_append_buffer(x, buf, 3);
  ------------------
  |  |  126|    112|    return (*(user)->callback)((user)->data, (const char*)buf, len)
  ------------------
  750|    112|    } else {
  751|      0|        unsigned char buf[5];
  752|      0|        buf[0] = 0xdf; _msgpack_store32(&buf[1], (uint32_t)n);
  ------------------
  |  |  184|      0|    do { uint32_t val = _msgpack_be32(num); memcpy(to, &val, 4); } while(0)
  |  |  ------------------
  |  |  |  |  124|      0|#       define _msgpack_be32(x) ntohl((uint32_t)x)
  |  |  ------------------
  |  |  |  Branch (184:74): [Folded - Ignored]
  |  |  ------------------
  ------------------
  753|      0|        msgpack_pack_append_buffer(x, buf, 5);
  ------------------
  |  |  126|      0|    return (*(user)->callback)((user)->data, (const char*)buf, len)
  ------------------
  754|      0|    }
  755|  4.81k|}
flb_pack.c:msgpack_pack_str:
  763|  13.7k|{
  764|  13.7k|    if(l < 32) {
  ------------------
  |  Branch (764:8): [True: 13.2k, False: 481]
  ------------------
  765|  13.2k|        unsigned char d = 0xa0 | (uint8_t)l;
  766|  13.2k|        msgpack_pack_append_buffer(x, &TAKE8_8(d), 1);
  ------------------
  |  |  126|  13.2k|    return (*(user)->callback)((user)->data, (const char*)buf, len)
  ------------------
  767|  13.2k|    } else if(l < 256) {
  ------------------
  |  Branch (767:15): [True: 385, False: 96]
  ------------------
  768|    385|        unsigned char buf[2];
  769|    385|        buf[0] = 0xd9; buf[1] = (uint8_t)l;
  770|    385|        msgpack_pack_append_buffer(x, buf, 2);
  ------------------
  |  |  126|    385|    return (*(user)->callback)((user)->data, (const char*)buf, len)
  ------------------
  771|    385|    } else if(l < 65536) {
  ------------------
  |  Branch (771:15): [True: 96, False: 0]
  ------------------
  772|     96|        unsigned char buf[3];
  773|     96|        buf[0] = 0xda; _msgpack_store16(&buf[1], (uint16_t)l);
  ------------------
  |  |  182|     96|    do { uint16_t val = _msgpack_be16(num); memcpy(to, &val, 2); } while(0)
  |  |  ------------------
  |  |  |  |  110|     96|#       define _msgpack_be16(x) ntohs((uint16_t)x)
  |  |  ------------------
  |  |  |  Branch (182:74): [Folded - Ignored]
  |  |  ------------------
  ------------------
  774|     96|        msgpack_pack_append_buffer(x, buf, 3);
  ------------------
  |  |  126|     96|    return (*(user)->callback)((user)->data, (const char*)buf, len)
  ------------------
  775|     96|    } else {
  776|      0|        unsigned char buf[5];
  777|      0|        buf[0] = 0xdb; _msgpack_store32(&buf[1], (uint32_t)l);
  ------------------
  |  |  184|      0|    do { uint32_t val = _msgpack_be32(num); memcpy(to, &val, 4); } while(0)
  |  |  ------------------
  |  |  |  |  124|      0|#       define _msgpack_be32(x) ntohl((uint32_t)x)
  |  |  ------------------
  |  |  |  Branch (184:74): [Folded - Ignored]
  |  |  ------------------
  ------------------
  778|      0|        msgpack_pack_append_buffer(x, buf, 5);
  ------------------
  |  |  126|      0|    return (*(user)->callback)((user)->data, (const char*)buf, len)
  ------------------
  779|      0|    }
  780|  13.7k|}
flb_pack.c:msgpack_pack_str_body:
  783|  13.7k|{
  784|  13.7k|    msgpack_pack_append_buffer(x, (const unsigned char*)b, l);
  ------------------
  |  |  126|  13.7k|    return (*(user)->callback)((user)->data, (const char*)buf, len)
  ------------------
  785|  13.7k|}
flb_pack.c:msgpack_pack_double:
  672|   123k|{
  673|   123k|    unsigned char buf[9];
  674|   123k|    union { double f; uint64_t i; } mem;
  675|   123k|    mem.f = d;
  676|   123k|    buf[0] = 0xcb;
  677|       |#if defined(TARGET_OS_IPHONE)
  678|       |    // ok
  679|       |#elif defined(__arm__) && !(__ARM_EABI__) // arm-oabi
  680|       |    // https://github.com/msgpack/msgpack-perl/pull/1
  681|       |    mem.i = (mem.i & 0xFFFFFFFFUL) << 32UL | (mem.i >> 32UL);
  682|       |#endif
  683|   123k|    _msgpack_store64(&buf[1], mem.i);
  ------------------
  |  |  186|   123k|    do { uint64_t val = _msgpack_be64(num); memcpy(to, &val, 8); } while(0)
  |  |  ------------------
  |  |  |  |  142|   123k|#        define _msgpack_be64(x) bswap_64(x)
  |  |  ------------------
  |  |  |  Branch (186:74): [Folded - Ignored]
  |  |  ------------------
  ------------------
  684|   123k|    msgpack_pack_append_buffer(x, buf, 9);
  ------------------
  |  |  126|   123k|    return (*(user)->callback)((user)->data, (const char*)buf, len)
  ------------------
  685|   123k|}

flb_pack.c:msgpack_sbuffer_init:
   35|  1.54k|{
   36|  1.54k|    memset(sbuf, 0, sizeof(msgpack_sbuffer));
   37|  1.54k|}
flb_pack.c:msgpack_sbuffer_write:
   61|   190k|{
   62|   190k|    msgpack_sbuffer* sbuf = (msgpack_sbuffer*)data;
   63|       |
   64|   190k|    assert(buf || len == 0);
   65|   190k|    if(!buf) return 0;
  ------------------
  |  Branch (65:8): [True: 0, False: 190k]
  ------------------
   66|       |
   67|   190k|    if(sbuf->alloc - sbuf->size < len) {
  ------------------
  |  Branch (67:8): [True: 1.58k, False: 188k]
  ------------------
   68|  1.58k|        void* tmp;
   69|  1.58k|        size_t nsize = (sbuf->alloc) ?
  ------------------
  |  Branch (69:24): [True: 37, False: 1.54k]
  ------------------
   70|  1.54k|                sbuf->alloc * 2 : MSGPACK_SBUFFER_INIT_SIZE;
  ------------------
  |  |   57|  1.54k|#define MSGPACK_SBUFFER_INIT_SIZE 8192
  ------------------
   71|       |
   72|  1.58k|        while(nsize < sbuf->size + len) {
  ------------------
  |  Branch (72:15): [True: 0, False: 1.58k]
  ------------------
   73|      0|            size_t tmp_nsize = nsize * 2;
   74|      0|            if (tmp_nsize <= nsize) {
  ------------------
  |  Branch (74:17): [True: 0, False: 0]
  ------------------
   75|      0|                nsize = sbuf->size + len;
   76|      0|                break;
   77|      0|            }
   78|      0|            nsize = tmp_nsize;
   79|      0|        }
   80|       |
   81|  1.58k|        tmp = realloc(sbuf->data, nsize);
   82|  1.58k|        if(!tmp) { return -1; }
  ------------------
  |  Branch (82:12): [True: 0, False: 1.58k]
  ------------------
   83|       |
   84|  1.58k|        sbuf->data = (char*)tmp;
   85|  1.58k|        sbuf->alloc = nsize;
   86|  1.58k|    }
   87|       |
   88|   190k|    memcpy(sbuf->data + sbuf->size, buf, len);
   89|   190k|    sbuf->size += len;
   90|       |
   91|   190k|    return 0;
   92|   190k|}

flb_json_tokenise:
   55|  2.06k|{
   56|  2.06k|    int ret;
   57|  2.06k|    int new_tokens = 256;
   58|  2.06k|    size_t old_size;
   59|  2.06k|    size_t new_size;
   60|  2.06k|    void *tmp;
   61|       |
   62|  2.06k|    ret = jsmn_parse(&state->parser, js, len,
   63|  2.06k|                     state->tokens, state->tokens_size);
   64|  2.91k|    while (ret == JSMN_ERROR_NOMEM) {
  ------------------
  |  Branch (64:12): [True: 851, False: 2.06k]
  ------------------
   65|       |        /* Get current size of the array in bytes */
   66|    851|        old_size = state->tokens_size * sizeof(jsmntok_t);
   67|       |
   68|       |        /* New size: add capacity for new 256 entries */
   69|    851|        new_size = old_size + (sizeof(jsmntok_t) * new_tokens);
   70|       |
   71|    851|        tmp = flb_realloc(state->tokens, new_size);
   72|    851|        if (!tmp) {
  ------------------
  |  Branch (72:13): [True: 0, False: 851]
  ------------------
   73|      0|            flb_errno();
  ------------------
  |  |  232|      0|#define flb_errno() flb_errno_print(errno, __FLB_FILENAME__, __LINE__)
  ------------------
   74|      0|            return -1;
   75|      0|        }
   76|    851|        state->tokens = tmp;
   77|    851|        state->tokens_size += new_tokens;
   78|       |
   79|    851|        ret = jsmn_parse(&state->parser, js, len,
   80|    851|                         state->tokens, state->tokens_size);
   81|    851|    }
   82|       |
   83|  2.06k|    if (ret == JSMN_ERROR_INVAL) {
  ------------------
  |  Branch (83:9): [True: 90, False: 1.97k]
  ------------------
   84|     90|        return FLB_ERR_JSON_INVAL;
  ------------------
  |  |   45|     90|#define FLB_ERR_JSON_INVAL           -501
  ------------------
   85|     90|    }
   86|       |
   87|  1.97k|    if (ret == JSMN_ERROR_PART) {
  ------------------
  |  Branch (87:9): [True: 505, False: 1.46k]
  ------------------
   88|       |        /* This is a partial JSON message, just stop */
   89|    505|        flb_trace("[json tokenise] incomplete");
  ------------------
  |  |  223|    505|#define flb_trace(fmt, ...)  do {} while(0)
  |  |  ------------------
  |  |  |  Branch (223:42): [Folded - Ignored]
  |  |  ------------------
  ------------------
   90|    505|        return FLB_ERR_JSON_PART;
  ------------------
  |  |   46|    505|#define FLB_ERR_JSON_PART            -502
  ------------------
   91|    505|    }
   92|       |
   93|  1.46k|    state->tokens_count += ret;
   94|  1.46k|    return 0;
   95|  1.97k|}
flb_pack_state_init:
  310|  2.06k|{
  311|  2.06k|    int tokens = 256;
  312|  2.06k|    size_t size = 256;
  313|       |
  314|  2.06k|    jsmn_init(&s->parser);
  315|       |
  316|  2.06k|    size = sizeof(jsmntok_t) * tokens;
  317|  2.06k|    s->tokens = flb_malloc(size);
  318|  2.06k|    if (!s->tokens) {
  ------------------
  |  Branch (318:9): [True: 0, False: 2.06k]
  ------------------
  319|      0|        flb_errno();
  ------------------
  |  |  232|      0|#define flb_errno() flb_errno_print(errno, __FLB_FILENAME__, __LINE__)
  ------------------
  320|      0|        return -1;
  321|      0|    }
  322|  2.06k|    s->tokens_size   = tokens;
  323|  2.06k|    s->tokens_count  = 0;
  324|  2.06k|    s->last_byte     = 0;
  325|  2.06k|    s->multiple      = FLB_FALSE;
  ------------------
  |  |   25|  2.06k|#define FLB_FALSE  0
  ------------------
  326|       |
  327|  2.06k|    s->buf_data = flb_malloc(size);
  328|  2.06k|    if (!s->buf_data) {
  ------------------
  |  Branch (328:9): [True: 0, False: 2.06k]
  ------------------
  329|      0|        flb_errno();
  ------------------
  |  |  232|      0|#define flb_errno() flb_errno_print(errno, __FLB_FILENAME__, __LINE__)
  ------------------
  330|      0|        flb_free(s->tokens);
  331|      0|        s->tokens = NULL;
  332|      0|        return -1;
  333|      0|    }
  334|  2.06k|    s->buf_size = size;
  335|  2.06k|    s->buf_len = 0;
  336|       |
  337|  2.06k|    return 0;
  338|  2.06k|}
flb_pack_state_reset:
  341|  2.06k|{
  342|  2.06k|    flb_free(s->tokens);
  343|  2.06k|    s->tokens = NULL;
  344|  2.06k|    s->tokens_size  = 0;
  345|  2.06k|    s->tokens_count = 0;
  346|  2.06k|    s->last_byte    = 0;
  347|  2.06k|    s->buf_size     = 0;
  348|  2.06k|    flb_free(s->buf_data);
  349|  2.06k|    s->buf_data = NULL;
  350|  2.06k|}
flb_pack_json_state:
  362|  2.06k|{
  363|  2.06k|    int ret;
  364|  2.06k|    int out;
  365|  2.06k|    int delim = 0;
  366|  2.06k|    int last =  0;
  367|  2.06k|    int records;
  368|  2.06k|    char *buf;
  369|  2.06k|    jsmntok_t *t;
  370|       |
  371|  2.06k|    ret = flb_json_tokenise(js, len, state);
  372|  2.06k|    state->multiple = FLB_TRUE;
  ------------------
  |  |   26|  2.06k|#define FLB_TRUE   !FLB_FALSE
  |  |  ------------------
  |  |  |  |   25|  2.06k|#define FLB_FALSE  0
  |  |  ------------------
  ------------------
  373|  2.06k|    if (ret == FLB_ERR_JSON_PART && state->multiple == FLB_TRUE) {
  ------------------
  |  |   46|  4.12k|#define FLB_ERR_JSON_PART            -502
  ------------------
                  if (ret == FLB_ERR_JSON_PART && state->multiple == FLB_TRUE) {
  ------------------
  |  |   26|    505|#define FLB_TRUE   !FLB_FALSE
  |  |  ------------------
  |  |  |  |   25|    505|#define FLB_FALSE  0
  |  |  ------------------
  ------------------
  |  Branch (373:9): [True: 505, False: 1.55k]
  |  Branch (373:37): [True: 505, False: 0]
  ------------------
  374|       |        /*
  375|       |         * If the caller enabled 'multiple' flag, it means that the incoming
  376|       |         * JSON message may have multiple messages concatenated and likely
  377|       |         * the last one is only incomplete.
  378|       |         *
  379|       |         * The following routine aims to determinate how many JSON messages
  380|       |         * are OK in the array of tokens, if any, process them and adjust
  381|       |         * the JSMN context/buffers.
  382|       |         */
  383|       |
  384|       |        /*
  385|       |         * jsmn_parse updates jsmn_parser members. (state->parser)
  386|       |         * A member 'toknext' points next incomplete object token.
  387|       |         * We use toknext - 1 as an index of last member of complete JSON.
  388|       |         */
  389|    505|        int i;
  390|    505|        int found = 0;
  391|       |
  392|    505|        if (state->parser.toknext == 0) {
  ------------------
  |  Branch (392:13): [True: 175, False: 330]
  ------------------
  393|    175|            return ret;
  394|    175|        }
  395|       |
  396|  92.1k|        for (i = (int)state->parser.toknext - 1; i >= 1; i--) {
  ------------------
  |  Branch (396:50): [True: 91.9k, False: 201]
  ------------------
  397|  91.9k|            t = &state->tokens[i];
  398|       |
  399|  91.9k|            if (t->parent == -1 && (t->end != 0)) {
  ------------------
  |  Branch (399:17): [True: 129, False: 91.8k]
  |  Branch (399:36): [True: 129, False: 0]
  ------------------
  400|    129|                found++;
  401|    129|                delim = i;
  402|    129|                break;
  403|    129|            }
  404|  91.9k|        }
  405|       |
  406|    330|        if (found == 0) {
  ------------------
  |  Branch (406:13): [True: 201, False: 129]
  ------------------
  407|    201|            return ret; /* FLB_ERR_JSON_PART */
  408|    201|        }
  409|    129|        state->tokens_count += delim;
  410|    129|    }
  411|  1.55k|    else if (ret != 0) {
  ------------------
  |  Branch (411:14): [True: 90, False: 1.46k]
  ------------------
  412|     90|        return ret;
  413|     90|    }
  414|       |
  415|  1.59k|    if (state->tokens_count == 0 || state->tokens == NULL) {
  ------------------
  |  Branch (415:9): [True: 49, False: 1.54k]
  |  Branch (415:37): [True: 0, False: 1.54k]
  ------------------
  416|     49|        state->last_byte = last;
  417|     49|        return FLB_ERR_JSON_INVAL;
  ------------------
  |  |   45|     49|#define FLB_ERR_JSON_INVAL           -501
  ------------------
  418|     49|    }
  419|       |
  420|  1.54k|    buf = tokens_to_msgpack(state, js, &out, &last, &records);
  421|  1.54k|    if (!buf) {
  ------------------
  |  Branch (421:9): [True: 0, False: 1.54k]
  ------------------
  422|      0|        return -1;
  423|      0|    }
  424|       |
  425|  1.54k|    *size = out;
  426|  1.54k|    *buffer = buf;
  427|  1.54k|    state->last_byte = last;
  428|       |
  429|  1.54k|    return 0;
  430|  1.54k|}
flb_pack.c:tokens_to_msgpack:
  154|  1.54k|{
  155|  1.54k|    int i;
  156|  1.54k|    int flen;
  157|  1.54k|    int arr_size;
  158|  1.54k|    int records = 0;
  159|  1.54k|    const char *p;
  160|  1.54k|    char *buf;
  161|  1.54k|    const jsmntok_t *t;
  162|  1.54k|    msgpack_packer pck;
  163|  1.54k|    msgpack_sbuffer sbuf;
  164|  1.54k|    jsmntok_t *tokens;
  165|       |
  166|  1.54k|    tokens = state->tokens;
  167|  1.54k|    arr_size = state->tokens_count;
  168|       |
  169|  1.54k|    if (arr_size == 0) {
  ------------------
  |  Branch (169:9): [True: 0, False: 1.54k]
  ------------------
  170|      0|        return NULL;
  171|      0|    }
  172|       |
  173|       |    /* initialize buffers */
  174|  1.54k|    msgpack_sbuffer_init(&sbuf);
  175|  1.54k|    msgpack_packer_init(&pck, &sbuf, msgpack_sbuffer_write);
  176|       |
  177|   177k|    for (i = 0; i < arr_size ; i++) {
  ------------------
  |  Branch (177:17): [True: 176k, False: 1.54k]
  ------------------
  178|   176k|        t = &tokens[i];
  179|       |
  180|   176k|        if (t->start == -1 || t->end == -1 || (t->start == 0 && t->end == 0)) {
  ------------------
  |  Branch (180:13): [True: 0, False: 176k]
  |  Branch (180:31): [True: 0, False: 176k]
  |  Branch (180:48): [True: 1.18k, False: 175k]
  |  Branch (180:65): [True: 0, False: 1.18k]
  ------------------
  181|      0|            break;
  182|      0|        }
  183|       |
  184|   176k|        if (t->parent == -1) {
  ------------------
  |  Branch (184:13): [True: 122k, False: 53.9k]
  ------------------
  185|   122k|            *last_byte = t->end;
  186|   122k|            records++;
  187|   122k|        }
  188|       |
  189|   176k|        flen = (t->end - t->start);
  190|   176k|        switch (t->type) {
  ------------------
  |  Branch (190:17): [True: 0, False: 176k]
  ------------------
  191|  4.81k|        case JSMN_OBJECT:
  ------------------
  |  Branch (191:9): [True: 4.81k, False: 171k]
  ------------------
  192|  4.81k|            msgpack_pack_map(&pck, t->size);
  193|  4.81k|            break;
  194|  14.0k|        case JSMN_ARRAY:
  ------------------
  |  Branch (194:9): [True: 14.0k, False: 162k]
  ------------------
  195|  14.0k|            msgpack_pack_array(&pck, t->size);
  196|  14.0k|            break;
  197|  13.7k|        case JSMN_STRING:
  ------------------
  |  Branch (197:9): [True: 13.7k, False: 162k]
  ------------------
  198|  13.7k|            pack_string_token(state, js + t->start, flen, &pck);
  199|  13.7k|            break;
  200|   143k|        case JSMN_PRIMITIVE:
  ------------------
  |  Branch (200:9): [True: 143k, False: 32.6k]
  ------------------
  201|   143k|            p = js + t->start;
  202|   143k|            if (*p == 'f') {
  ------------------
  |  Branch (202:17): [True: 1.12k, False: 142k]
  ------------------
  203|  1.12k|                msgpack_pack_false(&pck);
  204|  1.12k|            }
  205|   142k|            else if (*p == 't') {
  ------------------
  |  Branch (205:22): [True: 897, False: 141k]
  ------------------
  206|    897|                msgpack_pack_true(&pck);
  207|    897|            }
  208|   141k|            else if (*p == 'n') {
  ------------------
  |  Branch (208:22): [True: 3.67k, False: 138k]
  ------------------
  209|  3.67k|                msgpack_pack_nil(&pck);
  210|  3.67k|            }
  211|   138k|            else {
  212|   138k|                if (is_float(p, flen)) {
  ------------------
  |  Branch (212:21): [True: 123k, False: 14.7k]
  ------------------
  213|   123k|                    msgpack_pack_double(&pck, atof(p));
  214|   123k|                }
  215|  14.7k|                else {
  216|  14.7k|                    msgpack_pack_int64(&pck, atoll(p));
  217|  14.7k|                }
  218|   138k|            }
  219|   143k|            break;
  220|      0|        case JSMN_UNDEFINED:
  ------------------
  |  Branch (220:9): [True: 0, False: 176k]
  ------------------
  221|      0|            msgpack_sbuffer_destroy(&sbuf);
  222|      0|            return NULL;
  223|   176k|        }
  224|   176k|    }
  225|       |
  226|  1.54k|    *out_size = sbuf.size;
  227|  1.54k|    *out_records = records;
  228|  1.54k|    buf = sbuf.data;
  229|       |
  230|  1.54k|    return buf;
  231|  1.54k|}
flb_pack.c:pack_string_token:
  119|  13.7k|{
  120|  13.7k|    int s;
  121|  13.7k|    int out_len;
  122|  13.7k|    char *tmp;
  123|  13.7k|    char *out_buf;
  124|       |
  125|  13.7k|    if (state->buf_size < len + 1) {
  ------------------
  |  Branch (125:9): [True: 0, False: 13.7k]
  ------------------
  126|      0|        s = len + 1;
  127|      0|        tmp = flb_realloc(state->buf_data, s);
  128|      0|        if (!tmp) {
  ------------------
  |  Branch (128:13): [True: 0, False: 0]
  ------------------
  129|      0|            flb_errno();
  ------------------
  |  |  232|      0|#define flb_errno() flb_errno_print(errno, __FLB_FILENAME__, __LINE__)
  ------------------
  130|      0|            return -1;
  131|      0|        }
  132|      0|        else {
  133|      0|            state->buf_data = tmp;
  134|      0|            state->buf_size = s;
  135|      0|        }
  136|      0|    }
  137|  13.7k|    out_buf = state->buf_data;
  138|       |
  139|       |    /* Always decode any UTF-8 or special characters */
  140|  13.7k|    out_len = flb_unescape_string_utf8(str, len, out_buf);
  141|       |
  142|       |    /* Pack decoded text */
  143|  13.7k|    msgpack_pack_str(pck, out_len);
  144|  13.7k|    msgpack_pack_str_body(pck, out_buf, out_len);
  145|       |
  146|  13.7k|    return out_len;
  147|  13.7k|}
flb_pack.c:is_float:
   98|   138k|{
   99|   138k|    const char *end = buf + len;
  100|   138k|    const char *p = buf;
  101|       |
  102|   313k|    while (p <= end) {
  ------------------
  |  Branch (102:12): [True: 298k, False: 14.7k]
  ------------------
  103|   298k|        if ((*p == 'e' || *p == 'E') && p < end && (*(p + 1) == '-' || *(p + 1) == '+')) {
  ------------------
  |  Branch (103:14): [True: 587, False: 298k]
  |  Branch (103:27): [True: 211, False: 298k]
  |  Branch (103:41): [True: 798, False: 0]
  |  Branch (103:53): [True: 208, False: 590]
  |  Branch (103:72): [True: 5, False: 585]
  ------------------
  104|    213|            return 1;
  105|    213|        }
  106|   298k|        else if (*p == '.') {
  ------------------
  |  Branch (106:18): [True: 123k, False: 175k]
  ------------------
  107|   123k|            return 1;
  108|   123k|        }
  109|   175k|        p++;
  110|   175k|    }
  111|       |
  112|  14.7k|    return 0;
  113|   138k|}

flb_unescape_string_utf8:
  128|  13.7k|{
  129|  13.7k|    uint32_t ch;
  130|  13.7k|    char temp[4];
  131|  13.7k|    const char *end;
  132|  13.7k|    const char *next;
  133|  13.7k|                int size;
  134|       |
  135|       |
  136|  13.7k|    int count_out = 0;
  137|  13.7k|    int count_in = 0;
  138|  13.7k|    int esc_in = 0;
  139|  13.7k|    int esc_out = 0;
  140|       |
  141|  13.7k|    end = in_buf + sz;
  142|   105k|    while (in_buf < end && *in_buf && count_in < sz) {
  ------------------
  |  Branch (142:12): [True: 91.8k, False: 13.7k]
  |  Branch (142:28): [True: 91.8k, False: 0]
  |  Branch (142:39): [True: 91.8k, False: 0]
  ------------------
  143|  91.8k|        next = in_buf + 1;
  144|  91.8k|        if (next < end && *in_buf == '\\') {
  ------------------
  |  Branch (144:13): [True: 90.9k, False: 916]
  |  Branch (144:27): [True: 4.82k, False: 86.1k]
  ------------------
  145|  4.82k|            esc_in = 2;
  146|  4.82k|            switch (*next) {
  147|    526|            case '"':
  ------------------
  |  Branch (147:13): [True: 526, False: 4.29k]
  ------------------
  148|    526|                ch = '"';
  149|    526|                break;
  150|      0|            case '\'':
  ------------------
  |  Branch (150:13): [True: 0, False: 4.82k]
  ------------------
  151|      0|                ch = '\'';
  152|      0|                break;
  153|    345|            case '\\':
  ------------------
  |  Branch (153:13): [True: 345, False: 4.48k]
  ------------------
  154|    345|                ch = '\\';
  155|    345|                break;
  156|    371|            case '/':
  ------------------
  |  Branch (156:13): [True: 371, False: 4.45k]
  ------------------
  157|    371|                ch = '/';
  158|    371|                break;
  159|    303|            case 'n':
  ------------------
  |  Branch (159:13): [True: 303, False: 4.52k]
  ------------------
  160|    303|                ch = '\n';
  161|    303|                break;
  162|    275|            case 'b':
  ------------------
  |  Branch (162:13): [True: 275, False: 4.55k]
  ------------------
  163|    275|                ch = '\b';
  164|    275|                break;
  165|    228|            case 't':
  ------------------
  |  Branch (165:13): [True: 228, False: 4.59k]
  ------------------
  166|    228|                ch = '\t';
  167|    228|                break;
  168|    343|            case 'f':
  ------------------
  |  Branch (168:13): [True: 343, False: 4.48k]
  ------------------
  169|    343|                ch = '\f';
  170|    343|                break;
  171|    354|            case 'r':
  ------------------
  |  Branch (171:13): [True: 354, False: 4.47k]
  ------------------
  172|    354|                ch = '\r';
  173|    354|                break;
  174|  2.08k|            default:
  ------------------
  |  Branch (174:13): [True: 2.08k, False: 2.74k]
  ------------------
  175|  2.08k|                size = end - next;
  176|  2.08k|                if (size > 0) {
  ------------------
  |  Branch (176:21): [True: 2.08k, False: 0]
  ------------------
  177|  2.08k|                    esc_in = u8_read_escape_sequence(next, size, &ch) + 1;
  178|  2.08k|                }
  179|      0|                else {
  180|       |                    /* because char is unsigned char by default on arm, so we need to do a explicit conversion */
  181|      0|                    ch = (uint32_t) (signed char) *in_buf;
  182|      0|                    esc_in = 1;
  183|      0|                }
  184|  4.82k|            }
  185|  4.82k|        }
  186|  87.0k|        else {
  187|       |            /* explicit convert char to signed char */
  188|  87.0k|            ch = (uint32_t) (signed char) *in_buf;
  189|  87.0k|            esc_in = 1;
  190|  87.0k|        }
  191|       |
  192|  91.8k|        in_buf += esc_in;
  193|  91.8k|        count_in += esc_in;
  194|       |
  195|  91.8k|        esc_out = u8_wc_toutf8(temp, ch);
  196|  91.8k|        if (esc_out > sz-count_out) {
  ------------------
  |  Branch (196:13): [True: 0, False: 91.8k]
  ------------------
  197|      0|            flb_error("Crossing over string boundary");
  ------------------
  |  |  170|      0|    if (flb_log_check(FLB_LOG_ERROR))                                \
  |  |  ------------------
  |  |  |  |   40|      0|#define FLB_LOG_ERROR   1
  |  |  ------------------
  |  |  |  Branch (170:9): [True: 0, False: 0]
  |  |  ------------------
  |  |  171|      0|        flb_log_print(FLB_LOG_ERROR, NULL, 0, fmt, ##__VA_ARGS__)
  |  |  ------------------
  |  |  |  |   40|      0|#define FLB_LOG_ERROR   1
  |  |  ------------------
  ------------------
  198|      0|            break;
  199|      0|        }
  200|       |
  201|  91.8k|        if (esc_out == 0) {
  ------------------
  |  Branch (201:13): [True: 21.8k, False: 70.0k]
  ------------------
  202|  21.8k|            out_buf[count_out] = ch;
  203|  21.8k|            esc_out = 1;
  204|  21.8k|        }
  205|  70.0k|        else if (esc_out == 1) {
  ------------------
  |  Branch (205:18): [True: 67.9k, False: 2.08k]
  ------------------
  206|  67.9k|            out_buf[count_out] = (char) temp[0];
  207|  67.9k|        }
  208|  2.08k|        else {
  209|  2.08k|            memcpy(&out_buf[count_out], temp, esc_out);
  210|  2.08k|        }
  211|  91.8k|        count_out += esc_out;
  212|  91.8k|    }
  213|  13.7k|    if (count_in < sz) {
  ------------------
  |  Branch (213:9): [True: 0, False: 13.7k]
  ------------------
  214|      0|        flb_error("Not at boundary but still NULL terminating : %d - '%s'", sz, in_buf);
  ------------------
  |  |  170|      0|    if (flb_log_check(FLB_LOG_ERROR))                                \
  |  |  ------------------
  |  |  |  |   40|      0|#define FLB_LOG_ERROR   1
  |  |  ------------------
  |  |  |  Branch (170:9): [True: 0, False: 0]
  |  |  ------------------
  |  |  171|      0|        flb_log_print(FLB_LOG_ERROR, NULL, 0, fmt, ##__VA_ARGS__)
  |  |  ------------------
  |  |  |  |   40|      0|#define FLB_LOG_ERROR   1
  |  |  ------------------
  ------------------
  215|      0|    }
  216|  13.7k|    out_buf[count_out] = '\0';
  217|  13.7k|    return count_out;
  218|  13.7k|}
flb_unescape.c:u8_read_escape_sequence:
   70|  2.08k|{
   71|  2.08k|    uint32_t ch;
   72|  2.08k|    char digs[9]="\0\0\0\0\0\0\0\0";
   73|  2.08k|    int dno=0, i=1;
   74|       |
   75|  2.08k|    ch = (uint32_t)str[0];    /* take literal character */
   76|       |
   77|  2.08k|    if (str[0] == 'n')
  ------------------
  |  Branch (77:9): [True: 0, False: 2.08k]
  ------------------
   78|      0|        ch = L'\n';
   79|  2.08k|    else if (str[0] == 't')
  ------------------
  |  Branch (79:14): [True: 0, False: 2.08k]
  ------------------
   80|      0|        ch = L'\t';
   81|  2.08k|    else if (str[0] == 'r')
  ------------------
  |  Branch (81:14): [True: 0, False: 2.08k]
  ------------------
   82|      0|        ch = L'\r';
   83|  2.08k|    else if (str[0] == 'b')
  ------------------
  |  Branch (83:14): [True: 0, False: 2.08k]
  ------------------
   84|      0|        ch = L'\b';
   85|  2.08k|    else if (str[0] == 'f')
  ------------------
  |  Branch (85:14): [True: 0, False: 2.08k]
  ------------------
   86|      0|        ch = L'\f';
   87|  2.08k|    else if (str[0] == 'v')
  ------------------
  |  Branch (87:14): [True: 0, False: 2.08k]
  ------------------
   88|      0|        ch = L'\v';
   89|  2.08k|    else if (str[0] == 'a')
  ------------------
  |  Branch (89:14): [True: 0, False: 2.08k]
  ------------------
   90|      0|        ch = L'\a';
   91|  2.08k|    else if (octal_digit(str[0])) {
  ------------------
  |  Branch (91:14): [True: 0, False: 2.08k]
  ------------------
   92|      0|        i = 0;
   93|      0|        do {
   94|      0|            digs[dno++] = str[i++];
   95|      0|        } while (i < size && octal_digit(str[i]) && dno < 3);
  ------------------
  |  Branch (95:18): [True: 0, False: 0]
  |  Branch (95:30): [True: 0, False: 0]
  |  Branch (95:53): [True: 0, False: 0]
  ------------------
   96|      0|        ch = strtol(digs, NULL, 8);
   97|      0|    }
   98|  2.08k|    else if (str[0] == 'x') {
  ------------------
  |  Branch (98:14): [True: 0, False: 2.08k]
  ------------------
   99|      0|        while (i < size && hex_digit(str[i]) && dno < 2) {
  ------------------
  |  Branch (99:16): [True: 0, False: 0]
  |  Branch (99:28): [True: 0, False: 0]
  |  Branch (99:49): [True: 0, False: 0]
  ------------------
  100|      0|            digs[dno++] = str[i++];
  101|      0|        }
  102|      0|        if (dno > 0) {
  ------------------
  |  Branch (102:13): [True: 0, False: 0]
  ------------------
  103|      0|            ch = strtol(digs, NULL, 16);
  104|      0|        }
  105|      0|    }
  106|  2.08k|    else if (str[0] == 'u') {
  ------------------
  |  Branch (106:14): [True: 2.08k, False: 0]
  ------------------
  107|  10.4k|        while (i < size && hex_digit(str[i]) && dno < 4) {
  ------------------
  |  Branch (107:16): [True: 9.97k, False: 421]
  |  Branch (107:28): [True: 8.73k, False: 1.24k]
  |  Branch (107:49): [True: 8.32k, False: 410]
  ------------------
  108|  8.32k|            digs[dno++] = str[i++];
  109|  8.32k|        }
  110|  2.08k|        if (dno > 0) {
  ------------------
  |  Branch (110:13): [True: 2.08k, False: 0]
  ------------------
  111|  2.08k|            ch = strtol(digs, NULL, 16);
  112|  2.08k|        }
  113|  2.08k|    }
  114|      0|    else if (str[0] == 'U') {
  ------------------
  |  Branch (114:14): [True: 0, False: 0]
  ------------------
  115|      0|        while (i < size && hex_digit(str[i]) && dno < 8) {
  ------------------
  |  Branch (115:16): [True: 0, False: 0]
  |  Branch (115:28): [True: 0, False: 0]
  |  Branch (115:49): [True: 0, False: 0]
  ------------------
  116|      0|            digs[dno++] = str[i++];
  117|      0|        }
  118|      0|        if (dno > 0) {
  ------------------
  |  Branch (118:13): [True: 0, False: 0]
  ------------------
  119|      0|            ch = strtol(digs, NULL, 16);
  120|      0|        }
  121|      0|    }
  122|  2.08k|    *dest = ch;
  123|       |
  124|  2.08k|    return i;
  125|  2.08k|}
flb_unescape.c:octal_digit:
   29|  2.08k|{
   30|  2.08k|    return (c >= '0' && c <= '7');
  ------------------
  |  Branch (30:13): [True: 2.08k, False: 0]
  |  Branch (30:25): [True: 0, False: 2.08k]
  ------------------
   31|  2.08k|}
flb_unescape.c:hex_digit:
   34|  9.97k|{
   35|  9.97k|    return ((c >= '0' && c <= '9') ||
  ------------------
  |  Branch (35:14): [True: 9.60k, False: 379]
  |  Branch (35:26): [True: 3.18k, False: 6.41k]
  ------------------
   36|  9.97k|            (c >= 'A' && c <= 'F') ||
  ------------------
  |  Branch (36:14): [True: 6.40k, False: 386]
  |  Branch (36:26): [True: 2.88k, False: 3.52k]
  ------------------
   37|  9.97k|            (c >= 'a' && c <= 'f'));
  ------------------
  |  Branch (37:14): [True: 2.67k, False: 1.23k]
  |  Branch (37:26): [True: 2.65k, False: 17]
  ------------------
   38|  9.97k|}
flb_unescape.c:u8_wc_toutf8:
   41|  91.8k|{
   42|  91.8k|    if (ch < 0x80) {
  ------------------
  |  Branch (42:9): [True: 67.9k, False: 23.9k]
  ------------------
   43|  67.9k|        dest[0] = (char)ch;
   44|  67.9k|        return 1;
   45|  67.9k|    }
   46|  23.9k|    if (ch < 0x800) {
  ------------------
  |  Branch (46:9): [True: 322, False: 23.5k]
  ------------------
   47|    322|        dest[0] = (ch>>6) | 0xC0;
   48|    322|        dest[1] = (ch & 0x3F) | 0x80;
   49|    322|        return 2;
   50|    322|    }
   51|  23.5k|    if (ch < 0x10000) {
  ------------------
  |  Branch (51:9): [True: 1.75k, False: 21.8k]
  ------------------
   52|  1.75k|        dest[0] = (ch>>12) | 0xE0;
   53|  1.75k|        dest[1] = ((ch>>6) & 0x3F) | 0x80;
   54|  1.75k|        dest[2] = (ch & 0x3F) | 0x80;
   55|  1.75k|        return 3;
   56|  1.75k|    }
   57|  21.8k|    if (ch < 0x110000) {
  ------------------
  |  Branch (57:9): [True: 0, False: 21.8k]
  ------------------
   58|      0|        dest[0] = (ch>>18) | 0xF0;
   59|      0|        dest[1] = ((ch>>12) & 0x3F) | 0x80;
   60|      0|        dest[2] = ((ch>>6) & 0x3F) | 0x80;
   61|      0|        dest[3] = (ch & 0x3F) | 0x80;
   62|      0|        return 4;
   63|      0|    }
   64|  21.8k|    return 0;
   65|  21.8k|}

LLVMFuzzerTestOneInput:
    5|  2.07k|int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size){
    6|  2.07k|    int out_size= 0;
    7|  2.07k|    char *out_buf = NULL;
    8|  2.07k|    struct flb_pack_state state;
    9|       |    /* Set fuzzer-malloc chance of failure */
   10|  2.07k|    flb_malloc_mod = 25000;
   11|  2.07k|    flb_malloc_p = 0;
   12|       |
   13|       |    /* Exit early to avoid timeouts due to excessive size */
   14|  2.07k|    if (size > 4096)
  ------------------
  |  Branch (14:9): [True: 12, False: 2.06k]
  ------------------
   15|     12|        return 0;
   16|       |
   17|       |    /* Target json packer */
   18|  2.06k|    flb_pack_state_init(&state);
   19|  2.06k|    flb_pack_json_state(data, size, &out_buf, &out_size, &state);
   20|  2.06k|    flb_pack_state_reset(&state);
   21|  2.06k|    if (out_buf != NULL)
  ------------------
  |  Branch (21:9): [True: 1.54k, False: 515]
  ------------------
   22|  1.54k|        flb_free(out_buf);
   23|       |
   24|  2.06k|    return 0;
   25|  2.07k|}

