SOPC_Helper_URI_SplitUri:
  224|    302|{
  225|    302|    if (NULL == uri || NULL == hostname || NULL == port || NULL != *port || NULL != *hostname)
  ------------------
  |  Branch (225:9): [True: 0, False: 302]
  |  Branch (225:24): [True: 0, False: 302]
  |  Branch (225:44): [True: 0, False: 302]
  |  Branch (225:60): [True: 0, False: 302]
  |  Branch (225:77): [True: 0, False: 302]
  ------------------
  226|      0|    {
  227|      0|        return (SOPC_STATUS_INVALID_PARAMETERS);
  228|      0|    }
  229|    302|    if (strlen(uri) + 4 > TCP_UA_MAX_URL_LENGTH) // Encoded value shall be less than 4096 byte
  ------------------
  |  |   22|    302|#define TCP_UA_MAX_URL_LENGTH 4096
  ------------------
  |  Branch (229:9): [True: 22, False: 280]
  ------------------
  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|    280|    const char* pCursor = uri;
  237|    280|    char* prefix = NULL;
  238|    280|    SOPC_ReturnStatus result = SOPC_STATUS_OK;
  239|       |
  240|    280|    if (SOPC_STATUS_OK == result)
  ------------------
  |  Branch (240:9): [True: 280, False: 0]
  ------------------
  241|    280|    {
  242|    280|        result = getUriPrefixOrPort(&pCursor, &prefix, URI_PREFIX_SEP, SOPC_URI_PREFIX);
  ------------------
  |  |   28|    280|#define URI_PREFIX_SEP "://"
  ------------------
  243|    280|    }
  244|    280|    if (SOPC_STATUS_OK == result)
  ------------------
  |  Branch (244:9): [True: 274, False: 6]
  ------------------
  245|    274|    {
  246|    274|        result = getUriHostname(&pCursor, hostname);
  247|    274|    }
  248|    280|    if (SOPC_STATUS_OK == result)
  ------------------
  |  Branch (248:9): [True: 160, False: 120]
  ------------------
  249|    160|    {
  250|    160|        result = getUriPrefixOrPort(&pCursor, port, URI_PORT_SEP, SOPC_URI_PORT);
  ------------------
  |  |   30|    160|#define URI_PORT_SEP "/"
  ------------------
  251|    160|    }
  252|    280|    if (SOPC_STATUS_OK == result)
  ------------------
  |  Branch (252:9): [True: 157, False: 123]
  ------------------
  253|    157|    {
  254|    157|        result = getUriTypeFromEnum(&prefix, type);
  255|    157|    }
  256|    280|    SOPC_Free(prefix);
  257|    280|    if (SOPC_STATUS_OK != result)
  ------------------
  |  Branch (257:9): [True: 275, False: 5]
  ------------------
  258|    275|    {
  259|    275|        SOPC_Free(*hostname);
  260|    275|        SOPC_Free(*port);
  261|    275|        *hostname = NULL;
  262|       |        *port = NULL;
  263|    275|    }
  264|    280|    return (result);
  265|    302|}
sopc_helper_uri.c:getUriPrefixOrPort:
  135|    440|{
  136|    440|    if (NULL == ppCursor || NULL == *ppCursor || NULL == ppFind || NULL != *ppFind || NULL == sep_match)
  ------------------
  |  Branch (136:9): [True: 0, False: 440]
  |  Branch (136:29): [True: 0, False: 440]
  |  Branch (136:50): [True: 0, False: 440]
  |  Branch (136:68): [True: 0, False: 440]
  |  Branch (136:87): [True: 0, False: 440]
  ------------------
  137|      0|    {
  138|      0|        return (SOPC_STATUS_INVALID_PARAMETERS);
  139|      0|    }
  140|       |
  141|    440|    const char* start = *ppCursor;
  142|    440|    const char* pCursor = *ppCursor;
  143|    440|    SOPC_ReturnStatus res = SOPC_STATUS_OK;
  144|    440|    char* resStr = NULL;
  145|    440|    size_t len = 0;
  146|       |
  147|    440|    pCursor = strstr(start, sep_match);
  148|    440|    if (SOPC_URI_PREFIX == uriSwitch)
  ------------------
  |  Branch (148:9): [True: 280, False: 160]
  ------------------
  149|    280|    {
  150|    280|        if (NULL == pCursor)
  ------------------
  |  Branch (150:13): [True: 5, False: 275]
  ------------------
  151|      5|        {
  152|      5|            res = SOPC_STATUS_INVALID_PARAMETERS;
  153|      5|        }
  154|    280|    }
  155|    160|    else if (SOPC_URI_PORT == uriSwitch)
  ------------------
  |  Branch (155:14): [True: 160, False: 0]
  ------------------
  156|    160|    {
  157|    160|        if (NULL == pCursor)
  ------------------
  |  Branch (157:13): [True: 157, False: 3]
  ------------------
  158|    157|        {
  159|    157|            pCursor = start + strlen(start);
  160|    157|        }
  161|    160|    }
  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|    440|    if (SOPC_STATUS_OK == res)
  ------------------
  |  Branch (167:9): [True: 435, False: 5]
  ------------------
  168|    435|    {
  169|    435|        if (pCursor > start)
  ------------------
  |  Branch (169:13): [True: 431, False: 4]
  ------------------
  170|    431|        {
  171|    431|            len = (size_t)(pCursor - start);
  172|    431|        }
  173|      4|        else
  174|      4|        {
  175|      4|            res = SOPC_STATUS_INVALID_PARAMETERS;
  176|      4|        }
  177|    435|    }
  178|       |
  179|    440|    if (SOPC_STATUS_OK == res)
  ------------------
  |  Branch (179:9): [True: 431, False: 9]
  ------------------
  180|    431|    {
  181|    431|        resStr = SOPC_Calloc(len + 1, sizeof(char));
  182|    431|        if (NULL == resStr)
  ------------------
  |  Branch (182:13): [True: 0, False: 431]
  ------------------
  183|      0|        {
  184|      0|            res = SOPC_STATUS_OUT_OF_MEMORY;
  185|      0|        }
  186|    431|    }
  187|       |
  188|    440|    if (SOPC_STATUS_OK == res)
  ------------------
  |  Branch (188:9): [True: 431, False: 9]
  ------------------
  189|    431|    {
  190|    431|        resStr = strncpy(resStr, start, len);
  191|    431|        pCursor += strlen(sep_match);
  192|    431|        *ppFind = resStr;
  193|    431|        *ppCursor = pCursor;
  194|    431|    }
  195|    440|    return (res);
  196|    440|}
