SOPC_Helper_URI_SplitUri:
  224|    296|{
  225|    296|    if (NULL == uri || NULL == hostname || NULL == port || NULL != *port || NULL != *hostname)
  ------------------
  |  Branch (225:9): [True: 0, False: 296]
  |  Branch (225:24): [True: 0, False: 296]
  |  Branch (225:44): [True: 0, False: 296]
  |  Branch (225:60): [True: 0, False: 296]
  |  Branch (225:77): [True: 0, False: 296]
  ------------------
  226|      0|    {
  227|      0|        return (SOPC_STATUS_INVALID_PARAMETERS);
  228|      0|    }
  229|    296|    if (strlen(uri) + 4 > TCP_UA_MAX_URL_LENGTH) // Encoded value shall be less than 4096 byte
  ------------------
  |  |   22|    296|#define TCP_UA_MAX_URL_LENGTH 4096
  ------------------
  |  Branch (229:9): [True: 22, False: 274]
  ------------------
  230|     22|    {
  231|     22|        return (SOPC_STATUS_INVALID_PARAMETERS);
  232|     22|    }
  233|       |
  234|       |    /* *pCursor is a tmp copy to the uri. its purpose is to run through the URI
  235|       |     * Its pos must be at the beginning of each sequence and must be strictly after the last separator found */
  236|    274|    const char* pCursor = uri;
  237|    274|    char* prefix = NULL;
  238|    274|    SOPC_ReturnStatus result = SOPC_STATUS_OK;
  239|       |
  240|    274|    if (SOPC_STATUS_OK == result)
  ------------------
  |  Branch (240:9): [True: 274, False: 0]
  ------------------
  241|    274|    {
  242|    274|        result = getUriPrefixOrPort(&pCursor, &prefix, URI_PREFIX_SEP, SOPC_URI_PREFIX);
  ------------------
  |  |   28|    274|#define URI_PREFIX_SEP "://"
  ------------------
  243|    274|    }
  244|    274|    if (SOPC_STATUS_OK == result)
  ------------------
  |  Branch (244:9): [True: 267, False: 7]
  ------------------
  245|    267|    {
  246|    267|        result = getUriHostname(&pCursor, hostname);
  247|    267|    }
  248|    274|    if (SOPC_STATUS_OK == result)
  ------------------
  |  Branch (248:9): [True: 158, False: 116]
  ------------------
  249|    158|    {
  250|    158|        result = getUriPrefixOrPort(&pCursor, port, URI_PORT_SEP, SOPC_URI_PORT);
  ------------------
  |  |   30|    158|#define URI_PORT_SEP "/"
  ------------------
  251|    158|    }
  252|    274|    if (SOPC_STATUS_OK == result)
  ------------------
  |  Branch (252:9): [True: 154, False: 120]
  ------------------
  253|    154|    {
  254|    154|        result = getUriTypeFromEnum(&prefix, type);
  255|    154|    }
  256|    274|    SOPC_Free(prefix);
  257|    274|    if (SOPC_STATUS_OK != result)
  ------------------
  |  Branch (257:9): [True: 270, False: 4]
  ------------------
  258|    270|    {
  259|    270|        SOPC_Free(*hostname);
  260|    270|        SOPC_Free(*port);
  261|    270|        *hostname = NULL;
  262|       |        *port = NULL;
  263|    270|    }
  264|    274|    return (result);
  265|    296|}
