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

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

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