sopc_helper_uri.c:getUriHostname:
   66|    274|{
   67|    274|    if (NULL == ppCursor || NULL == *ppCursor || NULL == ppHostname || NULL != *ppHostname)
  ------------------
  |  Branch (67:9): [True: 0, False: 274]
  |  Branch (67:29): [True: 0, False: 274]
  |  Branch (67:50): [True: 0, False: 274]
  |  Branch (67:72): [True: 0, False: 274]
  ------------------
   68|      0|    {
   69|      0|        return (SOPC_STATUS_INVALID_PARAMETERS);
   70|      0|    }
   71|       |
   72|    274|    const char* start = *ppCursor;
   73|    274|    const char* pCursor = *ppCursor;
   74|    274|    SOPC_ReturnStatus res = SOPC_STATUS_OK;
   75|    274|    bool match = false;
   76|    274|    char* resStr = NULL;
   77|    274|    size_t len = 0;
   78|    274|    size_t NbBracketOpen = 0;
   79|       |
   80|  19.3k|    while (!match && res == SOPC_STATUS_OK)
  ------------------
  |  Branch (80:12): [True: 19.1k, False: 162]
  |  Branch (80:22): [True: 19.0k, False: 112]
  ------------------
   81|  19.0k|    {
   82|  19.0k|        if (0 == NbBracketOpen)
  ------------------
  |  Branch (82:13): [True: 5.07k, False: 13.9k]
  ------------------
   83|  5.07k|        {
   84|  5.07k|            match = strchr(URI_HOSTNAME_SEP, *pCursor) != NULL;
  ------------------
  |  |   29|  5.07k|#define URI_HOSTNAME_SEP ":"
  ------------------
   85|  5.07k|        }
   86|  19.0k|        if (!match)
  ------------------
  |  Branch (86:13): [True: 18.8k, False: 162]
  ------------------
   87|  18.8k|        {
   88|  18.8k|            if (*pCursor == URI_OPEN_BRACKET)
  ------------------
  |  |   32|  18.8k|#define URI_OPEN_BRACKET '['
  ------------------
  |  Branch (88:17): [True: 12.7k, False: 6.12k]
  ------------------
   89|  12.7k|            {
   90|  12.7k|                ++start;
   91|  12.7k|                ++NbBracketOpen;
   92|  12.7k|            }
   93|  18.8k|            if (NbBracketOpen > 0 && URI_CLOSE_BRACKET == *pCursor)
  ------------------
  |  |   33|  14.2k|#define URI_CLOSE_BRACKET ']'
  ------------------
  |  Branch (93:17): [True: 14.2k, False: 4.61k]
  |  Branch (93:38): [True: 397, False: 13.8k]
  ------------------
   94|    397|            {
   95|    397|                --len;
   96|    397|                --NbBracketOpen;
   97|    397|            }
   98|  18.5k|            else
   99|  18.5k|            {
  100|  18.5k|                ++len;
  101|  18.5k|            }
  102|  18.8k|            ++pCursor;
  103|  18.8k|        }
  104|  19.0k|        if ('\0' == *pCursor)
  ------------------
  |  Branch (104:13): [True: 113, False: 18.9k]
  ------------------
  105|    113|        {
  106|    113|            res = SOPC_STATUS_INVALID_PARAMETERS;
  107|    113|        }
  108|  19.0k|    }
  109|    274|    if (NbBracketOpen > 0 || 0 == len)
  ------------------
  |  Branch (109:9): [True: 60, False: 214]
  |  Branch (109:30): [True: 10, False: 204]
  ------------------
  110|     70|    {
  111|     70|        res = SOPC_STATUS_INVALID_PARAMETERS;
  112|     70|    }
  113|    274|    if (SOPC_STATUS_OK == res)
  ------------------
  |  Branch (113:9): [True: 160, False: 114]
  ------------------
  114|    160|    {
  115|    160|        resStr = SOPC_Calloc(len + 1, sizeof(char));
  116|    160|        if (NULL == resStr)
  ------------------
  |  Branch (116:13): [True: 0, False: 160]
  ------------------
  117|      0|        {
  118|      0|            res = SOPC_STATUS_OUT_OF_MEMORY;
  119|      0|        }
  120|    160|    }
  121|    274|    if (SOPC_STATUS_OK == res)
  ------------------
  |  Branch (121:9): [True: 160, False: 114]
  ------------------
  122|    160|    {
  123|    160|        resStr = strncpy(resStr, start, len);
  124|    160|        *ppHostname = resStr;
  125|    160|        pCursor += strlen(URI_HOSTNAME_SEP);
  ------------------
  |  |   29|    160|#define URI_HOSTNAME_SEP ":"
  ------------------
  126|    160|        *ppCursor = pCursor;
  127|    160|    }
  128|    274|    return (res);
  129|    274|}