sopc_helper_uri.c:getUriPrefixOrPort:
  135|    432|{
  136|    432|    if (NULL == ppCursor || NULL == *ppCursor || NULL == ppFind || NULL != *ppFind || NULL == sep_match)
  ------------------
  |  Branch (136:9): [True: 0, False: 432]
  |  Branch (136:29): [True: 0, False: 432]
  |  Branch (136:50): [True: 0, False: 432]
  |  Branch (136:68): [True: 0, False: 432]
  |  Branch (136:87): [True: 0, False: 432]
  ------------------
  137|      0|    {
  138|      0|        return (SOPC_STATUS_INVALID_PARAMETERS);
  139|      0|    }
  140|       |
  141|    432|    const char* start = *ppCursor;
  142|    432|    const char* pCursor = *ppCursor;
  143|    432|    SOPC_ReturnStatus res = SOPC_STATUS_OK;
  144|    432|    char* resStr = NULL;
  145|    432|    size_t len = 0;
  146|       |
  147|    432|    pCursor = strstr(start, sep_match);
  148|    432|    if (SOPC_URI_PREFIX == uriSwitch)
  ------------------
  |  Branch (148:9): [True: 274, False: 158]
  ------------------
  149|    274|    {
  150|    274|        if (NULL == pCursor)
  ------------------
  |  Branch (150:13): [True: 6, False: 268]
  ------------------
  151|      6|        {
  152|      6|            res = SOPC_STATUS_INVALID_PARAMETERS;
  153|      6|        }
  154|    274|    }
  155|    158|    else if (SOPC_URI_PORT == uriSwitch)
  ------------------
  |  Branch (155:14): [True: 158, False: 0]
  ------------------
  156|    158|    {
  157|    158|        if (NULL == pCursor)
  ------------------
  |  Branch (157:13): [True: 155, False: 3]
  ------------------
  158|    155|        {
  159|    155|            pCursor = start + strlen(start);
  160|    155|        }
  161|    158|    }
  162|      0|    else
  163|      0|    {
  164|      0|        SOPC_ASSERT(false && "Unknown uriSwitch");
  ------------------
  |  |   81|      0|#define SOPC_ASSERT assert
  ------------------
  |  Branch (164:9): [Folded, False: 0]
  |  Branch (164:9): [True: 0, False: 0]
  ------------------
  165|      0|    }
  166|       |
  167|    432|    if (SOPC_STATUS_OK == res)
  ------------------
  |  Branch (167:9): [True: 426, False: 6]
  ------------------
  168|    426|    {
  169|    426|        if (pCursor > start)
  ------------------
  |  Branch (169:13): [True: 421, False: 5]
  ------------------
  170|    421|        {
  171|    421|            len = (size_t)(pCursor - start);
  172|    421|        }
  173|      5|        else
  174|      5|        {
  175|      5|            res = SOPC_STATUS_INVALID_PARAMETERS;
  176|      5|        }
  177|    426|    }
  178|       |
  179|    432|    if (SOPC_STATUS_OK == res)
  ------------------
  |  Branch (179:9): [True: 421, False: 11]
  ------------------
  180|    421|    {
  181|    421|        resStr = SOPC_Calloc(len + 1, sizeof(char));
  182|    421|        if (NULL == resStr)
  ------------------
  |  Branch (182:13): [True: 0, False: 421]
  ------------------
  183|      0|        {
  184|      0|            res = SOPC_STATUS_OUT_OF_MEMORY;
  185|      0|        }
  186|    421|    }
  187|       |
  188|    432|    if (SOPC_STATUS_OK == res)
  ------------------
  |  Branch (188:9): [True: 421, False: 11]
  ------------------
  189|    421|    {
  190|    421|        resStr = strncpy(resStr, start, len);
  191|    421|        pCursor += strlen(sep_match);
  192|    421|        *ppFind = resStr;
  193|    421|        *ppCursor = pCursor;
  194|    421|    }
  195|    432|    return (res);
  196|    432|}