sopc_helper_uri.c:getUriTypeFromEnum:
  199|    157|{
  200|    157|    if (strncmp(*prefix, TCPUA_PREFIX, (strlen(*prefix) + 1)) == 0)
  ------------------
  |  |   35|    157|#define TCPUA_PREFIX ((const char*) "opc.tcp")
  ------------------
  |  Branch (200:9): [True: 2, False: 155]
  ------------------
  201|      2|    {
  202|      2|        *type = SOPC_URI_TCPUA;
  203|      2|        return (SOPC_STATUS_OK);
  204|      2|    }
  205|    155|    else if (strncmp(*prefix, UDPUA_PREFIX, (strlen(*prefix) + 1)) == 0)
  ------------------
  |  |   36|    155|#define UDPUA_PREFIX ((const char*) "opc.udp")
  ------------------
  |  Branch (205:14): [True: 1, False: 154]
  ------------------
  206|      1|    {
  207|      1|        *type = SOPC_URI_UDPUA;
  208|      1|        return (SOPC_STATUS_OK);
  209|      1|    }
  210|    154|    else if (strncmp(*prefix, ETHUA_PREFIX, (strlen(*prefix) + 1)) == 0)
  ------------------
  |  |   37|    154|#define ETHUA_PREFIX ((const char*) "opc.eth")
  ------------------
  |  Branch (210:14): [True: 1, False: 153]
  ------------------
  211|      1|    {
  212|      1|        *type = SOPC_URI_ETHUA;
  213|      1|        return (SOPC_STATUS_OK);
  214|      1|    }
  215|    153|    else if (strncmp(*prefix, MQTTUA_PREFIX, (strlen(*prefix) + 1)) == 0)
  ------------------
  |  |   38|    153|#define MQTTUA_PREFIX ((const char*) "MqttUa")
  ------------------
  |  Branch (215:14): [True: 1, False: 152]
  ------------------
  216|      1|    {
  217|      1|        *type = SOPC_URI_MQTTUA;
  218|      1|        return (SOPC_STATUS_OK);
  219|      1|    }
  220|    152|    return (SOPC_STATUS_INVALID_PARAMETERS);
  221|    157|}

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

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|    302|{
   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|    302|    static bool init = false;
   34|    302|    static SOPC_String dummy;
   35|       |
   36|    302|    if (!init)
  ------------------
  |  Branch (36:9): [True: 1, False: 301]
  ------------------
   37|      1|    {
   38|      1|        SOPC_String_Initialize(&dummy);
   39|      1|        init = true;
   40|      1|    }
   41|       |
   42|    302|    char* buf_copy = SOPC_Calloc(1 + len, sizeof(char));
   43|    302|    SOPC_ASSERT(buf_copy != NULL);
  ------------------
  |  |   81|    302|#define SOPC_ASSERT assert
  ------------------
  |  Branch (43:5): [True: 0, False: 302]
  |  Branch (43:5): [True: 302, False: 0]
  ------------------
   44|       |
   45|    302|    memcpy(buf_copy, buf, len);
   46|       |
   47|    302|    char* hostname = NULL;
   48|    302|    char* port = NULL;
   49|    302|    SOPC_UriType type = SOPC_URI_UNDETERMINED;
   50|    302|    SOPC_Helper_URI_SplitUri(buf_copy, &type, &hostname, &port);
   51|       |
   52|    302|    SOPC_Free(hostname);
   53|    302|    SOPC_Free(port);
   54|    302|    SOPC_Free(buf_copy);
   55|       |
   56|    302|    return 0;
   57|    302|}