sopc_helper_uri.c:getUriHostname:
   66|    267|{
   67|    267|    if (NULL == ppCursor || NULL == *ppCursor || NULL == ppHostname || NULL != *ppHostname)
  ------------------
  |  Branch (67:9): [True: 0, False: 267]
  |  Branch (67:29): [True: 0, False: 267]
  |  Branch (67:50): [True: 0, False: 267]
  |  Branch (67:72): [True: 0, False: 267]
  ------------------
   68|      0|    {
   69|      0|        return (SOPC_STATUS_INVALID_PARAMETERS);
   70|      0|    }
   71|       |
   72|    267|    const char* start = *ppCursor;
   73|    267|    const char* pCursor = *ppCursor;
   74|    267|    SOPC_ReturnStatus res = SOPC_STATUS_OK;
   75|    267|    bool match = false;
   76|    267|    char* resStr = NULL;
   77|    267|    size_t len = 0;
   78|    267|    size_t NbBracketOpen = 0;
   79|       |
   80|  19.0k|    while (!match && res == SOPC_STATUS_OK)
  ------------------
  |  Branch (80:12): [True: 18.8k, False: 160]
  |  Branch (80:22): [True: 18.7k, False: 107]
  ------------------
   81|  18.7k|    {
   82|  18.7k|        if (0 == NbBracketOpen)
  ------------------
  |  Branch (82:13): [True: 6.23k, False: 12.5k]
  ------------------
   83|  6.23k|        {
   84|  6.23k|            match = strchr(URI_HOSTNAME_SEP, *pCursor) != NULL;
  ------------------
  |  |   29|  6.23k|#define URI_HOSTNAME_SEP ":"
  ------------------
   85|  6.23k|        }
   86|  18.7k|        if (!match)
  ------------------
  |  Branch (86:13): [True: 18.6k, False: 160]
  ------------------
   87|  18.6k|        {
   88|  18.6k|            if (*pCursor == URI_OPEN_BRACKET)
  ------------------
  |  |   32|  18.6k|#define URI_OPEN_BRACKET '['
  ------------------
  |  Branch (88:17): [True: 9.89k, False: 8.72k]
  ------------------
   89|  9.89k|            {
   90|  9.89k|                ++start;
   91|  9.89k|                ++NbBracketOpen;
   92|  9.89k|            }
   93|  18.6k|            if (NbBracketOpen > 0 && URI_CLOSE_BRACKET == *pCursor)
  ------------------
  |  |   33|  12.8k|#define URI_CLOSE_BRACKET ']'
  ------------------
  |  Branch (93:17): [True: 12.8k, False: 5.76k]
  |  Branch (93:38): [True: 472, False: 12.3k]
  ------------------
   94|    472|            {
   95|    472|                --len;
   96|    472|                --NbBracketOpen;
   97|    472|            }
   98|  18.1k|            else
   99|  18.1k|            {
  100|  18.1k|                ++len;
  101|  18.1k|            }
  102|  18.6k|            ++pCursor;
  103|  18.6k|        }
  104|  18.7k|        if ('\0' == *pCursor)
  ------------------
  |  Branch (104:13): [True: 108, False: 18.6k]
  ------------------
  105|    108|        {
  106|    108|            res = SOPC_STATUS_INVALID_PARAMETERS;
  107|    108|        }
  108|  18.7k|    }
  109|    267|    if (NbBracketOpen > 0 || 0 == len)
  ------------------
  |  Branch (109:9): [True: 59, False: 208]
  |  Branch (109:30): [True: 10, False: 198]
  ------------------
  110|     69|    {
  111|     69|        res = SOPC_STATUS_INVALID_PARAMETERS;
  112|     69|    }
  113|    267|    if (SOPC_STATUS_OK == res)
  ------------------
  |  Branch (113:9): [True: 158, False: 109]
  ------------------
  114|    158|    {
  115|    158|        resStr = SOPC_Calloc(len + 1, sizeof(char));
  116|    158|        if (NULL == resStr)
  ------------------
  |  Branch (116:13): [True: 0, False: 158]
  ------------------
  117|      0|        {
  118|      0|            res = SOPC_STATUS_OUT_OF_MEMORY;
  119|      0|        }
  120|    158|    }
  121|    267|    if (SOPC_STATUS_OK == res)
  ------------------
  |  Branch (121:9): [True: 158, False: 109]
  ------------------
  122|    158|    {
  123|    158|        resStr = strncpy(resStr, start, len);
  124|    158|        *ppHostname = resStr;
  125|    158|        pCursor += strlen(URI_HOSTNAME_SEP);
  ------------------
  |  |   29|    158|#define URI_HOSTNAME_SEP ":"
  ------------------
  126|    158|        *ppCursor = pCursor;
  127|    158|    }
  128|    267|    return (res);
  129|    267|}
sopc_helper_uri.c:getUriTypeFromEnum:
  199|    154|{
  200|    154|    if (strncmp(*prefix, TCPUA_PREFIX, (strlen(*prefix) + 1)) == 0)
  ------------------
  |  |   35|    154|#define TCPUA_PREFIX ((const char*) "opc.tcp")
  ------------------
  |  Branch (200:9): [True: 1, False: 153]
  ------------------
  201|      1|    {
  202|      1|        *type = SOPC_URI_TCPUA;
  203|      1|        return (SOPC_STATUS_OK);
  204|      1|    }
  205|    153|    else if (strncmp(*prefix, UDPUA_PREFIX, (strlen(*prefix) + 1)) == 0)
  ------------------
  |  |   36|    153|#define UDPUA_PREFIX ((const char*) "opc.udp")
  ------------------
  |  Branch (205:14): [True: 1, False: 152]
  ------------------
  206|      1|    {
  207|      1|        *type = SOPC_URI_UDPUA;
  208|      1|        return (SOPC_STATUS_OK);
  209|      1|    }
  210|    152|    else if (strncmp(*prefix, ETHUA_PREFIX, (strlen(*prefix) + 1)) == 0)
  ------------------
  |  |   37|    152|#define ETHUA_PREFIX ((const char*) "opc.eth")
  ------------------
  |  Branch (210:14): [True: 1, False: 151]
  ------------------
  211|      1|    {
  212|      1|        *type = SOPC_URI_ETHUA;
  213|      1|        return (SOPC_STATUS_OK);
  214|      1|    }
  215|    151|    else if (strncmp(*prefix, MQTTUA_PREFIX, (strlen(*prefix) + 1)) == 0)
  ------------------
  |  |   38|    151|#define MQTTUA_PREFIX ((const char*) "MqttUa")
  ------------------
  |  Branch (215:14): [True: 1, False: 150]
  ------------------
  216|      1|    {
  217|      1|        *type = SOPC_URI_MQTTUA;
  218|      1|        return (SOPC_STATUS_OK);
  219|      1|    }
  220|    150|    return (SOPC_STATUS_INVALID_PARAMETERS);
  221|    154|}

SOPC_Free:
   31|  1.70k|{
   32|  1.70k|    free(ptr);
   33|  1.70k|}
SOPC_Calloc:
   36|    875|{
   37|    875|    return calloc(nmemb, size);
   38|    875|}

SOPC_String_Initialize:
  984|      1|{
  985|      1|    if (string != NULL)
  ------------------
  |  Branch (985:9): [True: 1, False: 0]
  ------------------
  986|      1|    {
  987|      1|        string->Length = -1;
  988|      1|        string->Data = NULL;
  989|       |        string->DoNotClear = false; // False unless characters attached
  990|      1|    }
  991|      1|}

LLVMFuzzerTestOneInput:
   30|    296|{
   31|       |    /* Make an awkward reference to another translation unit, increasing the complexity of this function.
   32|       |     * TODO: rework this test to avoid this, maybe by enlarging its scope. */
   33|    296|    static bool init = false;
   34|    296|    static SOPC_String dummy;
   35|       |
   36|    296|    if (!init)
  ------------------
  |  Branch (36:9): [True: 1, False: 295]
  ------------------
   37|      1|    {
   38|      1|        SOPC_String_Initialize(&dummy);
   39|      1|        init = true;
   40|      1|    }
   41|       |
   42|    296|    char* buf_copy = SOPC_Calloc(1 + len, sizeof(char));
   43|    296|    SOPC_ASSERT(buf_copy != NULL);
  ------------------
  |  |   81|    296|#define SOPC_ASSERT assert
  ------------------
  |  Branch (43:5): [True: 0, False: 296]
  |  Branch (43:5): [True: 296, False: 0]
  ------------------
   44|       |
   45|    296|    memcpy(buf_copy, buf, len);
   46|       |
   47|    296|    char* hostname = NULL;
   48|    296|    char* port = NULL;
   49|    296|    SOPC_UriType type = SOPC_URI_UNDETERMINED;
   50|    296|    SOPC_Helper_URI_SplitUri(buf_copy, &type, &hostname, &port);
   51|       |
   52|    296|    SOPC_Free(hostname);
   53|    296|    SOPC_Free(port);
   54|    296|    SOPC_Free(buf_copy);
   55|       |
   56|    296|    return 0;
   57|    296|}

