create_callback_file:
   59|    365|void create_callback_file(const char *filename) {}

LLVMFuzzerInitialize:
   22|      2|int LLVMFuzzerInitialize(int *argc, char ***argv) {
   23|      2|  setenv("HOME", "/tmp", 1);
   24|      2|  system("mkdir -p $HOME/.local/share/vulkan/implicit_layer.d");
   25|      2|  system("mkdir -p $HOME/.local/share/vulkan/loader_settings.d");
   26|      2|  return 0;
   27|      2|}
create_config_file:
   32|  4.86k|int create_config_file(const char* config_path, const char* config_filename, const uint8_t* data, size_t size) {
   33|  4.86k|  char filename[512];
   34|  4.86k|  char path[256];
   35|       |
   36|       |
   37|  4.86k|  sprintf(path, "%s/%s", getenv("HOME"), config_path);
   38|  4.86k|  sprintf(filename, "%s/%s", path, config_filename);
   39|       |
   40|  4.86k|  FILE *fp = fopen(filename, "wb");
   41|  4.86k|  if (!fp) {
  ------------------
  |  Branch (41:7): [True: 0, False: 4.86k]
  ------------------
   42|      0|    return 1;
   43|      0|  }
   44|  4.86k|  fwrite(data, size, 1, fp);
   45|  4.86k|  fclose(fp);
   46|       |
   47|  4.86k|  return 0;
   48|  4.86k|}
remove_config_file:
   53|  4.86k|void remove_config_file(const char* config_path, const char* config_filename) {
   54|  4.86k|  char filename[512];
   55|  4.86k|  sprintf(filename, "%s/%s/%s", getenv("HOME"), config_path, config_filename);
   56|  4.86k|  unlink(filename);
   57|  4.86k|}
LLVMFuzzerTestOneInput:
   62|  2.45k|int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
   63|       |
   64|  2.45k|# ifdef SPLIT_INPUT
   65|  2.45k|  if (size < 2*sizeof(size_t)) {
  ------------------
  |  Branch (65:7): [True: 6, False: 2.45k]
  ------------------
   66|      6|    return 0;
   67|      6|  }
   68|       |
   69|       |  // Split the loaders into two different parts so the files
   70|       |  // are independently seeded with fuzz data.
   71|  2.45k|  size_t first_size = (*(size_t*)data) % 64000;
   72|  2.45k|  size_t second_size = (*(size_t*)(data + sizeof(size_t))) % 64000;
   73|       |
   74|  2.45k|  data += 2*sizeof(size_t); // Move past the first two integers
   75|  2.45k|  size -= 2*sizeof(size_t); // Adjust size to account for the first two integers
   76|  2.45k|  size_t total_size_needed = first_size + second_size;
   77|  2.45k|  if (size <= total_size_needed) {
  ------------------
  |  Branch (77:7): [True: 20, False: 2.43k]
  ------------------
   78|     20|    return 0;
   79|     20|  }
   80|  2.43k|  int result = create_config_file(".local/share/vulkan/implicit_layer.d", "complex_layer.json", data, first_size);
   81|  2.43k|  if (result) {
  ------------------
  |  Branch (81:7): [True: 0, False: 2.43k]
  ------------------
   82|      0|    return 0;
   83|      0|  }
   84|       |
   85|  2.43k|  data += first_size;
   86|       |
   87|  2.43k|  result = create_config_file(".local/share/vulkan/loader_settings.d", "vk_loader_settings.json", data, second_size);
   88|  2.43k|  if (result) {
  ------------------
  |  Branch (88:7): [True: 0, False: 2.43k]
  ------------------
   89|      0|    return 0;
   90|      0|  }
   91|       |#else
   92|       |  int result = create_config_file(".local/share/vulkan/implicit_layer.d", "complex_layer.json", data, size);
   93|       |  if (result) {
   94|       |    return 0;
   95|       |  }
   96|       |
   97|       |  result = create_config_file(".local/share/vulkan/loader_settings.d", "vk_loader_settings.json", data, size);
   98|       |  if (result) {
   99|       |    return 0;
  100|       |  }
  101|       |#endif
  102|       |
  103|       |
  104|       |  //printf("Status: %d\n", (int)ms);
  105|  2.43k|  setenv("VK_LOADER_LAYERS_ENABLE", "all", 1);
  106|       |
  107|  2.43k|  uint32_t pPropertyCount = 0;
  108|  2.43k|  VkResult vk_result = vkEnumerateInstanceExtensionProperties("test_auto", &pPropertyCount, NULL);
  109|       |  
  110|  2.43k|  if (vk_result == VK_SUCCESS) {
  ------------------
  |  Branch (110:7): [True: 5, False: 2.42k]
  ------------------
  111|       |  
  112|      5|    VkExtensionProperties* pProperties = (VkExtensionProperties*)malloc(sizeof(VkExtensionProperties) * pPropertyCount); 
  113|       |  
  114|      5|    vkEnumerateInstanceExtensionProperties("test_auto", &pPropertyCount, pProperties);
  115|       |    
  116|      5|    free(pProperties);
  117|      5|  }
  118|       |  // Clean up config files
  119|  2.43k|  remove_config_file(".local/share/vulkan/implicit_layer.d", "complex_layer.json");
  120|  2.43k|  remove_config_file(".local/share/vulkan/loader_settings.d", "vk_loader_settings.json");
  121|       |
  122|  2.43k|  return 0;
  123|  2.43k|}

loader_calloc:
   51|   206k|void *loader_calloc(const VkAllocationCallbacks *pAllocator, size_t size, VkSystemAllocationScope allocation_scope) {
   52|   206k|    void *pMemory = NULL;
   53|       |#if (DEBUG_DISABLE_APP_ALLOCATORS == 1)
   54|       |    {
   55|       |#else
   56|   206k|    if (pAllocator && pAllocator->pfnAllocation) {
  ------------------
  |  Branch (56:9): [True: 0, False: 206k]
  |  Branch (56:23): [True: 0, False: 0]
  ------------------
   57|       |        // These are internal structures, so it's best to align everything to
   58|       |        // the largest unit size which is the size of a uint64_t.
   59|      0|        pMemory = pAllocator->pfnAllocation(pAllocator->pUserData, size, sizeof(uint64_t), allocation_scope);
   60|      0|        if (pMemory) {
  ------------------
  |  Branch (60:13): [True: 0, False: 0]
  ------------------
   61|      0|            memset(pMemory, 0, size);
   62|      0|        }
   63|   206k|    } else {
   64|   206k|#endif
   65|   206k|        pMemory = calloc(1, size);
   66|   206k|    }
   67|       |
   68|   206k|    return pMemory;
   69|   206k|}
loader_free:
   71|   291k|void loader_free(const VkAllocationCallbacks *pAllocator, void *pMemory) {
   72|   291k|    if (pMemory != NULL) {
  ------------------
  |  Branch (72:9): [True: 206k, False: 85.2k]
  ------------------
   73|       |#if (DEBUG_DISABLE_APP_ALLOCATORS == 1)
   74|       |        {
   75|       |#else
   76|   206k|        if (pAllocator && pAllocator->pfnFree) {
  ------------------
  |  Branch (76:13): [True: 0, False: 206k]
  |  Branch (76:27): [True: 0, False: 0]
  ------------------
   77|      0|            pAllocator->pfnFree(pAllocator->pUserData, pMemory);
   78|   206k|        } else {
   79|   206k|#endif
   80|   206k|            free(pMemory);
   81|   206k|        }
   82|   206k|    }
   83|   291k|}
loader_realloc:
   86|    950|                     VkSystemAllocationScope allocation_scope) {
   87|    950|    void *pNewMem = NULL;
   88|    950|    if (pMemory == NULL || orig_size == 0) {
  ------------------
  |  Branch (88:9): [True: 0, False: 950]
  |  Branch (88:28): [True: 0, False: 950]
  ------------------
   89|      0|        pNewMem = loader_alloc(pAllocator, size, allocation_scope);
   90|    950|    } else if (size == 0) {
  ------------------
  |  Branch (90:16): [True: 0, False: 950]
  ------------------
   91|      0|        loader_free(pAllocator, pMemory);
   92|       |#if (DEBUG_DISABLE_APP_ALLOCATORS == 1)
   93|       |#else
   94|    950|    } else if (pAllocator && pAllocator->pfnReallocation) {
  ------------------
  |  Branch (94:16): [True: 0, False: 950]
  |  Branch (94:30): [True: 0, False: 0]
  ------------------
   95|       |        // These are internal structures, so it's best to align everything to
   96|       |        // the largest unit size which is the size of a uint64_t.
   97|      0|        pNewMem = pAllocator->pfnReallocation(pAllocator->pUserData, pMemory, size, sizeof(uint64_t), allocation_scope);
   98|      0|#endif
   99|    950|    } else {
  100|    950|        pNewMem = realloc(pMemory, size);
  101|       |        // Clear out the newly allocated memory. On failure realloc returns NULL and leaves the original block valid, so
  102|       |        // only write through pNewMem once we know it points at the resized allocation.
  103|    950|        if (NULL != pNewMem && size > orig_size) {
  ------------------
  |  Branch (103:13): [True: 950, False: 0]
  |  Branch (103:32): [True: 154, False: 796]
  ------------------
  104|    154|            memset((uint8_t *)pNewMem + orig_size, 0, size - orig_size);
  105|    154|        }
  106|    950|    }
  107|    950|    return pNewMem;
  108|    950|}
loader_instance_heap_calloc:
  114|   101k|void *loader_instance_heap_calloc(const struct loader_instance *inst, size_t size, VkSystemAllocationScope allocation_scope) {
  115|   101k|    return loader_calloc(inst ? &inst->alloc_callbacks : NULL, size, allocation_scope);
  ------------------
  |  Branch (115:26): [True: 0, False: 101k]
  ------------------
  116|   101k|}
loader_instance_heap_free:
  118|   187k|void loader_instance_heap_free(const struct loader_instance *inst, void *pMemory) {
  119|   187k|    loader_free(inst ? &inst->alloc_callbacks : NULL, pMemory);
  ------------------
  |  Branch (119:17): [True: 0, False: 187k]
  ------------------
  120|   187k|}

loader_cJSON_GetStringValue:
   98|  6.08k|CJSON_PUBLIC(char *) loader_cJSON_GetStringValue(const cJSON *const item) {
   99|  6.08k|    if (!loader_cJSON_IsString(item)) {
  ------------------
  |  Branch (99:9): [True: 1.35k, False: 4.73k]
  ------------------
  100|  1.35k|        return NULL;
  101|  1.35k|    }
  102|       |
  103|  4.73k|    return item->valuestring;
  104|  6.08k|}
loader_cJSON_Delete:
  151|  33.2k|TEST_FUNCTION_EXPORT CJSON_PUBLIC(void) loader_cJSON_Delete(cJSON *item) {
  152|  33.2k|    cJSON *next = NULL;
  153|  91.5k|    while (item != NULL) {
  ------------------
  |  Branch (153:12): [True: 58.3k, False: 33.2k]
  ------------------
  154|  58.3k|        next = item->next;
  155|  58.3k|        if (!(item->type & cJSON_IsReference) && (item->child != NULL)) {
  ------------------
  |  |  106|  58.3k|#define cJSON_IsReference 256
  ------------------
  |  Branch (155:13): [True: 58.3k, False: 0]
  |  Branch (155:50): [True: 8.33k, False: 50.0k]
  ------------------
  156|  8.33k|            loader_cJSON_Delete(item->child);
  157|  8.33k|        }
  158|  58.3k|        if (!(item->type & cJSON_IsReference) && (item->valuestring != NULL)) {
  ------------------
  |  |  106|  58.3k|#define cJSON_IsReference 256
  ------------------
  |  Branch (158:13): [True: 58.3k, False: 0]
  |  Branch (158:50): [True: 16.3k, False: 42.0k]
  ------------------
  159|  16.3k|            loader_free(item->pAllocator, item->valuestring);
  160|  16.3k|            item->valuestring = NULL;
  161|  16.3k|        }
  162|  58.3k|        if (!(item->type & cJSON_StringIsConst) && (item->string != NULL)) {
  ------------------
  |  |  107|  58.3k|#define cJSON_StringIsConst 512
  ------------------
  |  Branch (162:13): [True: 58.3k, False: 0]
  |  Branch (162:52): [True: 29.0k, False: 29.3k]
  ------------------
  163|  29.0k|            loader_free(item->pAllocator, item->string);
  164|       |            item->string = NULL;
  165|  29.0k|        }
  166|  58.3k|        loader_free(item->pAllocator, item);
  167|  58.3k|        item = next;
  168|  58.3k|    }
  169|  33.2k|}
loader_cJSON_ParseWithLengthOpts:
  824|  5.22k|                                 const char **return_parse_end, cJSON_bool require_null_terminated, bool *out_of_memory) {
  825|  5.22k|    parse_buffer buffer = {0, 0, 0, 0, 0};
  826|  5.22k|    cJSON *item = NULL;
  827|       |
  828|       |    /* reset error position */
  829|       |    // global_error.json = NULL;
  830|       |    // global_error.position = 0;
  831|       |
  832|  5.22k|    if (value == NULL || 0 == buffer_length) {
  ------------------
  |  Branch (832:9): [True: 0, False: 5.22k]
  |  Branch (832:26): [True: 0, False: 5.22k]
  ------------------
  833|      0|        goto fail;
  834|      0|    }
  835|       |
  836|  5.22k|    buffer.content = (const unsigned char *)value;
  837|  5.22k|    buffer.length = buffer_length;
  838|  5.22k|    buffer.offset = 0;
  839|  5.22k|    buffer.pAllocator = pAllocator;
  840|       |
  841|  5.22k|    item = cJSON_New_Item(pAllocator);
  842|  5.22k|    if (item == NULL) /* memory fail */
  ------------------
  |  Branch (842:9): [True: 0, False: 5.22k]
  ------------------
  843|      0|    {
  844|      0|        *out_of_memory = true;
  ------------------
  |  |   67|      0|#define true ((cJSON_bool)1)
  ------------------
  845|      0|        goto fail;
  846|      0|    }
  847|       |
  848|  5.22k|    if (!parse_value(item, buffer_skip_whitespace(skip_utf8_bom(&buffer)), out_of_memory)) {
  ------------------
  |  Branch (848:9): [True: 3.23k, False: 1.99k]
  ------------------
  849|       |        /* parse failure. ep is set. */
  850|  3.23k|        goto fail;
  851|  3.23k|    }
  852|       |
  853|       |    /* if we require null-terminated JSON without appended garbage, skip and then check for a null terminator */
  854|  1.99k|    if (require_null_terminated) {
  ------------------
  |  Branch (854:9): [True: 0, False: 1.99k]
  ------------------
  855|      0|        buffer_skip_whitespace(&buffer);
  856|      0|        if ((buffer.offset >= buffer.length) || buffer_at_offset(&buffer)[0] != '\0') {
  ------------------
  |  |  195|      0|#define buffer_at_offset(buffer) ((buffer)->content + (buffer)->offset)
  ------------------
  |  Branch (856:13): [True: 0, False: 0]
  |  Branch (856:49): [True: 0, False: 0]
  ------------------
  857|      0|            goto fail;
  858|      0|        }
  859|      0|    }
  860|  1.99k|    if (return_parse_end) {
  ------------------
  |  Branch (860:9): [True: 0, False: 1.99k]
  ------------------
  861|      0|        *return_parse_end = (const char *)buffer_at_offset(&buffer);
  ------------------
  |  |  195|      0|#define buffer_at_offset(buffer) ((buffer)->content + (buffer)->offset)
  ------------------
  862|      0|    }
  863|       |
  864|  1.99k|    return item;
  865|       |
  866|  3.23k|fail:
  867|  3.23k|    if (item != NULL) {
  ------------------
  |  Branch (867:9): [True: 3.23k, False: 0]
  ------------------
  868|  3.23k|        loader_cJSON_Delete(item);
  869|  3.23k|    }
  870|       |
  871|  3.23k|    if (value != NULL) {
  ------------------
  |  Branch (871:9): [True: 3.23k, False: 0]
  ------------------
  872|  3.23k|        error local_error;
  873|  3.23k|        local_error.json = (const unsigned char *)value;
  874|  3.23k|        local_error.position = 0;
  875|       |
  876|  3.23k|        if (buffer.offset < buffer.length) {
  ------------------
  |  Branch (876:13): [True: 3.18k, False: 51]
  ------------------
  877|  3.18k|            local_error.position = buffer.offset;
  878|  3.18k|        } else if (buffer.length > 0) {
  ------------------
  |  Branch (878:20): [True: 51, False: 0]
  ------------------
  879|     51|            local_error.position = buffer.length - 1;
  880|     51|        }
  881|       |
  882|  3.23k|        if (return_parse_end != NULL) {
  ------------------
  |  Branch (882:13): [True: 0, False: 3.23k]
  ------------------
  883|      0|            *return_parse_end = (const char *)local_error.json + local_error.position;
  884|      0|        }
  885|       |
  886|       |        // global_error = local_error;
  887|  3.23k|    }
  888|       |
  889|       |    return NULL;
  890|  1.99k|}
loader_cJSON_ParseWithLength:
  899|  5.22k|                             bool *out_of_memory) {
  900|  5.22k|    return loader_cJSON_ParseWithLengthOpts(pAllocator, value, buffer_length, 0, 0, out_of_memory);
  901|  5.22k|}
loader_cJSON_Print:
  953|    796|TEST_FUNCTION_EXPORT CJSON_PUBLIC(char *) loader_cJSON_Print(const cJSON *item, bool *out_of_memory) {
  954|    796|    return (char *)print(item, true, out_of_memory);
  ------------------
  |  |   67|    796|#define true ((cJSON_bool)1)
  ------------------
  955|    796|}
loader_cJSON_PrintPreallocated:
  990|  3.33k|    loader_cJSON_PrintPreallocated(cJSON *item, char *buffer, const int length, const cJSON_bool format) {
  991|  3.33k|    printbuffer p = {0, 0, 0, 0, 0, 0, 0};
  992|       |
  993|  3.33k|    if ((length < 0) || (buffer == NULL)) {
  ------------------
  |  Branch (993:9): [True: 0, False: 3.33k]
  |  Branch (993:25): [True: 0, False: 3.33k]
  ------------------
  994|      0|        return false;
  ------------------
  |  |   72|      0|#define false ((cJSON_bool)0)
  ------------------
  995|      0|    }
  996|       |
  997|  3.33k|    p.buffer = (unsigned char *)buffer;
  998|  3.33k|    p.length = (size_t)length;
  999|  3.33k|    p.offset = 0;
 1000|  3.33k|    p.noalloc = true;
  ------------------
  |  |   67|  3.33k|#define true ((cJSON_bool)1)
  ------------------
 1001|  3.33k|    p.format = format;
 1002|  3.33k|    p.pAllocator = item->pAllocator;
 1003|  3.33k|    bool out_of_memory = false;
  ------------------
  |  |   72|  3.33k|#define false ((cJSON_bool)0)
  ------------------
 1004|  3.33k|    return print_value(item, &p, &out_of_memory);
 1005|  3.33k|}
loader_cJSON_GetArraySize:
 1457|    133|CJSON_PUBLIC(int) loader_cJSON_GetArraySize(const cJSON *array) {
 1458|    133|    cJSON *child = NULL;
 1459|    133|    size_t size = 0;
 1460|       |
 1461|    133|    if (array == NULL) {
  ------------------
  |  Branch (1461:9): [True: 0, False: 133]
  ------------------
 1462|      0|        return 0;
 1463|      0|    }
 1464|       |
 1465|    133|    child = array->child;
 1466|       |
 1467|    543|    while (child != NULL) {
  ------------------
  |  Branch (1467:12): [True: 410, False: 133]
  ------------------
 1468|    410|        size++;
 1469|    410|        child = child->next;
 1470|    410|    }
 1471|       |
 1472|       |    /* FIXME: Can overflow here. Cannot be fixed without breaking the API */
 1473|       |
 1474|    133|    return (int)size;
 1475|    133|}
loader_cJSON_GetObjectItem:
 1527|  18.1k|CJSON_PUBLIC(cJSON *) loader_cJSON_GetObjectItem(const cJSON *const object, const char *const string) {
 1528|  18.1k|    return get_object_item(object, string, false);
  ------------------
  |  |   72|  18.1k|#define false ((cJSON_bool)0)
  ------------------
 1529|  18.1k|}
loader_cJSON_IsString:
 1670|  6.08k|CJSON_PUBLIC(cJSON_bool) loader_cJSON_IsString(const cJSON *const item) {
 1671|  6.08k|    if (item == NULL) {
  ------------------
  |  Branch (1671:9): [True: 1.27k, False: 4.81k]
  ------------------
 1672|  1.27k|        return false;
  ------------------
  |  |   72|  1.27k|#define false ((cJSON_bool)0)
  ------------------
 1673|  1.27k|    }
 1674|       |
 1675|  4.81k|    return (item->type & 0xFF) == cJSON_String;
  ------------------
  |  |  101|  4.81k|#define cJSON_String (1 << 4)
  ------------------
 1676|  6.08k|}
cJSON.c:cJSON_New_Item:
  142|  58.3k|static cJSON *cJSON_New_Item(const VkAllocationCallbacks *pAllocator) {
  143|  58.3k|    cJSON *node = (cJSON *)loader_calloc(pAllocator, sizeof(cJSON), VK_SYSTEM_ALLOCATION_SCOPE_COMMAND);
  144|  58.3k|    if (NULL != node) {
  ------------------
  |  Branch (144:9): [True: 58.3k, False: 0]
  ------------------
  145|  58.3k|        node->pAllocator = pAllocator;
  146|  58.3k|    }
  147|  58.3k|    return node;
  148|  58.3k|}
cJSON.c:buffer_skip_whitespace:
  772|   178k|static parse_buffer *buffer_skip_whitespace(parse_buffer *const buffer) {
  773|   178k|    if ((buffer == NULL) || (buffer->content == NULL)) {
  ------------------
  |  Branch (773:9): [True: 0, False: 178k]
  |  Branch (773:29): [True: 0, False: 178k]
  ------------------
  774|      0|        return NULL;
  775|      0|    }
  776|       |
  777|   178k|    if (cannot_access_at_index(buffer, 0)) {
  ------------------
  |  |  193|   178k|#define cannot_access_at_index(buffer, index) (!can_access_at_index(buffer, index))
  |  |  ------------------
  |  |  |  |  192|   178k|#define can_access_at_index(buffer, index) ((buffer != NULL) && (((buffer)->offset + index) < (buffer)->length))
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (192:45): [True: 178k, False: 0]
  |  |  |  |  |  Branch (192:65): [True: 178k, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  778|      0|        return buffer;
  779|      0|    }
  780|       |
  781|   313k|    while (can_access_at_index(buffer, 0) && (buffer_at_offset(buffer)[0] <= 32)) {
  ------------------
  |  |  192|   626k|#define can_access_at_index(buffer, index) ((buffer != NULL) && (((buffer)->offset + index) < (buffer)->length))
  |  |  ------------------
  |  |  |  Branch (192:45): [True: 313k, False: 0]
  |  |  |  Branch (192:65): [True: 310k, False: 2.55k]
  |  |  ------------------
  ------------------
                  while (can_access_at_index(buffer, 0) && (buffer_at_offset(buffer)[0] <= 32)) {
  ------------------
  |  |  195|   310k|#define buffer_at_offset(buffer) ((buffer)->content + (buffer)->offset)
  ------------------
  |  Branch (781:46): [True: 134k, False: 176k]
  ------------------
  782|   134k|        buffer->offset++;
  783|   134k|    }
  784|       |
  785|   178k|    if (buffer->offset == buffer->length) {
  ------------------
  |  Branch (785:9): [True: 2.55k, False: 176k]
  ------------------
  786|  2.55k|        buffer->offset--;
  787|  2.55k|    }
  788|       |
  789|   178k|    return buffer;
  790|   178k|}
cJSON.c:skip_utf8_bom:
  793|  5.22k|static parse_buffer *skip_utf8_bom(parse_buffer *const buffer) {
  794|  5.22k|    if ((buffer == NULL) || (buffer->content == NULL) || (buffer->offset != 0)) {
  ------------------
  |  Branch (794:9): [True: 0, False: 5.22k]
  |  Branch (794:29): [True: 0, False: 5.22k]
  |  Branch (794:58): [True: 0, False: 5.22k]
  ------------------
  795|      0|        return NULL;
  796|      0|    }
  797|       |
  798|  5.22k|    if (can_access_at_index(buffer, 4) && (strncmp((const char *)buffer_at_offset(buffer), "\xEF\xBB\xBF", 3) == 0)) {
  ------------------
  |  |  192|  10.4k|#define can_access_at_index(buffer, index) ((buffer != NULL) && (((buffer)->offset + index) < (buffer)->length))
  |  |  ------------------
  |  |  |  Branch (192:45): [True: 5.22k, False: 0]
  |  |  |  Branch (192:65): [True: 2.66k, False: 2.55k]
  |  |  ------------------
  ------------------
                  if (can_access_at_index(buffer, 4) && (strncmp((const char *)buffer_at_offset(buffer), "\xEF\xBB\xBF", 3) == 0)) {
  ------------------
  |  |  195|  2.66k|#define buffer_at_offset(buffer) ((buffer)->content + (buffer)->offset)
  ------------------
  |  Branch (798:43): [True: 28, False: 2.64k]
  ------------------
  799|     28|        buffer->offset += 3;
  800|     28|    }
  801|       |
  802|  5.22k|    return buffer;
  803|  5.22k|}
cJSON.c:print:
  905|    796|static unsigned char *print(const cJSON *const item, cJSON_bool format, bool *out_of_memory) {
  906|    796|    static const size_t default_buffer_size = 256;
  907|    796|    printbuffer buffer[1];
  908|    796|    unsigned char *printed = NULL;
  909|       |
  910|    796|    memset(buffer, 0, sizeof(buffer));
  911|       |
  912|       |    /* create buffer */
  913|    796|    buffer->buffer = (unsigned char *)loader_calloc(item->pAllocator, default_buffer_size, VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE);
  914|    796|    buffer->length = default_buffer_size;
  915|    796|    buffer->format = format;
  916|    796|    buffer->pAllocator = item->pAllocator;
  917|    796|    if (buffer->buffer == NULL) {
  ------------------
  |  Branch (917:9): [True: 0, False: 796]
  ------------------
  918|      0|        *out_of_memory = true;
  ------------------
  |  |   67|      0|#define true ((cJSON_bool)1)
  ------------------
  919|      0|        goto fail;
  920|      0|    }
  921|       |
  922|       |    /* print the value */
  923|    796|    if (!print_value(item, buffer, out_of_memory)) {
  ------------------
  |  Branch (923:9): [True: 0, False: 796]
  ------------------
  924|      0|        goto fail;
  925|      0|    }
  926|    796|    update_offset(buffer);
  927|       |
  928|    796|    printed = (unsigned char *)loader_realloc(item->pAllocator, buffer->buffer, buffer->length, buffer->offset + 1,
  929|    796|                                              VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE);
  930|    796|    if (printed == NULL) {
  ------------------
  |  Branch (930:9): [True: 0, False: 796]
  ------------------
  931|      0|        *out_of_memory = true;
  ------------------
  |  |   67|      0|#define true ((cJSON_bool)1)
  ------------------
  932|      0|        goto fail;
  933|      0|    }
  934|    796|    buffer->buffer = NULL;
  935|       |
  936|    796|    return printed;
  937|       |
  938|      0|fail:
  939|      0|    if (buffer->buffer != NULL) {
  ------------------
  |  Branch (939:9): [True: 0, False: 0]
  ------------------
  940|      0|        loader_free(item->pAllocator, buffer->buffer);
  941|      0|        buffer->buffer = NULL;
  942|      0|    }
  943|       |
  944|      0|    if (printed != NULL) {
  ------------------
  |  Branch (944:9): [True: 0, False: 0]
  ------------------
  945|      0|        loader_free(item->pAllocator, printed);
  946|      0|        printed = NULL;
  947|      0|    }
  948|       |
  949|       |    return NULL;
  950|    796|}
cJSON.c:update_offset:
  331|    796|static void update_offset(printbuffer *const buffer) {
  332|    796|    const unsigned char *buffer_pointer = NULL;
  333|    796|    if ((buffer == NULL) || (buffer->buffer == NULL)) {
  ------------------
  |  Branch (333:9): [True: 0, False: 796]
  |  Branch (333:29): [True: 0, False: 796]
  ------------------
  334|      0|        return;
  335|      0|    }
  336|    796|    buffer_pointer = buffer->buffer + buffer->offset;
  337|       |
  338|    796|    buffer->offset += strlen((const char *)buffer_pointer);
  339|    796|}
cJSON.c:parse_value:
 1008|  58.2k|static cJSON_bool parse_value(cJSON *const item, parse_buffer *const input_buffer, bool *out_of_memory) {
 1009|  58.2k|    if ((input_buffer == NULL) || (input_buffer->content == NULL)) {
  ------------------
  |  Branch (1009:9): [True: 0, False: 58.2k]
  |  Branch (1009:35): [True: 0, False: 58.2k]
  ------------------
 1010|      0|        return false; /* no input */
  ------------------
  |  |   72|      0|#define false ((cJSON_bool)0)
  ------------------
 1011|      0|    }
 1012|       |
 1013|       |    /* parse the different types of values */
 1014|       |    /* null */
 1015|  58.2k|    if (can_read(input_buffer, 4) && (strncmp((const char *)buffer_at_offset(input_buffer), "null", 4) == 0)) {
  ------------------
  |  |  190|   116k|#define can_read(buffer, size) ((buffer != NULL) && (((buffer)->offset + size) <= (buffer)->length))
  |  |  ------------------
  |  |  |  Branch (190:33): [True: 58.2k, False: 0]
  |  |  |  Branch (190:53): [True: 55.4k, False: 2.79k]
  |  |  ------------------
  ------------------
                  if (can_read(input_buffer, 4) && (strncmp((const char *)buffer_at_offset(input_buffer), "null", 4) == 0)) {
  ------------------
  |  |  195|  55.4k|#define buffer_at_offset(buffer) ((buffer)->content + (buffer)->offset)
  ------------------
  |  Branch (1015:38): [True: 88, False: 55.3k]
  ------------------
 1016|     88|        item->type = cJSON_NULL;
  ------------------
  |  |   99|     88|#define cJSON_NULL (1 << 2)
  ------------------
 1017|     88|        input_buffer->offset += 4;
 1018|     88|        return true;
  ------------------
  |  |   67|     88|#define true ((cJSON_bool)1)
  ------------------
 1019|     88|    }
 1020|       |    /* false */
 1021|  58.1k|    if (can_read(input_buffer, 5) && (strncmp((const char *)buffer_at_offset(input_buffer), "false", 5) == 0)) {
  ------------------
  |  |  190|   116k|#define can_read(buffer, size) ((buffer != NULL) && (((buffer)->offset + size) <= (buffer)->length))
  |  |  ------------------
  |  |  |  Branch (190:33): [True: 58.1k, False: 0]
  |  |  |  Branch (190:53): [True: 55.0k, False: 3.10k]
  |  |  ------------------
  ------------------
                  if (can_read(input_buffer, 5) && (strncmp((const char *)buffer_at_offset(input_buffer), "false", 5) == 0)) {
  ------------------
  |  |  195|  55.0k|#define buffer_at_offset(buffer) ((buffer)->content + (buffer)->offset)
  ------------------
  |  Branch (1021:38): [True: 44, False: 54.9k]
  ------------------
 1022|     44|        item->type = cJSON_False;
  ------------------
  |  |   97|     44|#define cJSON_False (1 << 0)
  ------------------
 1023|     44|        input_buffer->offset += 5;
 1024|     44|        return true;
  ------------------
  |  |   67|     44|#define true ((cJSON_bool)1)
  ------------------
 1025|     44|    }
 1026|       |    /* true */
 1027|  58.0k|    if (can_read(input_buffer, 4) && (strncmp((const char *)buffer_at_offset(input_buffer), "true", 4) == 0)) {
  ------------------
  |  |  190|   116k|#define can_read(buffer, size) ((buffer != NULL) && (((buffer)->offset + size) <= (buffer)->length))
  |  |  ------------------
  |  |  |  Branch (190:33): [True: 58.0k, False: 0]
  |  |  |  Branch (190:53): [True: 55.2k, False: 2.79k]
  |  |  ------------------
  ------------------
                  if (can_read(input_buffer, 4) && (strncmp((const char *)buffer_at_offset(input_buffer), "true", 4) == 0)) {
  ------------------
  |  |  195|  55.2k|#define buffer_at_offset(buffer) ((buffer)->content + (buffer)->offset)
  ------------------
  |  Branch (1027:38): [True: 147, False: 55.1k]
  ------------------
 1028|    147|        item->type = cJSON_True;
  ------------------
  |  |   98|    147|#define cJSON_True (1 << 1)
  ------------------
 1029|    147|        item->valueint = 1;
 1030|    147|        input_buffer->offset += 4;
 1031|    147|        return true;
  ------------------
  |  |   67|    147|#define true ((cJSON_bool)1)
  ------------------
 1032|    147|    }
 1033|       |    /* string */
 1034|  57.9k|    if (can_access_at_index(input_buffer, 0) && (buffer_at_offset(input_buffer)[0] == '\"')) {
  ------------------
  |  |  192|   115k|#define can_access_at_index(buffer, index) ((buffer != NULL) && (((buffer)->offset + index) < (buffer)->length))
  |  |  ------------------
  |  |  |  Branch (192:45): [True: 57.9k, False: 0]
  |  |  |  Branch (192:65): [True: 57.9k, False: 0]
  |  |  ------------------
  ------------------
                  if (can_access_at_index(input_buffer, 0) && (buffer_at_offset(input_buffer)[0] == '\"')) {
  ------------------
  |  |  195|  57.9k|#define buffer_at_offset(buffer) ((buffer)->content + (buffer)->offset)
  ------------------
  |  Branch (1034:49): [True: 16.5k, False: 41.3k]
  ------------------
 1035|  16.5k|        return parse_string(item, input_buffer, out_of_memory);
 1036|  16.5k|    }
 1037|       |    /* number */
 1038|  41.3k|    if (can_access_at_index(input_buffer, 0) &&
  ------------------
  |  |  192|  82.6k|#define can_access_at_index(buffer, index) ((buffer != NULL) && (((buffer)->offset + index) < (buffer)->length))
  |  |  ------------------
  |  |  |  Branch (192:45): [True: 41.3k, False: 0]
  |  |  |  Branch (192:65): [True: 41.3k, False: 0]
  |  |  ------------------
  ------------------
 1039|  41.3k|        ((buffer_at_offset(input_buffer)[0] == '-') ||
  ------------------
  |  |  195|  41.3k|#define buffer_at_offset(buffer) ((buffer)->content + (buffer)->offset)
  ------------------
  |  Branch (1039:10): [True: 1.92k, False: 39.4k]
  ------------------
 1040|  39.4k|         ((buffer_at_offset(input_buffer)[0] >= '0') && (buffer_at_offset(input_buffer)[0] <= '9')))) {
  ------------------
  |  |  195|  39.4k|#define buffer_at_offset(buffer) ((buffer)->content + (buffer)->offset)
  ------------------
                       ((buffer_at_offset(input_buffer)[0] >= '0') && (buffer_at_offset(input_buffer)[0] <= '9')))) {
  ------------------
  |  |  195|  37.0k|#define buffer_at_offset(buffer) ((buffer)->content + (buffer)->offset)
  ------------------
  |  Branch (1040:11): [True: 37.0k, False: 2.33k]
  |  Branch (1040:57): [True: 7.79k, False: 29.2k]
  ------------------
 1041|  9.72k|        return parse_number(item, input_buffer);
 1042|  9.72k|    }
 1043|       |    /* array */
 1044|  31.6k|    if (can_access_at_index(input_buffer, 0) && (buffer_at_offset(input_buffer)[0] == '[')) {
  ------------------
  |  |  192|  63.2k|#define can_access_at_index(buffer, index) ((buffer != NULL) && (((buffer)->offset + index) < (buffer)->length))
  |  |  ------------------
  |  |  |  Branch (192:45): [True: 31.6k, False: 0]
  |  |  |  Branch (192:65): [True: 31.6k, False: 0]
  |  |  ------------------
  ------------------
                  if (can_access_at_index(input_buffer, 0) && (buffer_at_offset(input_buffer)[0] == '[')) {
  ------------------
  |  |  195|  31.6k|#define buffer_at_offset(buffer) ((buffer)->content + (buffer)->offset)
  ------------------
  |  Branch (1044:49): [True: 21.0k, False: 10.5k]
  ------------------
 1045|  21.0k|        return parse_array(item, input_buffer, out_of_memory);
 1046|  21.0k|    }
 1047|       |    /* object */
 1048|  10.5k|    if (can_access_at_index(input_buffer, 0) && (buffer_at_offset(input_buffer)[0] == '{')) {
  ------------------
  |  |  192|  21.1k|#define can_access_at_index(buffer, index) ((buffer != NULL) && (((buffer)->offset + index) < (buffer)->length))
  |  |  ------------------
  |  |  |  Branch (192:45): [True: 10.5k, False: 0]
  |  |  |  Branch (192:65): [True: 10.5k, False: 0]
  |  |  ------------------
  ------------------
                  if (can_access_at_index(input_buffer, 0) && (buffer_at_offset(input_buffer)[0] == '{')) {
  ------------------
  |  |  195|  10.5k|#define buffer_at_offset(buffer) ((buffer)->content + (buffer)->offset)
  ------------------
  |  Branch (1048:49): [True: 7.96k, False: 2.61k]
  ------------------
 1049|  7.96k|        return parse_object(item, input_buffer, out_of_memory);
 1050|  7.96k|    }
 1051|       |
 1052|  2.61k|    return false;
  ------------------
  |  |   72|  2.61k|#define false ((cJSON_bool)0)
  ------------------
 1053|  10.5k|}
cJSON.c:parse_string:
  533|  45.7k|static cJSON_bool parse_string(cJSON *const item, parse_buffer *const input_buffer, bool *out_of_memory) {
  534|  45.7k|    const unsigned char *input_pointer = buffer_at_offset(input_buffer) + 1;
  ------------------
  |  |  195|  45.7k|#define buffer_at_offset(buffer) ((buffer)->content + (buffer)->offset)
  ------------------
  535|  45.7k|    const unsigned char *input_end = buffer_at_offset(input_buffer) + 1;
  ------------------
  |  |  195|  45.7k|#define buffer_at_offset(buffer) ((buffer)->content + (buffer)->offset)
  ------------------
  536|  45.7k|    unsigned char *output_pointer = NULL;
  537|  45.7k|    unsigned char *output = NULL;
  538|       |
  539|       |    /* not a string */
  540|  45.7k|    if (buffer_at_offset(input_buffer)[0] != '\"') {
  ------------------
  |  |  195|  45.7k|#define buffer_at_offset(buffer) ((buffer)->content + (buffer)->offset)
  ------------------
  |  Branch (540:9): [True: 91, False: 45.6k]
  ------------------
  541|     91|        goto fail;
  542|     91|    }
  543|       |
  544|  45.6k|    {
  545|       |        /* calculate approximate size of the output (overestimate) */
  546|  45.6k|        size_t allocation_length = 0;
  547|  45.6k|        size_t skipped_bytes = 0;
  548|  1.18M|        while (((size_t)(input_end - input_buffer->content) < input_buffer->length) && (*input_end != '\"')) {
  ------------------
  |  Branch (548:16): [True: 1.18M, False: 77]
  |  Branch (548:88): [True: 1.14M, False: 45.5k]
  ------------------
  549|       |            /* is escape sequence */
  550|  1.14M|            if (input_end[0] == '\\') {
  ------------------
  |  Branch (550:17): [True: 16.1k, False: 1.12M]
  ------------------
  551|  16.1k|                if ((size_t)(input_end + 1 - input_buffer->content) >= input_buffer->length) {
  ------------------
  |  Branch (551:21): [True: 0, False: 16.1k]
  ------------------
  552|       |                    /* prevent buffer overflow when last input character is a backslash */
  553|      0|                    goto fail;
  554|      0|                }
  555|  16.1k|                skipped_bytes++;
  556|  16.1k|                input_end++;
  557|  16.1k|            }
  558|  1.14M|            input_end++;
  559|  1.14M|        }
  560|  45.6k|        if (((size_t)(input_end - input_buffer->content) >= input_buffer->length) || (*input_end != '\"')) {
  ------------------
  |  Branch (560:13): [True: 77, False: 45.5k]
  |  Branch (560:86): [True: 0, False: 45.5k]
  ------------------
  561|     77|            goto fail; /* string ended unexpectedly */
  562|     77|        }
  563|       |
  564|       |        /* This is at most how much we need for the output */
  565|  45.5k|        allocation_length = (size_t)(input_end - buffer_at_offset(input_buffer)) - skipped_bytes;
  ------------------
  |  |  195|  45.5k|#define buffer_at_offset(buffer) ((buffer)->content + (buffer)->offset)
  ------------------
  566|  45.5k|        output = (unsigned char *)loader_calloc(input_buffer->pAllocator, allocation_length + sizeof(""),
  567|  45.5k|                                                VK_SYSTEM_ALLOCATION_SCOPE_COMMAND);
  568|  45.5k|        if (output == NULL) {
  ------------------
  |  Branch (568:13): [True: 0, False: 45.5k]
  ------------------
  569|      0|            *out_of_memory = true;
  ------------------
  |  |   67|      0|#define true ((cJSON_bool)1)
  ------------------
  570|      0|            goto fail; /* allocation failure */
  571|      0|        }
  572|  45.5k|    }
  573|       |
  574|  45.5k|    output_pointer = output;
  575|       |    /* loop through the string literal */
  576|  1.06M|    while (input_pointer < input_end) {
  ------------------
  |  Branch (576:12): [True: 1.01M, False: 45.3k]
  ------------------
  577|  1.01M|        if (*input_pointer != '\\') {
  ------------------
  |  Branch (577:13): [True: 1.00M, False: 10.8k]
  ------------------
  578|  1.00M|            *output_pointer++ = *input_pointer++;
  579|  1.00M|        }
  580|       |        /* escape sequence */
  581|  10.8k|        else {
  582|  10.8k|            unsigned char sequence_length = 2;
  583|  10.8k|            if ((input_end - input_pointer) < 1) {
  ------------------
  |  Branch (583:17): [True: 0, False: 10.8k]
  ------------------
  584|      0|                goto fail;
  585|      0|            }
  586|       |
  587|  10.8k|            switch (input_pointer[1]) {
  588|     80|                case 'b':
  ------------------
  |  Branch (588:17): [True: 80, False: 10.8k]
  ------------------
  589|     80|                    *output_pointer++ = '\b';
  590|     80|                    break;
  591|    345|                case 'f':
  ------------------
  |  Branch (591:17): [True: 345, False: 10.5k]
  ------------------
  592|    345|                    *output_pointer++ = '\f';
  593|    345|                    break;
  594|    224|                case 'n':
  ------------------
  |  Branch (594:17): [True: 224, False: 10.6k]
  ------------------
  595|    224|                    *output_pointer++ = '\n';
  596|    224|                    break;
  597|    120|                case 'r':
  ------------------
  |  Branch (597:17): [True: 120, False: 10.7k]
  ------------------
  598|    120|                    *output_pointer++ = '\r';
  599|    120|                    break;
  600|    951|                case 't':
  ------------------
  |  Branch (600:17): [True: 951, False: 9.94k]
  ------------------
  601|    951|                    *output_pointer++ = '\t';
  602|    951|                    break;
  603|    293|                case '\"':
  ------------------
  |  Branch (603:17): [True: 293, False: 10.5k]
  ------------------
  604|  1.07k|                case '\\':
  ------------------
  |  Branch (604:17): [True: 777, False: 10.1k]
  ------------------
  605|  1.25k|                case '/':
  ------------------
  |  Branch (605:17): [True: 181, False: 10.7k]
  ------------------
  606|  1.25k|                    *output_pointer++ = input_pointer[1];
  607|  1.25k|                    break;
  608|       |
  609|       |                /* UTF-16 literal */
  610|  7.89k|                case 'u':
  ------------------
  |  Branch (610:17): [True: 7.89k, False: 2.99k]
  ------------------
  611|  7.89k|                    sequence_length = utf16_literal_to_utf8(input_pointer, input_end, &output_pointer);
  612|  7.89k|                    if (sequence_length == 0) {
  ------------------
  |  Branch (612:25): [True: 169, False: 7.72k]
  ------------------
  613|       |                        /* failed to convert UTF16-literal to UTF-8 */
  614|    169|                        goto fail;
  615|    169|                    }
  616|  7.72k|                    break;
  617|       |
  618|  7.72k|                default:
  ------------------
  |  Branch (618:17): [True: 24, False: 10.8k]
  ------------------
  619|     24|                    goto fail;
  620|  10.8k|            }
  621|  10.6k|            input_pointer += sequence_length;
  622|  10.6k|        }
  623|  1.01M|    }
  624|       |
  625|       |    /* zero terminate the output */
  626|  45.3k|    *output_pointer = '\0';
  627|       |
  628|  45.3k|    item->type = cJSON_String;
  ------------------
  |  |  101|  45.3k|#define cJSON_String (1 << 4)
  ------------------
  629|  45.3k|    item->valuestring = (char *)output;
  630|       |
  631|  45.3k|    input_buffer->offset = (size_t)(input_end - input_buffer->content);
  632|  45.3k|    input_buffer->offset++;
  633|       |
  634|  45.3k|    return true;
  ------------------
  |  |   67|  45.3k|#define true ((cJSON_bool)1)
  ------------------
  635|       |
  636|    361|fail:
  637|    361|    if (output != NULL) {
  ------------------
  |  Branch (637:9): [True: 193, False: 168]
  ------------------
  638|    193|        loader_free(input_buffer->pAllocator, output);
  639|    193|        output = NULL;
  640|    193|    }
  641|       |
  642|    361|    if (input_pointer != NULL) {
  ------------------
  |  Branch (642:9): [True: 361, False: 0]
  ------------------
  643|    361|        input_buffer->offset = (size_t)(input_pointer - input_buffer->content);
  644|    361|    }
  645|       |
  646|    361|    return false;
  ------------------
  |  |   72|    361|#define false ((cJSON_bool)0)
  ------------------
  647|  45.5k|}
cJSON.c:utf16_literal_to_utf8:
  435|  7.89k|                                           unsigned char **output_pointer) {
  436|  7.89k|    long unsigned int codepoint = 0;
  437|  7.89k|    unsigned int first_code = 0;
  438|  7.89k|    const unsigned char *first_sequence = input_pointer;
  439|  7.89k|    unsigned char utf8_length = 0;
  440|  7.89k|    unsigned char utf8_position = 0;
  441|  7.89k|    unsigned char sequence_length = 0;
  442|  7.89k|    unsigned char first_byte_mark = 0;
  443|       |
  444|  7.89k|    if ((input_end - first_sequence) < 6) {
  ------------------
  |  Branch (444:9): [True: 20, False: 7.87k]
  ------------------
  445|       |        /* input ends unexpectedly */
  446|     20|        goto fail;
  447|     20|    }
  448|       |
  449|       |    /* get the first utf16 sequence */
  450|  7.87k|    first_code = parse_hex4(first_sequence + 2);
  451|       |
  452|       |    /* check that the code is valid */
  453|  7.87k|    if (((first_code >= 0xDC00) && (first_code <= 0xDFFF))) {
  ------------------
  |  Branch (453:10): [True: 1.65k, False: 6.22k]
  |  Branch (453:36): [True: 27, False: 1.62k]
  ------------------
  454|     27|        goto fail;
  455|     27|    }
  456|       |
  457|       |    /* UTF16 surrogate pair */
  458|  7.84k|    if ((first_code >= 0xD800) && (first_code <= 0xDBFF)) {
  ------------------
  |  Branch (458:9): [True: 1.95k, False: 5.89k]
  |  Branch (458:35): [True: 331, False: 1.62k]
  ------------------
  459|    331|        const unsigned char *second_sequence = first_sequence + 6;
  460|    331|        unsigned int second_code = 0;
  461|    331|        sequence_length = 12; /* \uXXXX\uXXXX */
  462|       |
  463|    331|        if ((input_end - second_sequence) < 6) {
  ------------------
  |  Branch (463:13): [True: 20, False: 311]
  ------------------
  464|       |            /* input ends unexpectedly */
  465|     20|            goto fail;
  466|     20|        }
  467|       |
  468|    311|        if ((second_sequence[0] != '\\') || (second_sequence[1] != 'u')) {
  ------------------
  |  Branch (468:13): [True: 24, False: 287]
  |  Branch (468:45): [True: 16, False: 271]
  ------------------
  469|       |            /* missing second half of the surrogate pair */
  470|     40|            goto fail;
  471|     40|        }
  472|       |
  473|       |        /* get the second utf16 sequence */
  474|    271|        second_code = parse_hex4(second_sequence + 2);
  475|       |        /* check that the code is valid */
  476|    271|        if ((second_code < 0xDC00) || (second_code > 0xDFFF)) {
  ------------------
  |  Branch (476:13): [True: 40, False: 231]
  |  Branch (476:39): [True: 22, False: 209]
  ------------------
  477|       |            /* invalid second half of the surrogate pair */
  478|     62|            goto fail;
  479|     62|        }
  480|       |
  481|       |        /* calculate the unicode codepoint from the surrogate pair */
  482|    209|        codepoint = 0x10000 + (((first_code & 0x3FF) << 10) | (second_code & 0x3FF));
  483|  7.51k|    } else {
  484|  7.51k|        sequence_length = 6; /* \uXXXX */
  485|  7.51k|        codepoint = first_code;
  486|  7.51k|    }
  487|       |
  488|       |    /* encode as UTF-8
  489|       |     * takes at maximum 4 bytes to encode:
  490|       |     * 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx */
  491|  7.72k|    if (codepoint < 0x80) {
  ------------------
  |  Branch (491:9): [True: 5.29k, False: 2.43k]
  ------------------
  492|       |        /* normal ascii, encoding 0xxxxxxx */
  493|  5.29k|        utf8_length = 1;
  494|  5.29k|    } else if (codepoint < 0x800) {
  ------------------
  |  Branch (494:16): [True: 292, False: 2.14k]
  ------------------
  495|       |        /* two bytes, encoding 110xxxxx 10xxxxxx */
  496|    292|        utf8_length = 2;
  497|    292|        first_byte_mark = 0xC0; /* 11000000 */
  498|  2.14k|    } else if (codepoint < 0x10000) {
  ------------------
  |  Branch (498:16): [True: 1.93k, False: 209]
  ------------------
  499|       |        /* three bytes, encoding 1110xxxx 10xxxxxx 10xxxxxx */
  500|  1.93k|        utf8_length = 3;
  501|  1.93k|        first_byte_mark = 0xE0; /* 11100000 */
  502|  1.93k|    } else if (codepoint <= 0x10FFFF) {
  ------------------
  |  Branch (502:16): [True: 209, False: 0]
  ------------------
  503|       |        /* four bytes, encoding 1110xxxx 10xxxxxx 10xxxxxx 10xxxxxx */
  504|    209|        utf8_length = 4;
  505|    209|        first_byte_mark = 0xF0; /* 11110000 */
  506|    209|    } else {
  507|       |        /* invalid unicode codepoint */
  508|      0|        goto fail;
  509|      0|    }
  510|       |
  511|       |    /* encode as utf8 */
  512|  12.5k|    for (utf8_position = (unsigned char)(utf8_length - 1); utf8_position > 0; utf8_position--) {
  ------------------
  |  Branch (512:60): [True: 4.78k, False: 7.72k]
  ------------------
  513|       |        /* 10xxxxxx */
  514|  4.78k|        (*output_pointer)[utf8_position] = (unsigned char)((codepoint | 0x80) & 0xBF);
  515|  4.78k|        codepoint >>= 6;
  516|  4.78k|    }
  517|       |    /* encode first byte */
  518|  7.72k|    if (utf8_length > 1) {
  ------------------
  |  Branch (518:9): [True: 2.43k, False: 5.29k]
  ------------------
  519|  2.43k|        (*output_pointer)[0] = (unsigned char)((codepoint | first_byte_mark) & 0xFF);
  520|  5.29k|    } else {
  521|  5.29k|        (*output_pointer)[0] = (unsigned char)(codepoint & 0x7F);
  522|  5.29k|    }
  523|       |
  524|  7.72k|    *output_pointer += utf8_length;
  525|       |
  526|  7.72k|    return sequence_length;
  527|       |
  528|    169|fail:
  529|    169|    return 0;
  530|  7.72k|}
cJSON.c:parse_hex4:
  406|  8.14k|static unsigned parse_hex4(const unsigned char *const input) {
  407|  8.14k|    unsigned int h = 0;
  408|  8.14k|    size_t i = 0;
  409|       |
  410|  26.3k|    for (i = 0; i < 4; i++) {
  ------------------
  |  Branch (410:17): [True: 23.4k, False: 2.88k]
  ------------------
  411|       |        /* parse digit */
  412|  23.4k|        if ((input[i] >= '0') && (input[i] <= '9')) {
  ------------------
  |  Branch (412:13): [True: 22.3k, False: 1.15k]
  |  Branch (412:34): [True: 4.70k, False: 17.6k]
  ------------------
  413|  4.70k|            h += (unsigned int)input[i] - '0';
  414|  18.7k|        } else if ((input[i] >= 'A') && (input[i] <= 'F')) {
  ------------------
  |  Branch (414:20): [True: 16.3k, False: 2.37k]
  |  Branch (414:41): [True: 3.93k, False: 12.4k]
  ------------------
  415|  3.93k|            h += (unsigned int)10 + input[i] - 'A';
  416|  14.8k|        } else if ((input[i] >= 'a') && (input[i] <= 'f')) {
  ------------------
  |  Branch (416:20): [True: 11.1k, False: 3.73k]
  |  Branch (416:41): [True: 9.58k, False: 1.52k]
  ------------------
  417|  9.58k|            h += (unsigned int)10 + input[i] - 'a';
  418|  9.58k|        } else /* invalid */
  419|  5.26k|        {
  420|  5.26k|            return 0;
  421|  5.26k|        }
  422|       |
  423|  18.2k|        if (i < 3) {
  ------------------
  |  Branch (423:13): [True: 15.3k, False: 2.88k]
  ------------------
  424|       |            /* shift left to make place for the next nibble */
  425|  15.3k|            h = h << 4;
  426|  15.3k|        }
  427|  18.2k|    }
  428|       |
  429|  2.88k|    return h;
  430|  8.14k|}
cJSON.c:parse_number:
  198|  9.72k|static cJSON_bool parse_number(cJSON *const item, parse_buffer *const input_buffer) {
  199|  9.72k|    double number = 0;
  200|  9.72k|    unsigned char *after_end = NULL;
  201|  9.72k|    unsigned char number_c_string[64];
  202|  9.72k|    unsigned char decimal_point = get_decimal_point();
  203|  9.72k|    size_t i = 0;
  204|       |
  205|  9.72k|    if ((input_buffer == NULL) || (input_buffer->content == NULL)) {
  ------------------
  |  Branch (205:9): [True: 0, False: 9.72k]
  |  Branch (205:35): [True: 0, False: 9.72k]
  ------------------
  206|      0|        return false;
  ------------------
  |  |   72|      0|#define false ((cJSON_bool)0)
  ------------------
  207|      0|    }
  208|       |
  209|       |    /* copy the number into a temporary buffer and replace '.' with the decimal point
  210|       |     * of the current locale (for strtod)
  211|       |     * This also takes care of '\0' not necessarily being available for marking the end of the input */
  212|  72.1k|    for (i = 0; (i < (sizeof(number_c_string) - 1)) && can_access_at_index(input_buffer, i); i++) {
  ------------------
  |  |  192|  72.0k|#define can_access_at_index(buffer, index) ((buffer != NULL) && (((buffer)->offset + index) < (buffer)->length))
  |  |  ------------------
  |  |  |  Branch (192:45): [True: 72.0k, False: 0]
  |  |  |  Branch (192:65): [True: 72.0k, False: 0]
  |  |  ------------------
  ------------------
  |  Branch (212:17): [True: 72.0k, False: 35]
  ------------------
  213|  72.0k|        switch (buffer_at_offset(input_buffer)[i]) {
  ------------------
  |  |  195|  72.0k|#define buffer_at_offset(buffer) ((buffer)->content + (buffer)->offset)
  ------------------
  214|  8.40k|            case '0':
  ------------------
  |  Branch (214:13): [True: 8.40k, False: 63.6k]
  ------------------
  215|  13.3k|            case '1':
  ------------------
  |  Branch (215:13): [True: 4.96k, False: 67.1k]
  ------------------
  216|  19.8k|            case '2':
  ------------------
  |  Branch (216:13): [True: 6.52k, False: 65.5k]
  ------------------
  217|  27.3k|            case '3':
  ------------------
  |  Branch (217:13): [True: 7.48k, False: 64.6k]
  ------------------
  218|  32.5k|            case '4':
  ------------------
  |  Branch (218:13): [True: 5.12k, False: 66.9k]
  ------------------
  219|  36.4k|            case '5':
  ------------------
  |  Branch (219:13): [True: 3.97k, False: 68.1k]
  ------------------
  220|  41.0k|            case '6':
  ------------------
  |  Branch (220:13): [True: 4.61k, False: 67.4k]
  ------------------
  221|  44.9k|            case '7':
  ------------------
  |  Branch (221:13): [True: 3.85k, False: 68.2k]
  ------------------
  222|  48.7k|            case '8':
  ------------------
  |  Branch (222:13): [True: 3.79k, False: 68.3k]
  ------------------
  223|  52.8k|            case '9':
  ------------------
  |  Branch (223:13): [True: 4.10k, False: 67.9k]
  ------------------
  224|  53.2k|            case '+':
  ------------------
  |  Branch (224:13): [True: 363, False: 71.7k]
  ------------------
  225|  57.2k|            case '-':
  ------------------
  |  Branch (225:13): [True: 4.06k, False: 68.0k]
  ------------------
  226|  58.4k|            case 'e':
  ------------------
  |  Branch (226:13): [True: 1.23k, False: 70.8k]
  ------------------
  227|  60.1k|            case 'E':
  ------------------
  |  Branch (227:13): [True: 1.68k, False: 70.4k]
  ------------------
  228|  60.1k|                number_c_string[i] = buffer_at_offset(input_buffer)[i];
  ------------------
  |  |  195|  60.1k|#define buffer_at_offset(buffer) ((buffer)->content + (buffer)->offset)
  ------------------
  229|  60.1k|                break;
  230|       |
  231|  2.22k|            case '.':
  ------------------
  |  Branch (231:13): [True: 2.22k, False: 69.8k]
  ------------------
  232|  2.22k|                number_c_string[i] = decimal_point;
  233|  2.22k|                break;
  234|       |
  235|  9.69k|            default:
  ------------------
  |  Branch (235:13): [True: 9.69k, False: 62.4k]
  ------------------
  236|  9.69k|                goto loop_end;
  237|  72.0k|        }
  238|  72.0k|    }
  239|  9.72k|loop_end:
  240|  9.72k|    number_c_string[i] = '\0';
  241|       |
  242|  9.72k|    number = strtod((const char *)number_c_string, (char **)&after_end);
  243|  9.72k|    if (number_c_string == after_end) {
  ------------------
  |  Branch (243:9): [True: 56, False: 9.66k]
  ------------------
  244|     56|        return false; /* parse_error */
  ------------------
  |  |   72|     56|#define false ((cJSON_bool)0)
  ------------------
  245|     56|    }
  246|       |
  247|  9.66k|    item->valuedouble = number;
  248|       |
  249|       |    /* use saturation in case of overflow */
  250|  9.66k|    if (number >= INT_MAX) {
  ------------------
  |  Branch (250:9): [True: 1.00k, False: 8.66k]
  ------------------
  251|  1.00k|        item->valueint = INT_MAX;
  252|  8.66k|    } else if (number <= (double)INT_MIN) {
  ------------------
  |  Branch (252:16): [True: 124, False: 8.53k]
  ------------------
  253|    124|        item->valueint = INT_MIN;
  254|  8.53k|    } else {
  255|  8.53k|        item->valueint = (int)number;
  256|  8.53k|    }
  257|       |
  258|  9.66k|    item->type = cJSON_Number;
  ------------------
  |  |  100|  9.66k|#define cJSON_Number (1 << 3)
  ------------------
  259|       |
  260|  9.66k|    input_buffer->offset += (size_t)(after_end - number_c_string);
  261|  9.66k|    return true;
  ------------------
  |  |   67|  9.66k|#define true ((cJSON_bool)1)
  ------------------
  262|  9.72k|}
cJSON.c:get_decimal_point:
  172|  9.72k|static unsigned char get_decimal_point(void) {
  173|       |#ifdef ENABLE_LOCALES
  174|       |    struct lconv *lconv = localeconv();
  175|       |    return (unsigned char)lconv->decimal_point[0];
  176|       |#else
  177|  9.72k|    return '.';
  178|  9.72k|#endif
  179|  9.72k|}
cJSON.c:parse_array:
 1121|  21.0k|static cJSON_bool parse_array(cJSON *const item, parse_buffer *const input_buffer, bool *out_of_memory) {
 1122|  21.0k|    cJSON *head = NULL; /* head of the linked list */
 1123|  21.0k|    cJSON *current_item = NULL;
 1124|       |
 1125|  21.0k|    if (input_buffer->depth >= CJSON_NESTING_LIMIT) {
  ------------------
  |  |  138|  21.0k|#define CJSON_NESTING_LIMIT 1000
  ------------------
  |  Branch (1125:9): [True: 2, False: 21.0k]
  ------------------
 1126|      2|        return false; /* to deeply nested */
  ------------------
  |  |   72|      2|#define false ((cJSON_bool)0)
  ------------------
 1127|      2|    }
 1128|  21.0k|    input_buffer->depth++;
 1129|       |
 1130|  21.0k|    if (buffer_at_offset(input_buffer)[0] != '[') {
  ------------------
  |  |  195|  21.0k|#define buffer_at_offset(buffer) ((buffer)->content + (buffer)->offset)
  ------------------
  |  Branch (1130:9): [True: 0, False: 21.0k]
  ------------------
 1131|       |        /* not an array */
 1132|      0|        goto fail;
 1133|      0|    }
 1134|       |
 1135|  21.0k|    input_buffer->offset++;
 1136|  21.0k|    buffer_skip_whitespace(input_buffer);
 1137|  21.0k|    if (can_access_at_index(input_buffer, 0) && (buffer_at_offset(input_buffer)[0] == ']')) {
  ------------------
  |  |  192|  42.0k|#define can_access_at_index(buffer, index) ((buffer != NULL) && (((buffer)->offset + index) < (buffer)->length))
  |  |  ------------------
  |  |  |  Branch (192:45): [True: 21.0k, False: 0]
  |  |  |  Branch (192:65): [True: 21.0k, False: 0]
  |  |  ------------------
  ------------------
                  if (can_access_at_index(input_buffer, 0) && (buffer_at_offset(input_buffer)[0] == ']')) {
  ------------------
  |  |  195|  21.0k|#define buffer_at_offset(buffer) ((buffer)->content + (buffer)->offset)
  ------------------
  |  Branch (1137:49): [True: 309, False: 20.7k]
  ------------------
 1138|       |        /* empty array */
 1139|    309|        goto success;
 1140|    309|    }
 1141|       |
 1142|       |    /* check if we skipped to the end of the buffer */
 1143|  20.7k|    if (cannot_access_at_index(input_buffer, 0)) {
  ------------------
  |  |  193|  20.7k|#define cannot_access_at_index(buffer, index) (!can_access_at_index(buffer, index))
  |  |  ------------------
  |  |  |  |  192|  20.7k|#define can_access_at_index(buffer, index) ((buffer != NULL) && (((buffer)->offset + index) < (buffer)->length))
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (192:45): [True: 20.7k, False: 0]
  |  |  |  |  |  Branch (192:65): [True: 20.7k, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1144|      0|        input_buffer->offset--;
 1145|      0|        goto fail;
 1146|      0|    }
 1147|       |
 1148|       |    /* step back to character in front of the first element */
 1149|  20.7k|    input_buffer->offset--;
 1150|       |    /* loop through the comma separated array elements */
 1151|  23.9k|    do {
 1152|       |        /* allocate next item */
 1153|  23.9k|        cJSON *new_item = cJSON_New_Item(input_buffer->pAllocator);
 1154|  23.9k|        if (new_item == NULL) {
  ------------------
  |  Branch (1154:13): [True: 0, False: 23.9k]
  ------------------
 1155|      0|            *out_of_memory = true;
  ------------------
  |  |   67|      0|#define true ((cJSON_bool)1)
  ------------------
 1156|      0|            goto fail; /* allocation failure */
 1157|      0|        }
 1158|       |
 1159|       |        /* attach next item to list */
 1160|  23.9k|        if (head == NULL) {
  ------------------
  |  Branch (1160:13): [True: 20.7k, False: 3.26k]
  ------------------
 1161|       |            /* start the linked list */
 1162|  20.7k|            current_item = head = new_item;
 1163|  20.7k|        } else {
 1164|       |            /* add to the end and advance */
 1165|  3.26k|            current_item->next = new_item;
 1166|  3.26k|            new_item->prev = current_item;
 1167|  3.26k|            current_item = new_item;
 1168|  3.26k|        }
 1169|       |
 1170|       |        /* parse next value */
 1171|  23.9k|        input_buffer->offset++;
 1172|  23.9k|        buffer_skip_whitespace(input_buffer);
 1173|  23.9k|        if (!parse_value(current_item, input_buffer, out_of_memory)) {
  ------------------
  |  Branch (1173:13): [True: 19.0k, False: 4.95k]
  ------------------
 1174|  19.0k|            goto fail; /* failed to parse value */
 1175|  19.0k|        }
 1176|  4.95k|        buffer_skip_whitespace(input_buffer);
 1177|  4.95k|    } while (can_access_at_index(input_buffer, 0) && (buffer_at_offset(input_buffer)[0] == ','));
  ------------------
  |  |  192|  9.90k|#define can_access_at_index(buffer, index) ((buffer != NULL) && (((buffer)->offset + index) < (buffer)->length))
  |  |  ------------------
  |  |  |  Branch (192:45): [True: 4.95k, False: 0]
  |  |  |  Branch (192:65): [True: 4.95k, False: 0]
  |  |  ------------------
  ------------------
                  } while (can_access_at_index(input_buffer, 0) && (buffer_at_offset(input_buffer)[0] == ','));
  ------------------
  |  |  195|  4.95k|#define buffer_at_offset(buffer) ((buffer)->content + (buffer)->offset)
  ------------------
  |  Branch (1177:54): [True: 3.26k, False: 1.68k]
  ------------------
 1178|       |
 1179|  1.68k|    if (cannot_access_at_index(input_buffer, 0) || buffer_at_offset(input_buffer)[0] != ']') {
  ------------------
  |  |  193|  3.37k|#define cannot_access_at_index(buffer, index) (!can_access_at_index(buffer, index))
  |  |  ------------------
  |  |  |  |  192|  1.68k|#define can_access_at_index(buffer, index) ((buffer != NULL) && (((buffer)->offset + index) < (buffer)->length))
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (192:45): [True: 1.68k, False: 0]
  |  |  |  |  |  Branch (192:65): [True: 1.68k, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
                  if (cannot_access_at_index(input_buffer, 0) || buffer_at_offset(input_buffer)[0] != ']') {
  ------------------
  |  |  195|  1.68k|#define buffer_at_offset(buffer) ((buffer)->content + (buffer)->offset)
  ------------------
  |  Branch (1179:52): [True: 128, False: 1.56k]
  ------------------
 1180|    128|        goto fail; /* expected end of array */
 1181|    128|    }
 1182|       |
 1183|  1.87k|success:
 1184|  1.87k|    input_buffer->depth--;
 1185|       |
 1186|  1.87k|    if (head != NULL) {
  ------------------
  |  Branch (1186:9): [True: 1.56k, False: 309]
  ------------------
 1187|  1.56k|        head->prev = current_item;
 1188|  1.56k|    }
 1189|       |
 1190|  1.87k|    item->type = cJSON_Array;
  ------------------
  |  |  102|  1.87k|#define cJSON_Array (1 << 5)
  ------------------
 1191|  1.87k|    item->child = head;
 1192|       |
 1193|  1.87k|    input_buffer->offset++;
 1194|       |
 1195|  1.87k|    return true;
  ------------------
  |  |   67|  1.87k|#define true ((cJSON_bool)1)
  ------------------
 1196|       |
 1197|  19.1k|fail:
 1198|  19.1k|    if (head != NULL) {
  ------------------
  |  Branch (1198:9): [True: 19.1k, False: 0]
  ------------------
 1199|  19.1k|        loader_cJSON_Delete(head);
 1200|  19.1k|    }
 1201|       |
 1202|  19.1k|    return false;
  ------------------
  |  |   72|  19.1k|#define false ((cJSON_bool)0)
  ------------------
 1203|  1.68k|}
cJSON.c:parse_object:
 1259|  7.96k|static cJSON_bool parse_object(cJSON *const item, parse_buffer *const input_buffer, bool *out_of_memory) {
 1260|  7.96k|    cJSON *head = NULL; /* linked list head */
 1261|  7.96k|    cJSON *current_item = NULL;
 1262|       |
 1263|  7.96k|    if (input_buffer->depth >= CJSON_NESTING_LIMIT) {
  ------------------
  |  |  138|  7.96k|#define CJSON_NESTING_LIMIT 1000
  ------------------
  |  Branch (1263:9): [True: 1, False: 7.96k]
  ------------------
 1264|      1|        return false; /* to deeply nested */
  ------------------
  |  |   72|      1|#define false ((cJSON_bool)0)
  ------------------
 1265|      1|    }
 1266|  7.96k|    input_buffer->depth++;
 1267|       |
 1268|  7.96k|    if (cannot_access_at_index(input_buffer, 0) || (buffer_at_offset(input_buffer)[0] != '{')) {
  ------------------
  |  |  193|  15.9k|#define cannot_access_at_index(buffer, index) (!can_access_at_index(buffer, index))
  |  |  ------------------
  |  |  |  |  192|  7.96k|#define can_access_at_index(buffer, index) ((buffer != NULL) && (((buffer)->offset + index) < (buffer)->length))
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (192:45): [True: 7.96k, False: 0]
  |  |  |  |  |  Branch (192:65): [True: 7.96k, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
                  if (cannot_access_at_index(input_buffer, 0) || (buffer_at_offset(input_buffer)[0] != '{')) {
  ------------------
  |  |  195|  7.96k|#define buffer_at_offset(buffer) ((buffer)->content + (buffer)->offset)
  ------------------
  |  Branch (1268:52): [True: 0, False: 7.96k]
  ------------------
 1269|      0|        goto fail; /* not an object */
 1270|      0|    }
 1271|       |
 1272|  7.96k|    input_buffer->offset++;
 1273|  7.96k|    buffer_skip_whitespace(input_buffer);
 1274|  7.96k|    if (can_access_at_index(input_buffer, 0) && (buffer_at_offset(input_buffer)[0] == '}')) {
  ------------------
  |  |  192|  15.9k|#define can_access_at_index(buffer, index) ((buffer != NULL) && (((buffer)->offset + index) < (buffer)->length))
  |  |  ------------------
  |  |  |  Branch (192:45): [True: 7.96k, False: 0]
  |  |  |  Branch (192:65): [True: 7.96k, False: 0]
  |  |  ------------------
  ------------------
                  if (can_access_at_index(input_buffer, 0) && (buffer_at_offset(input_buffer)[0] == '}')) {
  ------------------
  |  |  195|  7.96k|#define buffer_at_offset(buffer) ((buffer)->content + (buffer)->offset)
  ------------------
  |  Branch (1274:49): [True: 664, False: 7.30k]
  ------------------
 1275|    664|        goto success; /* empty object */
 1276|    664|    }
 1277|       |
 1278|       |    /* check if we skipped to the end of the buffer */
 1279|  7.30k|    if (cannot_access_at_index(input_buffer, 0)) {
  ------------------
  |  |  193|  7.30k|#define cannot_access_at_index(buffer, index) (!can_access_at_index(buffer, index))
  |  |  ------------------
  |  |  |  |  192|  7.30k|#define can_access_at_index(buffer, index) ((buffer != NULL) && (((buffer)->offset + index) < (buffer)->length))
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (192:45): [True: 7.30k, False: 0]
  |  |  |  |  |  Branch (192:65): [True: 7.30k, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1280|      0|        input_buffer->offset--;
 1281|      0|        goto fail;
 1282|      0|    }
 1283|       |
 1284|       |    /* step back to character in front of the first element */
 1285|  7.30k|    input_buffer->offset--;
 1286|       |    /* loop through the comma separated array elements */
 1287|  29.1k|    do {
 1288|       |        /* allocate next item */
 1289|  29.1k|        cJSON *new_item = cJSON_New_Item(input_buffer->pAllocator);
 1290|  29.1k|        if (new_item == NULL) {
  ------------------
  |  Branch (1290:13): [True: 0, False: 29.1k]
  ------------------
 1291|      0|            *out_of_memory = true;
  ------------------
  |  |   67|      0|#define true ((cJSON_bool)1)
  ------------------
 1292|      0|            goto fail; /* allocation failure */
 1293|      0|        }
 1294|       |
 1295|       |        /* attach next item to list */
 1296|  29.1k|        if (head == NULL) {
  ------------------
  |  Branch (1296:13): [True: 7.30k, False: 21.8k]
  ------------------
 1297|       |            /* start the linked list */
 1298|  7.30k|            current_item = head = new_item;
 1299|  21.8k|        } else {
 1300|       |            /* add to the end and advance */
 1301|  21.8k|            current_item->next = new_item;
 1302|  21.8k|            new_item->prev = current_item;
 1303|  21.8k|            current_item = new_item;
 1304|  21.8k|        }
 1305|       |
 1306|  29.1k|        if (cannot_access_at_index(input_buffer, 1)) {
  ------------------
  |  |  193|  29.1k|#define cannot_access_at_index(buffer, index) (!can_access_at_index(buffer, index))
  |  |  ------------------
  |  |  |  |  192|  29.1k|#define can_access_at_index(buffer, index) ((buffer != NULL) && (((buffer)->offset + index) < (buffer)->length))
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (192:45): [True: 29.1k, False: 0]
  |  |  |  |  |  Branch (192:65): [True: 29.1k, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1307|      0|            goto fail; /* nothing comes after the comma */
 1308|      0|        }
 1309|       |
 1310|       |        /* parse the name of the child */
 1311|  29.1k|        input_buffer->offset++;
 1312|  29.1k|        buffer_skip_whitespace(input_buffer);
 1313|  29.1k|        if (!parse_string(current_item, input_buffer, out_of_memory)) {
  ------------------
  |  Branch (1313:13): [True: 118, False: 29.0k]
  ------------------
 1314|    118|            goto fail; /* failed to parse name */
 1315|    118|        }
 1316|  29.0k|        buffer_skip_whitespace(input_buffer);
 1317|       |
 1318|       |        /* swap valuestring and string, because we parsed the name */
 1319|  29.0k|        current_item->string = current_item->valuestring;
 1320|  29.0k|        current_item->valuestring = NULL;
 1321|       |
 1322|  29.0k|        if (cannot_access_at_index(input_buffer, 0) || (buffer_at_offset(input_buffer)[0] != ':')) {
  ------------------
  |  |  193|  58.0k|#define cannot_access_at_index(buffer, index) (!can_access_at_index(buffer, index))
  |  |  ------------------
  |  |  |  |  192|  29.0k|#define can_access_at_index(buffer, index) ((buffer != NULL) && (((buffer)->offset + index) < (buffer)->length))
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (192:45): [True: 29.0k, False: 0]
  |  |  |  |  |  Branch (192:65): [True: 29.0k, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
                      if (cannot_access_at_index(input_buffer, 0) || (buffer_at_offset(input_buffer)[0] != ':')) {
  ------------------
  |  |  195|  29.0k|#define buffer_at_offset(buffer) ((buffer)->content + (buffer)->offset)
  ------------------
  |  Branch (1322:56): [True: 34, False: 29.0k]
  ------------------
 1323|     34|            goto fail; /* invalid object */
 1324|     34|        }
 1325|       |
 1326|       |        /* parse the value */
 1327|  29.0k|        input_buffer->offset++;
 1328|  29.0k|        buffer_skip_whitespace(input_buffer);
 1329|  29.0k|        if (!parse_value(current_item, input_buffer, out_of_memory)) {
  ------------------
  |  Branch (1329:13): [True: 333, False: 28.6k]
  ------------------
 1330|    333|            goto fail; /* failed to parse value */
 1331|    333|        }
 1332|  28.6k|        buffer_skip_whitespace(input_buffer);
 1333|  28.6k|    } while (can_access_at_index(input_buffer, 0) && (buffer_at_offset(input_buffer)[0] == ','));
  ------------------
  |  |  192|  57.3k|#define can_access_at_index(buffer, index) ((buffer != NULL) && (((buffer)->offset + index) < (buffer)->length))
  |  |  ------------------
  |  |  |  Branch (192:45): [True: 28.6k, False: 0]
  |  |  |  Branch (192:65): [True: 28.6k, False: 0]
  |  |  ------------------
  ------------------
                  } while (can_access_at_index(input_buffer, 0) && (buffer_at_offset(input_buffer)[0] == ','));
  ------------------
  |  |  195|  28.6k|#define buffer_at_offset(buffer) ((buffer)->content + (buffer)->offset)
  ------------------
  |  Branch (1333:54): [True: 21.8k, False: 6.81k]
  ------------------
 1334|       |
 1335|  6.81k|    if (cannot_access_at_index(input_buffer, 0) || (buffer_at_offset(input_buffer)[0] != '}')) {
  ------------------
  |  |  193|  13.6k|#define cannot_access_at_index(buffer, index) (!can_access_at_index(buffer, index))
  |  |  ------------------
  |  |  |  |  192|  6.81k|#define can_access_at_index(buffer, index) ((buffer != NULL) && (((buffer)->offset + index) < (buffer)->length))
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (192:45): [True: 6.81k, False: 0]
  |  |  |  |  |  Branch (192:65): [True: 6.81k, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
                  if (cannot_access_at_index(input_buffer, 0) || (buffer_at_offset(input_buffer)[0] != '}')) {
  ------------------
  |  |  195|  6.81k|#define buffer_at_offset(buffer) ((buffer)->content + (buffer)->offset)
  ------------------
  |  Branch (1335:52): [True: 39, False: 6.77k]
  ------------------
 1336|     39|        goto fail; /* expected end of object */
 1337|     39|    }
 1338|       |
 1339|  7.44k|success:
 1340|  7.44k|    input_buffer->depth--;
 1341|       |
 1342|  7.44k|    if (head != NULL) {
  ------------------
  |  Branch (1342:9): [True: 6.77k, False: 664]
  ------------------
 1343|  6.77k|        head->prev = current_item;
 1344|  6.77k|    }
 1345|       |
 1346|  7.44k|    item->type = cJSON_Object;
  ------------------
  |  |  103|  7.44k|#define cJSON_Object (1 << 6)
  ------------------
 1347|  7.44k|    item->child = head;
 1348|       |
 1349|  7.44k|    input_buffer->offset++;
 1350|  7.44k|    return true;
  ------------------
  |  |   67|  7.44k|#define true ((cJSON_bool)1)
  ------------------
 1351|       |
 1352|    524|fail:
 1353|    524|    if (head != NULL) {
  ------------------
  |  Branch (1353:9): [True: 524, False: 0]
  ------------------
 1354|    524|        loader_cJSON_Delete(head);
 1355|    524|    }
 1356|       |
 1357|    524|    return false;
  ------------------
  |  |   72|    524|#define false ((cJSON_bool)0)
  ------------------
 1358|  6.81k|}
cJSON.c:print_value:
 1056|  4.13k|static cJSON_bool print_value(const cJSON *const item, printbuffer *const output_buffer, bool *out_of_memory) {
 1057|  4.13k|    unsigned char *output = NULL;
 1058|       |
 1059|  4.13k|    if ((item == NULL) || (output_buffer == NULL)) {
  ------------------
  |  Branch (1059:9): [True: 0, False: 4.13k]
  |  Branch (1059:27): [True: 0, False: 4.13k]
  ------------------
 1060|      0|        return false;
  ------------------
  |  |   72|      0|#define false ((cJSON_bool)0)
  ------------------
 1061|      0|    }
 1062|       |
 1063|  4.13k|    switch ((item->type) & 0xFF) {
 1064|      0|        case cJSON_NULL:
  ------------------
  |  |   99|      0|#define cJSON_NULL (1 << 2)
  ------------------
  |  Branch (1064:9): [True: 0, False: 4.13k]
  ------------------
 1065|      0|            output = ensure(output_buffer, 5, out_of_memory);
 1066|      0|            if (output == NULL) {
  ------------------
  |  Branch (1066:17): [True: 0, False: 0]
  ------------------
 1067|      0|                return false;
  ------------------
  |  |   72|      0|#define false ((cJSON_bool)0)
  ------------------
 1068|      0|            }
 1069|      0|            strcpy((char *)output, "null");
 1070|      0|            return true;
  ------------------
  |  |   67|      0|#define true ((cJSON_bool)1)
  ------------------
 1071|       |
 1072|      0|        case cJSON_False:
  ------------------
  |  |   97|      0|#define cJSON_False (1 << 0)
  ------------------
  |  Branch (1072:9): [True: 0, False: 4.13k]
  ------------------
 1073|      0|            output = ensure(output_buffer, 6, out_of_memory);
 1074|      0|            if (output == NULL) {
  ------------------
  |  Branch (1074:17): [True: 0, False: 0]
  ------------------
 1075|      0|                return false;
  ------------------
  |  |   72|      0|#define false ((cJSON_bool)0)
  ------------------
 1076|      0|            }
 1077|      0|            strcpy((char *)output, "false");
 1078|      0|            return true;
  ------------------
  |  |   67|      0|#define true ((cJSON_bool)1)
  ------------------
 1079|       |
 1080|      0|        case cJSON_True:
  ------------------
  |  |   98|      0|#define cJSON_True (1 << 1)
  ------------------
  |  Branch (1080:9): [True: 0, False: 4.13k]
  ------------------
 1081|      0|            output = ensure(output_buffer, 5, out_of_memory);
 1082|      0|            if (output == NULL) {
  ------------------
  |  Branch (1082:17): [True: 0, False: 0]
  ------------------
 1083|      0|                return false;
  ------------------
  |  |   72|      0|#define false ((cJSON_bool)0)
  ------------------
 1084|      0|            }
 1085|      0|            strcpy((char *)output, "true");
 1086|      0|            return true;
  ------------------
  |  |   67|      0|#define true ((cJSON_bool)1)
  ------------------
 1087|       |
 1088|      0|        case cJSON_Number:
  ------------------
  |  |  100|      0|#define cJSON_Number (1 << 3)
  ------------------
  |  Branch (1088:9): [True: 0, False: 4.13k]
  ------------------
 1089|      0|            return print_number(item, output_buffer, out_of_memory);
 1090|       |
 1091|      0|        case cJSON_Raw: {
  ------------------
  |  |  104|      0|#define cJSON_Raw (1 << 7) /* raw json */
  ------------------
  |  Branch (1091:9): [True: 0, False: 4.13k]
  ------------------
 1092|      0|            size_t raw_length = 0;
 1093|      0|            if (item->valuestring == NULL) {
  ------------------
  |  Branch (1093:17): [True: 0, False: 0]
  ------------------
 1094|      0|                return false;
  ------------------
  |  |   72|      0|#define false ((cJSON_bool)0)
  ------------------
 1095|      0|            }
 1096|       |
 1097|      0|            raw_length = strlen(item->valuestring) + sizeof("");
 1098|      0|            output = ensure(output_buffer, raw_length, out_of_memory);
 1099|      0|            if (output == NULL) {
  ------------------
  |  Branch (1099:17): [True: 0, False: 0]
  ------------------
 1100|      0|                return false;
  ------------------
  |  |   72|      0|#define false ((cJSON_bool)0)
  ------------------
 1101|      0|            }
 1102|      0|            memcpy(output, item->valuestring, raw_length);
 1103|      0|            return true;
  ------------------
  |  |   67|      0|#define true ((cJSON_bool)1)
  ------------------
 1104|      0|        }
 1105|       |
 1106|  4.13k|        case cJSON_String:
  ------------------
  |  |  101|  4.13k|#define cJSON_String (1 << 4)
  ------------------
  |  Branch (1106:9): [True: 4.13k, False: 0]
  ------------------
 1107|  4.13k|            return print_string(item, output_buffer, out_of_memory);
 1108|       |
 1109|      0|        case cJSON_Array:
  ------------------
  |  |  102|      0|#define cJSON_Array (1 << 5)
  ------------------
  |  Branch (1109:9): [True: 0, False: 4.13k]
  ------------------
 1110|      0|            return print_array(item, output_buffer, out_of_memory);
 1111|       |
 1112|      0|        case cJSON_Object:
  ------------------
  |  |  103|      0|#define cJSON_Object (1 << 6)
  ------------------
  |  Branch (1112:9): [True: 0, False: 4.13k]
  ------------------
 1113|      0|            return print_object(item, output_buffer, out_of_memory);
 1114|       |
 1115|      0|        default:
  ------------------
  |  Branch (1115:9): [True: 0, False: 4.13k]
  ------------------
 1116|      0|            return false;
  ------------------
  |  |   72|      0|#define false ((cJSON_bool)0)
  ------------------
 1117|  4.13k|    }
 1118|  4.13k|}
cJSON.c:ensure:
  275|  4.13k|static unsigned char *ensure(printbuffer *const p, size_t needed, bool *out_of_memory) {
  276|  4.13k|    unsigned char *newbuffer = NULL;
  277|  4.13k|    size_t newsize = 0;
  278|       |
  279|  4.13k|    if ((p == NULL) || (p->buffer == NULL)) {
  ------------------
  |  Branch (279:9): [True: 0, False: 4.13k]
  |  Branch (279:24): [True: 0, False: 4.13k]
  ------------------
  280|      0|        return NULL;
  281|      0|    }
  282|       |
  283|  4.13k|    if ((p->length > 0) && (p->offset >= p->length)) {
  ------------------
  |  Branch (283:9): [True: 4.13k, False: 0]
  |  Branch (283:28): [True: 0, False: 4.13k]
  ------------------
  284|       |        /* make sure that offset is valid */
  285|      0|        return NULL;
  286|      0|    }
  287|       |
  288|  4.13k|    if (needed > INT_MAX) {
  ------------------
  |  Branch (288:9): [True: 0, False: 4.13k]
  ------------------
  289|       |        /* sizes bigger than INT_MAX are currently not supported */
  290|      0|        return NULL;
  291|      0|    }
  292|       |
  293|  4.13k|    needed += p->offset + 1;
  294|  4.13k|    if (needed <= p->length) {
  ------------------
  |  Branch (294:9): [True: 3.88k, False: 247]
  ------------------
  295|  3.88k|        return p->buffer + p->offset;
  296|  3.88k|    }
  297|       |
  298|    247|    if (p->noalloc) {
  ------------------
  |  Branch (298:9): [True: 93, False: 154]
  ------------------
  299|     93|        return NULL;
  300|     93|    }
  301|       |
  302|       |    /* calculate new buffer size */
  303|    154|    if (needed > (INT_MAX / 2)) {
  ------------------
  |  Branch (303:9): [True: 0, False: 154]
  ------------------
  304|       |        /* overflow of int, use INT_MAX if possible */
  305|      0|        if (needed <= INT_MAX) {
  ------------------
  |  Branch (305:13): [True: 0, False: 0]
  ------------------
  306|      0|            newsize = INT_MAX;
  307|      0|        } else {
  308|      0|            return NULL;
  309|      0|        }
  310|    154|    } else {
  311|    154|        newsize = needed * 2;
  312|    154|    }
  313|       |
  314|    154|    newbuffer = (unsigned char *)loader_realloc(p->pAllocator, p->buffer, p->length, newsize, VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE);
  315|    154|    if (newbuffer == NULL) {
  ------------------
  |  Branch (315:9): [True: 0, False: 154]
  ------------------
  316|      0|        *out_of_memory = true;
  ------------------
  |  |   67|      0|#define true ((cJSON_bool)1)
  ------------------
  317|      0|        loader_free(p->pAllocator, p->buffer);
  318|      0|        p->length = 0;
  319|      0|        p->buffer = NULL;
  320|       |
  321|      0|        return NULL;
  322|      0|    }
  323|       |
  324|    154|    p->length = newsize;
  325|    154|    p->buffer = newbuffer;
  326|       |
  327|    154|    return newbuffer + p->offset;
  328|    154|}
cJSON.c:print_string:
  759|  4.13k|static cJSON_bool print_string(const cJSON *const item, printbuffer *const p, bool *out_of_memory) {
  760|  4.13k|    return print_string_ptr((unsigned char *)item->valuestring, p, out_of_memory);
  761|  4.13k|}
cJSON.c:print_string_ptr:
  650|  4.13k|static cJSON_bool print_string_ptr(const unsigned char *const input, printbuffer *const output_buffer, bool *out_of_memory) {
  651|  4.13k|    const unsigned char *input_pointer = NULL;
  652|  4.13k|    unsigned char *output = NULL;
  653|  4.13k|    unsigned char *output_pointer = NULL;
  654|  4.13k|    size_t output_length = 0;
  655|       |    /* numbers of additional characters needed for escaping */
  656|  4.13k|    size_t escape_characters = 0;
  657|       |
  658|  4.13k|    if (output_buffer == NULL) {
  ------------------
  |  Branch (658:9): [True: 0, False: 4.13k]
  ------------------
  659|      0|        return false;
  ------------------
  |  |   72|      0|#define false ((cJSON_bool)0)
  ------------------
  660|      0|    }
  661|       |
  662|       |    /* empty string */
  663|  4.13k|    if (input == NULL) {
  ------------------
  |  Branch (663:9): [True: 0, False: 4.13k]
  ------------------
  664|      0|        output = ensure(output_buffer, sizeof(""), out_of_memory);
  665|      0|        if (output == NULL) {
  ------------------
  |  Branch (665:13): [True: 0, False: 0]
  ------------------
  666|      0|            return false;
  ------------------
  |  |   72|      0|#define false ((cJSON_bool)0)
  ------------------
  667|      0|        }
  668|       |
  669|      0|        return true;
  ------------------
  |  |   67|      0|#define true ((cJSON_bool)1)
  ------------------
  670|      0|    }
  671|       |
  672|       |    /* set "flag" to 1 if something needs to be escaped */
  673|   218k|    for (input_pointer = input; *input_pointer; input_pointer++) {
  ------------------
  |  Branch (673:33): [True: 214k, False: 4.13k]
  ------------------
  674|   214k|        switch (*input_pointer) {
  675|     92|            case '\"':
  ------------------
  |  Branch (675:13): [True: 92, False: 214k]
  ------------------
  676|    196|            case '\\':
  ------------------
  |  Branch (676:13): [True: 104, False: 214k]
  ------------------
  677|    499|            case '\b':
  ------------------
  |  Branch (677:13): [True: 303, False: 213k]
  ------------------
  678|  1.06k|            case '\f':
  ------------------
  |  Branch (678:13): [True: 563, False: 213k]
  ------------------
  679|  1.44k|            case '\n':
  ------------------
  |  Branch (679:13): [True: 387, False: 213k]
  ------------------
  680|  2.62k|            case '\r':
  ------------------
  |  Branch (680:13): [True: 1.17k, False: 213k]
  ------------------
  681|  2.96k|            case '\t':
  ------------------
  |  Branch (681:13): [True: 337, False: 213k]
  ------------------
  682|       |                /* one character escape sequence */
  683|  2.96k|                escape_characters++;
  684|  2.96k|                break;
  685|   211k|            default:
  ------------------
  |  Branch (685:13): [True: 211k, False: 2.96k]
  ------------------
  686|   211k|                if (*input_pointer < 32) {
  ------------------
  |  Branch (686:21): [True: 156k, False: 54.9k]
  ------------------
  687|       |                    /* UTF-16 escape sequence uXXXX */
  688|   156k|                    escape_characters += 5;
  689|   156k|                }
  690|   211k|                break;
  691|   214k|        }
  692|   214k|    }
  693|  4.13k|    output_length = (size_t)(input_pointer - input) + escape_characters;
  694|       |
  695|  4.13k|    output = ensure(output_buffer, output_length + sizeof(""), out_of_memory);
  696|  4.13k|    if (output == NULL) {
  ------------------
  |  Branch (696:9): [True: 93, False: 4.03k]
  ------------------
  697|     93|        return false;
  ------------------
  |  |   72|     93|#define false ((cJSON_bool)0)
  ------------------
  698|     93|    }
  699|       |
  700|       |    /* no characters have to be escaped */
  701|  4.03k|    if (escape_characters == 0) {
  ------------------
  |  Branch (701:9): [True: 3.30k, False: 733]
  ------------------
  702|  3.30k|        memcpy(output, input, output_length);
  703|  3.30k|        output[output_length] = '\0';
  704|       |
  705|  3.30k|        return true;
  ------------------
  |  |   67|  3.30k|#define true ((cJSON_bool)1)
  ------------------
  706|  3.30k|    }
  707|       |
  708|    733|    output_pointer = output;
  709|       |    /* copy the string */
  710|   179k|    for (input_pointer = input; *input_pointer != '\0'; (void)input_pointer++, output_pointer++) {
  ------------------
  |  Branch (710:33): [True: 178k, False: 733]
  ------------------
  711|   178k|        if ((*input_pointer > 31) && (*input_pointer != '\"') && (*input_pointer != '\\')) {
  ------------------
  |  Branch (711:13): [True: 24.3k, False: 154k]
  |  Branch (711:38): [True: 24.2k, False: 92]
  |  Branch (711:66): [True: 24.1k, False: 104]
  ------------------
  712|       |            /* normal character, copy */
  713|  24.1k|            *output_pointer = *input_pointer;
  714|   154k|        } else {
  715|       |            // Loader specific modification - don't add a backslash because that will 'double up' any existing back slashes.
  716|       |            // This change was added right after vulkan's public release, so while it may not be a problem, there are plenty
  717|       |            // of API calls made which might not work if the paths have "\\"" in them
  718|       |            /* character needs to be escaped */
  719|       |            //*output_pointer++ = '\\';
  720|   154k|            switch (*input_pointer) {
  721|    104|                case '\\':
  ------------------
  |  Branch (721:17): [True: 104, False: 154k]
  ------------------
  722|    104|                    *output_pointer = '\\';
  723|    104|                    break;
  724|     92|                case '\"':
  ------------------
  |  Branch (724:17): [True: 92, False: 154k]
  ------------------
  725|     92|                    *output_pointer = '\"';
  726|     92|                    break;
  727|    303|                case '\b':
  ------------------
  |  Branch (727:17): [True: 303, False: 154k]
  ------------------
  728|    303|                    *output_pointer = '\b';
  729|    303|                    break;
  730|    545|                case '\f':
  ------------------
  |  Branch (730:17): [True: 545, False: 154k]
  ------------------
  731|    545|                    *output_pointer = '\f';
  732|    545|                    break;
  733|    287|                case '\n':
  ------------------
  |  Branch (733:17): [True: 287, False: 154k]
  ------------------
  734|    287|                    *output_pointer = '\n';
  735|    287|                    break;
  736|  1.17k|                case '\r':
  ------------------
  |  Branch (736:17): [True: 1.17k, False: 153k]
  ------------------
  737|  1.17k|                    *output_pointer = '\r';
  738|  1.17k|                    break;
  739|    335|                case '\t':
  ------------------
  |  Branch (739:17): [True: 335, False: 154k]
  ------------------
  740|    335|                    *output_pointer = '\t';
  741|    335|                    break;
  742|   151k|                default:
  ------------------
  |  Branch (742:17): [True: 151k, False: 2.84k]
  ------------------
  743|       |                    /* escape and print as unicode codepoint */
  744|   151k|                    snprintf((char *)output_pointer, output_length - (size_t)(output_pointer - output), "u%04x", *input_pointer);
  745|   151k|                    output_pointer += 4;
  746|   151k|                    break;
  747|   154k|            }
  748|   154k|        }
  749|   178k|    }
  750|       |    // The loader-specific escaping above emits one byte where the standard form emits two, so the written
  751|       |    // length is shorter than output_length. Terminate at the actual end, otherwise the bytes between it and
  752|       |    // output_length (uninitialized when the caller buffer is not zeroed) get read back as part of the string.
  753|    733|    *output_pointer = '\0';
  754|       |
  755|    733|    return true;
  ------------------
  |  |   67|    733|#define true ((cJSON_bool)1)
  ------------------
  756|    733|}
cJSON.c:get_object_item:
 1501|  18.1k|static cJSON *get_object_item(const cJSON *const object, const char *const name, const cJSON_bool case_sensitive) {
 1502|  18.1k|    cJSON *current_element = NULL;
 1503|       |
 1504|  18.1k|    if ((object == NULL) || (name == NULL)) {
  ------------------
  |  Branch (1504:9): [True: 0, False: 18.1k]
  |  Branch (1504:29): [True: 0, False: 18.1k]
  ------------------
 1505|      0|        return NULL;
 1506|      0|    }
 1507|       |
 1508|  18.1k|    current_element = object->child;
 1509|  18.1k|    if (case_sensitive) {
  ------------------
  |  Branch (1509:9): [True: 0, False: 18.1k]
  ------------------
 1510|      0|        while ((current_element != NULL) && (current_element->string != NULL) && (strcmp(name, current_element->string) != 0)) {
  ------------------
  |  Branch (1510:16): [True: 0, False: 0]
  |  Branch (1510:45): [True: 0, False: 0]
  |  Branch (1510:82): [True: 0, False: 0]
  ------------------
 1511|      0|            current_element = current_element->next;
 1512|      0|        }
 1513|  18.1k|    } else {
 1514|  62.9k|        while ((current_element != NULL) &&
  ------------------
  |  Branch (1514:16): [True: 54.8k, False: 8.17k]
  ------------------
 1515|  54.8k|               (case_insensitive_strcmp((const unsigned char *)name, (const unsigned char *)(current_element->string)) != 0)) {
  ------------------
  |  Branch (1515:16): [True: 44.7k, False: 10.0k]
  ------------------
 1516|  44.7k|            current_element = current_element->next;
 1517|  44.7k|        }
 1518|  18.1k|    }
 1519|       |
 1520|  18.1k|    if ((current_element == NULL) || (current_element->string == NULL)) {
  ------------------
  |  Branch (1520:9): [True: 8.17k, False: 10.0k]
  |  Branch (1520:38): [True: 0, False: 10.0k]
  ------------------
 1521|  8.17k|        return NULL;
 1522|  8.17k|    }
 1523|       |
 1524|  10.0k|    return current_element;
 1525|  18.1k|}
cJSON.c:case_insensitive_strcmp:
  120|  54.8k|static int case_insensitive_strcmp(const unsigned char *string1, const unsigned char *string2) {
  121|  54.8k|    if ((string1 == NULL) || (string2 == NULL)) {
  ------------------
  |  Branch (121:9): [True: 0, False: 54.8k]
  |  Branch (121:30): [True: 175, False: 54.6k]
  ------------------
  122|    175|        return 1;
  123|    175|    }
  124|       |
  125|  54.6k|    if (string1 == string2) {
  ------------------
  |  Branch (125:9): [True: 0, False: 54.6k]
  ------------------
  126|      0|        return 0;
  127|      0|    }
  128|       |
  129|   152k|    for (; tolower(*string1) == tolower(*string2); (void)string1++, string2++) {
  ------------------
  |  Branch (129:12): [True: 0, False: 0]
  |  Branch (129:12): [True: 0, False: 0]
  |  Branch (129:12): [Folded, False: 152k]
  |  Branch (129:12): [True: 107k, False: 44.6k]
  |  Branch (129:33): [True: 0, False: 0]
  |  Branch (129:33): [True: 0, False: 0]
  |  Branch (129:33): [Folded, False: 152k]
  ------------------
  130|   107k|        if (*string1 == '\0') {
  ------------------
  |  Branch (130:13): [True: 10.0k, False: 97.8k]
  ------------------
  131|  10.0k|            return 0;
  132|  10.0k|        }
  133|   107k|    }
  134|       |
  135|  44.6k|    return tolower(*string1) - tolower(*string2);
  ------------------
  |  Branch (135:12): [True: 0, False: 0]
  |  Branch (135:12): [True: 0, False: 0]
  |  Branch (135:12): [Folded, False: 44.6k]
  |  Branch (135:32): [True: 0, False: 0]
  |  Branch (135:32): [True: 0, False: 0]
  |  Branch (135:32): [Folded, False: 44.6k]
  ------------------
  136|  54.6k|}

loader_make_version:
  113|     26|loader_api_version loader_make_version(uint32_t version) {
  114|     26|    loader_api_version out_version;
  115|     26|    out_version.major = VK_API_VERSION_MAJOR(version);
  116|       |    out_version.minor = VK_API_VERSION_MINOR(version);
  117|     26|    out_version.patch = 0;
  118|     26|    return out_version;
  119|     26|}
loader_make_full_version:
  122|    960|loader_api_version loader_make_full_version(uint32_t version) {
  123|    960|    loader_api_version out_version;
  124|    960|    out_version.major = VK_API_VERSION_MAJOR(version);
  125|    960|    out_version.minor = VK_API_VERSION_MINOR(version);
  126|       |    out_version.patch = VK_API_VERSION_PATCH(version);
  127|    960|    return out_version;
  128|    960|}
loader_combine_version:
  131|    853|loader_api_version loader_combine_version(uint32_t major, uint32_t minor, uint32_t patch) {
  132|    853|    loader_api_version out_version;
  133|    853|    out_version.major = (uint16_t)major;
  134|    853|    out_version.minor = (uint16_t)minor;
  135|    853|    out_version.patch = (uint16_t)patch;
  136|    853|    return out_version;
  137|    853|}
loader_check_version_meets_required:
  140|    853|bool loader_check_version_meets_required(loader_api_version required, loader_api_version version) {
  141|       |    // major version is satisfied
  142|    853|    return (version.major > required.major) ||
  ------------------
  |  Branch (142:12): [True: 147, False: 706]
  ------------------
  143|       |           // major version is equal, minor version is patch version is greater to minimum minor
  144|    706|           (version.major == required.major && version.minor > required.minor) ||
  ------------------
  |  Branch (144:13): [True: 245, False: 461]
  |  Branch (144:48): [True: 78, False: 167]
  ------------------
  145|       |           // major and minor version are equal, patch version is greater or equal to minimum patch
  146|    628|           (version.major == required.major && version.minor == required.minor && version.patch >= required.patch);
  ------------------
  |  Branch (146:13): [True: 167, False: 461]
  |  Branch (146:48): [True: 122, False: 45]
  |  Branch (146:83): [True: 88, False: 34]
  ------------------
  147|    853|}
loader_opendir:
  172|  50.9k|DIR *loader_opendir(const struct loader_instance *instance, const char *name) {
  173|       |#if defined(_WIN32)
  174|       |    return opendir(instance ? &instance->alloc_callbacks : NULL, name);
  175|       |#elif COMMON_UNIX_PLATFORMS
  176|       |    (void)instance;
  177|  50.9k|    return opendir(name);
  178|       |#else
  179|       |#warning dirent.h - opendir not available on this platform
  180|       |#endif  // _WIN32
  181|  50.9k|}
loader_closedir:
  182|  4.84k|int loader_closedir(const struct loader_instance *instance, DIR *dir) {
  183|       |#if defined(_WIN32)
  184|       |    return closedir(instance ? &instance->alloc_callbacks : NULL, dir);
  185|       |#elif COMMON_UNIX_PLATFORMS
  186|       |    (void)instance;
  187|  4.84k|    return closedir(dir);
  188|       |#else
  189|       |#warning dirent.h - closedir not available on this platform
  190|       |#endif  // _WIN32
  191|  4.84k|}
is_json:
  193|   114k|bool is_json(const char *path, size_t len) {
  194|   114k|    if (len < 5) {
  ------------------
  |  Branch (194:9): [True: 7.30k, False: 107k]
  ------------------
  195|  7.30k|        return false;
  196|  7.30k|    }
  197|   107k|    return !strncmp(path + len - 5, ".json", 5);
  198|   114k|}
loader_free_layer_properties:
  248|  5.42k|void loader_free_layer_properties(const struct loader_instance *inst, struct loader_layer_properties *layer_properties) {
  249|  5.42k|    loader_instance_heap_free(inst, layer_properties->manifest_file_name);
  250|  5.42k|    loader_instance_heap_free(inst, layer_properties->lib_name);
  251|  5.42k|    loader_instance_heap_free(inst, layer_properties->functions.str_gipa);
  252|  5.42k|    loader_instance_heap_free(inst, layer_properties->functions.str_gdpa);
  253|  5.42k|    loader_instance_heap_free(inst, layer_properties->functions.str_negotiate_interface);
  254|  5.42k|    loader_destroy_generic_list(inst, (struct loader_generic_list *)&layer_properties->instance_extension_list);
  255|  5.42k|    if (layer_properties->device_extension_list.capacity > 0 && NULL != layer_properties->device_extension_list.list) {
  ------------------
  |  Branch (255:9): [True: 0, False: 5.42k]
  |  Branch (255:65): [True: 0, False: 0]
  ------------------
  256|      0|        for (uint32_t i = 0; i < layer_properties->device_extension_list.count; i++) {
  ------------------
  |  Branch (256:30): [True: 0, False: 0]
  ------------------
  257|      0|            free_string_list(inst, &layer_properties->device_extension_list.list[i].entrypoints);
  258|      0|        }
  259|      0|    }
  260|  5.42k|    loader_destroy_generic_list(inst, (struct loader_generic_list *)&layer_properties->device_extension_list);
  261|  5.42k|    loader_instance_heap_free(inst, layer_properties->disable_env_var.name);
  262|  5.42k|    loader_instance_heap_free(inst, layer_properties->disable_env_var.value);
  263|  5.42k|    loader_instance_heap_free(inst, layer_properties->enable_env_var.name);
  264|  5.42k|    loader_instance_heap_free(inst, layer_properties->enable_env_var.value);
  265|  5.42k|    free_string_list(inst, &layer_properties->component_layer_names);
  266|  5.42k|    loader_instance_heap_free(inst, layer_properties->pre_instance_functions.enumerate_instance_extension_properties);
  267|  5.42k|    loader_instance_heap_free(inst, layer_properties->pre_instance_functions.enumerate_instance_layer_properties);
  268|  5.42k|    loader_instance_heap_free(inst, layer_properties->pre_instance_functions.enumerate_instance_version);
  269|  5.42k|    free_string_list(inst, &layer_properties->override_paths);
  270|  5.42k|    free_string_list(inst, &layer_properties->blacklist_layer_names);
  271|  5.42k|    free_string_list(inst, &layer_properties->app_key_paths);
  272|       |
  273|       |    // Make sure to clear out the removed layer, in case new layers are added in the previous location
  274|  5.42k|    memset(layer_properties, 0, sizeof(struct loader_layer_properties));
  275|  5.42k|}
is_string_in_string_list:
  288|  50.9k|bool is_string_in_string_list(struct loader_string_list *string_list, const char *str) {
  289|       |    // Remove duplicate paths, or it would result in duplicate extensions, duplicate devices, etc.
  290|   203k|    for (size_t i = 0; i < string_list->count; i++) {
  ------------------
  |  Branch (290:24): [True: 152k, False: 50.9k]
  ------------------
  291|   152k|        if (strcmp(string_list->list[i], str) == 0) {
  ------------------
  |  Branch (291:13): [True: 0, False: 152k]
  ------------------
  292|      0|            return true;
  293|      0|        }
  294|   152k|    }
  295|  50.9k|    return false;
  296|  50.9k|}
loader_copy_to_new_str:
  298|  5.52k|VkResult loader_copy_to_new_str(const struct loader_instance *inst, const char *source_str, char **dest_str) {
  299|  5.52k|    assert(source_str && dest_str);
  300|  5.52k|    size_t str_len = strlen(source_str) + 1;
  301|  5.52k|    *dest_str = loader_instance_heap_calloc(inst, str_len, VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE);
  302|  5.52k|    if (NULL == *dest_str) return VK_ERROR_OUT_OF_HOST_MEMORY;
  ------------------
  |  Branch (302:9): [True: 0, False: 5.52k]
  ------------------
  303|  5.52k|    loader_strncpy(*dest_str, str_len, source_str, str_len);
  304|  5.52k|    (*dest_str)[str_len - 1] = 0;
  305|  5.52k|    return VK_SUCCESS;
  306|  5.52k|}
create_string_list:
  308|     52|VkResult create_string_list(const struct loader_instance *inst, uint32_t allocated_count, struct loader_string_list *string_list) {
  309|     52|    assert(string_list);
  310|     52|    string_list->list =
  311|     52|        (char **)loader_instance_heap_calloc(inst, sizeof(char *) * allocated_count, VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE);
  312|     52|    if (NULL == string_list->list) {
  ------------------
  |  Branch (312:9): [True: 0, False: 52]
  ------------------
  313|      0|        return VK_ERROR_OUT_OF_HOST_MEMORY;
  314|      0|    }
  315|     52|    string_list->allocated_count = allocated_count;
  316|     52|    string_list->count = 0;
  317|     52|    return VK_SUCCESS;
  318|     52|}
increase_str_capacity_by_at_least_one:
  320|  54.3k|VkResult increase_str_capacity_by_at_least_one(const struct loader_instance *inst, struct loader_string_list *string_list) {
  321|  54.3k|    assert(string_list);
  322|  54.3k|    if (string_list->allocated_count == 0) {
  ------------------
  |  Branch (322:9): [True: 10.6k, False: 43.7k]
  ------------------
  323|  10.6k|        string_list->allocated_count = 32;
  324|  10.6k|        string_list->list = (char **)loader_instance_heap_calloc(inst, sizeof(char *) * string_list->allocated_count,
  325|  10.6k|                                                                 VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE);
  326|  10.6k|        if (NULL == string_list->list) {
  ------------------
  |  Branch (326:13): [True: 0, False: 10.6k]
  ------------------
  327|      0|            return VK_ERROR_OUT_OF_HOST_MEMORY;
  328|      0|        }
  329|  43.7k|    } else if (string_list->count + 1 > string_list->allocated_count) {
  ------------------
  |  Branch (329:16): [True: 0, False: 43.7k]
  ------------------
  330|      0|        uint32_t new_allocated_count = string_list->allocated_count * 2;
  331|      0|        void *new_ptr = loader_instance_heap_realloc(inst, (void *)string_list->list, sizeof(char *) * string_list->allocated_count,
  332|      0|                                                     sizeof(char *) * new_allocated_count, VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE);
  333|      0|        if (NULL == new_ptr) {
  ------------------
  |  Branch (333:13): [True: 0, False: 0]
  ------------------
  334|      0|            return VK_ERROR_OUT_OF_HOST_MEMORY;
  335|      0|        }
  336|      0|        string_list->list = (char **)new_ptr;
  337|      0|        string_list->allocated_count *= 2;
  338|      0|    }
  339|  54.3k|    return VK_SUCCESS;
  340|  54.3k|}
append_str_to_string_list:
  342|  54.3k|VkResult append_str_to_string_list(const struct loader_instance *inst, struct loader_string_list *string_list, char *str) {
  343|  54.3k|    assert(string_list && str);
  344|  54.3k|    VkResult res = increase_str_capacity_by_at_least_one(inst, string_list);
  345|  54.3k|    if (res == VK_ERROR_OUT_OF_HOST_MEMORY) {
  ------------------
  |  Branch (345:9): [True: 0, False: 54.3k]
  ------------------
  346|      0|        loader_instance_heap_free(inst, str);  // Must clean up in case of failure
  347|      0|        return res;
  348|      0|    }
  349|  54.3k|    string_list->list[string_list->count++] = str;
  350|  54.3k|    return VK_SUCCESS;
  351|  54.3k|}
append_str_to_string_list_if_unique:
  354|  50.9k|                                             char *str) {
  355|  50.9k|    if (is_string_in_string_list(string_list, str)) {
  ------------------
  |  Branch (355:9): [True: 0, False: 50.9k]
  ------------------
  356|       |        // Since this string is a duplicate and this function takes ownership, we need to free it.
  357|      0|        loader_instance_heap_free(inst, str);
  358|      0|        return VK_SUCCESS;
  359|      0|    }
  360|  50.9k|    return append_str_to_string_list(inst, string_list, str);
  361|  50.9k|}
copy_str_to_string_list:
  379|  3.37k|                                 size_t str_len) {
  380|  3.37k|    assert(string_list && str);
  381|  3.37k|    char *new_str = loader_instance_heap_calloc(inst, str_len + 1, VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE);
  382|  3.37k|    if (NULL == new_str) {
  ------------------
  |  Branch (382:9): [True: 0, False: 3.37k]
  ------------------
  383|      0|        return VK_ERROR_OUT_OF_HOST_MEMORY;
  384|      0|    }
  385|  3.37k|    loader_strncpy(new_str, str_len + 1, str, str_len);
  386|  3.37k|    new_str[str_len] = '\0';
  387|  3.37k|    return append_str_to_string_list(inst, string_list, new_str);
  388|  3.37k|}
free_string_list:
  410|  48.4k|void free_string_list(const struct loader_instance *inst, struct loader_string_list *string_list) {
  411|  48.4k|    assert(string_list);
  412|  48.4k|    if (string_list->list) {
  ------------------
  |  Branch (412:9): [True: 10.7k, False: 37.7k]
  ------------------
  413|  65.1k|        for (uint32_t i = 0; i < string_list->count; i++) {
  ------------------
  |  Branch (413:30): [True: 54.3k, False: 10.7k]
  ------------------
  414|  54.3k|            loader_instance_heap_free(inst, string_list->list[i]);
  415|       |            string_list->list[i] = NULL;
  416|  54.3k|        }
  417|  10.7k|        loader_instance_heap_free(inst, (void *)string_list->list);
  418|  10.7k|    }
  419|  48.4k|    memset(string_list, 0, sizeof(struct loader_string_list));
  420|  48.4k|}
loader_parse_version_string:
  697|  2.05k|uint32_t loader_parse_version_string(char *vers_str) {
  698|  2.05k|    uint32_t variant = 0;
  699|  2.05k|    uint32_t major = 0;
  700|  2.05k|    uint32_t minor = 0;
  701|  2.05k|    uint32_t patch = 0;
  702|  2.05k|    char *vers_tok;
  703|  2.05k|    char *context = NULL;
  704|  2.05k|    if (!vers_str) {
  ------------------
  |  Branch (704:9): [True: 0, False: 2.05k]
  ------------------
  705|      0|        return 0;
  706|      0|    }
  707|       |
  708|  2.05k|    vers_tok = thread_safe_strtok(vers_str, ".\"\n\r", &context);
  709|  2.05k|    if (NULL != vers_tok) {
  ------------------
  |  Branch (709:9): [True: 1.36k, False: 688]
  ------------------
  710|  1.36k|        major = (uint16_t)strtoul(vers_tok, NULL, 10);
  711|  1.36k|        vers_tok = thread_safe_strtok(NULL, ".\"\n\r", &context);
  712|  1.36k|        if (NULL != vers_tok) {
  ------------------
  |  Branch (712:13): [True: 505, False: 863]
  ------------------
  713|    505|            minor = (uint16_t)strtoul(vers_tok, NULL, 10);
  714|    505|            vers_tok = thread_safe_strtok(NULL, ".\"\n\r", &context);
  715|    505|            if (NULL != vers_tok) {
  ------------------
  |  Branch (715:17): [True: 394, False: 111]
  ------------------
  716|    394|                patch = (uint16_t)strtoul(vers_tok, NULL, 10);
  717|    394|                vers_tok = thread_safe_strtok(NULL, ".\"\n\r", &context);
  718|       |                // check that we are using a 4 part version string
  719|    394|                if (NULL != vers_tok) {
  ------------------
  |  Branch (719:21): [True: 224, False: 170]
  ------------------
  720|       |                    // if we are, move the values over into the correct place
  721|    224|                    variant = major;
  722|    224|                    major = minor;
  723|    224|                    minor = patch;
  724|    224|                    patch = (uint16_t)strtoul(vers_tok, NULL, 10);
  725|    224|                }
  726|    394|            }
  727|    505|        }
  728|  1.36k|    }
  729|       |
  730|       |    return VK_MAKE_API_VERSION(variant, major, minor, patch);
  731|  2.05k|}
has_vk_extension_property:
  747|      4|bool has_vk_extension_property(const VkExtensionProperties *vk_ext_prop, const struct loader_extension_list *ext_list) {
  748|      4|    for (uint32_t i = 0; i < ext_list->count; i++) {
  ------------------
  |  Branch (748:26): [True: 0, False: 4]
  ------------------
  749|      0|        if (compare_vk_extension_properties(&ext_list->list[i], vk_ext_prop)) return true;
  ------------------
  |  Branch (749:13): [True: 0, False: 0]
  ------------------
  750|      0|    }
  751|      4|    return false;
  752|      4|}
loader_append_layer_property:
  763|     79|                                      struct loader_layer_properties *layer_property) {
  764|     79|    VkResult res = VK_SUCCESS;
  765|     79|    if (layer_list->capacity == 0) {
  ------------------
  |  Branch (765:9): [True: 65, False: 14]
  ------------------
  766|     65|        res = loader_init_generic_list(inst, (struct loader_generic_list *)layer_list, sizeof(struct loader_layer_properties));
  767|     65|        if (VK_SUCCESS != res) {
  ------------------
  |  Branch (767:13): [True: 0, False: 65]
  ------------------
  768|      0|            goto out;
  769|      0|        }
  770|     65|    }
  771|       |
  772|       |    // Ensure enough room to add an entry
  773|     79|    if ((layer_list->count + 1) * sizeof(struct loader_layer_properties) > layer_list->capacity) {
  ------------------
  |  Branch (773:9): [True: 0, False: 79]
  ------------------
  774|      0|        void *new_ptr = loader_instance_heap_realloc(inst, layer_list->list, layer_list->capacity, layer_list->capacity * 2,
  775|      0|                                                     VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE);
  776|      0|        if (NULL == new_ptr) {
  ------------------
  |  Branch (776:13): [True: 0, False: 0]
  ------------------
  777|      0|            loader_log(inst, VULKAN_LOADER_ERROR_BIT, 0, "loader_append_layer_property: realloc failed for layer list");
  778|      0|            res = VK_ERROR_OUT_OF_HOST_MEMORY;
  779|      0|            goto out;
  780|      0|        }
  781|      0|        layer_list->list = new_ptr;
  782|      0|        layer_list->capacity *= 2;
  783|      0|    }
  784|     79|    memcpy(&layer_list->list[layer_list->count], layer_property, sizeof(struct loader_layer_properties));
  785|     79|    layer_list->count++;
  786|     79|    memset(layer_property, 0, sizeof(struct loader_layer_properties));
  787|     79|out:
  788|     79|    if (res != VK_SUCCESS) {
  ------------------
  |  Branch (788:9): [True: 0, False: 79]
  ------------------
  789|      0|        loader_free_layer_properties(inst, layer_property);
  790|      0|    }
  791|     79|    return res;
  792|     79|}
loader_find_layer_property:
  795|      3|struct loader_layer_properties *loader_find_layer_property(const char *name, const struct loader_layer_list *layer_list) {
  796|      3|    for (uint32_t i = 0; i < layer_list->count; i++) {
  ------------------
  |  Branch (796:26): [True: 3, False: 0]
  ------------------
  797|      3|        const VkLayerProperties *item = &layer_list->list[i].info;
  798|      3|        if (strcmp(name, item->layerName) == 0) return &layer_list->list[i];
  ------------------
  |  Branch (798:13): [True: 3, False: 0]
  ------------------
  799|      3|    }
  800|      0|    return NULL;
  801|      3|}
loader_delete_layer_list_and_properties:
  835|  14.6k|                                                                  struct loader_layer_list *layer_list) {
  836|  14.6k|    uint32_t i;
  837|  14.6k|    if (!layer_list) return;
  ------------------
  |  Branch (837:9): [True: 0, False: 14.6k]
  ------------------
  838|       |
  839|  14.6k|    for (i = 0; i < layer_list->count; i++) {
  ------------------
  |  Branch (839:17): [True: 52, False: 14.6k]
  ------------------
  840|     52|        if (layer_list->list[i].lib_handle) {
  ------------------
  |  Branch (840:13): [True: 0, False: 52]
  ------------------
  841|      0|            loader_platform_close_library(layer_list->list[i].lib_handle);
  842|      0|            loader_log(inst, VULKAN_LOADER_DEBUG_BIT | VULKAN_LOADER_LAYER_BIT, 0, "Unloading layer library %s",
  843|      0|                       layer_list->list[i].lib_name);
  844|      0|            layer_list->list[i].lib_handle = NULL;
  845|      0|        }
  846|     52|        loader_free_layer_properties(inst, &(layer_list->list[i]));
  847|     52|    }
  848|  14.6k|    layer_list->count = 0;
  849|       |
  850|  14.6k|    if (layer_list->capacity > 0) {
  ------------------
  |  Branch (850:9): [True: 65, False: 14.5k]
  ------------------
  851|     65|        layer_list->capacity = 0;
  852|     65|        loader_instance_heap_free(inst, layer_list->list);
  853|     65|    }
  854|  14.6k|    memset(layer_list, 0, sizeof(struct loader_layer_list));
  855|  14.6k|}
loader_remove_layer_in_list:
  858|     27|                                 uint32_t layer_to_remove) {
  859|     27|    if (layer_list == NULL || layer_to_remove >= layer_list->count) {
  ------------------
  |  Branch (859:9): [True: 0, False: 27]
  |  Branch (859:31): [True: 0, False: 27]
  ------------------
  860|      0|        return;
  861|      0|    }
  862|     27|    loader_free_layer_properties(inst, &(layer_list->list[layer_to_remove]));
  863|       |
  864|       |    // Remove the current invalid meta-layer from the layer list.  Use memmove since we are
  865|       |    // overlapping the source and destination addresses.
  866|     27|    if (layer_to_remove + 1 <= layer_list->count) {
  ------------------
  |  Branch (866:9): [True: 27, False: 0]
  ------------------
  867|     27|        memmove(&layer_list->list[layer_to_remove], &layer_list->list[layer_to_remove + 1],
  868|     27|                sizeof(struct loader_layer_properties) * (layer_list->count - 1 - layer_to_remove));
  869|     27|    }
  870|       |    // Decrement the count (because we now have one less) and decrement the loop index since we need to
  871|       |    // re-check this index.
  872|     27|    layer_list->count--;
  873|     27|}
loader_remove_layers_in_blacklist:
  877|      3|void loader_remove_layers_in_blacklist(const struct loader_instance *inst, struct loader_layer_list *layer_list) {
  878|      3|    struct loader_layer_properties *override_prop = loader_find_layer_property(VK_OVERRIDE_LAYER_NAME, layer_list);
  ------------------
  |  |  142|      3|#define VK_OVERRIDE_LAYER_NAME "VK_LAYER_LUNARG_override"
  ------------------
  879|      3|    if (NULL == override_prop) {
  ------------------
  |  Branch (879:9): [True: 0, False: 3]
  ------------------
  880|      0|        return;
  881|      0|    }
  882|       |
  883|      6|    for (int32_t j = 0; j < (int32_t)(layer_list->count); j++) {
  ------------------
  |  Branch (883:25): [True: 3, False: 3]
  ------------------
  884|      3|        struct loader_layer_properties cur_layer_prop = layer_list->list[j];
  885|      3|        const char *cur_layer_name = &cur_layer_prop.info.layerName[0];
  886|       |
  887|       |        // Skip the override layer itself.
  888|      3|        if (!strcmp(VK_OVERRIDE_LAYER_NAME, cur_layer_name)) {
  ------------------
  |  |  142|      3|#define VK_OVERRIDE_LAYER_NAME "VK_LAYER_LUNARG_override"
  ------------------
  |  Branch (888:13): [True: 3, False: 0]
  ------------------
  889|      3|            continue;
  890|      3|        }
  891|       |
  892|       |        // If found in the override layer's blacklist, remove it
  893|      0|        if (loader_find_layer_name_in_blacklist(cur_layer_name, override_prop)) {
  ------------------
  |  Branch (893:13): [True: 0, False: 0]
  ------------------
  894|      0|            loader_log(inst, VULKAN_LOADER_DEBUG_BIT, 0,
  895|      0|                       "loader_remove_layers_in_blacklist: Override layer is active and layer %s is in the blacklist inside of it. "
  896|      0|                       "Removing that layer from current layer list.",
  897|      0|                       cur_layer_name);
  898|      0|            loader_remove_layer_in_list(inst, layer_list, j);
  899|      0|            j--;
  900|       |
  901|       |            // Re-do the query for the override layer
  902|      0|            override_prop = loader_find_layer_property(VK_OVERRIDE_LAYER_NAME, layer_list);
  ------------------
  |  |  142|      0|#define VK_OVERRIDE_LAYER_NAME "VK_LAYER_LUNARG_override"
  ------------------
  903|      0|        }
  904|      0|    }
  905|      3|}
loader_remove_layers_not_in_implicit_meta_layers:
  908|     10|void loader_remove_layers_not_in_implicit_meta_layers(const struct loader_instance *inst, struct loader_layer_list *layer_list) {
  909|     10|    int32_t i;
  910|     10|    int32_t j;
  911|     10|    int32_t layer_count = (int32_t)(layer_list->count);
  912|       |
  913|     20|    for (i = 0; i < layer_count; i++) {
  ------------------
  |  Branch (913:17): [True: 10, False: 10]
  ------------------
  914|     10|        layer_list->list[i].keep = false;
  915|     10|    }
  916|       |
  917|     20|    for (i = 0; i < layer_count; i++) {
  ------------------
  |  Branch (917:17): [True: 10, False: 10]
  ------------------
  918|     10|        struct loader_layer_properties *cur_layer_prop = &layer_list->list[i];
  919|       |
  920|     10|        if (0 == (cur_layer_prop->type_flags & VK_LAYER_TYPE_FLAG_EXPLICIT_LAYER)) {
  ------------------
  |  Branch (920:13): [True: 10, False: 0]
  ------------------
  921|     10|            cur_layer_prop->keep = true;
  922|     10|            continue;
  923|     10|        }
  924|      0|        for (j = 0; j < layer_count; j++) {
  ------------------
  |  Branch (924:21): [True: 0, False: 0]
  ------------------
  925|      0|            struct loader_layer_properties *layer_to_check = &layer_list->list[j];
  926|       |
  927|      0|            if (i == j) {
  ------------------
  |  Branch (927:17): [True: 0, False: 0]
  ------------------
  928|      0|                continue;
  929|      0|            }
  930|       |
  931|      0|            if (layer_to_check->type_flags & VK_LAYER_TYPE_FLAG_META_LAYER) {
  ------------------
  |  Branch (931:17): [True: 0, False: 0]
  ------------------
  932|       |                // For all layers found in this meta layer, we want to keep them as well.
  933|      0|                for (uint32_t comp_layer = 0; comp_layer < layer_to_check->component_layer_names.count; comp_layer++) {
  ------------------
  |  Branch (933:47): [True: 0, False: 0]
  ------------------
  934|      0|                    if (!strcmp(layer_to_check->component_layer_names.list[comp_layer], cur_layer_prop->info.layerName)) {
  ------------------
  |  Branch (934:25): [True: 0, False: 0]
  ------------------
  935|      0|                        cur_layer_prop->keep = true;
  936|      0|                    }
  937|      0|                }
  938|      0|            }
  939|      0|        }
  940|      0|    }
  941|       |
  942|       |    // Remove any layers we don't want to keep (Don't use layer_count here as we need it to be
  943|       |    // dynamically updated if we delete a layer property in the list).
  944|     20|    for (i = 0; i < (int32_t)(layer_list->count); i++) {
  ------------------
  |  Branch (944:17): [True: 10, False: 10]
  ------------------
  945|     10|        struct loader_layer_properties *cur_layer_prop = &layer_list->list[i];
  946|     10|        if (!cur_layer_prop->keep) {
  ------------------
  |  Branch (946:13): [True: 0, False: 10]
  ------------------
  947|      0|            loader_log(
  948|      0|                inst, VULKAN_LOADER_DEBUG_BIT, 0,
  949|      0|                "loader_remove_layers_not_in_implicit_meta_layers : Implicit meta-layers are active, and layer %s is not list "
  950|      0|                "inside of any.  So removing layer from current layer list.",
  951|      0|                cur_layer_prop->info.layerName);
  952|      0|            loader_remove_layer_in_list(inst, layer_list, i);
  953|      0|            i--;
  954|      0|        }
  955|     10|    }
  956|     10|}
loader_init_generic_list:
 1062|     69|VkResult loader_init_generic_list(const struct loader_instance *inst, struct loader_generic_list *list_info, size_t element_size) {
 1063|     69|    size_t capacity = 32 * element_size;
 1064|     69|    list_info->count = 0;
 1065|     69|    list_info->capacity = 0;
 1066|     69|    list_info->list = loader_instance_heap_calloc(inst, capacity, VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE);
 1067|     69|    if (list_info->list == NULL) {
  ------------------
  |  Branch (1067:9): [True: 0, False: 69]
  ------------------
 1068|      0|        loader_log(inst, VULKAN_LOADER_ERROR_BIT, 0, "loader_init_generic_list: Failed to allocate space for generic list");
 1069|      0|        return VK_ERROR_OUT_OF_HOST_MEMORY;
 1070|      0|    }
 1071|     69|    list_info->capacity = capacity;
 1072|     69|    return VK_SUCCESS;
 1073|     69|}
loader_destroy_generic_list:
 1091|  15.7k|void loader_destroy_generic_list(const struct loader_instance *inst, struct loader_generic_list *list) {
 1092|  15.7k|    loader_instance_heap_free(inst, list->list);
 1093|  15.7k|    memset(list, 0, sizeof(struct loader_generic_list));
 1094|  15.7k|}
loader_add_to_ext_list:
 1147|      4|                                uint32_t prop_list_count, const VkExtensionProperties *props) {
 1148|      4|    if (ext_list->list == NULL || ext_list->capacity == 0) {
  ------------------
  |  Branch (1148:9): [True: 4, False: 0]
  |  Branch (1148:35): [True: 0, False: 0]
  ------------------
 1149|      4|        VkResult res = loader_init_generic_list(inst, (struct loader_generic_list *)ext_list, sizeof(VkExtensionProperties));
 1150|      4|        if (VK_SUCCESS != res) {
  ------------------
  |  Branch (1150:13): [True: 0, False: 4]
  ------------------
 1151|      0|            return res;
 1152|      0|        }
 1153|      4|    }
 1154|       |
 1155|      8|    for (uint32_t i = 0; i < prop_list_count; i++) {
  ------------------
  |  Branch (1155:26): [True: 4, False: 4]
  ------------------
 1156|      4|        const VkExtensionProperties *cur_ext = &props[i];
 1157|       |
 1158|       |        // look for duplicates
 1159|      4|        if (has_vk_extension_property(cur_ext, ext_list)) {
  ------------------
  |  Branch (1159:13): [True: 0, False: 4]
  ------------------
 1160|      0|            continue;
 1161|      0|        }
 1162|       |
 1163|       |        // add to list at end
 1164|       |        // check for enough capacity
 1165|      4|        if (ext_list->count * sizeof(VkExtensionProperties) >= ext_list->capacity) {
  ------------------
  |  Branch (1165:13): [True: 0, False: 4]
  ------------------
 1166|      0|            void *new_ptr = loader_instance_heap_realloc(inst, ext_list->list, ext_list->capacity, ext_list->capacity * 2,
 1167|      0|                                                         VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE);
 1168|      0|            if (new_ptr == NULL) {
  ------------------
  |  Branch (1168:17): [True: 0, False: 0]
  ------------------
 1169|      0|                loader_log(inst, VULKAN_LOADER_ERROR_BIT, 0,
 1170|      0|                           "loader_add_to_ext_list: Failed to reallocate space for extension list");
 1171|      0|                return VK_ERROR_OUT_OF_HOST_MEMORY;
 1172|      0|            }
 1173|      0|            ext_list->list = new_ptr;
 1174|       |
 1175|       |            // double capacity
 1176|      0|            ext_list->capacity *= 2;
 1177|      0|        }
 1178|       |
 1179|       |        // every caller passes the address of an array element or on-stack struct, never NULL
 1180|       |        // NOLINTNEXTLINE(clang-analyzer-core.NonNullParamChecker)
 1181|      4|        memcpy(&ext_list->list[ext_list->count], cur_ext, sizeof(VkExtensionProperties));
 1182|      4|        ext_list->count++;
 1183|      4|    }
 1184|      4|    return VK_SUCCESS;
 1185|      4|}
loader_layer_is_available:
 1300|     22|                               const struct loader_layer_properties *prop) {
 1301|     22|    bool available = true;
 1302|     22|    bool is_implicit = (0 == (prop->type_flags & VK_LAYER_TYPE_FLAG_EXPLICIT_LAYER));
 1303|     22|    bool disabled_by_type =
 1304|     22|        is_implicit ? filters->disable_filter.disable_all_implicit : filters->disable_filter.disable_all_explicit;
  ------------------
  |  Branch (1304:9): [True: 22, False: 0]
  ------------------
 1305|     22|    if ((filters->disable_filter.disable_all || disabled_by_type ||
  ------------------
  |  Branch (1305:10): [True: 0, False: 22]
  |  Branch (1305:49): [True: 0, False: 22]
  ------------------
 1306|     22|         check_name_matches_filter_environment_var(prop->info.layerName, &filters->disable_filter.additional_filters)) &&
  ------------------
  |  Branch (1306:10): [True: 0, False: 22]
  ------------------
 1307|      0|        !check_name_matches_filter_environment_var(prop->info.layerName, &filters->allow_filter)) {
  ------------------
  |  Branch (1307:9): [True: 0, False: 0]
  ------------------
 1308|      0|        available = false;
 1309|      0|    }
 1310|     22|    if (check_name_matches_filter_environment_var(prop->info.layerName, &filters->enable_filter)) {
  ------------------
  |  Branch (1310:9): [True: 0, False: 22]
  ------------------
 1311|      0|        available = true;
 1312|     22|    } else if (!available) {
  ------------------
  |  Branch (1312:16): [True: 0, False: 22]
  ------------------
 1313|      0|        loader_log(inst, VULKAN_LOADER_WARN_BIT | VULKAN_LOADER_LAYER_BIT, 0,
 1314|      0|                   "Layer \"%s\" forced disabled because name matches filter of env var \'%s\'.", prop->info.layerName,
 1315|      0|                   VK_LAYERS_DISABLE_ENV_VAR);
  ------------------
  |  |  120|      0|#define VK_LAYERS_DISABLE_ENV_VAR "VK_LOADER_LAYERS_DISABLE"
  ------------------
 1316|      0|    }
 1317|       |
 1318|     22|    return available;
 1319|     22|}
loader_implicit_layer_is_enabled:
 1368|     26|                                      const struct loader_layer_properties *prop) {
 1369|     26|    bool enable = false;
 1370|     26|    bool forced_disabled = false;
 1371|     26|    bool forced_enabled = false;
 1372|       |
 1373|     26|    if ((filters->disable_filter.disable_all || filters->disable_filter.disable_all_implicit ||
  ------------------
  |  Branch (1373:10): [True: 0, False: 26]
  |  Branch (1373:49): [True: 0, False: 26]
  ------------------
 1374|     26|         check_name_matches_filter_environment_var(prop->info.layerName, &filters->disable_filter.additional_filters)) &&
  ------------------
  |  Branch (1374:10): [True: 0, False: 26]
  ------------------
 1375|      0|        !check_name_matches_filter_environment_var(prop->info.layerName, &filters->allow_filter)) {
  ------------------
  |  Branch (1375:9): [True: 0, False: 0]
  ------------------
 1376|      0|        forced_disabled = true;
 1377|      0|    }
 1378|     26|    if (check_name_matches_filter_environment_var(prop->info.layerName, &filters->enable_filter)) {
  ------------------
  |  Branch (1378:9): [True: 0, False: 26]
  ------------------
 1379|      0|        forced_enabled = true;
 1380|      0|    }
 1381|       |
 1382|       |    // If no enable_environment variable is specified, this implicit layer is always be enabled by default.
 1383|     26|    if (NULL == prop->enable_env_var.name) {
  ------------------
  |  Branch (1383:9): [True: 22, False: 4]
  ------------------
 1384|     22|        enable = true;
 1385|     22|    } else {
 1386|      4|        char *env_value = loader_getenv(prop->enable_env_var.name, inst);
 1387|      4|        if (env_value && !strcmp(prop->enable_env_var.value, env_value)) {
  ------------------
  |  Branch (1387:13): [True: 4, False: 0]
  |  Branch (1387:26): [True: 0, False: 4]
  ------------------
 1388|      0|            enable = true;
 1389|      0|        }
 1390|       |
 1391|       |        // Otherwise, only enable this layer if the enable environment variable is defined
 1392|      4|        loader_free_getenv(env_value, inst);
 1393|      4|    }
 1394|       |
 1395|     26|    if (forced_enabled) {
  ------------------
  |  Branch (1395:9): [True: 0, False: 26]
  ------------------
 1396|       |        // Only report a message that we've forced on a layer if it wouldn't have been enabled
 1397|       |        // normally.
 1398|      0|        if (!enable) {
  ------------------
  |  Branch (1398:13): [True: 0, False: 0]
  ------------------
 1399|      0|            enable = true;
 1400|      0|            loader_log(inst, VULKAN_LOADER_WARN_BIT | VULKAN_LOADER_LAYER_BIT, 0,
 1401|      0|                       "Implicit layer \"%s\" forced enabled due to env var \'%s\'.", prop->info.layerName,
 1402|      0|                       VK_LAYERS_ENABLE_ENV_VAR);
  ------------------
  |  |  119|      0|#define VK_LAYERS_ENABLE_ENV_VAR "VK_LOADER_LAYERS_ENABLE"
  ------------------
 1403|      0|        }
 1404|     26|    } else if (enable && forced_disabled) {
  ------------------
  |  Branch (1404:16): [True: 22, False: 4]
  |  Branch (1404:26): [True: 0, False: 22]
  ------------------
 1405|      0|        enable = false;
 1406|       |        // Report a message that we've forced off a layer if it would have been enabled normally.
 1407|      0|        loader_log(inst, VULKAN_LOADER_WARN_BIT | VULKAN_LOADER_LAYER_BIT, 0,
 1408|      0|                   "Implicit layer \"%s\" forced disabled because name matches filter of env var \'%s\'.", prop->info.layerName,
 1409|      0|                   VK_LAYERS_DISABLE_ENV_VAR);
  ------------------
  |  |  120|      0|#define VK_LAYERS_DISABLE_ENV_VAR "VK_LOADER_LAYERS_DISABLE"
  ------------------
 1410|      0|        return enable;
 1411|      0|    }
 1412|       |
 1413|       |    // The disable_environment has priority over everything else.  If it is defined, the layer is always
 1414|       |    // disabled.
 1415|     26|    if (NULL != prop->disable_env_var.name) {
  ------------------
  |  Branch (1415:9): [True: 26, False: 0]
  ------------------
 1416|     26|        char *env_value = loader_getenv(prop->disable_env_var.name, inst);
 1417|     26|        if (NULL != env_value) {
  ------------------
  |  Branch (1417:13): [True: 0, False: 26]
  ------------------
 1418|      0|            enable = false;
 1419|      0|        }
 1420|     26|        loader_free_getenv(env_value, inst);
 1421|     26|    } else if ((prop->type_flags & VK_LAYER_TYPE_FLAG_EXPLICIT_LAYER) == 0) {
  ------------------
  |  Branch (1421:16): [True: 0, False: 0]
  ------------------
 1422|      0|        loader_log(inst, VULKAN_LOADER_WARN_BIT | VULKAN_LOADER_LAYER_BIT, 0,
 1423|      0|                   "Implicit layer \"%s\" missing disabled environment variable!", prop->info.layerName);
 1424|      0|    }
 1425|       |
 1426|       |    // Enable this layer if it is included in the override layer
 1427|     26|    if (inst != NULL && inst->override_layer_present) {
  ------------------
  |  Branch (1427:9): [True: 0, False: 26]
  |  Branch (1427:25): [True: 0, False: 0]
  ------------------
 1428|      0|        struct loader_layer_properties *override = NULL;
 1429|      0|        for (uint32_t i = 0; i < inst->instance_layer_list.count; ++i) {
  ------------------
  |  Branch (1429:30): [True: 0, False: 0]
  ------------------
 1430|      0|            if (strcmp(inst->instance_layer_list.list[i].info.layerName, VK_OVERRIDE_LAYER_NAME) == 0) {
  ------------------
  |  |  142|      0|#define VK_OVERRIDE_LAYER_NAME "VK_LAYER_LUNARG_override"
  ------------------
  |  Branch (1430:17): [True: 0, False: 0]
  ------------------
 1431|      0|                override = &inst->instance_layer_list.list[i];
 1432|      0|                break;
 1433|      0|            }
 1434|      0|        }
 1435|      0|        if (override != NULL) {
  ------------------
  |  Branch (1435:13): [True: 0, False: 0]
  ------------------
 1436|      0|            for (uint32_t i = 0; i < override->component_layer_names.count; ++i) {
  ------------------
  |  Branch (1436:34): [True: 0, False: 0]
  ------------------
 1437|      0|                if (strcmp(override->component_layer_names.list[i], prop->info.layerName) == 0) {
  ------------------
  |  Branch (1437:21): [True: 0, False: 0]
  ------------------
 1438|      0|                    enable = true;
 1439|      0|                    break;
 1440|      0|                }
 1441|      0|            }
 1442|      0|        }
 1443|      0|    }
 1444|       |
 1445|     26|    return enable;
 1446|     26|}
loader_initialize:
 2356|      2|void loader_initialize(void) {
 2357|      2|    loader_platform_thread_create_mutex(&loader_lock);
 2358|      2|    loader_platform_thread_create_mutex(&loader_preload_icd_lock);
 2359|      2|    init_global_loader_settings();
 2360|      2|#endif
 2361|       |
 2362|       |    // initialize logging
 2363|      2|    loader_init_global_debug_level();
 2364|       |#if defined(_WIN32)
 2365|       |    windows_initialization();
 2366|       |#endif
 2367|       |
 2368|      2|    loader_api_version version = loader_make_full_version(VK_HEADER_VERSION_COMPLETE);
 2369|      2|    loader_log(NULL, VULKAN_LOADER_INFO_BIT, 0, "Vulkan Loader Version %d.%d.%d", version.major, version.minor, version.patch);
 2370|       |
 2371|       |#if defined(GIT_BRANCH_NAME) && defined(GIT_TAG_INFO)
 2372|       |    loader_log(NULL, VULKAN_LOADER_INFO_BIT, 0, "[Vulkan Loader Git - Tag: " GIT_BRANCH_NAME ", Branch/Commit: " GIT_TAG_INFO "]");
 2373|       |#endif
 2374|       |
 2375|      2|    char *loader_disable_dynamic_library_unloading_env_var = loader_getenv("VK_LOADER_DISABLE_DYNAMIC_LIBRARY_UNLOADING", NULL);
 2376|      2|    if (loader_disable_dynamic_library_unloading_env_var &&
  ------------------
  |  Branch (2376:9): [True: 0, False: 2]
  ------------------
 2377|       |        // NOLINTNEXTLINE(bugprone-not-null-terminated-result) - n=2 intentionally excludes "1x" values like "10"
 2378|      0|        0 == strncmp(loader_disable_dynamic_library_unloading_env_var, "1", 2)) {
  ------------------
  |  Branch (2378:9): [True: 0, False: 0]
  ------------------
 2379|      0|        loader_disable_dynamic_library_unloading = true;
 2380|      0|        loader_log(NULL, VULKAN_LOADER_WARN_BIT, 0, "Vulkan Loader: library unloading is disabled");
 2381|      2|    } else {
 2382|      2|        loader_disable_dynamic_library_unloading = false;
 2383|      2|    }
 2384|      2|    loader_free_getenv(loader_disable_dynamic_library_unloading_env_var, NULL);
 2385|       |#if defined(LOADER_USE_UNSAFE_FILE_SEARCH)
 2386|       |    loader_log(NULL, VULKAN_LOADER_WARN_BIT, 0, "Vulkan Loader: unsafe searching is enabled");
 2387|       |#endif
 2388|       |#if defined(_WIN32)
 2389|       |    return TRUE;
 2390|       |#endif
 2391|      2|}
loader_init_library:
 2428|      2|__attribute__((constructor)) void loader_init_library(void) { loader_initialize(); }
loader_get_next_path:
 2439|  64.0k|char *loader_get_next_path(char *path) {
 2440|  64.0k|    uint32_t len;
 2441|  64.0k|    char *next;
 2442|       |
 2443|  64.0k|    if (path == NULL) return NULL;
  ------------------
  |  Branch (2443:9): [True: 0, False: 64.0k]
  ------------------
 2444|  64.0k|    next = strchr(path, PATH_SEPARATOR);
  ------------------
  |  |  154|  64.0k|#define PATH_SEPARATOR ':'
  ------------------
 2445|  64.0k|    if (next == NULL) {
  ------------------
  |  Branch (2445:9): [True: 64.0k, False: 0]
  ------------------
 2446|  64.0k|        len = (uint32_t)strlen(path);
 2447|  64.0k|        next = path + len;
 2448|  64.0k|    } else {
 2449|      0|        *next = '\0';
 2450|      0|        next++;
 2451|      0|    }
 2452|       |
 2453|  64.0k|    return next;
 2454|  64.0k|}
combine_manifest_directory_and_library_path:
 2464|    366|                                                     const char *manifest_file_path, char **out_fullpath) {
 2465|    366|    assert(library_path && manifest_file_path && out_fullpath);
 2466|    366|    if (loader_platform_is_path_absolute(library_path)) {
  ------------------
  |  Branch (2466:9): [True: 0, False: 366]
  ------------------
 2467|      0|        *out_fullpath = library_path;
 2468|      0|        return VK_SUCCESS;
 2469|      0|    }
 2470|    366|    VkResult res = VK_SUCCESS;
 2471|       |
 2472|    366|    size_t library_path_len = strlen(library_path);
 2473|    366|    size_t manifest_file_path_str_len = strlen(manifest_file_path);
 2474|    366|    bool library_path_contains_directory_symbol = false;
 2475|  11.7k|    for (size_t i = 0; i < library_path_len; i++) {
  ------------------
  |  Branch (2475:24): [True: 11.7k, False: 87]
  ------------------
 2476|  11.7k|        if (library_path[i] == DIRECTORY_SYMBOL) {
  ------------------
  |  |  155|  11.7k|#define DIRECTORY_SYMBOL '/'
  ------------------
  |  Branch (2476:13): [True: 279, False: 11.4k]
  ------------------
 2477|    279|            library_path_contains_directory_symbol = true;
 2478|    279|            break;
 2479|    279|        }
 2480|  11.7k|    }
 2481|       |    // Means that the library_path is neither absolute nor relative - thus we should not modify it at all
 2482|    366|    if (!library_path_contains_directory_symbol) {
  ------------------
  |  Branch (2482:9): [True: 87, False: 279]
  ------------------
 2483|     87|        *out_fullpath = library_path;
 2484|     87|        return VK_SUCCESS;
 2485|     87|    }
 2486|       |    // must include both a directory symbol and the null terminator
 2487|    279|    size_t new_str_len = library_path_len + manifest_file_path_str_len + 1 + 1;
 2488|       |
 2489|    279|    *out_fullpath = loader_instance_heap_calloc(inst, new_str_len, VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE);
 2490|    279|    if (NULL == *out_fullpath) {
  ------------------
  |  Branch (2490:9): [True: 0, False: 279]
  ------------------
 2491|      0|        res = VK_ERROR_OUT_OF_HOST_MEMORY;
 2492|      0|        goto out;
 2493|      0|    }
 2494|    279|    size_t cur_loc_in_out_fullpath = 0;
 2495|       |    // look for the last occurrence of DIRECTORY_SYMBOL in manifest_file_path
 2496|    279|    size_t last_directory_symbol = 0;
 2497|    279|    bool found_directory_symbol = false;
 2498|  17.0k|    for (size_t i = 0; i < manifest_file_path_str_len; i++) {
  ------------------
  |  Branch (2498:24): [True: 16.7k, False: 279]
  ------------------
 2499|  16.7k|        if (manifest_file_path[i] == DIRECTORY_SYMBOL) {
  ------------------
  |  |  155|  16.7k|#define DIRECTORY_SYMBOL '/'
  ------------------
  |  Branch (2499:13): [True: 1.67k, False: 15.0k]
  ------------------
 2500|  1.67k|            last_directory_symbol = i + 1;  // we want to include the symbol
 2501|  1.67k|            found_directory_symbol = true;
 2502|       |            // dont break because we want to find the last occurrence
 2503|  1.67k|        }
 2504|  16.7k|    }
 2505|       |    // Add manifest_file_path up to the last directory symbol
 2506|    279|    if (found_directory_symbol) {
  ------------------
  |  Branch (2506:9): [True: 279, False: 0]
  ------------------
 2507|    279|        loader_strncpy(*out_fullpath, new_str_len, manifest_file_path, last_directory_symbol);
 2508|    279|        cur_loc_in_out_fullpath += last_directory_symbol;
 2509|    279|    }
 2510|    279|    loader_strncpy(&(*out_fullpath)[cur_loc_in_out_fullpath], new_str_len - cur_loc_in_out_fullpath, library_path,
 2511|    279|                   library_path_len);
 2512|    279|    cur_loc_in_out_fullpath += library_path_len + 1;
 2513|    279|    (*out_fullpath)[cur_loc_in_out_fullpath] = '\0';
 2514|       |
 2515|    279|out:
 2516|    279|    loader_instance_heap_free(inst, library_path);
 2517|       |
 2518|    279|    return res;
 2519|    279|}
loader_get_fullpath:
 2525|  13.0k|void loader_get_fullpath(const char *file, const char *in_dirs, size_t out_size, char *out_fullpath) {
 2526|  13.0k|    if (!loader_platform_is_path(file) && *in_dirs) {
  ------------------
  |  Branch (2526:9): [True: 13.0k, False: 0]
  |  Branch (2526:43): [True: 13.0k, False: 0]
  ------------------
 2527|  13.0k|        size_t dirs_copy_len = strlen(in_dirs) + 1;
 2528|  13.0k|        char *dirs_copy = loader_stack_alloc(dirs_copy_len);
  ------------------
  |  |   42|  13.0k|#define loader_stack_alloc(size) alloca(size)
  ------------------
 2529|  13.0k|        loader_strncpy(dirs_copy, dirs_copy_len, in_dirs, dirs_copy_len);
 2530|       |
 2531|       |        // find if file exists after prepending paths in given list
 2532|       |        // for (dir = dirs_copy; *dir && (next_dir = loader_get_next_path(dir)); dir = next_dir) {
 2533|  13.0k|        char *dir = dirs_copy;
 2534|  13.0k|        char *next_dir = loader_get_next_path(dir);
 2535|  13.1k|        while (*dir && next_dir) {
  ------------------
  |  Branch (2535:16): [True: 13.0k, False: 47]
  |  Branch (2535:24): [True: 13.0k, False: 0]
  ------------------
 2536|  13.0k|            int path_concat_ret = snprintf(out_fullpath, out_size, "%s%c%s", dir, DIRECTORY_SYMBOL, file);
  ------------------
  |  |  155|  13.0k|#define DIRECTORY_SYMBOL '/'
  ------------------
 2537|  13.0k|            if (path_concat_ret < 0) {
  ------------------
  |  Branch (2537:17): [True: 0, False: 13.0k]
  ------------------
 2538|      0|                continue;
 2539|      0|            }
 2540|  13.0k|            if (loader_platform_file_exists(out_fullpath)) {
  ------------------
  |  Branch (2540:17): [True: 13.0k, False: 47]
  ------------------
 2541|  13.0k|                return;
 2542|  13.0k|            }
 2543|     47|            dir = next_dir;
 2544|     47|            next_dir = loader_get_next_path(dir);
 2545|     47|        }
 2546|  13.0k|    }
 2547|       |
 2548|     47|    (void)snprintf(out_fullpath, out_size, "%s", file);
 2549|     47|}
verify_meta_layer_component_layers:
 2556|     26|                                        struct loader_layer_list *instance_layers, bool *already_checked_meta_layers) {
 2557|     26|    struct loader_layer_properties *prop = &instance_layers->list[prop_index];
 2558|     26|    loader_api_version meta_layer_version = loader_make_version(prop->info.specVersion);
 2559|       |
 2560|     26|    if (NULL == already_checked_meta_layers) {
  ------------------
  |  Branch (2560:9): [True: 26, False: 0]
  ------------------
 2561|     26|        already_checked_meta_layers = loader_stack_alloc(sizeof(bool) * instance_layers->count);
  ------------------
  |  |   42|     26|#define loader_stack_alloc(size) alloca(size)
  ------------------
 2562|     26|        if (already_checked_meta_layers == NULL) {
  ------------------
  |  Branch (2562:13): [True: 0, False: 26]
  ------------------
 2563|      0|            return false;
 2564|      0|        }
 2565|     26|        memset(already_checked_meta_layers, 0, sizeof(bool) * instance_layers->count);
 2566|     26|    }
 2567|       |
 2568|       |    // Mark this meta layer as 'already checked', indicating which layers have already been recursed.
 2569|     26|    already_checked_meta_layers[prop_index] = true;
 2570|       |
 2571|     26|    for (uint32_t comp_layer = 0; comp_layer < prop->component_layer_names.count; comp_layer++) {
  ------------------
  |  Branch (2571:35): [True: 0, False: 26]
  ------------------
 2572|      0|        struct loader_layer_properties *comp_prop =
 2573|      0|            loader_find_layer_property(prop->component_layer_names.list[comp_layer], instance_layers);
 2574|      0|        if (comp_prop == NULL) {
  ------------------
  |  Branch (2574:13): [True: 0, False: 0]
  ------------------
 2575|      0|            loader_log(inst, VULKAN_LOADER_WARN_BIT, 0,
 2576|      0|                       "verify_meta_layer_component_layers: Meta-layer %s can't find component layer %s at index %d."
 2577|      0|                       "  Skipping this layer.",
 2578|      0|                       prop->info.layerName, prop->component_layer_names.list[comp_layer], comp_layer);
 2579|       |
 2580|      0|            return false;
 2581|      0|        }
 2582|       |
 2583|       |        // Check the version of each layer, they need to be at least MAJOR and MINOR
 2584|      0|        loader_api_version comp_prop_version = loader_make_version(comp_prop->info.specVersion);
 2585|      0|        if (!loader_check_version_meets_required(meta_layer_version, comp_prop_version)) {
  ------------------
  |  Branch (2585:13): [True: 0, False: 0]
  ------------------
 2586|      0|            loader_log(inst, VULKAN_LOADER_WARN_BIT, 0,
 2587|      0|                       "verify_meta_layer_component_layers: Meta-layer uses API version %d.%d, but component "
 2588|      0|                       "layer %d has API version %d.%d that is lower.  Skipping this layer.",
 2589|      0|                       meta_layer_version.major, meta_layer_version.minor, comp_layer, comp_prop_version.major,
 2590|      0|                       comp_prop_version.minor);
 2591|       |
 2592|      0|            return false;
 2593|      0|        }
 2594|       |
 2595|       |        // Make sure the layer isn't using it's own name
 2596|      0|        if (!strcmp(prop->info.layerName, prop->component_layer_names.list[comp_layer])) {
  ------------------
  |  Branch (2596:13): [True: 0, False: 0]
  ------------------
 2597|      0|            loader_log(inst, VULKAN_LOADER_WARN_BIT, 0,
 2598|      0|                       "verify_meta_layer_component_layers: Meta-layer %s lists itself in its component layer "
 2599|      0|                       "list at index %d.  Skipping this layer.",
 2600|      0|                       prop->info.layerName, comp_layer);
 2601|       |
 2602|      0|            return false;
 2603|      0|        }
 2604|      0|        if (comp_prop->type_flags & VK_LAYER_TYPE_FLAG_META_LAYER) {
  ------------------
  |  Branch (2604:13): [True: 0, False: 0]
  ------------------
 2605|      0|            size_t comp_prop_index = INT32_MAX;
 2606|       |            // Make sure we haven't verified this meta layer before
 2607|      0|            for (uint32_t i = 0; i < instance_layers->count; i++) {
  ------------------
  |  Branch (2607:34): [True: 0, False: 0]
  ------------------
 2608|      0|                if (strcmp(comp_prop->info.layerName, instance_layers->list[i].info.layerName) == 0) {
  ------------------
  |  Branch (2608:21): [True: 0, False: 0]
  ------------------
 2609|      0|                    comp_prop_index = i;
 2610|      0|                }
 2611|      0|            }
 2612|      0|            if (comp_prop_index != INT32_MAX && already_checked_meta_layers[comp_prop_index]) {
  ------------------
  |  Branch (2612:17): [True: 0, False: 0]
  |  Branch (2612:49): [True: 0, False: 0]
  ------------------
 2613|      0|                loader_log(inst, VULKAN_LOADER_WARN_BIT, 0,
 2614|      0|                           "verify_meta_layer_component_layers: Recursive dependency between Meta-layer %s and  Meta-layer %s.  "
 2615|      0|                           "Skipping this layer.",
 2616|      0|                           instance_layers->list[prop_index].info.layerName, comp_prop->info.layerName);
 2617|      0|                return false;
 2618|      0|            }
 2619|       |
 2620|      0|            loader_log(inst, VULKAN_LOADER_INFO_BIT, 0,
 2621|      0|                       "verify_meta_layer_component_layers: Adding meta-layer %s which also contains meta-layer %s",
 2622|      0|                       prop->info.layerName, comp_prop->info.layerName);
 2623|       |
 2624|       |            // Make sure if the layer is using a meta-layer in its component list that we also verify that.
 2625|      0|            if (!verify_meta_layer_component_layers(inst, comp_prop_index, instance_layers, already_checked_meta_layers)) {
  ------------------
  |  Branch (2625:17): [True: 0, False: 0]
  ------------------
 2626|      0|                loader_log(inst, VULKAN_LOADER_WARN_BIT, 0,
 2627|      0|                           "Meta-layer %s component layer %s can not find all component layers."
 2628|      0|                           "  Skipping this layer.",
 2629|      0|                           prop->info.layerName, prop->component_layer_names.list[comp_layer]);
 2630|      0|                return false;
 2631|      0|            }
 2632|      0|        }
 2633|      0|    }
 2634|       |    // Didn't exit early so that means it passed all checks
 2635|     26|    loader_log(inst, VULKAN_LOADER_INFO_BIT | VULKAN_LOADER_LAYER_BIT, 0,
 2636|     26|               "Meta-layer \"%s\" all %d component layers appear to be valid.", prop->info.layerName,
 2637|     26|               prop->component_layer_names.count);
 2638|       |
 2639|       |    // If layer logging is on, list the internals included in the meta-layer
 2640|     26|    for (uint32_t comp_layer = 0; comp_layer < prop->component_layer_names.count; comp_layer++) {
  ------------------
  |  Branch (2640:35): [True: 0, False: 26]
  ------------------
 2641|      0|        loader_log(inst, VULKAN_LOADER_LAYER_BIT, 0, "  [%d] %s", comp_layer, prop->component_layer_names.list[comp_layer]);
 2642|      0|    }
 2643|       |    return true;
 2644|     26|}
update_meta_layer_extensions_from_component_layers:
 2650|     26|                                                            struct loader_layer_list *instance_layers) {
 2651|     26|    VkResult res = VK_SUCCESS;
 2652|     26|    for (uint32_t comp_layer = 0; comp_layer < prop->component_layer_names.count; comp_layer++) {
  ------------------
  |  Branch (2652:35): [True: 0, False: 26]
  ------------------
 2653|      0|        struct loader_layer_properties *comp_prop =
 2654|      0|            loader_find_layer_property(prop->component_layer_names.list[comp_layer], instance_layers);
 2655|       |
 2656|      0|        if (NULL != comp_prop->instance_extension_list.list) {
  ------------------
  |  Branch (2656:13): [True: 0, False: 0]
  ------------------
 2657|      0|            for (uint32_t ext = 0; ext < comp_prop->instance_extension_list.count; ext++) {
  ------------------
  |  Branch (2657:36): [True: 0, False: 0]
  ------------------
 2658|      0|                loader_log(inst, VULKAN_LOADER_DEBUG_BIT, 0, "Meta-layer %s component layer %s adding instance extension %s",
 2659|      0|                           prop->info.layerName, prop->component_layer_names.list[comp_layer],
 2660|      0|                           comp_prop->instance_extension_list.list[ext].extensionName);
 2661|       |
 2662|      0|                if (!has_vk_extension_property(&comp_prop->instance_extension_list.list[ext], &prop->instance_extension_list)) {
  ------------------
  |  Branch (2662:21): [True: 0, False: 0]
  ------------------
 2663|      0|                    res = loader_add_to_ext_list(inst, &prop->instance_extension_list, 1,
 2664|      0|                                                 &comp_prop->instance_extension_list.list[ext]);
 2665|      0|                    if (VK_ERROR_OUT_OF_HOST_MEMORY == res) {
  ------------------
  |  Branch (2665:25): [True: 0, False: 0]
  ------------------
 2666|      0|                        return res;
 2667|      0|                    }
 2668|      0|                }
 2669|      0|            }
 2670|      0|        }
 2671|      0|        if (NULL != comp_prop->device_extension_list.list) {
  ------------------
  |  Branch (2671:13): [True: 0, False: 0]
  ------------------
 2672|      0|            for (uint32_t ext = 0; ext < comp_prop->device_extension_list.count; ext++) {
  ------------------
  |  Branch (2672:36): [True: 0, False: 0]
  ------------------
 2673|      0|                loader_log(inst, VULKAN_LOADER_DEBUG_BIT, 0, "Meta-layer %s component layer %s adding device extension %s",
 2674|      0|                           prop->info.layerName, prop->component_layer_names.list[comp_layer],
 2675|      0|                           comp_prop->device_extension_list.list[ext].props.extensionName);
 2676|       |
 2677|      0|                if (!has_vk_dev_ext_property(&comp_prop->device_extension_list.list[ext].props, &prop->device_extension_list)) {
  ------------------
  |  Branch (2677:21): [True: 0, False: 0]
  ------------------
 2678|      0|                    res = loader_add_to_dev_ext_list(inst, &prop->device_extension_list,
 2679|      0|                                                     &comp_prop->device_extension_list.list[ext].props, NULL);
 2680|      0|                    if (VK_ERROR_OUT_OF_HOST_MEMORY == res) {
  ------------------
  |  Branch (2680:25): [True: 0, False: 0]
  ------------------
 2681|      0|                        return res;
 2682|      0|                    }
 2683|      0|                }
 2684|      0|            }
 2685|      0|        }
 2686|      0|    }
 2687|     26|    return res;
 2688|     26|}
verify_all_meta_layers:
 2692|  4.84k|                                struct loader_layer_list *instance_layers, bool *override_layer_present) {
 2693|  4.84k|    VkResult res = VK_SUCCESS;
 2694|  4.84k|    *override_layer_present = false;
 2695|  4.88k|    for (int32_t i = 0; i < (int32_t)instance_layers->count; i++) {
  ------------------
  |  Branch (2695:25): [True: 38, False: 4.84k]
  ------------------
 2696|     38|        struct loader_layer_properties *prop = &instance_layers->list[i];
 2697|       |
 2698|       |        // If this is a meta-layer, make sure it is valid
 2699|     38|        if (prop->type_flags & VK_LAYER_TYPE_FLAG_META_LAYER) {
  ------------------
  |  Branch (2699:13): [True: 26, False: 12]
  ------------------
 2700|     26|            if (verify_meta_layer_component_layers(inst, i, instance_layers, NULL)) {
  ------------------
  |  Branch (2700:17): [True: 26, False: 0]
  ------------------
 2701|       |                // If any meta layer is valid, update its extension list to include the extensions from its component layers.
 2702|     26|                res = update_meta_layer_extensions_from_component_layers(inst, prop, instance_layers);
 2703|     26|                if (VK_ERROR_OUT_OF_HOST_MEMORY == res) {
  ------------------
  |  Branch (2703:21): [True: 0, False: 26]
  ------------------
 2704|      0|                    return res;
 2705|      0|                }
 2706|     26|                if (prop->is_override && loader_implicit_layer_is_enabled(inst, filters, prop)) {
  ------------------
  |  Branch (2706:21): [True: 5, False: 21]
  |  Branch (2706:42): [True: 5, False: 0]
  ------------------
 2707|      5|                    *override_layer_present = true;
 2708|      5|                }
 2709|     26|            } else {
 2710|      0|                loader_log(inst, VULKAN_LOADER_DEBUG_BIT, 0,
 2711|      0|                           "Removing meta-layer %s from instance layer list since it appears invalid.", prop->info.layerName);
 2712|       |
 2713|      0|                loader_remove_layer_in_list(inst, instance_layers, i);
 2714|      0|                i--;
 2715|      0|            }
 2716|     26|        }
 2717|     38|    }
 2718|  4.84k|    return res;
 2719|  4.84k|}
remove_all_non_valid_override_layers:
 2723|  4.84k|void remove_all_non_valid_override_layers(struct loader_instance *inst, struct loader_layer_list *instance_layers) {
 2724|  4.84k|    if (instance_layers == NULL) {
  ------------------
  |  Branch (2724:9): [True: 0, False: 4.84k]
  ------------------
 2725|      0|        return;
 2726|      0|    }
 2727|       |
 2728|  4.84k|    char cur_path[1024];
 2729|  4.84k|    char *ret = loader_platform_executable_path(cur_path, 1024);
 2730|  4.84k|    if (NULL == ret) {
  ------------------
  |  Branch (2730:9): [True: 0, False: 4.84k]
  ------------------
 2731|      0|        return;
 2732|      0|    }
 2733|       |    // Find out if there is an override layer with same the app_key_path as the path to the current executable.
 2734|       |    // If more than one is found, remove it and use the first layer
 2735|       |    // Remove any layers which aren't global and do not have the same app_key_path as the path to the current executable.
 2736|  4.84k|    bool found_active_override_layer = false;
 2737|  4.84k|    int global_layer_index = -1;
 2738|  4.88k|    for (uint32_t i = 0; i < instance_layers->count; i++) {
  ------------------
  |  Branch (2738:26): [True: 43, False: 4.84k]
  ------------------
 2739|     43|        struct loader_layer_properties *props = &instance_layers->list[i];
 2740|     43|        if (strcmp(props->info.layerName, VK_OVERRIDE_LAYER_NAME) == 0) {
  ------------------
  |  |  142|     43|#define VK_OVERRIDE_LAYER_NAME "VK_LAYER_LUNARG_override"
  ------------------
  |  Branch (2740:13): [True: 10, False: 33]
  ------------------
 2741|     10|            if (props->app_key_paths.count > 0) {  // not the global layer
  ------------------
  |  Branch (2741:17): [True: 5, False: 5]
  ------------------
 2742|     10|                for (uint32_t j = 0; j < props->app_key_paths.count; j++) {
  ------------------
  |  Branch (2742:38): [True: 5, False: 5]
  ------------------
 2743|      5|                    if (strcmp(props->app_key_paths.list[j], cur_path) == 0) {
  ------------------
  |  Branch (2743:25): [True: 0, False: 5]
  ------------------
 2744|      0|                        if (!found_active_override_layer) {
  ------------------
  |  Branch (2744:29): [True: 0, False: 0]
  ------------------
 2745|      0|                            found_active_override_layer = true;
 2746|      0|                        } else {
 2747|      0|                            loader_log(inst, VULKAN_LOADER_WARN_BIT | VULKAN_LOADER_LAYER_BIT, 0,
 2748|      0|                                       "remove_all_non_valid_override_layers: Multiple override layers where the same path in "
 2749|      0|                                       "app_keys "
 2750|      0|                                       "was found. Using the first layer found");
 2751|       |
 2752|       |                            // Remove duplicate active override layers that have the same app_key_path
 2753|      0|                            loader_remove_layer_in_list(inst, instance_layers, i);
 2754|      0|                            i--;
 2755|      0|                        }
 2756|      0|                    }
 2757|      5|                }
 2758|      5|                if (!found_active_override_layer) {
  ------------------
  |  Branch (2758:21): [True: 5, False: 0]
  ------------------
 2759|      5|                    loader_log(inst, VULKAN_LOADER_INFO_BIT | VULKAN_LOADER_LAYER_BIT, 0,
 2760|      5|                               "--Override layer found but not used because app \'%s\' is not in \'app_keys\' list!", cur_path);
 2761|       |
 2762|       |                    // Remove non-global override layers that don't have an app_key that matches cur_path
 2763|      5|                    loader_remove_layer_in_list(inst, instance_layers, i);
 2764|      5|                    i--;
 2765|      5|                }
 2766|      5|            } else {
 2767|      5|                if (global_layer_index == -1) {
  ------------------
  |  Branch (2767:21): [True: 5, False: 0]
  ------------------
 2768|      5|                    global_layer_index = (int)i;
 2769|      5|                } else {
 2770|      0|                    loader_log(
 2771|      0|                        inst, VULKAN_LOADER_WARN_BIT | VULKAN_LOADER_LAYER_BIT, 0,
 2772|      0|                        "remove_all_non_valid_override_layers: Multiple global override layers found. Using the first global "
 2773|      0|                        "layer found");
 2774|      0|                    loader_remove_layer_in_list(inst, instance_layers, i);
 2775|      0|                    i--;
 2776|      0|                }
 2777|      5|            }
 2778|     10|        }
 2779|     43|    }
 2780|       |    // Remove global layer if layer with same the app_key_path as the path to the current executable is found
 2781|  4.84k|    if (found_active_override_layer && global_layer_index >= 0) {
  ------------------
  |  Branch (2781:9): [True: 0, False: 4.84k]
  |  Branch (2781:40): [True: 0, False: 0]
  ------------------
 2782|      0|        loader_remove_layer_in_list(inst, instance_layers, global_layer_index);
 2783|      0|    }
 2784|       |    // Should be at most 1 override layer in the list now.
 2785|  4.84k|    if (found_active_override_layer) {
  ------------------
  |  Branch (2785:9): [True: 0, False: 4.84k]
  ------------------
 2786|      0|        loader_log(inst, VULKAN_LOADER_INFO_BIT | VULKAN_LOADER_LAYER_BIT, 0, "Using the override layer for app key %s", cur_path);
 2787|  4.84k|    } else if (global_layer_index >= 0) {
  ------------------
  |  Branch (2787:16): [True: 5, False: 4.84k]
  ------------------
 2788|      5|        loader_log(inst, VULKAN_LOADER_INFO_BIT | VULKAN_LOADER_LAYER_BIT, 0, "Using the global override layer");
 2789|      5|    }
 2790|  4.84k|}
loader_read_layer_json:
 2804|  5.38k|                                cJSON *layer_node, loader_api_version version, bool is_implicit, char *filename) {
 2805|  5.38k|    assert(layer_instance_list);
 2806|  5.38k|    char *library_path = NULL;
 2807|  5.38k|    VkResult result = VK_SUCCESS;
 2808|  5.38k|    struct loader_layer_properties props = {0};
 2809|       |
 2810|  5.38k|    result = loader_copy_to_new_str(inst, filename, &props.manifest_file_name);
 2811|  5.38k|    if (result == VK_ERROR_OUT_OF_HOST_MEMORY) {
  ------------------
  |  Branch (2811:9): [True: 0, False: 5.38k]
  ------------------
 2812|      0|        goto out;
 2813|      0|    }
 2814|       |
 2815|       |    // Parse name
 2816|       |
 2817|  5.38k|    result = loader_parse_json_string_to_existing_str(layer_node, "name", VK_MAX_EXTENSION_NAME_SIZE, props.info.layerName);
 2818|  5.38k|    if (VK_ERROR_INITIALIZATION_FAILED == result) {
  ------------------
  |  Branch (2818:9): [True: 2.76k, False: 2.61k]
  ------------------
 2819|  2.76k|        loader_log(inst, VULKAN_LOADER_WARN_BIT, 0,
 2820|  2.76k|                   "Layer located at %s didn't find required layer value \"name\" in manifest JSON file, skipping this layer",
 2821|  2.76k|                   filename);
 2822|  2.76k|        goto out;
 2823|  2.76k|    }
 2824|       |
 2825|       |    // Check if this layer's name matches the override layer name, set is_override to true if so.
 2826|  2.61k|    if (!strcmp(props.info.layerName, VK_OVERRIDE_LAYER_NAME)) {
  ------------------
  |  |  142|  2.61k|#define VK_OVERRIDE_LAYER_NAME "VK_LAYER_LUNARG_override"
  ------------------
  |  Branch (2826:9): [True: 223, False: 2.39k]
  ------------------
 2827|    223|        props.is_override = true;
 2828|    223|    }
 2829|       |
 2830|  2.61k|    if (0 != strncmp(props.info.layerName, "VK_LAYER_", 9)) {
  ------------------
  |  Branch (2830:9): [True: 2.11k, False: 499]
  ------------------
 2831|  2.11k|        loader_log(inst, VULKAN_LOADER_WARN_BIT, 0, "Layer name %s does not conform to naming standard (Policy #LLP_LAYER_3)",
 2832|  2.11k|                   props.info.layerName);
 2833|  2.11k|    }
 2834|       |
 2835|       |    // Parse type
 2836|  2.61k|    char *type = loader_cJSON_GetStringValue(loader_cJSON_GetObjectItem(layer_node, "type"));
 2837|  2.61k|    if (NULL == type) {
  ------------------
  |  Branch (2837:9): [True: 711, False: 1.90k]
  ------------------
 2838|    711|        loader_log(inst, VULKAN_LOADER_WARN_BIT, 0,
 2839|    711|                   "Layer located at %s didn't find required layer value \"type\" in manifest JSON file, skipping this layer",
 2840|    711|                   filename);
 2841|    711|        result = VK_ERROR_INITIALIZATION_FAILED;
 2842|    711|        goto out;
 2843|    711|    }
 2844|       |
 2845|       |    // Add list entry
 2846|  1.90k|    if (!strcmp(type, "DEVICE")) {
  ------------------
  |  Branch (2846:9): [True: 72, False: 1.83k]
  ------------------
 2847|     72|        loader_log(inst, VULKAN_LOADER_WARN_BIT | VULKAN_LOADER_LAYER_BIT, 0, "Device layers are deprecated. Skipping layer %s",
 2848|     72|                   props.info.layerName);
 2849|     72|        result = VK_ERROR_INITIALIZATION_FAILED;
 2850|     72|        goto out;
 2851|     72|    }
 2852|       |
 2853|       |    // Allow either GLOBAL or INSTANCE type interchangeably to handle layers that must work with older loaders
 2854|  1.83k|    if (!strcmp(type, "INSTANCE") || !strcmp(type, "GLOBAL")) {
  ------------------
  |  Branch (2854:9): [True: 227, False: 1.60k]
  |  Branch (2854:38): [True: 1.24k, False: 361]
  ------------------
 2855|  1.47k|        props.type_flags = VK_LAYER_TYPE_FLAG_INSTANCE_LAYER;
 2856|  1.47k|        if (!is_implicit) {
  ------------------
  |  Branch (2856:13): [True: 0, False: 1.47k]
  ------------------
 2857|      0|            props.type_flags |= VK_LAYER_TYPE_FLAG_EXPLICIT_LAYER;
 2858|      0|        }
 2859|  1.47k|    } else {
 2860|    361|        result = VK_ERROR_INITIALIZATION_FAILED;
 2861|    361|        goto out;
 2862|    361|    }
 2863|       |
 2864|       |    // Parse api_version
 2865|  1.47k|    char *api_version = loader_cJSON_GetStringValue(loader_cJSON_GetObjectItem(layer_node, "api_version"));
 2866|  1.47k|    if (NULL == api_version) {
  ------------------
  |  Branch (2866:9): [True: 374, False: 1.09k]
  ------------------
 2867|    374|        loader_log(
 2868|    374|            inst, VULKAN_LOADER_WARN_BIT, 0,
 2869|    374|            "Layer located at %s didn't find required layer value \"api_version\" in manifest JSON file, skipping this layer",
 2870|    374|            filename);
 2871|    374|        result = VK_ERROR_INITIALIZATION_FAILED;
 2872|    374|        goto out;
 2873|    374|    }
 2874|       |
 2875|  1.09k|    props.info.specVersion = loader_parse_version_string(api_version);
 2876|       |
 2877|       |    // Make sure the layer's manifest doesn't contain a non zero variant value
 2878|  1.09k|    if (VK_API_VERSION_VARIANT(props.info.specVersion) != 0) {
  ------------------
  |  Branch (2878:9): [True: 203, False: 895]
  ------------------
 2879|    203|        loader_log(inst, VULKAN_LOADER_INFO_BIT | VULKAN_LOADER_LAYER_BIT, 0,
 2880|    203|                   "Layer \"%s\" has an \'api_version\' field which contains a non-zero variant value of %d. "
 2881|    203|                   " Skipping Layer.",
 2882|    203|                   props.info.layerName, VK_API_VERSION_VARIANT(props.info.specVersion));
 2883|    203|        result = VK_ERROR_INITIALIZATION_FAILED;
 2884|    203|        goto out;
 2885|    203|    }
 2886|       |
 2887|       |    // Parse implementation_version
 2888|    895|    char *implementation_version = loader_cJSON_GetStringValue(loader_cJSON_GetObjectItem(layer_node, "implementation_version"));
 2889|    895|    if (NULL == implementation_version) {
  ------------------
  |  Branch (2889:9): [True: 188, False: 707]
  ------------------
 2890|    188|        loader_log(inst, VULKAN_LOADER_WARN_BIT, 0,
 2891|    188|                   "Layer located at %s didn't find required layer value \"implementation_version\" in manifest JSON file, "
 2892|    188|                   "skipping this layer",
 2893|    188|                   filename);
 2894|    188|        result = VK_ERROR_INITIALIZATION_FAILED;
 2895|    188|        goto out;
 2896|    188|    }
 2897|    707|    props.info.implementationVersion = (uint32_t)strtoul(implementation_version, NULL, 10);
 2898|       |
 2899|       |    // Parse description
 2900|       |
 2901|    707|    result = loader_parse_json_string_to_existing_str(layer_node, "description", VK_MAX_DESCRIPTION_SIZE, props.info.description);
 2902|    707|    if (VK_ERROR_INITIALIZATION_FAILED == result) {
  ------------------
  |  Branch (2902:9): [True: 84, False: 623]
  ------------------
 2903|     84|        loader_log(
 2904|     84|            inst, VULKAN_LOADER_WARN_BIT, 0,
 2905|     84|            "Layer located at %s didn't find required layer value \"description\" in manifest JSON file, skipping this layer",
 2906|     84|            filename);
 2907|     84|        goto out;
 2908|     84|    }
 2909|       |
 2910|       |    // Parse library_path
 2911|       |
 2912|       |    // Library path no longer required unless component_layers is also not defined
 2913|    623|    result = loader_parse_json_string(layer_node, "library_path", &library_path);
 2914|    623|    if (result == VK_ERROR_OUT_OF_HOST_MEMORY) {
  ------------------
  |  Branch (2914:9): [True: 0, False: 623]
  ------------------
 2915|      0|        loader_log(inst, VULKAN_LOADER_WARN_BIT, 0,
 2916|      0|                   "Skipping layer \"%s\" due to problem accessing the library_path value in the manifest JSON file",
 2917|      0|                   props.info.layerName);
 2918|      0|        result = VK_ERROR_OUT_OF_HOST_MEMORY;
 2919|      0|        goto out;
 2920|      0|    }
 2921|    623|    if (NULL != library_path) {
  ------------------
  |  Branch (2921:9): [True: 368, False: 255]
  ------------------
 2922|    368|        if (NULL != loader_cJSON_GetObjectItem(layer_node, "component_layers")) {
  ------------------
  |  Branch (2922:13): [True: 2, False: 366]
  ------------------
 2923|      2|            loader_log(
 2924|      2|                inst, VULKAN_LOADER_WARN_BIT, 0,
 2925|      2|                "Layer \"%s\" contains meta-layer-specific component_layers, but also defining layer library path.  Both are not "
 2926|      2|                "compatible, so skipping this layer",
 2927|      2|                props.info.layerName);
 2928|      2|            result = VK_ERROR_INITIALIZATION_FAILED;
 2929|      2|            loader_instance_heap_free(inst, library_path);
 2930|      2|            goto out;
 2931|      2|        }
 2932|       |
 2933|       |        // This function takes ownership of library_path_str - so we don't need to clean it up
 2934|    366|        result = combine_manifest_directory_and_library_path(inst, library_path, filename, &props.lib_name);
 2935|    366|        if (result == VK_ERROR_OUT_OF_HOST_MEMORY) goto out;
  ------------------
  |  Branch (2935:13): [True: 0, False: 366]
  ------------------
 2936|    366|    }
 2937|       |
 2938|       |    // Parse component_layers
 2939|       |
 2940|    621|    if (NULL == library_path) {
  ------------------
  |  Branch (2940:9): [True: 255, False: 366]
  ------------------
 2941|    255|        if (!loader_check_version_meets_required(LOADER_VERSION_1_1_0, version)) {
  ------------------
  |  |  271|    255|#define LOADER_VERSION_1_1_0 loader_combine_version(1, 1, 0)
  ------------------
  |  Branch (2941:13): [True: 76, False: 179]
  ------------------
 2942|     76|            loader_log(inst, VULKAN_LOADER_WARN_BIT, 0,
 2943|     76|                       "Layer \"%s\" contains meta-layer-specific component_layers, but using older JSON file version.",
 2944|     76|                       props.info.layerName);
 2945|     76|        }
 2946|       |
 2947|    255|        result = loader_parse_json_array_of_strings(inst, layer_node, "component_layers", &(props.component_layer_names));
 2948|    255|        if (VK_ERROR_OUT_OF_HOST_MEMORY == result) {
  ------------------
  |  Branch (2948:13): [True: 0, False: 255]
  ------------------
 2949|      0|            goto out;
 2950|      0|        }
 2951|    255|        if (VK_ERROR_INITIALIZATION_FAILED == result) {
  ------------------
  |  Branch (2951:13): [True: 224, False: 31]
  ------------------
 2952|    224|            loader_log(inst, VULKAN_LOADER_WARN_BIT, 0,
 2953|    224|                       "Layer \"%s\" is missing both library_path and component_layers fields.  One or the other MUST be defined.  "
 2954|    224|                       "Skipping this layer",
 2955|    224|                       props.info.layerName);
 2956|    224|            goto out;
 2957|    224|        }
 2958|       |        // This is now, officially, a meta-layer
 2959|     31|        props.type_flags |= VK_LAYER_TYPE_FLAG_META_LAYER;
 2960|     31|        loader_log(inst, VULKAN_LOADER_INFO_BIT | VULKAN_LOADER_LAYER_BIT, 0, "Encountered meta-layer \"%s\"",
 2961|     31|                   props.info.layerName);
 2962|     31|    }
 2963|       |
 2964|       |    // Parse blacklisted_layers
 2965|       |
 2966|    397|    if (props.is_override) {
  ------------------
  |  Branch (2966:9): [True: 131, False: 266]
  ------------------
 2967|    131|        result = loader_parse_json_array_of_strings(inst, layer_node, "blacklisted_layers", &(props.blacklist_layer_names));
 2968|    131|        if (VK_ERROR_OUT_OF_HOST_MEMORY == result) {
  ------------------
  |  Branch (2968:13): [True: 0, False: 131]
  ------------------
 2969|      0|            goto out;
 2970|      0|        }
 2971|    131|    }
 2972|       |
 2973|       |    // Parse override_paths
 2974|       |
 2975|    397|    result = loader_parse_json_array_of_strings(inst, layer_node, "override_paths", &(props.override_paths));
 2976|    397|    if (VK_ERROR_OUT_OF_HOST_MEMORY == result) {
  ------------------
  |  Branch (2976:9): [True: 0, False: 397]
  ------------------
 2977|      0|        goto out;
 2978|      0|    }
 2979|    397|    if (NULL != props.override_paths.list && !loader_check_version_meets_required(loader_combine_version(1, 1, 0), version)) {
  ------------------
  |  Branch (2979:9): [True: 11, False: 386]
  |  Branch (2979:46): [True: 9, False: 2]
  ------------------
 2980|      9|        loader_log(inst, VULKAN_LOADER_WARN_BIT, 0,
 2981|      9|                   "Layer \"%s\" contains meta-layer-specific override paths, but using older JSON file version.",
 2982|      9|                   props.info.layerName);
 2983|      9|    }
 2984|       |
 2985|       |    // Parse disable_environment
 2986|       |
 2987|    397|    if (is_implicit) {
  ------------------
  |  Branch (2987:9): [True: 397, False: 0]
  ------------------
 2988|    397|        cJSON *disable_environment = loader_cJSON_GetObjectItem(layer_node, "disable_environment");
 2989|    397|        if (disable_environment == NULL) {
  ------------------
  |  Branch (2989:13): [True: 354, False: 43]
  ------------------
 2990|    354|            loader_log(inst, VULKAN_LOADER_WARN_BIT, 0,
 2991|    354|                       "Layer \"%s\" doesn't contain required layer object disable_environment in the manifest JSON file, skipping "
 2992|    354|                       "this layer",
 2993|    354|                       props.info.layerName);
 2994|    354|            result = VK_ERROR_INITIALIZATION_FAILED;
 2995|    354|            goto out;
 2996|    354|        }
 2997|       |
 2998|     43|        if (!disable_environment->child || disable_environment->child->type != cJSON_String ||
  ------------------
  |  |  101|     86|#define cJSON_String (1 << 4)
  ------------------
  |  Branch (2998:13): [True: 0, False: 43]
  |  Branch (2998:44): [True: 0, False: 43]
  ------------------
 2999|     43|            !disable_environment->child->string || !disable_environment->child->valuestring) {
  ------------------
  |  Branch (2999:13): [True: 0, False: 43]
  |  Branch (2999:52): [True: 0, False: 43]
  ------------------
 3000|      0|            loader_log(inst, VULKAN_LOADER_WARN_BIT, 0,
 3001|      0|                       "Layer \"%s\" doesn't contain required child value in object disable_environment in the manifest JSON file, "
 3002|      0|                       "skipping this layer (Policy #LLP_LAYER_9)",
 3003|      0|                       props.info.layerName);
 3004|      0|            result = VK_ERROR_INITIALIZATION_FAILED;
 3005|      0|            goto out;
 3006|      0|        }
 3007|     43|        result = loader_copy_to_new_str(inst, disable_environment->child->string, &(props.disable_env_var.name));
 3008|     43|        if (VK_SUCCESS != result) goto out;
  ------------------
  |  Branch (3008:13): [True: 0, False: 43]
  ------------------
 3009|     43|        result = loader_copy_to_new_str(inst, disable_environment->child->valuestring, &(props.disable_env_var.value));
 3010|     43|        if (VK_SUCCESS != result) goto out;
  ------------------
  |  Branch (3010:13): [True: 0, False: 43]
  ------------------
 3011|     43|    }
 3012|       |
 3013|       |    // Now get all optional items and objects and put in list:
 3014|       |    // functions
 3015|       |    // instance_extensions
 3016|       |    // device_extensions
 3017|       |    // enable_environment (implicit layers only)
 3018|       |    // library_arch
 3019|       |
 3020|       |    // Layer interface functions
 3021|       |    //    vkGetInstanceProcAddr
 3022|       |    //    vkGetDeviceProcAddr
 3023|       |    //    vkNegotiateLoaderLayerInterfaceVersion (starting with JSON file 1.1.0)
 3024|     43|    cJSON *functions = loader_cJSON_GetObjectItem(layer_node, "functions");
 3025|     43|    if (functions != NULL) {
  ------------------
  |  Branch (3025:9): [True: 4, False: 39]
  ------------------
 3026|      4|        if (loader_check_version_meets_required(loader_combine_version(1, 1, 0), version)) {
  ------------------
  |  Branch (3026:13): [True: 4, False: 0]
  ------------------
 3027|      4|            result = loader_parse_json_string(functions, "vkNegotiateLoaderLayerInterfaceVersion",
 3028|      4|                                              &props.functions.str_negotiate_interface);
 3029|      4|            if (result == VK_ERROR_OUT_OF_HOST_MEMORY) goto out;
  ------------------
  |  Branch (3029:17): [True: 0, False: 4]
  ------------------
 3030|      4|        }
 3031|      4|        result = loader_parse_json_string(functions, "vkGetInstanceProcAddr", &props.functions.str_gipa);
 3032|      4|        if (result == VK_ERROR_OUT_OF_HOST_MEMORY) goto out;
  ------------------
  |  Branch (3032:13): [True: 0, False: 4]
  ------------------
 3033|       |
 3034|      4|        if (NULL == props.functions.str_negotiate_interface && props.functions.str_gipa &&
  ------------------
  |  Branch (3034:13): [True: 4, False: 0]
  |  Branch (3034:64): [True: 0, False: 4]
  ------------------
 3035|      0|            loader_check_version_meets_required(loader_combine_version(1, 1, 0), version)) {
  ------------------
  |  Branch (3035:13): [True: 0, False: 0]
  ------------------
 3036|      0|            loader_log(inst, VULKAN_LOADER_INFO_BIT, 0,
 3037|      0|                       "Layer \"%s\" using deprecated \'vkGetInstanceProcAddr\' tag which was deprecated starting with JSON "
 3038|      0|                       "file version 1.1.0. The new vkNegotiateLoaderLayerInterfaceVersion function is preferred, though for "
 3039|      0|                       "compatibility reasons it may be desirable to continue using the deprecated tag.",
 3040|      0|                       props.info.layerName);
 3041|      0|        }
 3042|       |
 3043|      4|        result = loader_parse_json_string(functions, "vkGetDeviceProcAddr", &props.functions.str_gdpa);
 3044|      4|        if (result == VK_ERROR_OUT_OF_HOST_MEMORY) goto out;
  ------------------
  |  Branch (3044:13): [True: 0, False: 4]
  ------------------
 3045|       |
 3046|      4|        if (NULL == props.functions.str_negotiate_interface && props.functions.str_gdpa &&
  ------------------
  |  Branch (3046:13): [True: 4, False: 0]
  |  Branch (3046:64): [True: 0, False: 4]
  ------------------
 3047|      0|            loader_check_version_meets_required(loader_combine_version(1, 1, 0), version)) {
  ------------------
  |  Branch (3047:13): [True: 0, False: 0]
  ------------------
 3048|      0|            loader_log(inst, VULKAN_LOADER_INFO_BIT, 0,
 3049|      0|                       "Layer \"%s\" using deprecated \'vkGetDeviceProcAddr\' tag which was deprecated starting with JSON "
 3050|      0|                       "file version 1.1.0. The new vkNegotiateLoaderLayerInterfaceVersion function is preferred, though for "
 3051|      0|                       "compatibility reasons it may be desirable to continue using the deprecated tag.",
 3052|      0|                       props.info.layerName);
 3053|      0|        }
 3054|      4|    }
 3055|       |
 3056|       |    // instance_extensions
 3057|       |    //   array of {
 3058|       |    //     name
 3059|       |    //     spec_version
 3060|       |    //   }
 3061|       |
 3062|     43|    cJSON *instance_extensions = loader_cJSON_GetObjectItem(layer_node, "instance_extensions");
 3063|     43|    if (instance_extensions != NULL && instance_extensions->type == cJSON_Array) {
  ------------------
  |  |  102|      7|#define cJSON_Array (1 << 5)
  ------------------
  |  Branch (3063:9): [True: 7, False: 36]
  |  Branch (3063:40): [True: 7, False: 0]
  ------------------
 3064|      7|        cJSON *ext_item = NULL;
 3065|      9|        cJSON_ArrayForEach(ext_item, instance_extensions) {
  ------------------
  |  |  213|     16|    for (element = (array != NULL) ? (array)->child : NULL; element != NULL; element = element->next)
  |  |  ------------------
  |  |  |  Branch (213:20): [True: 7, False: 0]
  |  |  |  Branch (213:61): [True: 9, False: 7]
  |  |  ------------------
  ------------------
 3066|      9|            if (ext_item->type != cJSON_Object) {
  ------------------
  |  |  103|      9|#define cJSON_Object (1 << 6)
  ------------------
  |  Branch (3066:17): [True: 3, False: 6]
  ------------------
 3067|      3|                continue;
 3068|      3|            }
 3069|       |
 3070|      6|            VkExtensionProperties ext_prop = {0};
 3071|      6|            result = loader_parse_json_string_to_existing_str(ext_item, "name", VK_MAX_EXTENSION_NAME_SIZE, ext_prop.extensionName);
 3072|      6|            if (result == VK_ERROR_INITIALIZATION_FAILED) {
  ------------------
  |  Branch (3072:17): [True: 2, False: 4]
  ------------------
 3073|      2|                continue;
 3074|      2|            }
 3075|      4|            char *spec_version = NULL;
 3076|      4|            result = loader_parse_json_string(ext_item, "spec_version", &spec_version);
 3077|      4|            if (result == VK_ERROR_OUT_OF_HOST_MEMORY) goto out;
  ------------------
  |  Branch (3077:17): [True: 0, False: 4]
  ------------------
 3078|      4|            if (NULL != spec_version) {
  ------------------
  |  Branch (3078:17): [True: 0, False: 4]
  ------------------
 3079|      0|                ext_prop.specVersion = (uint32_t)strtoul(spec_version, NULL, 10);
 3080|      0|            }
 3081|      4|            loader_instance_heap_free(inst, spec_version);
 3082|      4|            bool ext_unsupported = wsi_unsupported_instance_extension(&ext_prop);
 3083|      4|            if (!ext_unsupported) {
  ------------------
  |  Branch (3083:17): [True: 4, False: 0]
  ------------------
 3084|      4|                result = loader_add_to_ext_list(inst, &props.instance_extension_list, 1, &ext_prop);
 3085|      4|                if (result == VK_ERROR_OUT_OF_HOST_MEMORY) goto out;
  ------------------
  |  Branch (3085:21): [True: 0, False: 4]
  ------------------
 3086|      4|            }
 3087|      4|        }
 3088|      7|    }
 3089|       |
 3090|       |    // device_extensions
 3091|       |    //   array of {
 3092|       |    //     name
 3093|       |    //     spec_version
 3094|       |    //     entrypoints
 3095|       |    //   }
 3096|     43|    cJSON *device_extensions = loader_cJSON_GetObjectItem(layer_node, "device_extensions");
 3097|     43|    if (device_extensions != NULL && device_extensions->type == cJSON_Array) {
  ------------------
  |  |  102|      0|#define cJSON_Array (1 << 5)
  ------------------
  |  Branch (3097:9): [True: 0, False: 43]
  |  Branch (3097:38): [True: 0, False: 0]
  ------------------
 3098|      0|        cJSON *ext_item = NULL;
 3099|      0|        cJSON_ArrayForEach(ext_item, device_extensions) {
  ------------------
  |  |  213|      0|    for (element = (array != NULL) ? (array)->child : NULL; element != NULL; element = element->next)
  |  |  ------------------
  |  |  |  Branch (213:20): [True: 0, False: 0]
  |  |  |  Branch (213:61): [True: 0, False: 0]
  |  |  ------------------
  ------------------
 3100|      0|            if (ext_item->type != cJSON_Object) {
  ------------------
  |  |  103|      0|#define cJSON_Object (1 << 6)
  ------------------
  |  Branch (3100:17): [True: 0, False: 0]
  ------------------
 3101|      0|                continue;
 3102|      0|            }
 3103|       |
 3104|      0|            VkExtensionProperties ext_prop = {0};
 3105|      0|            result = loader_parse_json_string_to_existing_str(ext_item, "name", VK_MAX_EXTENSION_NAME_SIZE, ext_prop.extensionName);
 3106|      0|            if (result == VK_ERROR_INITIALIZATION_FAILED) {
  ------------------
  |  Branch (3106:17): [True: 0, False: 0]
  ------------------
 3107|      0|                continue;
 3108|      0|            }
 3109|       |
 3110|      0|            char *spec_version = NULL;
 3111|      0|            result = loader_parse_json_string(ext_item, "spec_version", &spec_version);
 3112|      0|            if (result == VK_ERROR_OUT_OF_HOST_MEMORY) goto out;
  ------------------
  |  Branch (3112:17): [True: 0, False: 0]
  ------------------
 3113|      0|            if (NULL != spec_version) {
  ------------------
  |  Branch (3113:17): [True: 0, False: 0]
  ------------------
 3114|      0|                ext_prop.specVersion = (uint32_t)strtoul(spec_version, NULL, 10);
 3115|      0|            }
 3116|      0|            loader_instance_heap_free(inst, spec_version);
 3117|       |
 3118|      0|            cJSON *entrypoints = loader_cJSON_GetObjectItem(ext_item, "entrypoints");
 3119|      0|            if (entrypoints == NULL) {
  ------------------
  |  Branch (3119:17): [True: 0, False: 0]
  ------------------
 3120|      0|                result = loader_add_to_dev_ext_list(inst, &props.device_extension_list, &ext_prop, NULL);
 3121|      0|                if (result == VK_ERROR_OUT_OF_HOST_MEMORY) goto out;
  ------------------
  |  Branch (3121:21): [True: 0, False: 0]
  ------------------
 3122|      0|                continue;
 3123|      0|            }
 3124|       |
 3125|      0|            struct loader_string_list entrys = {0};
 3126|      0|            result = loader_parse_json_array_of_strings(inst, ext_item, "entrypoints", &entrys);
 3127|      0|            if (result == VK_ERROR_OUT_OF_HOST_MEMORY) goto out;
  ------------------
  |  Branch (3127:17): [True: 0, False: 0]
  ------------------
 3128|      0|            result = loader_add_to_dev_ext_list(inst, &props.device_extension_list, &ext_prop, &entrys);
 3129|      0|            if (result == VK_ERROR_OUT_OF_HOST_MEMORY) goto out;
  ------------------
  |  Branch (3129:17): [True: 0, False: 0]
  ------------------
 3130|      0|        }
 3131|      0|    }
 3132|     43|    if (is_implicit) {
  ------------------
  |  Branch (3132:9): [True: 43, False: 0]
  ------------------
 3133|     43|        cJSON *enable_environment = loader_cJSON_GetObjectItem(layer_node, "enable_environment");
 3134|       |
 3135|       |        // enable_environment is optional
 3136|     43|        if (enable_environment && enable_environment->child && enable_environment->child->type == cJSON_String &&
  ------------------
  |  |  101|     55|#define cJSON_String (1 << 4)
  ------------------
  |  Branch (3136:13): [True: 12, False: 31]
  |  Branch (3136:35): [True: 12, False: 0]
  |  Branch (3136:64): [True: 12, False: 0]
  ------------------
 3137|     12|            enable_environment->child->string && enable_environment->child->valuestring) {
  ------------------
  |  Branch (3137:13): [True: 12, False: 0]
  |  Branch (3137:50): [True: 12, False: 0]
  ------------------
 3138|     12|            result = loader_copy_to_new_str(inst, enable_environment->child->string, &(props.enable_env_var.name));
 3139|     12|            if (VK_SUCCESS != result) goto out;
  ------------------
  |  Branch (3139:17): [True: 0, False: 12]
  ------------------
 3140|     12|            result = loader_copy_to_new_str(inst, enable_environment->child->valuestring, &(props.enable_env_var.value));
 3141|     12|            if (VK_SUCCESS != result) goto out;
  ------------------
  |  Branch (3141:17): [True: 0, False: 12]
  ------------------
 3142|     12|        }
 3143|     43|    }
 3144|       |
 3145|       |    // Read in the pre-instance stuff
 3146|     43|    cJSON *pre_instance = loader_cJSON_GetObjectItem(layer_node, "pre_instance_functions");
 3147|     43|    if (NULL != pre_instance) {
  ------------------
  |  Branch (3147:9): [True: 1, False: 42]
  ------------------
 3148|       |        // Supported versions started in 1.1.2, so anything newer
 3149|      1|        if (!loader_check_version_meets_required(loader_combine_version(1, 1, 2), version)) {
  ------------------
  |  Branch (3149:13): [True: 1, False: 0]
  ------------------
 3150|      1|            loader_log(inst, VULKAN_LOADER_ERROR_BIT, 0,
 3151|      1|                       "Found pre_instance_functions section in layer from \"%s\". This section is only valid in manifest version "
 3152|      1|                       "1.1.2 or later. The section will be ignored",
 3153|      1|                       filename);
 3154|      1|        } else if (!is_implicit) {
  ------------------
  |  Branch (3154:20): [True: 0, False: 0]
  ------------------
 3155|      0|            loader_log(inst, VULKAN_LOADER_WARN_BIT, 0,
 3156|      0|                       "Found pre_instance_functions section in explicit layer from \"%s\". This section is only valid in implicit "
 3157|      0|                       "layers. The section will be ignored",
 3158|      0|                       filename);
 3159|      0|        } else {
 3160|      0|            result = loader_parse_json_string(pre_instance, "vkEnumerateInstanceExtensionProperties",
 3161|      0|                                              &props.pre_instance_functions.enumerate_instance_extension_properties);
 3162|      0|            if (result == VK_ERROR_OUT_OF_HOST_MEMORY) goto out;
  ------------------
  |  Branch (3162:17): [True: 0, False: 0]
  ------------------
 3163|       |
 3164|      0|            result = loader_parse_json_string(pre_instance, "vkEnumerateInstanceLayerProperties",
 3165|      0|                                              &props.pre_instance_functions.enumerate_instance_layer_properties);
 3166|      0|            if (result == VK_ERROR_OUT_OF_HOST_MEMORY) goto out;
  ------------------
  |  Branch (3166:17): [True: 0, False: 0]
  ------------------
 3167|       |
 3168|      0|            result = loader_parse_json_string(pre_instance, "vkEnumerateInstanceVersion",
 3169|      0|                                              &props.pre_instance_functions.enumerate_instance_version);
 3170|      0|            if (result == VK_ERROR_OUT_OF_HOST_MEMORY) goto out;
  ------------------
  |  Branch (3170:17): [True: 0, False: 0]
  ------------------
 3171|      0|        }
 3172|      1|    }
 3173|       |
 3174|     43|    if (loader_cJSON_GetObjectItem(layer_node, "app_keys")) {
  ------------------
  |  Branch (3174:9): [True: 7, False: 36]
  ------------------
 3175|      7|        if (!props.is_override) {
  ------------------
  |  Branch (3175:13): [True: 2, False: 5]
  ------------------
 3176|      2|            loader_log(inst, VULKAN_LOADER_WARN_BIT | VULKAN_LOADER_LAYER_BIT, 0,
 3177|      2|                       "Layer %s contains app_keys, but any app_keys can only be provided by the override meta layer. "
 3178|      2|                       "These will be ignored.",
 3179|      2|                       props.info.layerName);
 3180|      2|        }
 3181|       |
 3182|      7|        result = loader_parse_json_array_of_strings(inst, layer_node, "app_keys", &props.app_key_paths);
 3183|      7|        if (result == VK_ERROR_OUT_OF_HOST_MEMORY) goto out;
  ------------------
  |  Branch (3183:13): [True: 0, False: 7]
  ------------------
 3184|      7|    }
 3185|       |
 3186|     43|    char *library_arch = loader_cJSON_GetStringValue(loader_cJSON_GetObjectItem(layer_node, "library_arch"));
 3187|     43|    if (NULL != library_arch) {
  ------------------
  |  Branch (3187:9): [True: 1, False: 42]
  ------------------
 3188|      1|        if ((strncmp(library_arch, "32", 2) == 0 && sizeof(void *) != 4) ||
  ------------------
  |  Branch (3188:14): [True: 0, False: 1]
  |  Branch (3188:53): [True: 0, Folded]
  ------------------
 3189|      1|            (strncmp(library_arch, "64", 2) == 0 && sizeof(void *) != 8)) {
  ------------------
  |  Branch (3189:14): [True: 0, False: 1]
  |  Branch (3189:53): [Folded, False: 0]
  ------------------
 3190|      0|            loader_log(inst, VULKAN_LOADER_INFO_BIT, 0,
 3191|      0|                       "The library architecture in layer %s doesn't match the current running architecture, skipping this layer",
 3192|      0|                       filename);
 3193|      0|            result = VK_ERROR_INITIALIZATION_FAILED;
 3194|      0|            goto out;
 3195|      0|        }
 3196|      1|    }
 3197|       |
 3198|     43|    result = VK_SUCCESS;
 3199|       |
 3200|  5.38k|out:
 3201|       |    // Try to append the layer property
 3202|  5.38k|    if (VK_SUCCESS == result) {
  ------------------
  |  Branch (3202:9): [True: 43, False: 5.34k]
  ------------------
 3203|     43|        result = loader_append_layer_property(inst, layer_instance_list, &props);
 3204|     43|    }
 3205|       |    // If appending fails - free all the memory allocated in it
 3206|  5.38k|    if (VK_SUCCESS != result) {
  ------------------
  |  Branch (3206:9): [True: 5.34k, False: 43]
  ------------------
 3207|  5.34k|        loader_free_layer_properties(inst, &props);
 3208|  5.34k|    }
 3209|  5.38k|    return result;
 3210|     43|}
is_valid_layer_json_version:
 3212|    958|bool is_valid_layer_json_version(const loader_api_version *layer_json) {
 3213|       |    // Supported versions are: 1.0.0, 1.0.1, 1.1.0 - 1.1.2, and 1.2.0 - 1.2.1.
 3214|    958|    if ((layer_json->major == 1 && layer_json->minor == 2 && layer_json->patch < 2) ||
  ------------------
  |  Branch (3214:10): [True: 141, False: 817]
  |  Branch (3214:36): [True: 26, False: 115]
  |  Branch (3214:62): [True: 10, False: 16]
  ------------------
 3215|    948|        (layer_json->major == 1 && layer_json->minor == 1 && layer_json->patch < 3) ||
  ------------------
  |  Branch (3215:10): [True: 131, False: 817]
  |  Branch (3215:36): [True: 17, False: 114]
  |  Branch (3215:62): [True: 10, False: 7]
  ------------------
 3216|    938|        (layer_json->major == 1 && layer_json->minor == 0 && layer_json->patch < 2)) {
  ------------------
  |  Branch (3216:10): [True: 121, False: 817]
  |  Branch (3216:36): [True: 64, False: 57]
  |  Branch (3216:62): [True: 39, False: 25]
  ------------------
 3217|     59|        return true;
 3218|     59|    }
 3219|    899|    return false;
 3220|    958|}
loader_add_layer_properties:
 3232|  1.50k|                                     bool is_implicit, char *filename) {
 3233|       |    // The following Fields in layer manifest file that are required:
 3234|       |    //   - "file_format_version"
 3235|       |    //   - If more than one "layer" object are used, then the "layers" array is
 3236|       |    //     required
 3237|  1.50k|    VkResult result = VK_ERROR_INITIALIZATION_FAILED;
 3238|       |    // Make sure sure the top level json value is an object
 3239|  1.50k|    if (!json || json->type != cJSON_Object) {
  ------------------
  |  |  103|  1.50k|#define cJSON_Object (1 << 6)
  ------------------
  |  Branch (3239:9): [True: 0, False: 1.50k]
  |  Branch (3239:18): [True: 527, False: 981]
  ------------------
 3240|    527|        goto out;
 3241|    527|    }
 3242|    981|    char *file_vers = loader_cJSON_GetStringValue(loader_cJSON_GetObjectItem(json, "file_format_version"));
 3243|    981|    if (NULL == file_vers) {
  ------------------
  |  Branch (3243:9): [True: 23, False: 958]
  ------------------
 3244|     23|        loader_log(inst, VULKAN_LOADER_WARN_BIT | VULKAN_LOADER_LAYER_BIT, 0,
 3245|     23|                   "loader_add_layer_properties: Manifest %s missing required field file_format_version", filename);
 3246|     23|        goto out;
 3247|     23|    }
 3248|       |
 3249|    958|    loader_log(inst, VULKAN_LOADER_INFO_BIT, 0, "Found manifest file %s (file version %s)", filename, file_vers);
 3250|       |    // Get the major/minor/and patch as integers for easier comparison
 3251|    958|    loader_api_version json_version = loader_make_full_version(loader_parse_version_string(file_vers));
 3252|       |
 3253|    958|    if (!is_valid_layer_json_version(&json_version)) {
  ------------------
  |  Branch (3253:9): [True: 899, False: 59]
  ------------------
 3254|    899|        loader_log(inst, VULKAN_LOADER_INFO_BIT | VULKAN_LOADER_LAYER_BIT, 0,
 3255|    899|                   "loader_add_layer_properties: %s has unknown layer manifest file version %d.%d.%d.  May cause errors.", filename,
 3256|    899|                   json_version.major, json_version.minor, json_version.patch);
 3257|    899|    }
 3258|       |
 3259|       |    // If "layers" is present, read in the array of layer objects
 3260|    958|    cJSON *layers_node = loader_cJSON_GetObjectItem(json, "layers");
 3261|    958|    if (layers_node != NULL) {
  ------------------
  |  Branch (3261:9): [True: 319, False: 639]
  ------------------
 3262|       |        // Supported versions started in 1.0.1, so anything newer
 3263|    319|        if (!loader_check_version_meets_required(loader_combine_version(1, 0, 1), json_version)) {
  ------------------
  |  Branch (3263:13): [True: 216, False: 103]
  ------------------
 3264|    216|            loader_log(inst, VULKAN_LOADER_WARN_BIT | VULKAN_LOADER_LAYER_BIT, 0,
 3265|    216|                       "loader_add_layer_properties: \'layers\' tag not supported until file version 1.0.1, but %s is reporting "
 3266|    216|                       "version %s",
 3267|    216|                       filename, file_vers);
 3268|    216|        }
 3269|    319|        cJSON *layer_node = NULL;
 3270|    883|        cJSON_ArrayForEach(layer_node, layers_node) {
  ------------------
  |  |  213|  1.19k|    for (element = (array != NULL) ? (array)->child : NULL; element != NULL; element = element->next)
  |  |  ------------------
  |  |  |  Branch (213:20): [True: 319, False: 0]
  |  |  |  Branch (213:61): [True: 883, False: 314]
  |  |  ------------------
  ------------------
 3271|    883|            if (layer_node->type != cJSON_Object) {
  ------------------
  |  |  103|    883|#define cJSON_Object (1 << 6)
  ------------------
  |  Branch (3271:17): [True: 5, False: 878]
  ------------------
 3272|      5|                loader_log(
 3273|      5|                    inst, VULKAN_LOADER_WARN_BIT | VULKAN_LOADER_LAYER_BIT, 0,
 3274|      5|                    "loader_add_layer_properties: Array element in \"layers\" field in manifest JSON file %s is not an object.  "
 3275|      5|                    "Skipping this file",
 3276|      5|                    filename);
 3277|      5|                goto out;
 3278|      5|            }
 3279|    878|            result = loader_read_layer_json(inst, layer_instance_list, layer_node, json_version, is_implicit, filename);
 3280|    878|        }
 3281|    639|    } else {
 3282|       |        // Otherwise, try to read in individual layers
 3283|    639|        cJSON *layer_node = loader_cJSON_GetObjectItem(json, "layer");
 3284|    639|        if (layer_node == NULL) {
  ------------------
  |  Branch (3284:13): [True: 348, False: 291]
  ------------------
 3285|       |            // Don't warn if this happens to be an ICD manifest
 3286|    348|            if (loader_cJSON_GetObjectItem(json, "ICD") == NULL) {
  ------------------
  |  Branch (3286:17): [True: 348, False: 0]
  ------------------
 3287|    348|                loader_log(
 3288|    348|                    inst, VULKAN_LOADER_WARN_BIT | VULKAN_LOADER_LAYER_BIT, 0,
 3289|    348|                    "loader_add_layer_properties: Can not find 'layer' object in manifest JSON file %s.  Skipping this file.",
 3290|    348|                    filename);
 3291|    348|            }
 3292|    348|            goto out;
 3293|    348|        }
 3294|       |        // Loop through all "layer" objects in the file to get a count of them
 3295|       |        // first.
 3296|    291|        uint16_t layer_count = 0;
 3297|    291|        cJSON *tempNode = layer_node;
 3298|  4.56k|        do {
 3299|  4.56k|            tempNode = tempNode->next;
 3300|  4.56k|            layer_count++;
 3301|  4.56k|        } while (tempNode != NULL);
  ------------------
  |  Branch (3301:18): [True: 4.27k, False: 291]
  ------------------
 3302|       |
 3303|       |        // Throw a warning if we encounter multiple "layer" objects in file
 3304|       |        // versions newer than 1.0.0.  Having multiple objects with the same
 3305|       |        // name at the same level is actually a JSON standard violation.
 3306|    291|        if (layer_count > 1 && loader_check_version_meets_required(loader_combine_version(1, 0, 1), json_version)) {
  ------------------
  |  Branch (3306:13): [True: 263, False: 28]
  |  Branch (3306:32): [True: 25, False: 238]
  ------------------
 3307|     25|            loader_log(inst, VULKAN_LOADER_ERROR_BIT | VULKAN_LOADER_LAYER_BIT, 0,
 3308|     25|                       "loader_add_layer_properties: Multiple 'layer' nodes are deprecated starting in file version \"1.0.1\".  "
 3309|     25|                       "Please use 'layers' : [] array instead in %s.",
 3310|     25|                       filename);
 3311|    266|        } else {
 3312|  4.50k|            do {
 3313|  4.50k|                result = loader_read_layer_json(inst, layer_instance_list, layer_node, json_version, is_implicit, filename);
 3314|  4.50k|                layer_node = layer_node->next;
 3315|  4.50k|            } while (layer_node != NULL);
  ------------------
  |  Branch (3315:22): [True: 4.24k, False: 266]
  ------------------
 3316|    266|        }
 3317|    291|    }
 3318|       |
 3319|  1.50k|out:
 3320|       |
 3321|  1.50k|    return result;
 3322|    958|}
copy_data_file_info:
 3326|  43.6k|                             size_t relative_path_size, struct loader_string_list *search_paths) {
 3327|  43.6k|    if (NULL != cur_path) {
  ------------------
  |  Branch (3327:9): [True: 43.6k, False: 0]
  ------------------
 3328|  43.6k|        uint32_t start = 0;
 3329|  43.6k|        uint32_t stop = 0;
 3330|       |
 3331|  94.5k|        while (cur_path[start] != '\0') {
  ------------------
  |  Branch (3331:16): [True: 50.9k, False: 43.6k]
  ------------------
 3332|  58.2k|            while (cur_path[start] == PATH_SEPARATOR && cur_path[start] != '\0') {
  ------------------
  |  |  154|   116k|#define PATH_SEPARATOR ':'
  ------------------
  |  Branch (3332:20): [True: 7.27k, False: 50.9k]
  |  Branch (3332:57): [True: 7.27k, False: 0]
  ------------------
 3333|  7.27k|                start++;
 3334|  7.27k|            }
 3335|  50.9k|            stop = start;
 3336|   640k|            while (cur_path[stop] != PATH_SEPARATOR && cur_path[stop] != '\0') {
  ------------------
  |  |  154|  1.28M|#define PATH_SEPARATOR ':'
  ------------------
  |  Branch (3336:20): [True: 632k, False: 7.27k]
  |  Branch (3336:56): [True: 589k, False: 43.6k]
  ------------------
 3337|   589k|                stop++;
 3338|   589k|            }
 3339|  50.9k|            const size_t s = stop - start;
 3340|  50.9k|            if (s) {
  ------------------
  |  Branch (3340:17): [True: 50.9k, False: 3]
  ------------------
 3341|       |                // space enough for base path, relative path, path separator, and null terminator
 3342|  50.9k|                size_t new_str_len = s + relative_path_size + 2;
 3343|       |
 3344|  50.9k|                char *new_str = loader_instance_heap_calloc(inst, new_str_len, VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE);
 3345|  50.9k|                if (NULL == new_str) {
  ------------------
  |  Branch (3345:21): [True: 0, False: 50.9k]
  ------------------
 3346|      0|                    return VK_ERROR_OUT_OF_HOST_MEMORY;
 3347|      0|                }
 3348|  50.9k|                memcpy(new_str, &cur_path[start], s);
 3349|  50.9k|                new_str[s] = '\0';
 3350|       |
 3351|       |                // If this is a specific JSON file, just add it and don't add any
 3352|       |                // relative path or directory symbol to it.
 3353|  50.9k|                if (!is_json(new_str, s)) {
  ------------------
  |  Branch (3353:21): [True: 50.9k, False: 0]
  ------------------
 3354|       |                    // Add the relative directory if present.
 3355|  50.9k|                    if (relative_path_size > 0) {
  ------------------
  |  Branch (3355:25): [True: 50.9k, False: 14]
  ------------------
 3356|  50.9k|                        char *rel_start = new_str + s;
 3357|       |
 3358|       |                        // If last symbol written was not a directory symbol, add it.
 3359|  50.9k|                        if (*(rel_start - 1) != DIRECTORY_SYMBOL) {
  ------------------
  |  |  155|  50.9k|#define DIRECTORY_SYMBOL '/'
  ------------------
  |  Branch (3359:29): [True: 50.9k, False: 0]
  ------------------
 3360|  50.9k|                            *rel_start++ = DIRECTORY_SYMBOL;
  ------------------
  |  |  155|  50.9k|#define DIRECTORY_SYMBOL '/'
  ------------------
 3361|  50.9k|                        }
 3362|  50.9k|                        memcpy(rel_start, relative_path, relative_path_size);
 3363|  50.9k|                        rel_start[relative_path_size] = '\0';
 3364|  50.9k|                    }
 3365|  50.9k|                }
 3366|       |
 3367|  50.9k|                VkResult res = append_str_to_string_list_if_unique(inst, search_paths, new_str);
 3368|  50.9k|                if (VK_SUCCESS != res) {
  ------------------
  |  Branch (3368:21): [True: 0, False: 50.9k]
  ------------------
 3369|      0|                    return res;
 3370|      0|                }
 3371|  50.9k|                start = stop;
 3372|  50.9k|            }
 3373|  50.9k|        }
 3374|  43.6k|    }
 3375|  43.6k|    return VK_SUCCESS;
 3376|  43.6k|}
add_if_manifest_file:
 3379|  13.0k|VkResult add_if_manifest_file(const struct loader_instance *inst, const char *file_name, struct loader_string_list *out_files) {
 3380|  13.0k|    assert(NULL != file_name && "add_if_manifest_file: Received NULL pointer for file_name");
 3381|  13.0k|    assert(NULL != out_files && "add_if_manifest_file: Received NULL pointer for out_files");
 3382|       |
 3383|       |    // Look for files ending with ".json" suffix
 3384|  13.0k|    size_t name_len = strlen(file_name);
 3385|  13.0k|    if (!is_json(file_name, name_len)) {
  ------------------
  |  Branch (3385:9): [True: 9.69k, False: 3.37k]
  ------------------
 3386|       |        // Use incomplete to indicate invalid name, but to keep going.
 3387|  9.69k|        return VK_INCOMPLETE;
 3388|  9.69k|    }
 3389|       |
 3390|  3.37k|    return copy_str_to_string_list(inst, out_files, file_name, name_len);
 3391|  13.0k|}
add_data_files:
 3412|  7.27k|                        struct loader_string_list *out_files) {
 3413|  7.27k|    VkResult vk_result = VK_SUCCESS;
 3414|  7.27k|    char full_path[2048];
 3415|  7.27k|#if !defined(_WIN32)
 3416|  7.27k|    char temp_path[2048];
 3417|  7.27k|#endif
 3418|       |
 3419|  58.2k|    for (size_t i = 0; i < search_paths->count; i++) {
  ------------------
  |  Branch (3419:24): [True: 50.9k, False: 7.27k]
  ------------------
 3420|       |        // Now, parse the paths
 3421|  50.9k|        char *next_file = search_paths->list[i];
 3422|   101k|        while (NULL != next_file && *next_file != '\0') {
  ------------------
  |  Branch (3422:16): [True: 101k, False: 0]
  |  Branch (3422:37): [True: 50.9k, False: 50.9k]
  ------------------
 3423|  50.9k|            char *name = NULL;
 3424|  50.9k|            char *cur_file = next_file;
 3425|  50.9k|            next_file = loader_get_next_path(cur_file);
 3426|       |
 3427|       |            // Is this a JSON file, then try to open it.
 3428|  50.9k|            size_t len = strlen(cur_file);
 3429|  50.9k|            if (is_json(cur_file, len)) {
  ------------------
  |  Branch (3429:17): [True: 0, False: 50.9k]
  ------------------
 3430|       |#if defined(_WIN32)
 3431|       |                name = cur_file;
 3432|       |#elif COMMON_UNIX_PLATFORMS
 3433|       |                // Only Linux has relative paths, make a copy of location so it isn't modified
 3434|      0|                size_t str_len;
 3435|      0|                if (NULL != next_file) {
  ------------------
  |  Branch (3435:21): [True: 0, False: 0]
  ------------------
 3436|      0|                    str_len = next_file - cur_file + 1;
 3437|      0|                } else {
 3438|      0|                    str_len = strlen(cur_file) + 1;
 3439|      0|                }
 3440|      0|                if (str_len > sizeof(temp_path)) {
  ------------------
  |  Branch (3440:21): [True: 0, False: 0]
  ------------------
 3441|      0|                    loader_log(inst, VULKAN_LOADER_DEBUG_BIT, 0, "add_data_files: Path to %s too long", cur_file);
 3442|      0|                    continue;
 3443|      0|                }
 3444|      0|                strncpy(temp_path, cur_file, str_len);
 3445|      0|                name = temp_path;
 3446|       |#else
 3447|       |#warning add_data_files must define relative path copy for this platform
 3448|       |#endif
 3449|      0|                loader_get_fullpath(cur_file, name, sizeof(full_path), full_path);
 3450|      0|                name = full_path;
 3451|       |
 3452|      0|                VkResult local_res;
 3453|      0|                local_res = add_if_manifest_file(inst, name, out_files);
 3454|       |
 3455|       |                // Incomplete means this was not a valid data file.
 3456|      0|                if (local_res == VK_INCOMPLETE) {
  ------------------
  |  Branch (3456:21): [True: 0, False: 0]
  ------------------
 3457|      0|                    continue;
 3458|      0|                }
 3459|      0|                if (local_res != VK_SUCCESS) {
  ------------------
  |  Branch (3459:21): [True: 0, False: 0]
  ------------------
 3460|      0|                    vk_result = local_res;
 3461|      0|                    break;
 3462|      0|                }
 3463|  50.9k|            } else {  // Otherwise, treat it as a directory
 3464|  50.9k|                DIR *dir_stream = loader_opendir(inst, cur_file);
 3465|  50.9k|                if (NULL == dir_stream) {
  ------------------
  |  Branch (3465:21): [True: 46.0k, False: 4.84k]
  ------------------
 3466|  46.0k|                    continue;
 3467|  46.0k|                }
 3468|  17.9k|                while (1) {
  ------------------
  |  Branch (3468:24): [True: 17.9k, Folded]
  ------------------
 3469|  17.9k|                    errno = 0;
 3470|       |                    // NOLINTNEXTLINE(concurrency-mt-unsafe) - readdir is safe here since each thread uses its own dir_stream
 3471|  17.9k|                    struct dirent *dir_entry = readdir(dir_stream);
 3472|  17.9k|#if !defined(WIN32)  // Windows doesn't use readdir, don't check errors on functions which aren't called
 3473|  17.9k|                    if (errno != 0) {
  ------------------
  |  Branch (3473:25): [True: 0, False: 17.9k]
  ------------------
 3474|       |                        // NOLINTNEXTLINE(concurrency-mt-unsafe) - strerror's static buffer is used immediately and not retained
 3475|      0|                        loader_log(inst, VULKAN_LOADER_ERROR_BIT, 0, "readdir failed with %d: %s", errno, strerror(errno));
 3476|      0|                        break;
 3477|      0|                    }
 3478|  17.9k|#endif
 3479|  17.9k|                    if (NULL == dir_entry) {
  ------------------
  |  Branch (3479:25): [True: 4.84k, False: 13.0k]
  ------------------
 3480|  4.84k|                        break;
 3481|  4.84k|                    }
 3482|       |
 3483|  13.0k|                    name = &(dir_entry->d_name[0]);
 3484|       |                    // 'name' is the bare filename, 'cur_file' is the directory being scanned; the substring "file" in
 3485|       |                    // cur_file just confuses the naming heuristic below.
 3486|       |                    // NOLINTNEXTLINE(readability-suspicious-call-argument) - arguments are correctly ordered, not swapped
 3487|  13.0k|                    loader_get_fullpath(name, cur_file, sizeof(full_path), full_path);
 3488|  13.0k|                    name = full_path;
 3489|       |
 3490|  13.0k|                    VkResult local_res;
 3491|  13.0k|                    local_res = add_if_manifest_file(inst, name, out_files);
 3492|       |
 3493|       |                    // Incomplete means this was not a valid data file.
 3494|  13.0k|                    if (local_res == VK_INCOMPLETE) {
  ------------------
  |  Branch (3494:25): [True: 9.69k, False: 3.37k]
  ------------------
 3495|  9.69k|                        continue;
 3496|  9.69k|                    }
 3497|  3.37k|                    if (local_res != VK_SUCCESS) {
  ------------------
  |  Branch (3497:25): [True: 0, False: 3.37k]
  ------------------
 3498|      0|                        vk_result = local_res;
 3499|      0|                        break;
 3500|      0|                    }
 3501|  3.37k|                }
 3502|  4.84k|                loader_closedir(inst, dir_stream);
 3503|  4.84k|                if (vk_result != VK_SUCCESS) {
  ------------------
  |  Branch (3503:21): [True: 0, False: 4.84k]
  ------------------
 3504|      0|                    goto out;
 3505|      0|                }
 3506|  4.84k|            }
 3507|  50.9k|        }
 3508|  50.9k|    }
 3509|       |
 3510|  7.27k|out:
 3511|       |
 3512|  7.27k|    return vk_result;
 3513|  7.27k|}
read_data_files_in_search_paths:
 3519|  7.27k|                                         struct loader_string_list *out_files) {
 3520|  7.27k|    VkResult vk_result = VK_SUCCESS;
 3521|  7.27k|    char *override_env = NULL;
 3522|  7.27k|    char *additional_env = NULL;
 3523|  7.27k|    struct loader_string_list search_paths = {0};
 3524|       |
 3525|  7.27k|#if COMMON_UNIX_PLATFORMS
 3526|  7.27k|    const char *relative_location = NULL;  // Only used on unix platforms
 3527|  7.27k|    size_t rel_size = 0;                   // unused in windows, dont declare so no compiler warnings are generated
 3528|  7.27k|#endif
 3529|       |
 3530|       |#if defined(__APPLE__)
 3531|       |    char *bundle_path = NULL;
 3532|       |    char *search_only_in_bundle_env_var = loader_secure_getenv(VK_LOADER_SEARCH_ONLY_IN_BUNDLE_ENV_VAR, inst);
 3533|       |#endif
 3534|       |
 3535|       |#if defined(_WIN32)
 3536|       |    char *package_path = NULL;
 3537|       |#elif COMMON_UNIX_PLATFORMS
 3538|       |    // Determine how much space is needed to generate the full search path
 3539|       |    // for the current manifest files.
 3540|  7.27k|    char *xdg_config_home = loader_secure_getenv("XDG_CONFIG_HOME", inst);
 3541|  7.27k|    char *xdg_config_dirs = loader_secure_getenv("XDG_CONFIG_DIRS", inst);
 3542|       |
 3543|  7.27k|#if !defined(__Fuchsia__) && !defined(__QNX__)
 3544|  7.27k|    if (NULL == xdg_config_dirs || '\0' == xdg_config_dirs[0]) {
  ------------------
  |  Branch (3544:9): [True: 7.27k, False: 0]
  |  Branch (3544:36): [True: 0, False: 0]
  ------------------
 3545|  7.27k|        xdg_config_dirs = FALLBACK_CONFIG_DIRS;
 3546|  7.27k|    }
 3547|  7.27k|#endif
 3548|       |
 3549|  7.27k|    char *xdg_data_home = loader_secure_getenv("XDG_DATA_HOME", inst);
 3550|  7.27k|    char *xdg_data_dirs = loader_secure_getenv("XDG_DATA_DIRS", inst);
 3551|       |
 3552|  7.27k|#if !defined(__Fuchsia__) && !defined(__QNX__)
 3553|  7.27k|    if (NULL == xdg_data_dirs || '\0' == xdg_data_dirs[0]) {
  ------------------
  |  Branch (3553:9): [True: 7.27k, False: 0]
  |  Branch (3553:34): [True: 0, False: 0]
  ------------------
 3554|  7.27k|        xdg_data_dirs = FALLBACK_DATA_DIRS;
 3555|  7.27k|    }
 3556|  7.27k|#endif
 3557|       |
 3558|  7.27k|    char *home = NULL;
 3559|  7.27k|    char *default_data_home = NULL;
 3560|  7.27k|    char *default_config_home = NULL;
 3561|  7.27k|    char *home_data_dir = NULL;
 3562|  7.27k|    char *home_config_dir = NULL;
 3563|       |
 3564|       |    // Only use HOME if XDG_DATA_HOME is not present on the system
 3565|  7.27k|    home = loader_secure_getenv("HOME", inst);
 3566|  7.27k|    if (home != NULL) {
  ------------------
  |  Branch (3566:9): [True: 7.27k, False: 0]
  ------------------
 3567|  7.27k|        if (NULL == xdg_config_home || '\0' == xdg_config_home[0]) {
  ------------------
  |  Branch (3567:13): [True: 7.27k, False: 0]
  |  Branch (3567:40): [True: 0, False: 0]
  ------------------
 3568|  7.27k|            const char config_suffix[] = "/.config";
 3569|  7.27k|            size_t default_config_home_len = strlen(home) + sizeof(config_suffix) + 1;
 3570|  7.27k|            default_config_home = loader_instance_heap_calloc(inst, default_config_home_len, VK_SYSTEM_ALLOCATION_SCOPE_COMMAND);
 3571|  7.27k|            if (default_config_home == NULL) {
  ------------------
  |  Branch (3571:17): [True: 0, False: 7.27k]
  ------------------
 3572|      0|                vk_result = VK_ERROR_OUT_OF_HOST_MEMORY;
 3573|      0|                goto out;
 3574|      0|            }
 3575|  7.27k|            strncpy(default_config_home, home, default_config_home_len);
 3576|  7.27k|            strncat(default_config_home, config_suffix, default_config_home_len);
 3577|  7.27k|        }
 3578|  7.27k|        if (NULL == xdg_data_home || '\0' == xdg_data_home[0]) {
  ------------------
  |  Branch (3578:13): [True: 7.27k, False: 0]
  |  Branch (3578:38): [True: 0, False: 0]
  ------------------
 3579|  7.27k|            const char data_suffix[] = "/.local/share";
 3580|  7.27k|            size_t default_data_home_len = strlen(home) + sizeof(data_suffix) + 1;
 3581|  7.27k|            default_data_home = loader_instance_heap_calloc(inst, default_data_home_len, VK_SYSTEM_ALLOCATION_SCOPE_COMMAND);
 3582|  7.27k|            if (default_data_home == NULL) {
  ------------------
  |  Branch (3582:17): [True: 0, False: 7.27k]
  ------------------
 3583|      0|                vk_result = VK_ERROR_OUT_OF_HOST_MEMORY;
 3584|      0|                goto out;
 3585|      0|            }
 3586|  7.27k|            strncpy(default_data_home, home, default_data_home_len);
 3587|  7.27k|            strncat(default_data_home, data_suffix, default_data_home_len);
 3588|  7.27k|        }
 3589|  7.27k|    }
 3590|       |
 3591|  7.27k|    if (NULL != default_config_home) {
  ------------------
  |  Branch (3591:9): [True: 7.27k, False: 0]
  ------------------
 3592|  7.27k|        home_config_dir = default_config_home;
 3593|  7.27k|    } else {
 3594|      0|        home_config_dir = xdg_config_home;
 3595|      0|    }
 3596|  7.27k|    if (NULL != default_data_home) {
  ------------------
  |  Branch (3596:9): [True: 7.27k, False: 0]
  ------------------
 3597|  7.27k|        home_data_dir = default_data_home;
 3598|  7.27k|    } else {
 3599|      0|        home_data_dir = xdg_data_home;
 3600|      0|    }
 3601|       |#else
 3602|       |#warning read_data_files_in_search_paths unsupported platform
 3603|       |#endif
 3604|       |
 3605|  7.27k|    switch (manifest_type) {
 3606|      0|        case LOADER_DATA_FILE_MANIFEST_DRIVER:
  ------------------
  |  Branch (3606:9): [True: 0, False: 7.27k]
  ------------------
 3607|      0|            if (loader_settings_should_use_driver_environment_variables(inst)) {
  ------------------
  |  Branch (3607:17): [True: 0, False: 0]
  ------------------
 3608|      0|                override_env = loader_secure_getenv(VK_DRIVER_FILES_ENV_VAR, inst);
  ------------------
  |  |  113|      0|#define VK_DRIVER_FILES_ENV_VAR "VK_DRIVER_FILES"
  ------------------
 3609|      0|                if (NULL == override_env) {
  ------------------
  |  Branch (3609:21): [True: 0, False: 0]
  ------------------
 3610|       |                    // Not there, so fall back to the old name
 3611|      0|                    override_env = loader_secure_getenv(VK_ICD_FILENAMES_ENV_VAR, inst);
  ------------------
  |  |  112|      0|#define VK_ICD_FILENAMES_ENV_VAR "VK_ICD_FILENAMES"  // Deprecated in v1.3.207 loader
  ------------------
 3612|      0|                }
 3613|      0|                additional_env = loader_secure_getenv(VK_ADDITIONAL_DRIVER_FILES_ENV_VAR, inst);
  ------------------
  |  |  116|      0|#define VK_ADDITIONAL_DRIVER_FILES_ENV_VAR "VK_ADD_DRIVER_FILES"
  ------------------
 3614|      0|            }
 3615|      0|#if COMMON_UNIX_PLATFORMS
 3616|      0|            relative_location = VK_DRIVERS_INFO_RELATIVE_DIR;
  ------------------
  |  |  165|      0|#define VK_DRIVERS_INFO_RELATIVE_DIR VULKAN_DIR VULKAN_ICDCONF_DIR
  |  |  ------------------
  |  |  |  |  157|      0|#define VULKAN_DIR "vulkan/"
  |  |  ------------------
  |  |               #define VK_DRIVERS_INFO_RELATIVE_DIR VULKAN_DIR VULKAN_ICDCONF_DIR
  |  |  ------------------
  |  |  |  |  158|      0|#define VULKAN_ICDCONF_DIR "icd.d"
  |  |  ------------------
  ------------------
 3617|      0|#endif
 3618|       |#if defined(_WIN32)
 3619|       |            package_path = windows_get_app_package_manifest_path(inst);
 3620|       |#endif
 3621|      0|            break;
 3622|  4.84k|        case LOADER_DATA_FILE_MANIFEST_IMPLICIT_LAYER:
  ------------------
  |  Branch (3622:9): [True: 4.84k, False: 2.43k]
  ------------------
 3623|  4.84k|            override_env = loader_secure_getenv(VK_IMPLICIT_LAYER_PATH_ENV_VAR, inst);
  ------------------
  |  |  130|  4.84k|#define VK_IMPLICIT_LAYER_PATH_ENV_VAR "VK_IMPLICIT_LAYER_PATH"
  ------------------
 3624|  4.84k|            additional_env = loader_secure_getenv(VK_ADDITIONAL_IMPLICIT_LAYER_PATH_ENV_VAR, inst);
  ------------------
  |  |  131|  4.84k|#define VK_ADDITIONAL_IMPLICIT_LAYER_PATH_ENV_VAR "VK_ADD_IMPLICIT_LAYER_PATH"
  ------------------
 3625|  4.84k|#if COMMON_UNIX_PLATFORMS
 3626|  4.84k|            relative_location = VK_ILAYERS_INFO_RELATIVE_DIR;
  ------------------
  |  |  168|  4.84k|#define VK_ILAYERS_INFO_RELATIVE_DIR VULKAN_DIR VULKAN_ILAYERCONF_DIR
  |  |  ------------------
  |  |  |  |  157|  4.84k|#define VULKAN_DIR "vulkan/"
  |  |  ------------------
  |  |               #define VK_ILAYERS_INFO_RELATIVE_DIR VULKAN_DIR VULKAN_ILAYERCONF_DIR
  |  |  ------------------
  |  |  |  |  162|  4.84k|#define VULKAN_ILAYERCONF_DIR "implicit_layer.d"
  |  |  ------------------
  ------------------
 3627|  4.84k|#endif
 3628|       |#if defined(_WIN32)
 3629|       |            package_path = windows_get_app_package_manifest_path(inst);
 3630|       |#endif
 3631|  4.84k|            break;
 3632|  2.43k|        case LOADER_DATA_FILE_MANIFEST_EXPLICIT_LAYER:
  ------------------
  |  Branch (3632:9): [True: 2.43k, False: 4.84k]
  ------------------
 3633|  2.43k|            override_env = loader_secure_getenv(VK_EXPLICIT_LAYER_PATH_ENV_VAR, inst);
  ------------------
  |  |  114|  2.43k|#define VK_EXPLICIT_LAYER_PATH_ENV_VAR "VK_LAYER_PATH"
  ------------------
 3634|  2.43k|            additional_env = loader_secure_getenv(VK_ADDITIONAL_EXPLICIT_LAYER_PATH_ENV_VAR, inst);
  ------------------
  |  |  117|  2.43k|#define VK_ADDITIONAL_EXPLICIT_LAYER_PATH_ENV_VAR "VK_ADD_LAYER_PATH"
  ------------------
 3635|  2.43k|#if COMMON_UNIX_PLATFORMS
 3636|  2.43k|            relative_location = VK_ELAYERS_INFO_RELATIVE_DIR;
  ------------------
  |  |  167|  2.43k|#define VK_ELAYERS_INFO_RELATIVE_DIR VULKAN_DIR VULKAN_ELAYERCONF_DIR
  |  |  ------------------
  |  |  |  |  157|  2.43k|#define VULKAN_DIR "vulkan/"
  |  |  ------------------
  |  |               #define VK_ELAYERS_INFO_RELATIVE_DIR VULKAN_DIR VULKAN_ELAYERCONF_DIR
  |  |  ------------------
  |  |  |  |  161|  2.43k|#define VULKAN_ELAYERCONF_DIR "explicit_layer.d"
  |  |  ------------------
  ------------------
 3637|  2.43k|#endif
 3638|  2.43k|            break;
 3639|      0|        default:
  ------------------
  |  Branch (3639:9): [True: 0, False: 7.27k]
  ------------------
 3640|      0|            assert(false && "Shouldn't get here!");
 3641|      0|            break;
 3642|  7.27k|    }
 3643|       |
 3644|       |    // Log a message when VK_LAYER_PATH is set but the override layer paths take priority
 3645|  7.27k|    if (manifest_type == LOADER_DATA_FILE_MANIFEST_EXPLICIT_LAYER &&
  ------------------
  |  Branch (3645:9): [True: 2.43k, False: 4.84k]
  ------------------
 3646|  2.43k|        (NULL != override_env && NULL != path_overrides && path_overrides->count > 0)) {
  ------------------
  |  Branch (3646:10): [True: 0, False: 2.43k]
  |  Branch (3646:34): [True: 0, False: 0]
  |  Branch (3646:60): [True: 0, False: 0]
  ------------------
 3647|      0|        loader_log(inst, VULKAN_LOADER_INFO_BIT | VULKAN_LOADER_LAYER_BIT, 0,
 3648|      0|                   "Ignoring VK_LAYER_PATH. The Override layer is active and has override paths set, which takes priority. "
 3649|      0|                   "VK_LAYER_PATH is set to %s",
 3650|      0|                   override_env);
 3651|      0|    }
 3652|       |
 3653|       |    // Add the remaining paths to the list
 3654|  7.27k|    if (NULL != path_overrides && path_overrides->count > 0) {
  ------------------
  |  Branch (3654:9): [True: 2.43k, False: 4.84k]
  |  Branch (3654:35): [True: 5, False: 2.42k]
  ------------------
 3655|     12|        for (size_t i = 0; i < path_overrides->count; i++) {
  ------------------
  |  Branch (3655:28): [True: 7, False: 5]
  ------------------
 3656|      7|            if (NULL != path_overrides->list[i]) {
  ------------------
  |  Branch (3656:17): [True: 7, False: 0]
  ------------------
 3657|      7|                if (manifest_type == LOADER_DATA_FILE_MANIFEST_EXPLICIT_LAYER) {
  ------------------
  |  Branch (3657:21): [True: 7, False: 0]
  ------------------
 3658|      7|                    loader_log(inst, VULKAN_LOADER_INFO_BIT | VULKAN_LOADER_LAYER_BIT, 0, "%s", path_overrides->list[i]);
 3659|      7|                }
 3660|      7|                vk_result = copy_data_file_info(inst, path_overrides->list[i], NULL, 0, &search_paths);
 3661|      7|                if (vk_result == VK_ERROR_OUT_OF_HOST_MEMORY) {
  ------------------
  |  Branch (3661:21): [True: 0, False: 7]
  ------------------
 3662|      0|                    goto out;
 3663|      0|                }
 3664|      7|            }
 3665|      7|        }
 3666|  7.27k|    } else if (override_env != NULL) {
  ------------------
  |  Branch (3666:16): [True: 0, False: 7.27k]
  ------------------
 3667|      0|        vk_result = copy_data_file_info(inst, override_env, NULL, 0, &search_paths);
 3668|      0|        if (vk_result == VK_ERROR_OUT_OF_HOST_MEMORY) {
  ------------------
  |  Branch (3668:13): [True: 0, False: 0]
  ------------------
 3669|      0|            goto out;
 3670|      0|        }
 3671|  7.27k|    } else {
 3672|       |        // Add any additional search paths defined in the additive environment variable
 3673|  7.27k|        if (NULL != additional_env) {
  ------------------
  |  Branch (3673:13): [True: 0, False: 7.27k]
  ------------------
 3674|      0|            vk_result = copy_data_file_info(inst, additional_env, NULL, 0, &search_paths);
 3675|      0|            if (vk_result == VK_ERROR_OUT_OF_HOST_MEMORY) {
  ------------------
  |  Branch (3675:17): [True: 0, False: 0]
  ------------------
 3676|      0|                goto out;
 3677|      0|            }
 3678|      0|        }
 3679|       |
 3680|       |#if defined(_WIN32)
 3681|       |        if (NULL != package_path) {
 3682|       |            vk_result = copy_data_file_info(inst, package_path, NULL, 0, &search_paths);
 3683|       |            if (vk_result == VK_ERROR_OUT_OF_HOST_MEMORY) {
 3684|       |                goto out;
 3685|       |            }
 3686|       |        }
 3687|       |#elif COMMON_UNIX_PLATFORMS
 3688|  7.27k|        bool search_outside_of_bundle = true;
 3689|       |
 3690|  7.27k|        rel_size = strlen(relative_location);
 3691|  7.27k|        if (rel_size > 0) {
  ------------------
  |  Branch (3691:13): [True: 7.27k, False: 0]
  ------------------
 3692|       |#if defined(__APPLE__)
 3693|       |            // Add the bundle's Resources dir to the beginning of the search path.
 3694|       |            // Looks for manifests in the bundle first, before any system directories.
 3695|       |            // This also appears to work unmodified for iOS, it finds the app bundle on the devices
 3696|       |            // file system. (RSW)
 3697|       |            CFBundleRef main_bundle = CFBundleGetMainBundle();
 3698|       |            if (NULL != main_bundle) {
 3699|       |                CFURLRef ref = CFBundleCopyResourcesDirectoryURL(main_bundle);
 3700|       |                if (NULL != ref) {
 3701|       |                    // Allocate large scratch buffer to hold the bundles path, the relative location inside the bundle, plus a path
 3702|       |                    // separator and null terminator. Since we are using a while loop, initialize length with half the intended size
 3703|       |                    size_t bundle_path_len = (MAXPATHLEN + rel_size + 2) / 2;
 3704|       |                    bool bundle_query_success = false;
 3705|       |                    uint32_t retry_count = 0;
 3706|       |                    while (!bundle_query_success && retry_count < 4) {
 3707|       |                        void *new_bundle_path = loader_instance_heap_realloc(
 3708|       |                            inst, bundle_path, bundle_path_len, bundle_path_len * 2, VK_SYSTEM_ALLOCATION_SCOPE_COMMAND);
 3709|       |                        if (NULL == new_bundle_path) {
 3710|       |                            loader_log(inst, VULKAN_LOADER_ERROR_BIT, 0,
 3711|       |                                       "read_data_files_in_search_paths: Failed to allocate space for bundle path of length %d",
 3712|       |                                       (uint32_t)bundle_path_len * 2);
 3713|       |                            vk_result = VK_ERROR_OUT_OF_HOST_MEMORY;
 3714|       |                            goto out;
 3715|       |                        }
 3716|       |                        bundle_path = new_bundle_path;
 3717|       |                        bundle_path_len = bundle_path_len * 2;
 3718|       |                        memset(bundle_path, 0, bundle_path_len);
 3719|       |                        bundle_query_success = CFURLGetFileSystemRepresentation(ref, TRUE, (UInt8 *)bundle_path, bundle_path_len);
 3720|       |                        retry_count++;
 3721|       |                    }
 3722|       |
 3723|       |                    if (bundle_query_success) {
 3724|       |                        size_t cur_bundle_len = strlen(bundle_path);
 3725|       |
 3726|       |                        if (cur_bundle_len + rel_size + 2 > bundle_path_len) {
 3727|       |                            loader_log(inst, VULKAN_LOADER_ERROR_BIT, 0,
 3728|       |                                       "read_data_files_in_search_paths: bundle_path %s of size %d does not have enough space to "
 3729|       |                                       "append relative_path",
 3730|       |                                       bundle_path, (uint32_t)bundle_path_len);
 3731|       |                            vk_result = VK_ERROR_INITIALIZATION_FAILED;
 3732|       |                            goto out;
 3733|       |                        }
 3734|       |                        bundle_path[cur_bundle_len] = DIRECTORY_SYMBOL;
 3735|       |                        cur_bundle_len++;
 3736|       |                        memcpy(bundle_path + cur_bundle_len, relative_location, rel_size);
 3737|       |                        cur_bundle_len += rel_size;
 3738|       |                        bundle_path[cur_bundle_len] = '\0';
 3739|       |
 3740|       |                        vk_result = copy_data_file_info(inst, bundle_path, NULL, 0, &search_paths);
 3741|       |                        if (vk_result == VK_ERROR_OUT_OF_HOST_MEMORY) {
 3742|       |                            goto out;
 3743|       |                        }
 3744|       |                    }
 3745|       |                    CFRelease(ref);
 3746|       |                }
 3747|       |            }
 3748|       |
 3749|       |            if (NULL != search_only_in_bundle_env_var) {
 3750|       |                search_outside_of_bundle = false;
 3751|       |            }
 3752|       |#endif  // __APPLE__
 3753|  7.27k|            if (search_outside_of_bundle) {
  ------------------
  |  Branch (3753:17): [True: 7.27k, False: 0]
  ------------------
 3754|       |                // Only add the home folders if not NULL
 3755|  7.27k|                if (NULL != home_config_dir) {
  ------------------
  |  Branch (3755:21): [True: 7.27k, False: 0]
  ------------------
 3756|  7.27k|                    vk_result = copy_data_file_info(inst, home_config_dir, relative_location, rel_size, &search_paths);
 3757|  7.27k|                    if (VK_SUCCESS != vk_result) {
  ------------------
  |  Branch (3757:25): [True: 0, False: 7.27k]
  ------------------
 3758|      0|                        goto out;
 3759|      0|                    }
 3760|  7.27k|                }
 3761|  7.27k|                vk_result = copy_data_file_info(inst, xdg_config_dirs, relative_location, rel_size, &search_paths);
 3762|  7.27k|                if (VK_SUCCESS != vk_result) {
  ------------------
  |  Branch (3762:21): [True: 0, False: 7.27k]
  ------------------
 3763|      0|                    goto out;
 3764|      0|                }
 3765|  7.27k|                vk_result = copy_data_file_info(inst, SYSCONFDIR, relative_location, rel_size, &search_paths);
 3766|  7.27k|                if (VK_SUCCESS != vk_result) {
  ------------------
  |  Branch (3766:21): [True: 0, False: 7.27k]
  ------------------
 3767|      0|                    goto out;
 3768|      0|                }
 3769|  7.27k|#if defined(EXTRASYSCONFDIR)
 3770|  7.27k|                vk_result = copy_data_file_info(inst, EXTRASYSCONFDIR, relative_location, rel_size, &search_paths);
 3771|  7.27k|                if (VK_SUCCESS != vk_result) {
  ------------------
  |  Branch (3771:21): [True: 0, False: 7.27k]
  ------------------
 3772|      0|                    goto out;
 3773|      0|                }
 3774|  7.27k|#endif
 3775|       |
 3776|       |                // Only add the home folders if not NULL
 3777|  7.27k|                if (NULL != home_data_dir) {
  ------------------
  |  Branch (3777:21): [True: 7.27k, False: 0]
  ------------------
 3778|  7.27k|                    vk_result = copy_data_file_info(inst, home_data_dir, relative_location, rel_size, &search_paths);
 3779|  7.27k|                    if (VK_SUCCESS != vk_result) {
  ------------------
  |  Branch (3779:25): [True: 0, False: 7.27k]
  ------------------
 3780|      0|                        goto out;
 3781|      0|                    }
 3782|  7.27k|                }
 3783|  7.27k|                vk_result = copy_data_file_info(inst, xdg_data_dirs, relative_location, rel_size, &search_paths);
 3784|  7.27k|                if (VK_SUCCESS != vk_result) {
  ------------------
  |  Branch (3784:21): [True: 0, False: 7.27k]
  ------------------
 3785|      0|                    goto out;
 3786|      0|                }
 3787|  7.27k|            }
 3788|  7.27k|        }
 3789|       |#else
 3790|       |#warning read_data_files_in_search_paths unsupported platform
 3791|       |#endif
 3792|  7.27k|    }
 3793|       |
 3794|       |    // Print out the paths being searched if debugging is enabled
 3795|  7.27k|    uint32_t log_flags = 0;
 3796|       |
 3797|  7.27k|    if (manifest_type == LOADER_DATA_FILE_MANIFEST_DRIVER) {
  ------------------
  |  Branch (3797:9): [True: 0, False: 7.27k]
  ------------------
 3798|      0|        log_flags = VULKAN_LOADER_DRIVER_BIT;
 3799|      0|        loader_log(inst, VULKAN_LOADER_DRIVER_BIT, 0, "Searching for driver manifest files");
 3800|  7.27k|    } else {
 3801|  7.27k|        log_flags = VULKAN_LOADER_LAYER_BIT;
 3802|  7.27k|        loader_log(inst, VULKAN_LOADER_LAYER_BIT, 0, "Searching for %s layer manifest files",
 3803|  7.27k|                   manifest_type == LOADER_DATA_FILE_MANIFEST_EXPLICIT_LAYER ? "explicit" : "implicit");
  ------------------
  |  Branch (3803:20): [True: 2.43k, False: 4.84k]
  ------------------
 3804|  7.27k|    }
 3805|  7.27k|    loader_log(inst, log_flags, 0, "   In following locations:");
 3806|       |
 3807|  58.2k|    for (size_t i = 0; i < search_paths.count; i++) {
  ------------------
  |  Branch (3807:24): [True: 50.9k, False: 7.27k]
  ------------------
 3808|  50.9k|        loader_log(inst, log_flags, 0, "      %s", search_paths.list[i]);
 3809|  50.9k|    }
 3810|       |
 3811|       |    // Now, parse the paths and add any manifest files found in them.
 3812|  7.27k|    vk_result = add_data_files(inst, &search_paths, out_files);
 3813|       |
 3814|  7.27k|    if (log_flags != 0 && out_files->count > 0) {
  ------------------
  |  Branch (3814:9): [True: 7.27k, False: 0]
  |  Branch (3814:27): [True: 3.37k, False: 3.90k]
  ------------------
 3815|  3.37k|        loader_log(inst, log_flags, 0, "   Found the following files:");
 3816|  6.75k|        for (uint32_t cur_file = 0; cur_file < out_files->count; ++cur_file) {
  ------------------
  |  Branch (3816:37): [True: 3.37k, False: 3.37k]
  ------------------
 3817|  3.37k|            loader_log(inst, log_flags, 0, "      %s", out_files->list[cur_file]);
 3818|  3.37k|        }
 3819|  3.90k|    } else {
 3820|  3.90k|        loader_log(inst, log_flags, 0, "   Found no files");
 3821|  3.90k|    }
 3822|       |
 3823|  7.27k|    if ((NULL != path_overrides && path_overrides->count > 0) || NULL != override_env) {
  ------------------
  |  Branch (3823:10): [True: 2.43k, False: 4.84k]
  |  Branch (3823:36): [True: 5, False: 2.42k]
  |  Branch (3823:66): [True: 0, False: 7.27k]
  ------------------
 3824|      5|        *override_active = true;
 3825|  7.27k|    } else {
 3826|  7.27k|        *override_active = false;
 3827|  7.27k|    }
 3828|       |
 3829|  7.27k|out:
 3830|       |
 3831|  7.27k|    loader_free_getenv(additional_env, inst);
 3832|  7.27k|    loader_free_getenv(override_env, inst);
 3833|       |#if defined(_WIN32)
 3834|       |    loader_instance_heap_free(inst, package_path);
 3835|       |#elif COMMON_UNIX_PLATFORMS
 3836|       |#if defined(__APPLE__)
 3837|       |    loader_instance_heap_free(inst, bundle_path);
 3838|       |    loader_free_getenv(search_only_in_bundle_env_var, inst);
 3839|       |#endif
 3840|  7.27k|    loader_free_getenv(xdg_config_home, inst);
 3841|  7.27k|    loader_free_getenv(xdg_config_dirs, inst);
 3842|  7.27k|    loader_free_getenv(xdg_data_home, inst);
 3843|  7.27k|    loader_free_getenv(xdg_data_dirs, inst);
 3844|  7.27k|    loader_free_getenv(xdg_data_home, inst);
 3845|  7.27k|    loader_free_getenv(home, inst);
 3846|  7.27k|    loader_instance_heap_free(inst, default_data_home);
 3847|  7.27k|    loader_instance_heap_free(inst, default_config_home);
 3848|       |#else
 3849|       |#warning read_data_files_in_search_paths unsupported platform
 3850|       |#endif
 3851|       |
 3852|  7.27k|    free_string_list(inst, &search_paths);
 3853|       |
 3854|  7.27k|    return vk_result;
 3855|  7.27k|}
loader_get_data_files:
 3881|  7.27k|                               const struct loader_string_list *path_overrides, struct loader_string_list *out_files) {
 3882|  7.27k|    VkResult res = VK_SUCCESS;
 3883|  7.27k|    bool override_active = false;
 3884|       |
 3885|       |    // Free and init the out_files information so there's no false data left from uninitialized variables.
 3886|  7.27k|    free_string_list(inst, out_files);
 3887|       |
 3888|  7.27k|    res = read_data_files_in_search_paths(inst, manifest_type, path_overrides, &override_active, out_files);
 3889|  7.27k|    if (VK_SUCCESS != res) {
  ------------------
  |  Branch (3889:9): [True: 0, False: 7.27k]
  ------------------
 3890|      0|        goto out;
 3891|      0|    }
 3892|       |
 3893|       |#if defined(_WIN32)
 3894|       |    // Read the registry if the override wasn't active.
 3895|       |    if (!override_active) {
 3896|       |        bool warn_if_not_present = false;
 3897|       |        char *registry_location = NULL;
 3898|       |
 3899|       |        switch (manifest_type) {
 3900|       |            default:
 3901|       |                goto out;
 3902|       |            case LOADER_DATA_FILE_MANIFEST_DRIVER:
 3903|       |                warn_if_not_present = true;
 3904|       |                registry_location = VK_DRIVERS_INFO_REGISTRY_LOC;
 3905|       |                break;
 3906|       |            case LOADER_DATA_FILE_MANIFEST_IMPLICIT_LAYER:
 3907|       |                registry_location = VK_ILAYERS_INFO_REGISTRY_LOC;
 3908|       |                break;
 3909|       |            case LOADER_DATA_FILE_MANIFEST_EXPLICIT_LAYER:
 3910|       |                warn_if_not_present = true;
 3911|       |                registry_location = VK_ELAYERS_INFO_REGISTRY_LOC;
 3912|       |                break;
 3913|       |        }
 3914|       |        VkResult tmp_res =
 3915|       |            windows_read_data_files_in_registry(inst, manifest_type, warn_if_not_present, registry_location, out_files);
 3916|       |        // Only return an error if there was an error this time, and no manifest files from before.
 3917|       |        if (VK_SUCCESS != tmp_res && out_files->count == 0) {
 3918|       |            res = tmp_res;
 3919|       |            goto out;
 3920|       |        }
 3921|       |    }
 3922|       |#endif
 3923|       |
 3924|  7.27k|out:
 3925|       |
 3926|  7.27k|    if (VK_SUCCESS != res) {
  ------------------
  |  Branch (3926:9): [True: 0, False: 7.27k]
  ------------------
 3927|      0|        free_string_list(inst, out_files);
 3928|      0|    }
 3929|       |
 3930|  7.27k|    return res;
 3931|  7.27k|}
loader_parse_instance_layers:
 4240|  7.27k|                                      const struct loader_string_list *path_overrides, struct loader_layer_list *instance_layers) {
 4241|  7.27k|    assert(manifest_type == LOADER_DATA_FILE_MANIFEST_IMPLICIT_LAYER || manifest_type == LOADER_DATA_FILE_MANIFEST_EXPLICIT_LAYER);
 4242|  7.27k|    VkResult res = VK_SUCCESS;
 4243|  7.27k|    struct loader_string_list manifest_files = {0};
 4244|       |
 4245|  7.27k|    res = loader_get_data_files(inst, manifest_type, path_overrides, &manifest_files);
 4246|  7.27k|    if (VK_SUCCESS != res) {
  ------------------
  |  Branch (4246:9): [True: 0, False: 7.27k]
  ------------------
 4247|      0|        goto out;
 4248|      0|    }
 4249|       |
 4250|  10.6k|    for (uint32_t i = 0; i < manifest_files.count; i++) {
  ------------------
  |  Branch (4250:26): [True: 3.37k, False: 7.27k]
  ------------------
 4251|  3.37k|        char *file_str = manifest_files.list[i];
 4252|  3.37k|        if (file_str == NULL) {
  ------------------
  |  Branch (4252:13): [True: 0, False: 3.37k]
  ------------------
 4253|      0|            continue;
 4254|      0|        }
 4255|       |
 4256|       |        // Parse file into JSON struct
 4257|  3.37k|        cJSON *json = NULL;
 4258|  3.37k|        VkResult local_res = loader_get_json(inst, file_str, &json);
 4259|  3.37k|        if (VK_ERROR_OUT_OF_HOST_MEMORY == local_res) {
  ------------------
  |  Branch (4259:13): [True: 0, False: 3.37k]
  ------------------
 4260|      0|            res = VK_ERROR_OUT_OF_HOST_MEMORY;
 4261|      0|            goto out;
 4262|  3.37k|        } else if (VK_SUCCESS != local_res || NULL == json) {
  ------------------
  |  Branch (4262:20): [True: 350, False: 3.02k]
  |  Branch (4262:47): [True: 1.51k, False: 1.50k]
  ------------------
 4263|  1.86k|            continue;
 4264|  1.86k|        }
 4265|       |
 4266|  1.50k|        local_res = loader_add_layer_properties(inst, instance_layers, json,
 4267|  1.50k|                                                manifest_type == LOADER_DATA_FILE_MANIFEST_IMPLICIT_LAYER, file_str);
 4268|  1.50k|        loader_cJSON_Delete(json);
 4269|       |
 4270|       |        // If the error is anything other than out of memory we still want to try to load the other layers
 4271|  1.50k|        if (VK_ERROR_OUT_OF_HOST_MEMORY == local_res) {
  ------------------
  |  Branch (4271:13): [True: 0, False: 1.50k]
  ------------------
 4272|      0|            res = VK_ERROR_OUT_OF_HOST_MEMORY;
 4273|      0|            goto out;
 4274|      0|        }
 4275|  1.50k|    }
 4276|  7.27k|out:
 4277|  7.27k|    free_string_list(inst, &manifest_files);
 4278|       |
 4279|  7.27k|    return res;
 4280|  7.27k|}
get_override_layer_override_paths:
 4285|      5|                                           struct loader_string_list *override_paths) {
 4286|      5|    if (prop->override_paths.count > 0) {
  ------------------
  |  Branch (4286:9): [True: 5, False: 0]
  ------------------
 4287|     10|        for (uint32_t j = 0; j < prop->override_paths.count; j++) {
  ------------------
  |  Branch (4287:30): [True: 5, False: 5]
  ------------------
 4288|      5|            VkResult result = copy_data_file_info(inst, prop->override_paths.list[j], NULL, 0, override_paths);
 4289|      5|            if (VK_SUCCESS != result) {
  ------------------
  |  Branch (4289:17): [True: 0, False: 5]
  ------------------
 4290|      0|                return result;
 4291|      0|            }
 4292|      5|            loader_log(inst, VULKAN_LOADER_WARN_BIT | VULKAN_LOADER_LAYER_BIT, 0, "Override layer has override path %s",
 4293|      5|                       prop->override_paths.list[j]);
 4294|      5|        }
 4295|      5|    }
 4296|      5|    return VK_SUCCESS;
 4297|      5|}
loader_remove_duplicate_layers:
 4299|  4.84k|void loader_remove_duplicate_layers(struct loader_instance *inst, struct loader_layer_list *layers) {
 4300|       |    // Remove duplicate layers (that share the same layerName)
 4301|  4.88k|    for (uint32_t i = 0; i < layers->count; ++i) {
  ------------------
  |  Branch (4301:26): [True: 34, False: 4.84k]
  ------------------
 4302|     34|        bool has_duplicate = false;
 4303|     34|        uint32_t duplicate_index = 0;
 4304|     34|        for (uint32_t j = i + 1; j < layers->count; ++j) {
  ------------------
  |  Branch (4304:34): [True: 0, False: 34]
  ------------------
 4305|      0|            if (strcmp(layers->list[i].info.layerName, layers->list[j].info.layerName) == 0) {
  ------------------
  |  Branch (4305:17): [True: 0, False: 0]
  ------------------
 4306|      0|                has_duplicate = true;
 4307|      0|                duplicate_index = j;
 4308|      0|                break;
 4309|      0|            }
 4310|      0|        }
 4311|     34|        if (has_duplicate) {
  ------------------
  |  Branch (4311:13): [True: 0, False: 34]
  ------------------
 4312|      0|            loader_log(inst, VULKAN_LOADER_WARN_BIT, 0, "Removing layer %s (%s) because it is a duplicate of %s (%s)",
 4313|      0|                       layers->list[duplicate_index].info.layerName, layers->list[duplicate_index].manifest_file_name,
 4314|      0|                       layers->list[i].info.layerName, layers->list[i].manifest_file_name);
 4315|      0|            loader_remove_layer_in_list(inst, layers, duplicate_index);
 4316|      0|        }
 4317|     34|    }
 4318|  4.84k|}
loader_scan_for_layers:
 4321|  2.43k|                                const struct loader_envvar_all_filters *filters) {
 4322|  2.43k|    VkResult res = VK_SUCCESS;
 4323|  2.43k|    struct loader_layer_list settings_layers = {0};
 4324|  2.43k|    struct loader_layer_list regular_instance_layers = {0};
 4325|  2.43k|    bool override_layer_valid = false;
 4326|  2.43k|    struct loader_string_list override_paths = {0};
 4327|       |
 4328|  2.43k|    bool should_search_for_other_layers = true;
 4329|  2.43k|    res = get_settings_layers(inst, &settings_layers, &should_search_for_other_layers);
 4330|  2.43k|    if (VK_SUCCESS != res) {
  ------------------
  |  Branch (4330:9): [True: 0, False: 2.43k]
  ------------------
 4331|      0|        goto out;
 4332|      0|    }
 4333|       |
 4334|       |    // If we should not look for layers using other mechanisms, assign settings_layers to instance_layers and jump to the
 4335|       |    // output
 4336|  2.43k|    if (!should_search_for_other_layers) {
  ------------------
  |  Branch (4336:9): [True: 15, False: 2.42k]
  ------------------
 4337|     15|        *instance_layers = settings_layers;
 4338|     15|        memset(&settings_layers, 0, sizeof(struct loader_layer_list));
 4339|     15|        goto out;
 4340|     15|    }
 4341|       |
 4342|  2.42k|    res = loader_parse_instance_layers(inst, LOADER_DATA_FILE_MANIFEST_IMPLICIT_LAYER, NULL, &regular_instance_layers);
 4343|  2.42k|    if (VK_SUCCESS != res) {
  ------------------
  |  Branch (4343:9): [True: 0, False: 2.42k]
  ------------------
 4344|      0|        goto out;
 4345|      0|    }
 4346|       |
 4347|       |    // Remove any extraneous override layers.
 4348|  2.42k|    remove_all_non_valid_override_layers(inst, &regular_instance_layers);
 4349|       |
 4350|       |    // Check to see if the override layer is present, and use it's override paths.
 4351|  2.44k|    for (uint32_t i = 0; i < regular_instance_layers.count; i++) {
  ------------------
  |  Branch (4351:26): [True: 22, False: 2.42k]
  ------------------
 4352|     22|        struct loader_layer_properties *prop = &regular_instance_layers.list[i];
 4353|     22|        if (prop->is_override && loader_implicit_layer_is_enabled(inst, filters, prop) && prop->override_paths.count > 0) {
  ------------------
  |  Branch (4353:13): [True: 3, False: 19]
  |  Branch (4353:34): [True: 3, False: 0]
  |  Branch (4353:91): [True: 3, False: 0]
  ------------------
 4354|      3|            res = get_override_layer_override_paths(inst, prop, &override_paths);
 4355|      3|            if (VK_SUCCESS != res) {
  ------------------
  |  Branch (4355:17): [True: 0, False: 3]
  ------------------
 4356|      0|                goto out;
 4357|      0|            }
 4358|      3|            break;
 4359|      3|        }
 4360|     22|    }
 4361|       |
 4362|       |    // Get a list of manifest files for explicit layers
 4363|  2.42k|    res = loader_parse_instance_layers(inst, LOADER_DATA_FILE_MANIFEST_EXPLICIT_LAYER, &override_paths, &regular_instance_layers);
 4364|  2.42k|    if (VK_SUCCESS != res) {
  ------------------
  |  Branch (4364:9): [True: 0, False: 2.42k]
  ------------------
 4365|      0|        goto out;
 4366|      0|    }
 4367|       |
 4368|       |    // Verify any meta-layers in the list are valid and all the component layers are
 4369|       |    // actually present in the available layer list
 4370|  2.42k|    res = verify_all_meta_layers(inst, filters, &regular_instance_layers, &override_layer_valid);
 4371|  2.42k|    if (VK_ERROR_OUT_OF_HOST_MEMORY == res) {
  ------------------
  |  Branch (4371:9): [True: 0, False: 2.42k]
  ------------------
 4372|      0|        return res;
 4373|      0|    }
 4374|       |
 4375|  2.42k|    if (override_layer_valid) {
  ------------------
  |  Branch (4375:9): [True: 3, False: 2.42k]
  ------------------
 4376|      3|        loader_remove_layers_in_blacklist(inst, &regular_instance_layers);
 4377|      3|        if (NULL != inst) {
  ------------------
  |  Branch (4377:13): [True: 0, False: 3]
  ------------------
 4378|      0|            inst->override_layer_present = true;
 4379|      0|        }
 4380|      3|    }
 4381|       |
 4382|       |    // Remove disabled layers
 4383|  2.44k|    for (uint32_t i = 0; i < regular_instance_layers.count; ++i) {
  ------------------
  |  Branch (4383:26): [True: 22, False: 2.42k]
  ------------------
 4384|     22|        if (!loader_layer_is_available(inst, filters, &regular_instance_layers.list[i])) {
  ------------------
  |  Branch (4384:13): [True: 0, False: 22]
  ------------------
 4385|      0|            loader_remove_layer_in_list(inst, &regular_instance_layers, i);
 4386|      0|            i--;
 4387|      0|        }
 4388|     22|    }
 4389|       |
 4390|       |    // Make sure no layers have the same layerName
 4391|  2.42k|    loader_remove_duplicate_layers(inst, &regular_instance_layers);
 4392|       |
 4393|  2.42k|    res = combine_settings_layers_with_regular_layers(inst, &settings_layers, &regular_instance_layers, instance_layers);
 4394|       |
 4395|  2.43k|out:
 4396|  2.43k|    loader_delete_layer_list_and_properties(inst, &settings_layers);
 4397|  2.43k|    loader_delete_layer_list_and_properties(inst, &regular_instance_layers);
 4398|       |
 4399|  2.43k|    free_string_list(inst, &override_paths);
 4400|  2.43k|    return res;
 4401|  2.42k|}
loader_scan_for_implicit_layers:
 4404|  2.43k|                                         const struct loader_envvar_all_filters *layer_filters) {
 4405|  2.43k|    VkResult res = VK_SUCCESS;
 4406|  2.43k|    struct loader_layer_list settings_layers = {0};
 4407|  2.43k|    struct loader_layer_list regular_instance_layers = {0};
 4408|  2.43k|    bool override_layer_valid = false;
 4409|  2.43k|    struct loader_string_list override_paths = {0};
 4410|  2.43k|    bool implicit_metalayer_present = false;
 4411|       |
 4412|  2.43k|    bool should_search_for_other_layers = true;
 4413|  2.43k|    res = get_settings_layers(inst, &settings_layers, &should_search_for_other_layers);
 4414|  2.43k|    if (VK_SUCCESS != res) {
  ------------------
  |  Branch (4414:9): [True: 0, False: 2.43k]
  ------------------
 4415|      0|        goto out;
 4416|      0|    }
 4417|       |
 4418|       |    // Remove layers from settings file that are off, are explicit, or are implicit layers that aren't active
 4419|  2.45k|    for (uint32_t i = 0; i < settings_layers.count; ++i) {
  ------------------
  |  Branch (4419:26): [True: 18, False: 2.43k]
  ------------------
 4420|     18|        if (settings_layers.list[i].settings_control_value == LOADER_SETTINGS_LAYER_CONTROL_OFF ||
  ------------------
  |  Branch (4420:13): [True: 14, False: 4]
  ------------------
 4421|      4|            settings_layers.list[i].settings_control_value == LOADER_SETTINGS_LAYER_UNORDERED_LAYER_LOCATION ||
  ------------------
  |  Branch (4421:13): [True: 4, False: 0]
  ------------------
 4422|      0|            (settings_layers.list[i].type_flags & VK_LAYER_TYPE_FLAG_EXPLICIT_LAYER) == VK_LAYER_TYPE_FLAG_EXPLICIT_LAYER ||
  ------------------
  |  Branch (4422:13): [True: 0, False: 0]
  ------------------
 4423|     18|            !loader_implicit_layer_is_enabled(inst, layer_filters, &settings_layers.list[i])) {
  ------------------
  |  Branch (4423:13): [True: 0, False: 0]
  ------------------
 4424|     18|            loader_remove_layer_in_list(inst, &settings_layers, i);
 4425|     18|            i--;
 4426|     18|        }
 4427|     18|    }
 4428|       |
 4429|       |    // If we should not look for layers using other mechanisms, assign settings_layers to instance_layers and jump to the
 4430|       |    // output
 4431|  2.43k|    if (!should_search_for_other_layers) {
  ------------------
  |  Branch (4431:9): [True: 15, False: 2.42k]
  ------------------
 4432|     15|        *instance_layers = settings_layers;
 4433|     15|        memset(&settings_layers, 0, sizeof(struct loader_layer_list));
 4434|     15|        goto out;
 4435|     15|    }
 4436|       |
 4437|  2.42k|    res = loader_parse_instance_layers(inst, LOADER_DATA_FILE_MANIFEST_IMPLICIT_LAYER, NULL, &regular_instance_layers);
 4438|  2.42k|    if (VK_SUCCESS != res) {
  ------------------
  |  Branch (4438:9): [True: 0, False: 2.42k]
  ------------------
 4439|      0|        goto out;
 4440|      0|    }
 4441|       |
 4442|       |    // Remove any extraneous override layers.
 4443|  2.42k|    remove_all_non_valid_override_layers(inst, &regular_instance_layers);
 4444|       |
 4445|       |    // Check to see if either the override layer is present, or another implicit meta-layer.
 4446|       |    // Each of these may require explicit layers to be enabled at this time.
 4447|  2.43k|    for (uint32_t i = 0; i < regular_instance_layers.count; i++) {
  ------------------
  |  Branch (4447:26): [True: 16, False: 2.42k]
  ------------------
 4448|     16|        struct loader_layer_properties *prop = &regular_instance_layers.list[i];
 4449|     16|        if (prop->is_override && loader_implicit_layer_is_enabled(inst, layer_filters, prop)) {
  ------------------
  |  Branch (4449:13): [True: 2, False: 14]
  |  Branch (4449:34): [True: 2, False: 0]
  ------------------
 4450|      2|            override_layer_valid = true;
 4451|      2|            res = get_override_layer_override_paths(inst, prop, &override_paths);
 4452|      2|            if (VK_SUCCESS != res) {
  ------------------
  |  Branch (4452:17): [True: 0, False: 2]
  ------------------
 4453|      0|                goto out;
 4454|      0|            }
 4455|     14|        } else if (!prop->is_override && prop->type_flags & VK_LAYER_TYPE_FLAG_META_LAYER) {
  ------------------
  |  Branch (4455:20): [True: 14, False: 0]
  |  Branch (4455:42): [True: 8, False: 6]
  ------------------
 4456|      8|            implicit_metalayer_present = true;
 4457|      8|        }
 4458|     16|    }
 4459|       |
 4460|       |    // If either the override layer or an implicit meta-layer are present, we need to add
 4461|       |    // explicit layer info as well.  Not to worry, though, all explicit layers not included
 4462|       |    // in the override layer will be removed below in loader_remove_layers_in_blacklist().
 4463|  2.42k|    if (override_layer_valid || implicit_metalayer_present) {
  ------------------
  |  Branch (4463:9): [True: 2, False: 2.42k]
  |  Branch (4463:33): [True: 8, False: 2.41k]
  ------------------
 4464|     10|        res =
 4465|     10|            loader_parse_instance_layers(inst, LOADER_DATA_FILE_MANIFEST_EXPLICIT_LAYER, &override_paths, &regular_instance_layers);
 4466|     10|        if (VK_SUCCESS != res) {
  ------------------
  |  Branch (4466:13): [True: 0, False: 10]
  ------------------
 4467|      0|            goto out;
 4468|      0|        }
 4469|     10|    }
 4470|       |
 4471|       |    // Verify any meta-layers in the list are valid and all the component layers are
 4472|       |    // actually present in the available layer list
 4473|  2.42k|    res = verify_all_meta_layers(inst, layer_filters, &regular_instance_layers, &override_layer_valid);
 4474|  2.42k|    if (VK_ERROR_OUT_OF_HOST_MEMORY == res) {
  ------------------
  |  Branch (4474:9): [True: 0, False: 2.42k]
  ------------------
 4475|      0|        return res;
 4476|      0|    }
 4477|       |
 4478|  2.42k|    if (override_layer_valid || implicit_metalayer_present) {
  ------------------
  |  Branch (4478:9): [True: 2, False: 2.42k]
  |  Branch (4478:33): [True: 8, False: 2.41k]
  ------------------
 4479|     10|        loader_remove_layers_not_in_implicit_meta_layers(inst, &regular_instance_layers);
 4480|     10|        if (override_layer_valid && inst != NULL) {
  ------------------
  |  Branch (4480:13): [True: 2, False: 8]
  |  Branch (4480:37): [True: 0, False: 2]
  ------------------
 4481|      0|            inst->override_layer_present = true;
 4482|      0|        }
 4483|     10|    }
 4484|       |
 4485|       |    // Remove disabled layers
 4486|  2.43k|    for (uint32_t i = 0; i < regular_instance_layers.count; ++i) {
  ------------------
  |  Branch (4486:26): [True: 16, False: 2.42k]
  ------------------
 4487|     16|        if (!loader_implicit_layer_is_enabled(inst, layer_filters, &regular_instance_layers.list[i])) {
  ------------------
  |  Branch (4487:13): [True: 4, False: 12]
  ------------------
 4488|      4|            loader_remove_layer_in_list(inst, &regular_instance_layers, i);
 4489|      4|            i--;
 4490|      4|        }
 4491|     16|    }
 4492|       |
 4493|       |    // Make sure no layers have the same layerName
 4494|  2.42k|    loader_remove_duplicate_layers(inst, &regular_instance_layers);
 4495|       |
 4496|  2.42k|    res = combine_settings_layers_with_regular_layers(inst, &settings_layers, &regular_instance_layers, instance_layers);
 4497|       |
 4498|  2.43k|out:
 4499|  2.43k|    loader_delete_layer_list_and_properties(inst, &settings_layers);
 4500|  2.43k|    loader_delete_layer_list_and_properties(inst, &regular_instance_layers);
 4501|       |
 4502|  2.43k|    free_string_list(inst, &override_paths);
 4503|  2.43k|    return res;
 4504|  2.42k|}
vk_string_validate:
 7542|  2.43k|TEST_FUNCTION_EXPORT VkStringErrorFlags vk_string_validate(const int max_length, const char *utf8) {
 7543|  2.43k|    VkStringErrorFlags result = VK_STRING_ERROR_NONE;
 7544|  2.43k|    int num_char_bytes = 0;
 7545|  2.43k|    int i;
 7546|  2.43k|    int j;
 7547|       |
 7548|  2.43k|    if (utf8 == NULL) {
  ------------------
  |  Branch (7548:9): [True: 0, False: 2.43k]
  ------------------
 7549|      0|        return VK_STRING_ERROR_NULL_PTR;
 7550|      0|    }
 7551|       |
 7552|  24.3k|    for (i = 0; i <= max_length; i++) {
  ------------------
  |  Branch (7552:17): [True: 24.3k, False: 0]
  ------------------
 7553|  24.3k|        if (utf8[i] == 0) {
  ------------------
  |  Branch (7553:13): [True: 2.43k, False: 21.9k]
  ------------------
 7554|  2.43k|            break;
 7555|  2.43k|        }
 7556|  21.9k|        if (i == max_length) {
  ------------------
  |  Branch (7556:13): [True: 0, False: 21.9k]
  ------------------
 7557|      0|            result |= VK_STRING_ERROR_LENGTH;
 7558|      0|            break;
 7559|      0|        }
 7560|  21.9k|        if ((utf8[i] >= 0x20) && (utf8[i] < 0x7f)) {
  ------------------
  |  Branch (7560:13): [True: 21.9k, False: 0]
  |  Branch (7560:34): [True: 21.9k, False: 0]
  ------------------
 7561|  21.9k|            num_char_bytes = 0;
 7562|  21.9k|        } else if ((utf8[i] & UTF8_ONE_BYTE_MASK) == UTF8_ONE_BYTE_CODE) {
  ------------------
  |  Branch (7562:20): [True: 0, False: 0]
  ------------------
 7563|      0|            num_char_bytes = 1;
 7564|      0|        } else if ((utf8[i] & UTF8_TWO_BYTE_MASK) == UTF8_TWO_BYTE_CODE) {
  ------------------
  |  Branch (7564:20): [True: 0, False: 0]
  ------------------
 7565|      0|            num_char_bytes = 2;
 7566|      0|        } else if ((utf8[i] & UTF8_THREE_BYTE_MASK) == UTF8_THREE_BYTE_CODE) {
  ------------------
  |  Branch (7566:20): [True: 0, False: 0]
  ------------------
 7567|      0|            num_char_bytes = 3;
 7568|      0|        } else {
 7569|      0|            result = VK_STRING_ERROR_BAD_DATA;
 7570|      0|        }
 7571|       |
 7572|       |        // Validate the following num_char_bytes of data
 7573|  21.9k|        for (j = 0; (j < num_char_bytes) && (i < max_length); j++) {
  ------------------
  |  Branch (7573:21): [True: 0, False: 21.9k]
  |  Branch (7573:45): [True: 0, False: 0]
  ------------------
 7574|      0|            if (++i == max_length) {
  ------------------
  |  Branch (7574:17): [True: 0, False: 0]
  ------------------
 7575|      0|                result |= VK_STRING_ERROR_LENGTH;
 7576|      0|                break;
 7577|      0|            }
 7578|      0|            if (utf8[i] == 0) {
  ------------------
  |  Branch (7578:17): [True: 0, False: 0]
  ------------------
 7579|       |                // The string terminated in the middle of a multi-byte character. Stop here so the
 7580|       |                // continuation-byte scan doesn't read past the terminator.
 7581|      0|                result |= VK_STRING_ERROR_BAD_DATA;
 7582|      0|                return result;
 7583|      0|            }
 7584|      0|            if ((utf8[i] & UTF8_DATA_BYTE_MASK) != UTF8_DATA_BYTE_CODE) {
  ------------------
  |  Branch (7584:17): [True: 0, False: 0]
  ------------------
 7585|      0|                result |= VK_STRING_ERROR_BAD_DATA;
 7586|      0|            }
 7587|      0|        }
 7588|  21.9k|    }
 7589|  2.43k|    return result;
 7590|  2.43k|}
terminator_EnumerateInstanceExtensionProperties:
 7606|  2.43k|                                                                               VkExtensionProperties *pProperties) {
 7607|  2.43k|    struct loader_extension_list *global_ext_list = NULL;
 7608|  2.43k|    struct loader_layer_list instance_layers;
 7609|  2.43k|    struct loader_extension_list local_ext_list;
 7610|  2.43k|    struct loader_icd_tramp_list icd_tramp_list;
 7611|  2.43k|    uint32_t copy_size;
 7612|  2.43k|    VkResult res = VK_SUCCESS;
 7613|  2.43k|    struct loader_envvar_all_filters layer_filters = {0};
 7614|       |
 7615|  2.43k|    memset(&local_ext_list, 0, sizeof(local_ext_list));
 7616|  2.43k|    memset(&instance_layers, 0, sizeof(instance_layers));
 7617|  2.43k|    memset(&icd_tramp_list, 0, sizeof(icd_tramp_list));
 7618|       |
 7619|  2.43k|    res = parse_layer_environment_var_filters(NULL, &layer_filters);
 7620|  2.43k|    if (VK_SUCCESS != res) {
  ------------------
  |  Branch (7620:9): [True: 0, False: 2.43k]
  ------------------
 7621|      0|        goto out;
 7622|      0|    }
 7623|       |
 7624|       |    // Get layer libraries if needed
 7625|  2.43k|    if (pLayerName && strlen(pLayerName) != 0) {
  ------------------
  |  Branch (7625:9): [True: 2.43k, False: 0]
  |  Branch (7625:23): [True: 2.43k, False: 0]
  ------------------
 7626|  2.43k|        if (vk_string_validate(MaxLoaderStringLength, pLayerName) != VK_STRING_ERROR_NONE) {
  ------------------
  |  Branch (7626:13): [True: 0, False: 2.43k]
  ------------------
 7627|      0|            assert(VK_FALSE && "vkEnumerateInstanceExtensionProperties: pLayerName is too long or is badly formed");
 7628|      0|            res = VK_ERROR_EXTENSION_NOT_PRESENT;
 7629|      0|            goto out;
 7630|      0|        }
 7631|       |
 7632|  2.43k|        res = loader_scan_for_layers(NULL, &instance_layers, &layer_filters);
 7633|  2.43k|        if (VK_SUCCESS != res) {
  ------------------
  |  Branch (7633:13): [True: 0, False: 2.43k]
  ------------------
 7634|      0|            goto out;
 7635|      0|        }
 7636|  2.47k|        for (uint32_t i = 0; i < instance_layers.count; i++) {
  ------------------
  |  Branch (7636:30): [True: 40, False: 2.43k]
  ------------------
 7637|     40|            struct loader_layer_properties *props = &instance_layers.list[i];
 7638|     40|            if (strcmp(props->info.layerName, pLayerName) == 0) {
  ------------------
  |  Branch (7638:17): [True: 6, False: 34]
  ------------------
 7639|      6|                global_ext_list = &props->instance_extension_list;
 7640|      6|                break;
 7641|      6|            }
 7642|     40|        }
 7643|  2.43k|    } else {
 7644|       |        // Preload ICD libraries so subsequent calls to EnumerateInstanceExtensionProperties don't have to load them
 7645|      0|        loader_preload_icds();
 7646|       |
 7647|       |        // Scan/discover all ICD libraries
 7648|      0|        res = loader_icd_scan(NULL, &icd_tramp_list, NULL, NULL);
 7649|       |        // EnumerateInstanceExtensionProperties can't return anything other than OOM or VK_ERROR_LAYER_NOT_PRESENT
 7650|      0|        if ((VK_SUCCESS != res && icd_tramp_list.count > 0) || res == VK_ERROR_OUT_OF_HOST_MEMORY) {
  ------------------
  |  Branch (7650:14): [True: 0, False: 0]
  |  Branch (7650:35): [True: 0, False: 0]
  |  Branch (7650:64): [True: 0, False: 0]
  ------------------
 7651|      0|            goto out;
 7652|      0|        }
 7653|       |        // Get extensions from all ICD's, merge so no duplicates
 7654|      0|        res = loader_get_icd_loader_instance_extensions(NULL, &icd_tramp_list, &local_ext_list);
 7655|      0|        if (VK_SUCCESS != res) {
  ------------------
  |  Branch (7655:13): [True: 0, False: 0]
  ------------------
 7656|      0|            goto out;
 7657|      0|        }
 7658|      0|        loader_clear_scanned_icd_list(NULL, &icd_tramp_list);
 7659|       |
 7660|       |        // Append enabled implicit layers.
 7661|      0|        res = loader_scan_for_implicit_layers(NULL, &instance_layers, &layer_filters);
 7662|      0|        if (VK_SUCCESS != res) {
  ------------------
  |  Branch (7662:13): [True: 0, False: 0]
  ------------------
 7663|      0|            goto out;
 7664|      0|        }
 7665|      0|        for (uint32_t i = 0; i < instance_layers.count; i++) {
  ------------------
  |  Branch (7665:30): [True: 0, False: 0]
  ------------------
 7666|      0|            struct loader_extension_list *ext_list = &instance_layers.list[i].instance_extension_list;
 7667|      0|            res = loader_add_to_ext_list(NULL, &local_ext_list, ext_list->count, ext_list->list);
 7668|      0|            if (VK_SUCCESS != res) {
  ------------------
  |  Branch (7668:17): [True: 0, False: 0]
  ------------------
 7669|      0|                goto out;
 7670|      0|            }
 7671|      0|        }
 7672|       |
 7673|      0|        global_ext_list = &local_ext_list;
 7674|      0|    }
 7675|       |
 7676|  2.43k|    if (global_ext_list == NULL) {
  ------------------
  |  Branch (7676:9): [True: 2.43k, False: 6]
  ------------------
 7677|  2.43k|        res = VK_ERROR_LAYER_NOT_PRESENT;
 7678|  2.43k|        goto out;
 7679|  2.43k|    }
 7680|       |
 7681|      6|    if (pProperties == NULL) {
  ------------------
  |  Branch (7681:9): [True: 5, False: 1]
  ------------------
 7682|      5|        *pPropertyCount = global_ext_list->count;
 7683|      5|        goto out;
 7684|      5|    }
 7685|       |
 7686|      1|    copy_size = *pPropertyCount < global_ext_list->count ? *pPropertyCount : global_ext_list->count;
  ------------------
  |  Branch (7686:17): [True: 0, False: 1]
  ------------------
 7687|      1|    for (uint32_t i = 0; i < copy_size; i++) {
  ------------------
  |  Branch (7687:26): [True: 0, False: 1]
  ------------------
 7688|      0|        memcpy(&pProperties[i], &global_ext_list->list[i], sizeof(VkExtensionProperties));
 7689|      0|    }
 7690|      1|    *pPropertyCount = copy_size;
 7691|       |
 7692|      1|    if (copy_size < global_ext_list->count) {
  ------------------
  |  Branch (7692:9): [True: 0, False: 1]
  ------------------
 7693|      0|        res = VK_INCOMPLETE;
 7694|      0|        goto out;
 7695|      0|    }
 7696|       |
 7697|  2.43k|out:
 7698|  2.43k|    loader_destroy_generic_list(NULL, (struct loader_generic_list *)&icd_tramp_list);
 7699|  2.43k|    loader_destroy_generic_list(NULL, (struct loader_generic_list *)&local_ext_list);
 7700|       |    loader_delete_layer_list_and_properties(NULL, &instance_layers);
 7701|  2.43k|    return res;
 7702|      1|}
terminator_pre_instance_EnumerateInstanceExtensionProperties:
 7706|  2.43k|    VkExtensionProperties *pProperties) {
 7707|  2.43k|    (void)chain;
 7708|  2.43k|    return terminator_EnumerateInstanceExtensionProperties(pLayerName, pPropertyCount, pProperties);
 7709|  2.43k|}

loader_getenv:
   43|     34|char *loader_getenv(const char *name, const struct loader_instance *inst) {
   44|     34|    if (NULL == name) return NULL;
  ------------------
  |  Branch (44:9): [True: 0, False: 34]
  ------------------
   45|       |    // No allocation of memory necessary for Linux, but we should at least touch
   46|       |    // the inst pointer to get rid of compiler warnings.
   47|     34|    (void)inst;
   48|       |    // NOLINTNEXTLINE(concurrency-mt-unsafe) - there is no portable reentrant getenv; the loader never calls setenv concurrently
   49|     34|    return getenv(name);
   50|     34|}
loader_secure_getenv:
   52|  77.7k|char *loader_secure_getenv(const char *name, const struct loader_instance *inst) {
   53|       |#if defined(__APPLE__) || defined(__FreeBSD__) || defined(__OpenBSD__)
   54|       |    // Apple does not appear to have a secure getenv implementation.
   55|       |    // The main difference between secure getenv and getenv is that secure getenv
   56|       |    // returns NULL if the process is being run with elevated privileges by a normal user.
   57|       |    // The idea is to prevent the reading of malicious environment variables by a process
   58|       |    // that can do damage.
   59|       |    // This algorithm is derived from glibc code that sets an internal
   60|       |    // variable (__libc_enable_secure) if the process is running under setuid or setgid.
   61|       |    return is_high_integrity() ? NULL : loader_getenv(name, inst);
   62|       |#elif defined(__Fuchsia__)
   63|       |    return loader_getenv(name, inst);
   64|       |#else
   65|       |    // Linux
   66|  77.7k|    char *out;
   67|  77.7k|#if defined(HAVE_SECURE_GETENV) && !defined(LOADER_USE_UNSAFE_FILE_SEARCH)
   68|  77.7k|    (void)inst;
   69|  77.7k|    out = secure_getenv(name);
   70|       |#elif defined(HAVE___SECURE_GETENV) && !defined(LOADER_USE_UNSAFE_FILE_SEARCH)
   71|       |    (void)inst;
   72|       |    out = __secure_getenv(name);
   73|       |#else
   74|       |    out = loader_getenv(name, inst);
   75|       |#if !defined(LOADER_USE_UNSAFE_FILE_SEARCH)
   76|       |    loader_log(inst, VULKAN_LOADER_INFO_BIT, 0, "Loader is using non-secure environment variable lookup for %s", name);
   77|       |#endif
   78|       |#endif
   79|  77.7k|    return out;
   80|  77.7k|#endif
   81|  77.7k|}
loader_free_getenv:
   83|  68.0k|void loader_free_getenv(const char *val, const struct loader_instance *inst) {
   84|       |    // No freeing of memory necessary for Linux, but we should at least touch
   85|       |    // the val and inst pointers to get rid of compiler warnings.
   86|  68.0k|    (void)val;
   87|  68.0k|    (void)inst;
   88|  68.0k|}
determine_filter_type:
  193|  4.87k|                           size_t *new_length) {
  194|  4.87k|    size_t filter_length = strlen(filter_string);
  195|  4.87k|    bool star_begin = false;
  196|  4.87k|    bool star_end = false;
  197|  4.87k|    if ('~' == filter_string[0]) {
  ------------------
  |  Branch (197:9): [True: 0, False: 4.87k]
  ------------------
  198|       |        // One of the special identifiers like: ~all~, ~implicit~, or ~explicit~
  199|      0|        *filter_type = FILTER_STRING_SPECIAL;
  200|      0|        *new_start = filter_string;
  201|      0|        *new_length = filter_length;
  202|  4.87k|    } else {
  203|  4.87k|        if ('*' == filter_string[0]) {
  ------------------
  |  Branch (203:13): [True: 0, False: 4.87k]
  ------------------
  204|       |            // Only the * means everything
  205|      0|            if (filter_length == 1) {
  ------------------
  |  Branch (205:17): [True: 0, False: 0]
  ------------------
  206|      0|                *filter_type = FILTER_STRING_SPECIAL;
  207|      0|                *new_start = filter_string;
  208|      0|                *new_length = filter_length;
  209|      0|                return;
  210|      0|            }
  211|      0|            star_begin = true;
  212|      0|        }
  213|  4.87k|        if ('*' == filter_string[filter_length - 1]) {
  ------------------
  |  Branch (213:13): [True: 0, False: 4.87k]
  ------------------
  214|       |            // Not really valid, but just catch this case so if someone accidentally types "**" it will also mean everything
  215|      0|            if (star_begin && filter_length == 2) {
  ------------------
  |  Branch (215:17): [True: 0, False: 0]
  |  Branch (215:31): [True: 0, False: 0]
  ------------------
  216|      0|                *filter_type = FILTER_STRING_SPECIAL;
  217|      0|                *new_start = filter_string;
  218|      0|                *new_length = filter_length;
  219|      0|                return;
  220|      0|            }
  221|      0|            star_end = true;
  222|      0|        }
  223|  4.87k|        if (star_begin && star_end) {
  ------------------
  |  Branch (223:13): [True: 0, False: 4.87k]
  |  Branch (223:27): [True: 0, False: 0]
  ------------------
  224|      0|            *filter_type = FILTER_STRING_SUBSTRING;
  225|      0|            *new_start = &filter_string[1];
  226|      0|            *new_length = filter_length - 2;
  227|  4.87k|        } else if (star_begin) {
  ------------------
  |  Branch (227:20): [True: 0, False: 4.87k]
  ------------------
  228|      0|            *new_start = &filter_string[1];
  229|      0|            *new_length = filter_length - 1;
  230|      0|            *filter_type = FILTER_STRING_SUFFIX;
  231|  4.87k|        } else if (star_end) {
  ------------------
  |  Branch (231:20): [True: 0, False: 4.87k]
  ------------------
  232|      0|            *filter_type = FILTER_STRING_PREFIX;
  233|      0|            *new_start = filter_string;
  234|      0|            *new_length = filter_length - 1;
  235|  4.87k|        } else {
  236|  4.87k|            *filter_type = FILTER_STRING_FULLNAME;
  237|  4.87k|            *new_start = filter_string;
  238|  4.87k|            *new_length = filter_length;
  239|  4.87k|        }
  240|  4.87k|    }
  241|  4.87k|}
parse_generic_filter_environment_var:
  246|  9.75k|                                              struct loader_envvar_filter *filter_struct) {
  247|  9.75k|    VkResult result = VK_SUCCESS;
  248|  9.75k|    memset(filter_struct, 0, sizeof(struct loader_envvar_filter));
  249|  9.75k|    char *parsing_string = NULL;
  250|  9.75k|    char *env_var_value = loader_secure_getenv(env_var_name, inst);
  251|  9.75k|    if (NULL == env_var_value) {
  ------------------
  |  Branch (251:9): [True: 4.87k, False: 4.87k]
  ------------------
  252|  4.87k|        return result;
  253|  4.87k|    }
  254|  4.87k|    const size_t env_var_len = strlen(env_var_value);
  255|  4.87k|    if (env_var_len == 0) {
  ------------------
  |  Branch (255:9): [True: 0, False: 4.87k]
  ------------------
  256|      0|        goto out;
  257|      0|    }
  258|       |    // Allocate a separate string since scan_for_next_comma modifies the original string
  259|  4.87k|    parsing_string = loader_instance_heap_calloc(inst, env_var_len + 1, VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE);
  260|  4.87k|    if (NULL == parsing_string) {
  ------------------
  |  Branch (260:9): [True: 0, False: 4.87k]
  ------------------
  261|      0|        loader_log(inst, VULKAN_LOADER_ERROR_BIT, 0,
  262|      0|                   "parse_generic_filter_environment_var: Failed to allocate space for parsing env var \'%s\'", env_var_name);
  263|      0|        result = VK_ERROR_OUT_OF_HOST_MEMORY;
  264|      0|        goto out;
  265|      0|    }
  266|       |
  267|  19.5k|    for (uint32_t iii = 0; iii < env_var_len; ++iii) {
  ------------------
  |  Branch (267:28): [True: 14.6k, False: 4.87k]
  ------------------
  268|  14.6k|        parsing_string[iii] = (char)tolower((unsigned char)env_var_value[iii]);
  ------------------
  |  Branch (268:37): [True: 0, False: 0]
  |  Branch (268:37): [True: 0, False: 0]
  |  Branch (268:37): [Folded, False: 14.6k]
  ------------------
  269|  14.6k|    }
  270|  4.87k|    parsing_string[env_var_len] = '\0';
  271|       |
  272|  4.87k|    char *context = NULL;
  273|  4.87k|    char *token = thread_safe_strtok(parsing_string, ",", &context);
  274|  9.75k|    while (NULL != token) {
  ------------------
  |  Branch (274:12): [True: 4.87k, False: 4.87k]
  ------------------
  275|  4.87k|        enum loader_filter_string_type cur_filter_type;
  276|  4.87k|        const char *actual_start;
  277|  4.87k|        size_t actual_len;
  278|  4.87k|        determine_filter_type(token, &cur_filter_type, &actual_start, &actual_len);
  279|       |        // value holds at most VK_MAX_EXTENSION_NAME_SIZE - 1 chars plus the null terminator. Keep the stored length in sync
  280|       |        // with what actually fits so the matcher never walks past the buffer, and make sure it stays null terminated.
  281|  4.87k|        size_t stored_len = actual_len < VK_MAX_EXTENSION_NAME_SIZE - 1 ? actual_len : VK_MAX_EXTENSION_NAME_SIZE - 1;
  ------------------
  |  Branch (281:29): [True: 4.87k, False: 0]
  ------------------
  282|  4.87k|        loader_strncpy(filter_struct->filters[filter_struct->count].value, VK_MAX_EXTENSION_NAME_SIZE, actual_start, stored_len);
  283|  4.87k|        filter_struct->filters[filter_struct->count].value[stored_len] = '\0';
  284|  4.87k|        filter_struct->filters[filter_struct->count].length = stored_len;
  285|  4.87k|        filter_struct->filters[filter_struct->count++].type = cur_filter_type;
  286|  4.87k|        if (filter_struct->count >= MAX_ADDITIONAL_FILTERS) {
  ------------------
  |  |  531|  4.87k|#define MAX_ADDITIONAL_FILTERS 16
  ------------------
  |  Branch (286:13): [True: 0, False: 4.87k]
  ------------------
  287|      0|            break;
  288|      0|        }
  289|  4.87k|        token = thread_safe_strtok(NULL, ",", &context);
  290|  4.87k|    }
  291|       |
  292|  4.87k|out:
  293|       |
  294|  4.87k|    loader_instance_heap_free(inst, parsing_string);
  295|  4.87k|    loader_free_getenv(env_var_value, inst);
  296|  4.87k|    return result;
  297|  4.87k|}
parse_layers_disable_filter_environment_var:
  303|  4.87k|                                                     struct loader_envvar_disable_layers_filter *disable_struct) {
  304|  4.87k|    VkResult result = VK_SUCCESS;
  305|  4.87k|    memset(disable_struct, 0, sizeof(struct loader_envvar_disable_layers_filter));
  306|  4.87k|    char *parsing_string = NULL;
  307|  4.87k|    char *env_var_value = loader_secure_getenv(VK_LAYERS_DISABLE_ENV_VAR, inst);
  ------------------
  |  |  120|  4.87k|#define VK_LAYERS_DISABLE_ENV_VAR "VK_LOADER_LAYERS_DISABLE"
  ------------------
  308|  4.87k|    if (NULL == env_var_value) {
  ------------------
  |  Branch (308:9): [True: 4.87k, False: 0]
  ------------------
  309|  4.87k|        goto out;
  310|  4.87k|    }
  311|      0|    const size_t env_var_len = strlen(env_var_value);
  312|      0|    if (env_var_len == 0) {
  ------------------
  |  Branch (312:9): [True: 0, False: 0]
  ------------------
  313|      0|        goto out;
  314|      0|    }
  315|       |    // Allocate a separate string since scan_for_next_comma modifies the original string
  316|      0|    parsing_string = loader_instance_heap_calloc(inst, env_var_len + 1, VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE);
  317|      0|    if (NULL == parsing_string) {
  ------------------
  |  Branch (317:9): [True: 0, False: 0]
  ------------------
  318|      0|        loader_log(inst, VULKAN_LOADER_ERROR_BIT, 0,
  319|      0|                   "parse_layers_disable_filter_environment_var: Failed to allocate space for parsing env var "
  320|      0|                   "\'VK_LAYERS_DISABLE_ENV_VAR\'");
  321|      0|        result = VK_ERROR_OUT_OF_HOST_MEMORY;
  322|      0|        goto out;
  323|      0|    }
  324|       |
  325|      0|    for (uint32_t iii = 0; iii < env_var_len; ++iii) {
  ------------------
  |  Branch (325:28): [True: 0, False: 0]
  ------------------
  326|      0|        parsing_string[iii] = (char)tolower((unsigned char)env_var_value[iii]);
  ------------------
  |  Branch (326:37): [True: 0, False: 0]
  |  Branch (326:37): [True: 0, False: 0]
  |  Branch (326:37): [Folded, False: 0]
  ------------------
  327|      0|    }
  328|      0|    parsing_string[env_var_len] = '\0';
  329|       |
  330|      0|    char *context = NULL;
  331|      0|    char *token = thread_safe_strtok(parsing_string, ",", &context);
  332|      0|    while (NULL != token) {
  ------------------
  |  Branch (332:12): [True: 0, False: 0]
  ------------------
  333|      0|        uint32_t cur_count = disable_struct->additional_filters.count;
  334|      0|        enum loader_filter_string_type cur_filter_type;
  335|      0|        const char *actual_start;
  336|      0|        size_t actual_len;
  337|      0|        determine_filter_type(token, &cur_filter_type, &actual_start, &actual_len);
  338|      0|        if (cur_filter_type == FILTER_STRING_SPECIAL) {
  ------------------
  |  Branch (338:13): [True: 0, False: 0]
  ------------------
  339|      0|            if (!strcmp(VK_LOADER_DISABLE_ALL_LAYERS_VAR_1, token) || !strcmp(VK_LOADER_DISABLE_ALL_LAYERS_VAR_2, token) ||
  ------------------
  |  |  124|      0|#define VK_LOADER_DISABLE_ALL_LAYERS_VAR_1 "~all~"
  ------------------
                          if (!strcmp(VK_LOADER_DISABLE_ALL_LAYERS_VAR_1, token) || !strcmp(VK_LOADER_DISABLE_ALL_LAYERS_VAR_2, token) ||
  ------------------
  |  |  125|      0|#define VK_LOADER_DISABLE_ALL_LAYERS_VAR_2 "*"
  ------------------
  |  Branch (339:17): [True: 0, False: 0]
  |  Branch (339:71): [True: 0, False: 0]
  ------------------
  340|      0|                !strcmp(VK_LOADER_DISABLE_ALL_LAYERS_VAR_3, token)) {
  ------------------
  |  |  126|      0|#define VK_LOADER_DISABLE_ALL_LAYERS_VAR_3 "**"
  ------------------
  |  Branch (340:17): [True: 0, False: 0]
  ------------------
  341|      0|                disable_struct->disable_all = true;
  342|      0|            } else if (!strcmp(VK_LOADER_DISABLE_IMPLICIT_LAYERS_VAR, token)) {
  ------------------
  |  |  127|      0|#define VK_LOADER_DISABLE_IMPLICIT_LAYERS_VAR "~implicit~"
  ------------------
  |  Branch (342:24): [True: 0, False: 0]
  ------------------
  343|      0|                disable_struct->disable_all_implicit = true;
  344|      0|            } else if (!strcmp(VK_LOADER_DISABLE_EXPLICIT_LAYERS_VAR, token)) {
  ------------------
  |  |  128|      0|#define VK_LOADER_DISABLE_EXPLICIT_LAYERS_VAR "~explicit~"
  ------------------
  |  Branch (344:24): [True: 0, False: 0]
  ------------------
  345|      0|                disable_struct->disable_all_explicit = true;
  346|      0|            }
  347|      0|        } else {
  348|       |            // Keep the stored length in sync with what actually fits (value is VK_MAX_EXTENSION_NAME_SIZE bytes including
  349|       |            // the null terminator) so the matcher never reads past the buffer.
  350|      0|            size_t stored_len = actual_len < VK_MAX_EXTENSION_NAME_SIZE - 1 ? actual_len : VK_MAX_EXTENSION_NAME_SIZE - 1;
  ------------------
  |  Branch (350:33): [True: 0, False: 0]
  ------------------
  351|      0|            loader_strncpy(disable_struct->additional_filters.filters[cur_count].value, VK_MAX_EXTENSION_NAME_SIZE, actual_start,
  352|      0|                           stored_len);
  353|      0|            disable_struct->additional_filters.filters[cur_count].value[stored_len] = '\0';
  354|      0|            disable_struct->additional_filters.filters[cur_count].length = stored_len;
  355|      0|            disable_struct->additional_filters.filters[cur_count].type = cur_filter_type;
  356|      0|            disable_struct->additional_filters.count++;
  357|      0|            if (disable_struct->additional_filters.count >= MAX_ADDITIONAL_FILTERS) {
  ------------------
  |  |  531|      0|#define MAX_ADDITIONAL_FILTERS 16
  ------------------
  |  Branch (357:17): [True: 0, False: 0]
  ------------------
  358|      0|                break;
  359|      0|            }
  360|      0|        }
  361|      0|        token = thread_safe_strtok(NULL, ",", &context);
  362|      0|    }
  363|  4.87k|out:
  364|  4.87k|    loader_instance_heap_free(inst, parsing_string);
  365|  4.87k|    loader_free_getenv(env_var_value, inst);
  366|  4.87k|    return result;
  367|      0|}
parse_layer_environment_var_filters:
  370|  4.87k|VkResult parse_layer_environment_var_filters(const struct loader_instance *inst, struct loader_envvar_all_filters *layer_filters) {
  371|  4.87k|    VkResult res = parse_generic_filter_environment_var(inst, VK_LAYERS_ENABLE_ENV_VAR, &layer_filters->enable_filter);
  ------------------
  |  |  119|  4.87k|#define VK_LAYERS_ENABLE_ENV_VAR "VK_LOADER_LAYERS_ENABLE"
  ------------------
  372|  4.87k|    if (VK_SUCCESS != res) {
  ------------------
  |  Branch (372:9): [True: 0, False: 4.87k]
  ------------------
  373|      0|        return res;
  374|      0|    }
  375|  4.87k|    res = parse_layers_disable_filter_environment_var(inst, &layer_filters->disable_filter);
  376|  4.87k|    if (VK_SUCCESS != res) {
  ------------------
  |  Branch (376:9): [True: 0, False: 4.87k]
  ------------------
  377|      0|        return res;
  378|      0|    }
  379|  4.87k|    res = parse_generic_filter_environment_var(inst, VK_LAYERS_ALLOW_ENV_VAR, &layer_filters->allow_filter);
  ------------------
  |  |  121|  4.87k|#define VK_LAYERS_ALLOW_ENV_VAR "VK_LOADER_LAYERS_ALLOW"
  ------------------
  380|  4.87k|    if (VK_SUCCESS != res) {
  ------------------
  |  Branch (380:9): [True: 0, False: 4.87k]
  ------------------
  381|      0|        return res;
  382|      0|    }
  383|  4.87k|    return res;
  384|  4.87k|}
check_name_matches_filter_environment_var:
  405|     96|bool check_name_matches_filter_environment_var(const char *name, const struct loader_envvar_filter *filter_struct) {
  406|     96|    bool ret_value = false;
  407|     96|    size_t name_len = strlen(name);
  408|       |    // Compare each filter against `name` directly. name_segment_matches_filter_value does a case-insensitive compare
  409|       |    // (filter values are already lowercased at parse time), so there's no need to make a lowercased copy of name first
  410|       |    // and no limit on how long name can be.
  411|    144|    for (uint32_t filt = 0; filt < filter_struct->count; ++filt) {
  ------------------
  |  Branch (411:29): [True: 48, False: 96]
  ------------------
  412|     48|        const struct loader_envvar_filter_value *filter = &filter_struct->filters[filt];
  413|       |        // The filter (with its wildcards stripped) is longer than the name, so it can't possibly match.
  414|     48|        if (filter->length > name_len) {
  ------------------
  |  Branch (414:13): [True: 17, False: 31]
  ------------------
  415|     17|            continue;
  416|     17|        }
  417|     31|        switch (filter->type) {
  ------------------
  |  Branch (417:17): [True: 31, False: 0]
  ------------------
  418|      0|            case FILTER_STRING_SPECIAL:
  ------------------
  |  Branch (418:13): [True: 0, False: 31]
  ------------------
  419|      0|                if (!strcmp(VK_LOADER_DISABLE_ALL_LAYERS_VAR_1, filter->value) ||
  ------------------
  |  |  124|      0|#define VK_LOADER_DISABLE_ALL_LAYERS_VAR_1 "~all~"
  ------------------
  |  Branch (419:21): [True: 0, False: 0]
  ------------------
  420|      0|                    !strcmp(VK_LOADER_DISABLE_ALL_LAYERS_VAR_2, filter->value) ||
  ------------------
  |  |  125|      0|#define VK_LOADER_DISABLE_ALL_LAYERS_VAR_2 "*"
  ------------------
  |  Branch (420:21): [True: 0, False: 0]
  ------------------
  421|      0|                    !strcmp(VK_LOADER_DISABLE_ALL_LAYERS_VAR_3, filter->value)) {
  ------------------
  |  |  126|      0|#define VK_LOADER_DISABLE_ALL_LAYERS_VAR_3 "**"
  ------------------
  |  Branch (421:21): [True: 0, False: 0]
  ------------------
  422|      0|                    ret_value = true;
  423|      0|                }
  424|      0|                break;
  425|       |
  426|      0|            case FILTER_STRING_SUBSTRING:
  ------------------
  |  Branch (426:13): [True: 0, False: 31]
  ------------------
  427|       |                // Slide the filter along the name looking for a match, stopping as soon as one is found.
  428|      0|                for (size_t start = 0; start + filter->length <= name_len; ++start) {
  ------------------
  |  Branch (428:40): [True: 0, False: 0]
  ------------------
  429|      0|                    if (name_segment_matches_filter_value(name + start, filter->value, filter->length)) {
  ------------------
  |  Branch (429:25): [True: 0, False: 0]
  ------------------
  430|      0|                        ret_value = true;
  431|      0|                        break;
  432|      0|                    }
  433|      0|                }
  434|      0|                break;
  435|       |
  436|      0|            case FILTER_STRING_SUFFIX:
  ------------------
  |  Branch (436:13): [True: 0, False: 31]
  ------------------
  437|      0|                ret_value = name_segment_matches_filter_value(name + name_len - filter->length, filter->value, filter->length);
  438|      0|                break;
  439|       |
  440|      0|            case FILTER_STRING_PREFIX:
  ------------------
  |  Branch (440:13): [True: 0, False: 31]
  ------------------
  441|      0|                ret_value = name_segment_matches_filter_value(name, filter->value, filter->length);
  442|      0|                break;
  443|       |
  444|     31|            case FILTER_STRING_FULLNAME:
  ------------------
  |  Branch (444:13): [True: 31, False: 0]
  ------------------
  445|     31|                ret_value = (name_len == filter->length) && name_segment_matches_filter_value(name, filter->value, filter->length);
  ------------------
  |  Branch (445:29): [True: 0, False: 31]
  |  Branch (445:61): [True: 0, False: 0]
  ------------------
  446|     31|                break;
  447|     31|        }
  448|     31|        if (ret_value) {
  ------------------
  |  Branch (448:13): [True: 0, False: 31]
  ------------------
  449|      0|            break;
  450|      0|        }
  451|     31|    }
  452|     96|    return ret_value;
  453|     96|}

loader_get_json:
  164|  5.62k|TEST_FUNCTION_EXPORT VkResult loader_get_json(const struct loader_instance *inst, const char *filename, cJSON **json) {
  165|  5.62k|    char *json_buf = NULL;
  166|  5.62k|    VkResult res = VK_SUCCESS;
  167|       |
  168|  5.62k|    assert(json != NULL);
  169|       |
  170|  5.62k|    size_t json_len = 0;
  171|  5.62k|    *json = NULL;
  172|  5.62k|    res = loader_read_entire_file(inst, filename, &json_len, &json_buf);
  173|  5.62k|    if (VK_SUCCESS != res) {
  ------------------
  |  Branch (173:9): [True: 395, False: 5.22k]
  ------------------
  174|    395|        goto out;
  175|    395|    }
  176|  5.62k|    bool out_of_memory = false;
  177|       |    // Parse text from file
  178|  5.22k|    *json = loader_cJSON_ParseWithLength(inst ? &inst->alloc_callbacks : NULL, json_buf, json_len, &out_of_memory);
  ------------------
  |  Branch (178:42): [True: 0, False: 5.22k]
  ------------------
  179|  5.22k|    if (out_of_memory) {
  ------------------
  |  Branch (179:9): [True: 0, False: 5.22k]
  ------------------
  180|      0|        loader_log(inst, VULKAN_LOADER_ERROR_BIT, 0, "loader_get_json: Out of Memory error occurred while parsing JSON file %s.",
  181|      0|                   filename);
  182|      0|        res = VK_ERROR_OUT_OF_HOST_MEMORY;
  183|      0|        goto out;
  184|  5.22k|    } else if (*json == NULL) {
  ------------------
  |  Branch (184:16): [True: 3.23k, False: 1.99k]
  ------------------
  185|  3.23k|        loader_log(inst, VULKAN_LOADER_ERROR_BIT, 0, "loader_get_json: Invalid JSON file %s.", filename);
  186|  3.23k|        goto out;
  187|  3.23k|    }
  188|       |
  189|  5.62k|out:
  190|  5.62k|    loader_instance_heap_free(inst, json_buf);
  191|  5.62k|    if (res != VK_SUCCESS && *json != NULL) {
  ------------------
  |  Branch (191:9): [True: 395, False: 5.22k]
  |  Branch (191:30): [True: 0, False: 395]
  ------------------
  192|      0|        loader_cJSON_Delete(*json);
  193|      0|        *json = NULL;
  194|      0|    }
  195|       |
  196|  5.62k|    return res;
  197|  5.22k|}
loader_parse_json_string_to_existing_str:
  199|  6.09k|VkResult loader_parse_json_string_to_existing_str(cJSON *object, const char *key, size_t out_str_len, char *out_string) {
  200|  6.09k|    if (NULL == key) {
  ------------------
  |  Branch (200:9): [True: 0, False: 6.09k]
  ------------------
  201|      0|        return VK_ERROR_INITIALIZATION_FAILED;
  202|      0|    }
  203|  6.09k|    cJSON *item = loader_cJSON_GetObjectItem(object, key);
  204|  6.09k|    if (NULL == item) {
  ------------------
  |  Branch (204:9): [True: 2.61k, False: 3.47k]
  ------------------
  205|  2.61k|        return VK_ERROR_INITIALIZATION_FAILED;
  206|  2.61k|    }
  207|       |
  208|  3.47k|    if (item->type != cJSON_String || item->valuestring == NULL) {
  ------------------
  |  |  101|  6.95k|#define cJSON_String (1 << 4)
  ------------------
  |  Branch (208:9): [True: 143, False: 3.33k]
  |  Branch (208:39): [True: 0, False: 3.33k]
  ------------------
  209|    143|        return VK_ERROR_INITIALIZATION_FAILED;
  210|    143|    }
  211|  3.47k|    bool out_of_memory = false;
  212|  3.33k|    bool success = loader_cJSON_PrintPreallocated(item, out_string, (int)out_str_len, cJSON_False);
  ------------------
  |  |   97|  3.33k|#define cJSON_False (1 << 0)
  ------------------
  213|  3.33k|    if (out_of_memory) {
  ------------------
  |  Branch (213:9): [True: 0, False: 3.33k]
  ------------------
  214|      0|        return VK_ERROR_OUT_OF_HOST_MEMORY;
  215|      0|    }
  216|  3.33k|    if (!success) {
  ------------------
  |  Branch (216:9): [True: 93, False: 3.24k]
  ------------------
  217|     93|        return VK_ERROR_INITIALIZATION_FAILED;
  218|     93|    }
  219|  3.24k|    return VK_SUCCESS;
  220|  3.33k|}
loader_parse_json_string:
  222|  1.02k|VkResult loader_parse_json_string(cJSON *object, const char *key, char **out_string) {
  223|  1.02k|    if (NULL == key) {
  ------------------
  |  Branch (223:9): [True: 0, False: 1.02k]
  ------------------
  224|      0|        return VK_ERROR_INITIALIZATION_FAILED;
  225|      0|    }
  226|       |
  227|  1.02k|    cJSON *item = loader_cJSON_GetObjectItem(object, key);
  228|  1.02k|    if (NULL == item || NULL == item->valuestring) {
  ------------------
  |  Branch (228:9): [True: 233, False: 792]
  |  Branch (228:25): [True: 80, False: 712]
  ------------------
  229|    313|        return VK_ERROR_INITIALIZATION_FAILED;
  230|    313|    }
  231|       |
  232|  1.02k|    bool out_of_memory = false;
  233|    712|    char *str = loader_cJSON_Print(item, &out_of_memory);
  234|    712|    if (out_of_memory || NULL == str) {
  ------------------
  |  Branch (234:9): [True: 0, False: 712]
  |  Branch (234:26): [True: 0, False: 712]
  ------------------
  235|      0|        return VK_ERROR_OUT_OF_HOST_MEMORY;
  236|      0|    }
  237|    712|    if (NULL != out_string) {
  ------------------
  |  Branch (237:9): [True: 712, False: 0]
  ------------------
  238|    712|        *out_string = str;
  239|    712|    }
  240|    712|    return VK_SUCCESS;
  241|    712|}
loader_parse_json_array_of_strings:
  243|    830|                                            struct loader_string_list *string_list) {
  244|    830|    if (NULL == key) {
  ------------------
  |  Branch (244:9): [True: 0, False: 830]
  ------------------
  245|      0|        return VK_ERROR_INITIALIZATION_FAILED;
  246|      0|    }
  247|    830|    cJSON *item = loader_cJSON_GetObjectItem(object, key);
  248|    830|    if (NULL == item) {
  ------------------
  |  Branch (248:9): [True: 747, False: 83]
  ------------------
  249|    747|        return VK_ERROR_INITIALIZATION_FAILED;
  250|    747|    }
  251|       |
  252|     83|    uint32_t count = loader_cJSON_GetArraySize(item);
  253|     83|    if (count == 0) {
  ------------------
  |  Branch (253:9): [True: 31, False: 52]
  ------------------
  254|     31|        return VK_SUCCESS;
  255|     31|    }
  256|       |
  257|     52|    VkResult res = create_string_list(inst, count, string_list);
  258|     52|    if (VK_ERROR_OUT_OF_HOST_MEMORY == res) {
  ------------------
  |  Branch (258:9): [True: 0, False: 52]
  ------------------
  259|      0|        goto out;
  260|      0|    }
  261|     52|    cJSON *element = NULL;
  262|     84|    cJSON_ArrayForEach(element, item) {
  ------------------
  |  |  213|    136|    for (element = (array != NULL) ? (array)->child : NULL; element != NULL; element = element->next)
  |  |  ------------------
  |  |  |  Branch (213:20): [True: 52, False: 0]
  |  |  |  Branch (213:61): [True: 84, False: 52]
  |  |  ------------------
  ------------------
  263|     84|        if (element->type != cJSON_String) {
  ------------------
  |  |  101|     84|#define cJSON_String (1 << 4)
  ------------------
  |  Branch (263:13): [True: 0, False: 84]
  ------------------
  264|      0|            return VK_ERROR_INITIALIZATION_FAILED;
  265|      0|        }
  266|     84|        bool out_of_memory = false;
  267|     84|        char *out_data = loader_cJSON_Print(element, &out_of_memory);
  268|     84|        if (out_of_memory) {
  ------------------
  |  Branch (268:13): [True: 0, False: 84]
  ------------------
  269|      0|            res = VK_ERROR_OUT_OF_HOST_MEMORY;
  270|      0|            goto out;
  271|      0|        }
  272|     84|        res = append_str_to_string_list(inst, string_list, out_data);
  273|     84|        if (VK_ERROR_OUT_OF_HOST_MEMORY == res) {
  ------------------
  |  Branch (273:13): [True: 0, False: 84]
  ------------------
  274|      0|            goto out;
  275|      0|        }
  276|     84|    }
  277|     52|out:
  278|     52|    if (res == VK_ERROR_OUT_OF_HOST_MEMORY && NULL != string_list->list) {
  ------------------
  |  Branch (278:9): [True: 0, False: 52]
  |  Branch (278:47): [True: 0, False: 0]
  ------------------
  279|      0|        free_string_list(inst, string_list);
  280|      0|    }
  281|       |
  282|     52|    return res;
  283|     52|}
loader_json.c:loader_read_entire_file:
  110|  5.62k|                                        char **out_buff) {
  111|  5.62k|    FILE *file = NULL;
  112|  5.62k|    struct stat stats = {0};
  113|  5.62k|    VkResult res = VK_SUCCESS;
  114|       |
  115|       |    // fprintf(stderr, "loader_get_json: Reading JSON file %s\n", filename);
  116|  5.62k|    file = fopen(filename, "rb");
  117|  5.62k|#ifdef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
  118|  5.62k|    if (file == NULL) {
  ------------------
  |  Branch (118:9): [True: 365, False: 5.25k]
  ------------------
  119|    365|        create_callback_file(filename);
  120|    365|        file = fopen(filename, "rb");
  121|    365|    }
  122|  5.62k|#endif
  123|  5.62k|    if (NULL == file) {
  ------------------
  |  Branch (123:9): [True: 365, False: 5.25k]
  ------------------
  124|    365|        loader_log(inst, VULKAN_LOADER_ERROR_BIT, 0, "loader_get_json: Failed to open JSON file %s", filename);
  125|    365|        res = VK_ERROR_INITIALIZATION_FAILED;
  126|    365|        goto out;
  127|    365|    }
  128|  5.25k|    if (-1 == fstat(fileno(file), &stats)) {
  ------------------
  |  Branch (128:9): [True: 0, False: 5.25k]
  ------------------
  129|      0|        loader_log(inst, VULKAN_LOADER_ERROR_BIT, 0, "loader_get_json: Failed to read file size of JSON file %s", filename);
  130|      0|        res = VK_ERROR_INITIALIZATION_FAILED;
  131|      0|        goto out;
  132|      0|    }
  133|  5.25k|    *out_buff = (char *)loader_instance_heap_calloc(inst, stats.st_size + 1, VK_SYSTEM_ALLOCATION_SCOPE_COMMAND);
  134|  5.25k|    if (NULL == *out_buff) {
  ------------------
  |  Branch (134:9): [True: 0, False: 5.25k]
  ------------------
  135|      0|        loader_log(inst, VULKAN_LOADER_ERROR_BIT, 0, "loader_get_json: Failed to allocate memory to read JSON file %s", filename);
  136|      0|        res = VK_ERROR_OUT_OF_HOST_MEMORY;
  137|      0|        goto out;
  138|      0|    }
  139|  5.25k|    if (stats.st_size != (long int)fread(*out_buff, sizeof(char), stats.st_size, file)) {
  ------------------
  |  Branch (139:9): [True: 30, False: 5.22k]
  ------------------
  140|     30|        loader_log(inst, VULKAN_LOADER_ERROR_BIT, 0, "loader_get_json: Failed to read entire JSON file %s", filename);
  141|     30|        res = VK_ERROR_INITIALIZATION_FAILED;
  142|     30|        goto out;
  143|     30|    }
  144|  5.22k|    *out_len = stats.st_size + 1;
  145|       |    // out_buff was allocated with stats.st_size + 1 bytes above, and the fread check already verified the file's
  146|       |    // contents did not change size out from under us; this is the last valid byte.
  147|       |    // NOLINTNEXTLINE(clang-analyzer-security.ArrayBound)
  148|  5.22k|    (*out_buff)[stats.st_size] = '\0';
  149|       |
  150|  5.62k|out:
  151|  5.62k|    if (NULL != file) {
  ------------------
  |  Branch (151:9): [True: 5.25k, False: 365]
  ------------------
  152|       |        // NOLINTNEXTLINE(cert-err33-c) - file was only opened for reading, nothing to flush; res already reflects any read failure
  153|  5.25k|        fclose(file);
  154|  5.25k|    }
  155|  5.62k|    return res;
  156|  5.22k|}

loader_init_global_debug_level:
   42|      2|void loader_init_global_debug_level(void) {
   43|      2|    char *env;
   44|      2|    char *orig;
   45|       |
   46|      2|    if (g_loader_debug > 0) return;
  ------------------
  |  Branch (46:9): [True: 0, False: 2]
  ------------------
   47|       |
   48|      2|    g_loader_debug = 0;
   49|       |
   50|       |    // Parse comma-separated debug options
   51|      2|    orig = env = loader_getenv("VK_LOADER_DEBUG", NULL);
   52|      2|    while (env) {
  ------------------
  |  Branch (52:12): [True: 0, False: 2]
  ------------------
   53|      0|        char *p = strchr(env, ',');
   54|      0|        size_t len;
   55|       |
   56|      0|        if (p) {
  ------------------
  |  Branch (56:13): [True: 0, False: 0]
  ------------------
   57|      0|            len = p - env;
   58|      0|        } else {
   59|      0|            len = strlen(env);
   60|      0|        }
   61|       |
   62|      0|        if (len > 0) {
  ------------------
  |  Branch (62:13): [True: 0, False: 0]
  ------------------
   63|      0|            if (strncmp(env, "all", len) == 0) {
  ------------------
  |  Branch (63:17): [True: 0, False: 0]
  ------------------
   64|      0|                g_loader_debug = ~0u;
   65|      0|            } else if (strncmp(env, "warn", len) == 0) {
  ------------------
  |  Branch (65:24): [True: 0, False: 0]
  ------------------
   66|      0|                g_loader_debug |= VULKAN_LOADER_WARN_BIT;
   67|      0|            } else if (strncmp(env, "info", len) == 0) {
  ------------------
  |  Branch (67:24): [True: 0, False: 0]
  ------------------
   68|      0|                g_loader_debug |= VULKAN_LOADER_INFO_BIT;
   69|      0|            } else if (strncmp(env, "perf", len) == 0) {
  ------------------
  |  Branch (69:24): [True: 0, False: 0]
  ------------------
   70|      0|                g_loader_debug |= VULKAN_LOADER_PERF_BIT;
   71|      0|            } else if (strncmp(env, "error", len) == 0) {
  ------------------
  |  Branch (71:24): [True: 0, False: 0]
  ------------------
   72|      0|                g_loader_debug |= VULKAN_LOADER_ERROR_BIT;
   73|      0|            } else if (strncmp(env, "debug", len) == 0) {
  ------------------
  |  Branch (73:24): [True: 0, False: 0]
  ------------------
   74|      0|                g_loader_debug |= VULKAN_LOADER_DEBUG_BIT;
   75|      0|            } else if (strncmp(env, "layer", len) == 0) {
  ------------------
  |  Branch (75:24): [True: 0, False: 0]
  ------------------
   76|      0|                g_loader_debug |= VULKAN_LOADER_LAYER_BIT;
   77|      0|            } else if (strncmp(env, "driver", len) == 0 || strncmp(env, "implem", len) == 0 || strncmp(env, "icd", len) == 0) {
  ------------------
  |  Branch (77:24): [True: 0, False: 0]
  |  Branch (77:60): [True: 0, False: 0]
  |  Branch (77:96): [True: 0, False: 0]
  ------------------
   78|      0|                g_loader_debug |= VULKAN_LOADER_DRIVER_BIT;
   79|      0|            }
   80|      0|        }
   81|       |
   82|      0|        if (!p) break;
  ------------------
  |  Branch (82:13): [True: 0, False: 0]
  ------------------
   83|       |
   84|      0|        env = p + 1;
   85|      0|    }
   86|       |
   87|       |    loader_free_getenv(orig, NULL);
   88|      2|}
loader_set_global_debug_level:
   90|      5|void loader_set_global_debug_level(uint32_t new_loader_debug) { g_loader_debug = new_loader_debug; }
generate_debug_flag_str:
   93|     37|void generate_debug_flag_str(VkFlags msg_type, size_t cmd_line_size, char *cmd_line_msg) {
   94|     37|    cmd_line_msg[0] = '\0';
   95|       |
   96|     37|    if ((msg_type & VULKAN_LOADER_ERROR_BIT) != 0) {
  ------------------
  |  Branch (96:9): [True: 2, False: 35]
  ------------------
   97|      2|        loader_strncat(cmd_line_msg, cmd_line_size, "ERROR", sizeof("ERROR"));
   98|      2|    }
   99|     37|    if ((msg_type & VULKAN_LOADER_WARN_BIT) != 0) {
  ------------------
  |  Branch (99:9): [True: 0, False: 37]
  ------------------
  100|      0|        if (strlen(cmd_line_msg) > 0) {
  ------------------
  |  Branch (100:13): [True: 0, False: 0]
  ------------------
  101|      0|            loader_strncat(cmd_line_msg, cmd_line_size, " | ", sizeof(" | "));
  102|      0|        }
  103|      0|        loader_strncat(cmd_line_msg, cmd_line_size, "WARNING", sizeof("WARNING"));
  104|      0|    }
  105|     37|    if ((msg_type & VULKAN_LOADER_INFO_BIT) != 0) {
  ------------------
  |  Branch (105:9): [True: 0, False: 37]
  ------------------
  106|      0|        if (strlen(cmd_line_msg) > 0) {
  ------------------
  |  Branch (106:13): [True: 0, False: 0]
  ------------------
  107|      0|            loader_strncat(cmd_line_msg, cmd_line_size, " | ", sizeof(" | "));
  108|      0|        }
  109|      0|        loader_strncat(cmd_line_msg, cmd_line_size, "INFO", sizeof("INFO"));
  110|      0|    }
  111|     37|    if ((msg_type & VULKAN_LOADER_DEBUG_BIT) != 0) {
  ------------------
  |  Branch (111:9): [True: 2, False: 35]
  ------------------
  112|      2|        if (strlen(cmd_line_msg) > 0) {
  ------------------
  |  Branch (112:13): [True: 1, False: 1]
  ------------------
  113|      1|            loader_strncat(cmd_line_msg, cmd_line_size, " | ", sizeof(" | "));
  114|      1|        }
  115|      2|        loader_strncat(cmd_line_msg, cmd_line_size, "DEBUG", sizeof("DEBUG"));
  116|      2|    }
  117|     37|    if ((msg_type & VULKAN_LOADER_PERF_BIT) != 0) {
  ------------------
  |  Branch (117:9): [True: 3, False: 34]
  ------------------
  118|      3|        if (strlen(cmd_line_msg) > 0) {
  ------------------
  |  Branch (118:13): [True: 1, False: 2]
  ------------------
  119|      1|            loader_strncat(cmd_line_msg, cmd_line_size, " | ", sizeof(" | "));
  120|      1|        }
  121|      3|        loader_strncat(cmd_line_msg, cmd_line_size, "PERF", sizeof("PERF"));
  122|      3|    }
  123|     37|    if ((msg_type & VULKAN_LOADER_DRIVER_BIT) != 0) {
  ------------------
  |  Branch (123:9): [True: 0, False: 37]
  ------------------
  124|      0|        if (strlen(cmd_line_msg) > 0) {
  ------------------
  |  Branch (124:13): [True: 0, False: 0]
  ------------------
  125|      0|            loader_strncat(cmd_line_msg, cmd_line_size, " | ", sizeof(" | "));
  126|      0|        }
  127|      0|        loader_strncat(cmd_line_msg, cmd_line_size, "DRIVER", sizeof("DRIVER"));
  128|      0|    }
  129|     37|    if ((msg_type & VULKAN_LOADER_LAYER_BIT) != 0) {
  ------------------
  |  Branch (129:9): [True: 2, False: 35]
  ------------------
  130|      2|        if (strlen(cmd_line_msg) > 0) {
  ------------------
  |  Branch (130:13): [True: 2, False: 0]
  ------------------
  131|      2|            loader_strncat(cmd_line_msg, cmd_line_size, " | ", sizeof(" | "));
  132|      2|        }
  133|      2|        loader_strncat(cmd_line_msg, cmd_line_size, "LAYER", sizeof("LAYER"));
  134|      2|    }
  135|       |
  136|     37|#undef STRNCAT_TO_BUFFER
  137|     37|}
loader_log:
  141|  90.1k|    loader_log(const struct loader_instance *inst, VkFlags msg_type, int32_t msg_code, const char *format, ...) {
  142|  90.1k|    (void)msg_code;
  143|  90.1k|    char msg[512] = {0};
  144|       |
  145|  90.1k|    va_list ap;
  146|  90.1k|    va_start(ap, format);
  147|  90.1k|    int ret = vsnprintf(msg, sizeof(msg), format, ap);
  148|  90.1k|    if ((ret >= (int)sizeof(msg)) || ret < 0) {
  ------------------
  |  Branch (148:9): [True: 4, False: 90.1k]
  |  Branch (148:38): [True: 0, False: 90.1k]
  ------------------
  149|      4|        msg[sizeof(msg) - 1] = '\0';
  150|      4|    }
  151|  90.1k|    va_end(ap);
  152|       |
  153|  90.1k|    if (inst) {
  ------------------
  |  Branch (153:9): [True: 0, False: 90.1k]
  ------------------
  154|       |        // NOLINTNEXTLINE(clang-analyzer-optin.core.EnumCastOutOfRange) - external Vulkan enum, has no zero value we can add
  155|      0|        VkDebugUtilsMessageSeverityFlagBitsEXT severity = 0;
  156|      0|        VkDebugUtilsMessageTypeFlagsEXT type = 0;
  157|      0|        VkDebugUtilsMessengerCallbackDataEXT callback_data = {0};
  158|      0|        VkDebugUtilsObjectNameInfoEXT object_name = {0};
  159|       |
  160|       |        // NOLINTNEXTLINE(bugprone-branch-clone) - duplicated so combined bit calls (e.g. WARN_BIT|LAYER_BIT) match first branch
  161|      0|        if ((msg_type & VULKAN_LOADER_INFO_BIT) != 0) {
  ------------------
  |  Branch (161:13): [True: 0, False: 0]
  ------------------
  162|      0|            severity = VK_DEBUG_UTILS_MESSAGE_SEVERITY_INFO_BIT_EXT;
  163|      0|        } else if ((msg_type & VULKAN_LOADER_WARN_BIT) != 0) {
  ------------------
  |  Branch (163:20): [True: 0, False: 0]
  ------------------
  164|      0|            severity = VK_DEBUG_UTILS_MESSAGE_SEVERITY_WARNING_BIT_EXT;
  165|      0|        } else if ((msg_type & VULKAN_LOADER_ERROR_BIT) != 0) {
  ------------------
  |  Branch (165:20): [True: 0, False: 0]
  ------------------
  166|      0|            severity = VK_DEBUG_UTILS_MESSAGE_SEVERITY_ERROR_BIT_EXT;
  167|      0|        } else if ((msg_type & VULKAN_LOADER_DEBUG_BIT) != 0) {
  ------------------
  |  Branch (167:20): [True: 0, False: 0]
  ------------------
  168|      0|            severity = VK_DEBUG_UTILS_MESSAGE_SEVERITY_VERBOSE_BIT_EXT;
  169|      0|        } else if ((msg_type & VULKAN_LOADER_LAYER_BIT) != 0 || (msg_type & VULKAN_LOADER_DRIVER_BIT) != 0) {
  ------------------
  |  Branch (169:20): [True: 0, False: 0]
  |  Branch (169:65): [True: 0, False: 0]
  ------------------
  170|       |            // Just driver or just layer bit should be treated as an info message in debug utils.
  171|      0|            severity = VK_DEBUG_UTILS_MESSAGE_SEVERITY_INFO_BIT_EXT;
  172|      0|        }
  173|       |
  174|      0|        if ((msg_type & VULKAN_LOADER_PERF_BIT) != 0) {
  ------------------
  |  Branch (174:13): [True: 0, False: 0]
  ------------------
  175|      0|            type = VK_DEBUG_UTILS_MESSAGE_TYPE_PERFORMANCE_BIT_EXT;
  176|      0|        } else if ((msg_type & VULKAN_LOADER_VALIDATION_BIT) != 0) {
  ------------------
  |  Branch (176:20): [True: 0, False: 0]
  ------------------
  177|       |            // For loader logging, if it's a validation message, we still want to also keep the general flag as well
  178|       |            // so messages of type validation can still be triggered for general message callbacks.
  179|      0|            type = VK_DEBUG_UTILS_MESSAGE_TYPE_GENERAL_BIT_EXT | VK_DEBUG_UTILS_MESSAGE_TYPE_VALIDATION_BIT_EXT;
  180|      0|        } else {
  181|      0|            type = VK_DEBUG_UTILS_MESSAGE_TYPE_GENERAL_BIT_EXT;
  182|      0|        }
  183|       |
  184|      0|        callback_data.sType = VK_STRUCTURE_TYPE_DEBUG_UTILS_MESSENGER_CALLBACK_DATA_EXT;
  185|      0|        callback_data.pMessageIdName = "Loader Message";
  186|      0|        callback_data.pMessage = msg;
  187|      0|        callback_data.objectCount = 1;
  188|      0|        callback_data.pObjects = &object_name;
  189|      0|        object_name.sType = VK_STRUCTURE_TYPE_DEBUG_UTILS_OBJECT_NAME_INFO_EXT;
  190|      0|        object_name.objectType = VK_OBJECT_TYPE_INSTANCE;
  191|      0|        object_name.objectHandle = (uint64_t)(uintptr_t)inst;
  192|       |
  193|      0|        util_SubmitDebugUtilsMessageEXT(inst, severity, type, &callback_data);
  194|      0|    }
  195|       |
  196|       |    // Always log to stderr if this is a fatal error
  197|  90.1k|    if (0 == (msg_type & VULKAN_LOADER_FATAL_ERROR_BIT)) {
  ------------------
  |  Branch (197:9): [True: 90.1k, False: 0]
  ------------------
  198|  90.1k|        if (inst && inst->settings.settings_active && inst->settings.debug_level > 0) {
  ------------------
  |  Branch (198:13): [True: 0, False: 90.1k]
  |  Branch (198:21): [True: 0, False: 0]
  |  Branch (198:55): [True: 0, False: 0]
  ------------------
  199|       |            // Exit early if the current instance settings have some debugging options but do match the current msg_type
  200|      0|            if (0 == (msg_type & inst->settings.debug_level)) {
  ------------------
  |  Branch (200:17): [True: 0, False: 0]
  ------------------
  201|      0|                return;
  202|      0|            }
  203|       |            // Check the global settings and if that doesn't say to skip, check the environment variable
  204|  90.1k|        } else if (0 == (msg_type & g_loader_debug)) {
  ------------------
  |  Branch (204:20): [True: 72.3k, False: 17.7k]
  ------------------
  205|  72.3k|            return;
  206|  72.3k|        }
  207|  90.1k|    }
  208|       |
  209|       |#if defined(DEBUG)
  210|       |    int debug_flag_mask =
  211|       |        (int)(msg_type & (VULKAN_LOADER_ERROR_BIT | VULKAN_LOADER_WARN_BIT | VULKAN_LOADER_INFO_BIT | VULKAN_LOADER_DEBUG_BIT));
  212|       |    assert((debug_flag_mask == 0 || debug_flag_mask == VULKAN_LOADER_ERROR_BIT || debug_flag_mask == VULKAN_LOADER_WARN_BIT ||
  213|       |            debug_flag_mask == VULKAN_LOADER_INFO_BIT || debug_flag_mask == VULKAN_LOADER_DEBUG_BIT) &&
  214|       |           "This log has more than one exclusive debug flags (error, warn, info, debug) set");
  215|       |#endif
  216|       |
  217|       |    // Only need enough space to create the filter description header for log messages
  218|       |    // Also use the same header for all output
  219|  17.7k|    char cmd_line_msg[64] = {0};
  220|  17.7k|    size_t cmd_line_size = sizeof(cmd_line_msg);
  221|       |
  222|  17.7k|    loader_strncat(cmd_line_msg, cmd_line_size, "[Vulkan Loader] ", sizeof("[Vulkan Loader] "));
  223|       |
  224|  17.7k|    bool need_separator = false;
  225|  17.7k|    if ((msg_type & VULKAN_LOADER_ERROR_BIT) != 0) {
  ------------------
  |  Branch (225:9): [True: 802, False: 16.9k]
  ------------------
  226|    802|        loader_strncat(cmd_line_msg, cmd_line_size, "ERROR", sizeof("ERROR"));
  227|    802|        need_separator = true;
  228|  16.9k|    } else if ((msg_type & VULKAN_LOADER_WARN_BIT) != 0) {
  ------------------
  |  Branch (228:16): [True: 260, False: 16.7k]
  ------------------
  229|    260|        loader_strncat(cmd_line_msg, cmd_line_size, "WARNING", sizeof("WARNING"));
  230|    260|        need_separator = true;
  231|  16.7k|    } else if ((msg_type & VULKAN_LOADER_INFO_BIT) != 0) {
  ------------------
  |  Branch (231:16): [True: 541, False: 16.1k]
  ------------------
  232|    541|        loader_strncat(cmd_line_msg, cmd_line_size, "INFO", sizeof("INFO"));
  233|    541|        need_separator = true;
  234|  16.1k|    } else if ((msg_type & VULKAN_LOADER_DEBUG_BIT) != 0) {
  ------------------
  |  Branch (234:16): [True: 188, False: 16.0k]
  ------------------
  235|    188|        loader_strncat(cmd_line_msg, cmd_line_size, "DEBUG", sizeof("DEBUG"));
  236|    188|        need_separator = true;
  237|    188|    }
  238|       |
  239|  17.7k|    if ((msg_type & VULKAN_LOADER_PERF_BIT) != 0) {
  ------------------
  |  Branch (239:9): [True: 0, False: 17.7k]
  ------------------
  240|      0|        if (need_separator) {
  ------------------
  |  Branch (240:13): [True: 0, False: 0]
  ------------------
  241|      0|            loader_strncat(cmd_line_msg, cmd_line_size, " | ", sizeof(" | "));
  242|      0|        }
  243|      0|        loader_strncat(cmd_line_msg, cmd_line_size, "PERF", sizeof("PERF"));
  244|  17.7k|    } else if ((msg_type & VULKAN_LOADER_DRIVER_BIT) != 0) {
  ------------------
  |  Branch (244:16): [True: 0, False: 17.7k]
  ------------------
  245|      0|        if (need_separator) {
  ------------------
  |  Branch (245:13): [True: 0, False: 0]
  ------------------
  246|      0|            loader_strncat(cmd_line_msg, cmd_line_size, " | ", sizeof(" | "));
  247|      0|        }
  248|      0|        loader_strncat(cmd_line_msg, cmd_line_size, "DRIVER", sizeof("DRIVER"));
  249|  17.7k|    } else if ((msg_type & VULKAN_LOADER_LAYER_BIT) != 0) {
  ------------------
  |  Branch (249:16): [True: 16.8k, False: 986]
  ------------------
  250|  16.8k|        if (need_separator) {
  ------------------
  |  Branch (250:13): [True: 805, False: 16.0k]
  ------------------
  251|    805|            loader_strncat(cmd_line_msg, cmd_line_size, " | ", sizeof(" | "));
  252|    805|        }
  253|  16.8k|        loader_strncat(cmd_line_msg, cmd_line_size, "LAYER", sizeof("LAYER"));
  254|  16.8k|    }
  255|       |
  256|  17.7k|    loader_strncat(cmd_line_msg, cmd_line_size, ": ", sizeof(": "));
  257|  17.7k|    size_t num_used = strlen(cmd_line_msg);
  258|       |
  259|       |    // Justifies the output to at least 29 spaces
  260|  17.7k|    if (num_used < 32) {
  ------------------
  |  Branch (260:9): [True: 17.5k, False: 260]
  ------------------
  261|  17.5k|        const char space_buffer[] = "                                ";
  262|       |        // Only write (32 - num_used) spaces
  263|  17.5k|        loader_strncat(cmd_line_msg, cmd_line_size, space_buffer, sizeof(space_buffer) - 1 - num_used);
  264|  17.5k|    }
  265|       |    // Assert that we didn't write more than what is available in cmd_line_msg
  266|  17.7k|    assert(cmd_line_size > num_used);
  267|       |
  268|       |    // NOLINTBEGIN(cert-err33-c) - this is the logger itself; no sane recovery from a failed stderr write
  269|       |    //fputs(cmd_line_msg, stderr);
  270|       |    //fputs(msg, stderr);
  271|       |    //fputc('\n', stderr);
  272|       |    // NOLINTEND(cert-err33-c)
  273|       |#if defined(WIN32)
  274|       |    OutputDebugString(cmd_line_msg);
  275|       |    OutputDebugString(msg);
  276|       |    OutputDebugString("\n");
  277|       |#endif
  278|  17.7k|}

free_layer_configuration:
   41|    355|void free_layer_configuration(const struct loader_instance* inst, loader_settings_layer_configuration* layer_configuration) {
   42|    355|    loader_instance_heap_free(inst, layer_configuration->name);
   43|    355|    loader_instance_heap_free(inst, layer_configuration->path);
   44|    355|    memset(layer_configuration, 0, sizeof(loader_settings_layer_configuration));
   45|    355|}
free_loader_settings:
   57|  2.06k|void free_loader_settings(const struct loader_instance* inst, loader_settings* settings) {
   58|  2.06k|    if (NULL != settings->layer_configurations) {
  ------------------
  |  Branch (58:9): [True: 12, False: 2.05k]
  ------------------
   59|     36|        for (uint32_t i = 0; i < settings->layer_configuration_count; i++) {
  ------------------
  |  Branch (59:30): [True: 24, False: 12]
  ------------------
   60|     24|            free_layer_configuration(inst, &settings->layer_configurations[i]);
   61|     24|        }
   62|     12|        loader_instance_heap_free(inst, settings->layer_configurations);
   63|     12|    }
   64|  2.06k|    if (NULL != settings->additional_drivers) {
  ------------------
  |  Branch (64:9): [True: 0, False: 2.06k]
  ------------------
   65|      0|        for (uint32_t i = 0; i < settings->additional_driver_count; i++) {
  ------------------
  |  Branch (65:30): [True: 0, False: 0]
  ------------------
   66|      0|            free_driver_configuration(inst, &settings->additional_drivers[i]);
   67|      0|        }
   68|      0|        loader_instance_heap_free(inst, settings->additional_drivers);
   69|      0|    }
   70|  2.06k|    if (NULL != settings->device_configurations) {
  ------------------
  |  Branch (70:9): [True: 0, False: 2.06k]
  ------------------
   71|      0|        for (uint32_t i = 0; i < settings->device_configuration_count; i++) {
  ------------------
  |  Branch (71:30): [True: 0, False: 0]
  ------------------
   72|      0|            free_device_configuration(inst, &settings->device_configurations[i]);
   73|      0|        }
   74|      0|        loader_instance_heap_free(inst, settings->device_configurations);
   75|      0|    }
   76|  2.06k|    loader_instance_heap_free(inst, settings->settings_file_path);
   77|  2.06k|    memset(settings, 0, sizeof(loader_settings));
   78|  2.06k|}
parse_control_string:
   80|     48|loader_settings_layer_control parse_control_string(char* control_string) {
   81|     48|    loader_settings_layer_control layer_control = LOADER_SETTINGS_LAYER_CONTROL_DEFAULT;
   82|     48|    if (strcmp(control_string, "auto") == 0)
  ------------------
  |  Branch (82:9): [True: 0, False: 48]
  ------------------
   83|      0|        layer_control = LOADER_SETTINGS_LAYER_CONTROL_DEFAULT;
   84|     48|    else if (strcmp(control_string, "on") == 0)
  ------------------
  |  Branch (84:14): [True: 1, False: 47]
  ------------------
   85|      1|        layer_control = LOADER_SETTINGS_LAYER_CONTROL_ON;
   86|     47|    else if (strcmp(control_string, "off") == 0)
  ------------------
  |  Branch (86:14): [True: 10, False: 37]
  ------------------
   87|     10|        layer_control = LOADER_SETTINGS_LAYER_CONTROL_OFF;
   88|     37|    else if (strcmp(control_string, "unordered_layer_location") == 0)
  ------------------
  |  Branch (88:14): [True: 2, False: 35]
  ------------------
   89|      2|        layer_control = LOADER_SETTINGS_LAYER_UNORDERED_LAYER_LOCATION;
   90|     48|    return layer_control;
   91|     48|}
loader_settings_layer_control_to_string:
   93|     20|const char* loader_settings_layer_control_to_string(loader_settings_layer_control control) {
   94|     20|    switch (control) {
   95|      9|        case LOADER_SETTINGS_LAYER_CONTROL_DEFAULT:
  ------------------
  |  Branch (95:9): [True: 9, False: 11]
  ------------------
   96|      9|            return "auto";
   97|      0|        case LOADER_SETTINGS_LAYER_CONTROL_ON:
  ------------------
  |  Branch (97:9): [True: 0, False: 20]
  ------------------
   98|      0|            return "on";
   99|      9|        case LOADER_SETTINGS_LAYER_CONTROL_OFF:
  ------------------
  |  Branch (99:9): [True: 9, False: 11]
  ------------------
  100|      9|            return "off";
  101|      2|        case LOADER_SETTINGS_LAYER_UNORDERED_LAYER_LOCATION:
  ------------------
  |  Branch (101:9): [True: 2, False: 18]
  ------------------
  102|      2|            return "unordered_layer_location";
  103|      0|        default:
  ------------------
  |  Branch (103:9): [True: 0, False: 20]
  ------------------
  104|      0|            return "UNKNOWN_LAYER_CONTROl";
  105|     20|    }
  106|     20|}
parse_log_filters_from_strings:
  108|     34|uint32_t parse_log_filters_from_strings(struct loader_string_list* log_filters) {
  109|     34|    uint32_t filters = 0;
  110|     91|    for (uint32_t i = 0; i < log_filters->count; i++) {
  ------------------
  |  Branch (110:26): [True: 57, False: 34]
  ------------------
  111|     57|        if (strcmp(log_filters->list[i], "all") == 0)
  ------------------
  |  Branch (111:13): [True: 0, False: 57]
  ------------------
  112|      0|            filters |= VULKAN_LOADER_INFO_BIT | VULKAN_LOADER_WARN_BIT | VULKAN_LOADER_PERF_BIT | VULKAN_LOADER_ERROR_BIT |
  113|      0|                       VULKAN_LOADER_DEBUG_BIT | VULKAN_LOADER_LAYER_BIT | VULKAN_LOADER_DRIVER_BIT | VULKAN_LOADER_VALIDATION_BIT;
  114|     57|        else if (strcmp(log_filters->list[i], "info") == 0)
  ------------------
  |  Branch (114:18): [True: 0, False: 57]
  ------------------
  115|      0|            filters |= VULKAN_LOADER_INFO_BIT;
  116|     57|        else if (strcmp(log_filters->list[i], "warn") == 0)
  ------------------
  |  Branch (116:18): [True: 0, False: 57]
  ------------------
  117|      0|            filters |= VULKAN_LOADER_WARN_BIT;
  118|     57|        else if (strcmp(log_filters->list[i], "perf") == 0)
  ------------------
  |  Branch (118:18): [True: 7, False: 50]
  ------------------
  119|      7|            filters |= VULKAN_LOADER_PERF_BIT;
  120|     50|        else if (strcmp(log_filters->list[i], "error") == 0)
  ------------------
  |  Branch (120:18): [True: 7, False: 43]
  ------------------
  121|      7|            filters |= VULKAN_LOADER_ERROR_BIT;
  122|     43|        else if (strcmp(log_filters->list[i], "debug") == 0)
  ------------------
  |  Branch (122:18): [True: 2, False: 41]
  ------------------
  123|      2|            filters |= VULKAN_LOADER_DEBUG_BIT;
  124|     41|        else if (strcmp(log_filters->list[i], "layer") == 0)
  ------------------
  |  Branch (124:18): [True: 2, False: 39]
  ------------------
  125|      2|            filters |= VULKAN_LOADER_LAYER_BIT;
  126|     39|        else if (strcmp(log_filters->list[i], "driver") == 0)
  ------------------
  |  Branch (126:18): [True: 0, False: 39]
  ------------------
  127|      0|            filters |= VULKAN_LOADER_DRIVER_BIT;
  128|     39|        else if (strcmp(log_filters->list[i], "validation") == 0)
  ------------------
  |  Branch (128:18): [True: 0, False: 39]
  ------------------
  129|      0|            filters |= VULKAN_LOADER_VALIDATION_BIT;
  130|     57|    }
  131|     34|    return filters;
  132|     34|}
parse_layer_configuration:
  147|     54|                                   loader_settings_layer_configuration* layer_configuration) {
  148|     54|    char* control_string = NULL;
  149|     54|    VkResult res = loader_parse_json_string(layer_configuration_json, "control", &control_string);
  150|     54|    if (res != VK_SUCCESS) {
  ------------------
  |  Branch (150:9): [True: 6, False: 48]
  ------------------
  151|      6|        goto out;
  152|      6|    }
  153|     48|    layer_configuration->control = parse_control_string(control_string);
  154|     48|    loader_instance_heap_free(inst, control_string);
  155|       |
  156|       |    // If that is the only value - do no further parsing
  157|     48|    if (layer_configuration->control == LOADER_SETTINGS_LAYER_UNORDERED_LAYER_LOCATION) {
  ------------------
  |  Branch (157:9): [True: 2, False: 46]
  ------------------
  158|      2|        goto out;
  159|      2|    }
  160|       |
  161|     46|    res = loader_parse_json_string(layer_configuration_json, "name", &(layer_configuration->name));
  162|     46|    if (res != VK_SUCCESS) {
  ------------------
  |  Branch (162:9): [True: 22, False: 24]
  ------------------
  163|     22|        goto out;
  164|     22|    }
  165|       |
  166|     24|    res = loader_parse_json_string(layer_configuration_json, "path", &(layer_configuration->path));
  167|     24|    if (res != VK_SUCCESS) {
  ------------------
  |  Branch (167:9): [True: 1, False: 23]
  ------------------
  168|      1|        goto out;
  169|      1|    }
  170|       |
  171|     23|    cJSON* treat_as_implicit_manifest = loader_cJSON_GetObjectItem(layer_configuration_json, "treat_as_implicit_manifest");
  172|     23|    if (treat_as_implicit_manifest && treat_as_implicit_manifest->type == cJSON_True) {
  ------------------
  |  |   98|      1|#define cJSON_True (1 << 1)
  ------------------
  |  Branch (172:9): [True: 1, False: 22]
  |  Branch (172:39): [True: 0, False: 1]
  ------------------
  173|      0|        layer_configuration->treat_as_implicit_manifest = true;
  174|      0|    }
  175|     54|out:
  176|     54|    if (VK_SUCCESS != res) {
  ------------------
  |  Branch (176:9): [True: 29, False: 25]
  ------------------
  177|     29|        free_layer_configuration(inst, layer_configuration);
  178|     29|    }
  179|     54|    return res;
  180|     23|}
parse_layer_configurations:
  182|     92|VkResult parse_layer_configurations(const struct loader_instance* inst, cJSON* settings_object, loader_settings* loader_settings) {
  183|     92|    VkResult res = VK_SUCCESS;
  184|       |
  185|     92|    cJSON* layer_configurations = loader_cJSON_GetObjectItem(settings_object, "layers");
  186|       |    // If the layers object isn't present, return early with success to allow the settings file to still apply
  187|     92|    if (NULL == layer_configurations) {
  ------------------
  |  Branch (187:9): [True: 42, False: 50]
  ------------------
  188|     42|        return VK_SUCCESS;
  189|     42|    }
  190|       |
  191|     50|    uint32_t layer_configurations_count = loader_cJSON_GetArraySize(layer_configurations);
  192|     50|    if (layer_configurations_count == 0) {
  ------------------
  |  Branch (192:9): [True: 3, False: 47]
  ------------------
  193|      3|        loader_settings->layer_configurations_active = true;
  194|      3|        return VK_SUCCESS;
  195|      3|    }
  196|       |
  197|     47|    loader_settings->layer_configuration_count = layer_configurations_count;
  198|       |
  199|     47|    loader_settings->layer_configurations = loader_instance_heap_calloc(
  200|     47|        inst, sizeof(loader_settings_layer_configuration) * layer_configurations_count, VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE);
  201|     47|    if (NULL == loader_settings->layer_configurations) {
  ------------------
  |  Branch (201:9): [True: 0, False: 47]
  ------------------
  202|      0|        res = VK_ERROR_OUT_OF_HOST_MEMORY;
  203|      0|        goto out;
  204|      0|    }
  205|       |
  206|     47|    cJSON* layer = NULL;
  207|     47|    size_t i = 0;
  208|     60|    cJSON_ArrayForEach(layer, layer_configurations) {
  ------------------
  |  |  213|     72|    for (element = (array != NULL) ? (array)->child : NULL; element != NULL; element = element->next)
  |  |  ------------------
  |  |  |  Branch (213:20): [True: 47, False: 0]
  |  |  |  Branch (213:61): [True: 60, False: 12]
  |  |  ------------------
  ------------------
  209|     60|        if (layer->type != cJSON_Object) {
  ------------------
  |  |  103|     60|#define cJSON_Object (1 << 6)
  ------------------
  |  Branch (209:13): [True: 6, False: 54]
  ------------------
  210|      6|            res = VK_ERROR_INITIALIZATION_FAILED;
  211|      6|            goto out;
  212|      6|        }
  213|     54|        res = parse_layer_configuration(inst, layer, &(loader_settings->layer_configurations[i++]));
  214|     54|        if (VK_SUCCESS != res) {
  ------------------
  |  Branch (214:13): [True: 29, False: 25]
  ------------------
  215|     29|            goto out;
  216|     29|        }
  217|     54|    }
  218|     12|    loader_settings->layer_configurations_active = true;
  219|     47|out:
  220|     47|    if (res != VK_SUCCESS) {
  ------------------
  |  Branch (220:9): [True: 35, False: 12]
  ------------------
  221|     35|        if (loader_settings->layer_configurations) {
  ------------------
  |  Branch (221:13): [True: 35, False: 0]
  ------------------
  222|    337|            for (size_t index = 0; index < loader_settings->layer_configuration_count; index++) {
  ------------------
  |  Branch (222:36): [True: 302, False: 35]
  ------------------
  223|    302|                free_layer_configuration(inst, &(loader_settings->layer_configurations[index]));
  224|    302|            }
  225|     35|            loader_settings->layer_configuration_count = 0;
  226|     35|            loader_instance_heap_free(inst, loader_settings->layer_configurations);
  227|     35|            loader_settings->layer_configurations = NULL;
  228|     35|        }
  229|     35|    }
  230|       |
  231|     47|    return res;
  232|     12|}
parse_additional_drivers:
  248|     92|VkResult parse_additional_drivers(const struct loader_instance* inst, cJSON* settings_object, loader_settings* loader_settings) {
  249|     92|    VkResult res = VK_SUCCESS;
  250|       |
  251|     92|    cJSON* additional_drivers_use_exclusively_json =
  252|     92|        loader_cJSON_GetObjectItem(settings_object, "additional_drivers_use_exclusively");
  253|     92|    if (additional_drivers_use_exclusively_json && additional_drivers_use_exclusively_json->type == cJSON_True) {
  ------------------
  |  |   98|      0|#define cJSON_True (1 << 1)
  ------------------
  |  Branch (253:9): [True: 0, False: 92]
  |  Branch (253:52): [True: 0, False: 0]
  ------------------
  254|      0|        loader_settings->additional_drivers_use_exclusively = true;
  255|      0|    }
  256|       |
  257|     92|    cJSON* additional_drivers_json = loader_cJSON_GetObjectItem(settings_object, "additional_drivers");
  258|     92|    if (NULL == additional_drivers_json) {
  ------------------
  |  Branch (258:9): [True: 92, False: 0]
  ------------------
  259|     92|        return VK_SUCCESS;
  260|     92|    }
  261|       |
  262|      0|    uint32_t additional_driver_count = loader_cJSON_GetArraySize(additional_drivers_json);
  263|      0|    if (additional_driver_count == 0) {
  ------------------
  |  Branch (263:9): [True: 0, False: 0]
  ------------------
  264|      0|        return VK_SUCCESS;
  265|      0|    }
  266|       |
  267|      0|    loader_settings->additional_driver_count = additional_driver_count;
  268|       |
  269|      0|    loader_settings->additional_drivers = loader_instance_heap_calloc(
  270|      0|        inst, sizeof(loader_settings_driver_configuration) * additional_driver_count, VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE);
  271|      0|    if (NULL == loader_settings->additional_drivers) {
  ------------------
  |  Branch (271:9): [True: 0, False: 0]
  ------------------
  272|      0|        res = VK_ERROR_OUT_OF_HOST_MEMORY;
  273|      0|        goto out;
  274|      0|    }
  275|       |
  276|      0|    cJSON* driver = NULL;
  277|      0|    size_t i = 0;
  278|      0|    cJSON_ArrayForEach(driver, additional_drivers_json) {
  ------------------
  |  |  213|      0|    for (element = (array != NULL) ? (array)->child : NULL; element != NULL; element = element->next)
  |  |  ------------------
  |  |  |  Branch (213:20): [True: 0, False: 0]
  |  |  |  Branch (213:61): [True: 0, False: 0]
  |  |  ------------------
  ------------------
  279|      0|        if (driver->type != cJSON_Object) {
  ------------------
  |  |  103|      0|#define cJSON_Object (1 << 6)
  ------------------
  |  Branch (279:13): [True: 0, False: 0]
  ------------------
  280|      0|            res = VK_ERROR_INITIALIZATION_FAILED;
  281|      0|            goto out;
  282|      0|        }
  283|      0|        res = parse_additional_driver(inst, driver, &(loader_settings->additional_drivers[i++]));
  284|      0|        if (VK_SUCCESS != res) {
  ------------------
  |  Branch (284:13): [True: 0, False: 0]
  ------------------
  285|      0|            goto out;
  286|      0|        }
  287|      0|    }
  288|      0|out:
  289|      0|    if (res != VK_SUCCESS) {
  ------------------
  |  Branch (289:9): [True: 0, False: 0]
  ------------------
  290|      0|        if (loader_settings->additional_drivers) {
  ------------------
  |  Branch (290:13): [True: 0, False: 0]
  ------------------
  291|      0|            for (size_t index = 0; index < loader_settings->additional_driver_count; index++) {
  ------------------
  |  Branch (291:36): [True: 0, False: 0]
  ------------------
  292|      0|                free_driver_configuration(inst, &(loader_settings->additional_drivers[index]));
  293|      0|            }
  294|      0|            loader_settings->additional_driver_count = 0;
  295|      0|            loader_instance_heap_free(inst, loader_settings->additional_drivers);
  296|       |            loader_settings->additional_drivers = NULL;
  297|      0|        }
  298|      0|    }
  299|      0|    return res;
  300|      0|}
parse_device_configurations:
  375|     92|VkResult parse_device_configurations(const struct loader_instance* inst, cJSON* settings_object, loader_settings* loader_settings) {
  376|     92|    VkResult res = VK_SUCCESS;
  377|       |
  378|     92|    cJSON* device_configurations = loader_cJSON_GetObjectItem(settings_object, "device_configurations");
  379|     92|    if (NULL == device_configurations) {
  ------------------
  |  Branch (379:9): [True: 92, False: 0]
  ------------------
  380|     92|        return VK_SUCCESS;
  381|     92|    }
  382|       |
  383|      0|    uint32_t device_configuration_count = loader_cJSON_GetArraySize(device_configurations);
  384|      0|    if (device_configuration_count == 0) {
  ------------------
  |  Branch (384:9): [True: 0, False: 0]
  ------------------
  385|      0|        loader_settings->device_configurations_active = true;
  386|      0|        return VK_SUCCESS;
  387|      0|    }
  388|       |
  389|      0|    loader_settings->device_configuration_count = device_configuration_count;
  390|       |
  391|      0|    loader_settings->device_configurations = loader_instance_heap_calloc(
  392|      0|        inst, sizeof(loader_settings_device_configuration) * device_configuration_count, VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE);
  393|      0|    if (NULL == loader_settings->device_configurations) {
  ------------------
  |  Branch (393:9): [True: 0, False: 0]
  ------------------
  394|      0|        res = VK_ERROR_OUT_OF_HOST_MEMORY;
  395|      0|        goto out;
  396|      0|    }
  397|       |
  398|      0|    cJSON* device = NULL;
  399|      0|    size_t i = 0;
  400|      0|    cJSON_ArrayForEach(device, device_configurations) {
  ------------------
  |  |  213|      0|    for (element = (array != NULL) ? (array)->child : NULL; element != NULL; element = element->next)
  |  |  ------------------
  |  |  |  Branch (213:20): [True: 0, False: 0]
  |  |  |  Branch (213:61): [True: 0, False: 0]
  |  |  ------------------
  ------------------
  401|      0|        if (device->type != cJSON_Object) {
  ------------------
  |  |  103|      0|#define cJSON_Object (1 << 6)
  ------------------
  |  Branch (401:13): [True: 0, False: 0]
  ------------------
  402|      0|            res = VK_ERROR_INITIALIZATION_FAILED;
  403|      0|            goto out;
  404|      0|        }
  405|      0|        res = parse_device_configuration(inst, device, &(loader_settings->device_configurations[i]));
  406|      0|        if (res == VK_ERROR_OUT_OF_HOST_MEMORY) {
  ------------------
  |  Branch (406:13): [True: 0, False: 0]
  ------------------
  407|      0|            goto out;
  408|      0|        } else if (res != VK_SUCCESS) {
  ------------------
  |  Branch (408:20): [True: 0, False: 0]
  ------------------
  409|       |            // Skip a malformed entry rather than discarding every device configuration in the file
  410|      0|            res = VK_SUCCESS;
  411|      0|            continue;
  412|      0|        }
  413|      0|        i++;
  414|      0|    }
  415|       |    // Only the first i entries were successfully parsed; the trailing entries are unpopulated
  416|      0|    loader_settings->device_configuration_count = (uint32_t)i;
  417|      0|    loader_settings->device_configurations_active = true;
  418|      0|out:
  419|      0|    if (res != VK_SUCCESS) {
  ------------------
  |  Branch (419:9): [True: 0, False: 0]
  ------------------
  420|      0|        if (loader_settings->device_configurations) {
  ------------------
  |  Branch (420:13): [True: 0, False: 0]
  ------------------
  421|      0|            for (size_t index = 0; index < loader_settings->device_configuration_count; index++) {
  ------------------
  |  Branch (421:36): [True: 0, False: 0]
  ------------------
  422|      0|                free_device_configuration(inst, &(loader_settings->device_configurations[index]));
  423|      0|            }
  424|      0|            loader_settings->device_configuration_count = 0;
  425|      0|            loader_instance_heap_free(inst, loader_settings->device_configurations);
  426|       |            loader_settings->device_configurations = NULL;
  427|      0|        }
  428|      0|    }
  429|      0|    return res;
  430|      0|}
check_if_settings_path_exists:
  437|  10.5k|                                       char** settings_file_path) {
  438|  10.5k|    if (NULL == base || NULL == suffix) {
  ------------------
  |  Branch (438:9): [True: 4.87k, False: 5.65k]
  |  Branch (438:25): [True: 0, False: 5.65k]
  ------------------
  439|  4.87k|        return VK_ERROR_INITIALIZATION_FAILED;
  440|  4.87k|    }
  441|       |
  442|  5.65k|    size_t base_len = strlen(base);
  443|  5.65k|    size_t suffix_len = strlen(suffix);
  444|       |
  445|  5.65k|    uint32_t start = 0;
  446|  5.65k|    uint32_t stop = 0;
  447|  9.26k|    while (base[start] != '\0' && start < base_len && stop < base_len) {
  ------------------
  |  Branch (447:12): [True: 9.26k, False: 0]
  |  Branch (447:35): [True: 9.26k, False: 0]
  |  Branch (447:55): [True: 5.85k, False: 3.41k]
  ------------------
  448|  5.85k|        start = stop;
  449|  5.85k|        stop = start + 1;
  450|  29.8k|        while (base[stop] != PATH_SEPARATOR && base[stop] != '\0' && stop < base_len) {
  ------------------
  |  |  154|  59.6k|#define PATH_SEPARATOR ':'
  ------------------
  |  Branch (450:16): [True: 29.6k, False: 195]
  |  Branch (450:48): [True: 23.9k, False: 5.65k]
  |  Branch (450:70): [True: 23.9k, False: 0]
  ------------------
  451|  23.9k|            stop++;
  452|  23.9k|        }
  453|       |
  454|  5.85k|        size_t segment_len = (stop - start);
  455|  5.85k|        if (segment_len <= 1) {
  ------------------
  |  Branch (455:13): [True: 0, False: 5.85k]
  ------------------
  456|       |            // segment is *just* a PATH_SEPARATOR, skip it
  457|      0|            continue;
  458|      0|        }
  459|  5.85k|        size_t path_len = segment_len + suffix_len + 1;
  460|  5.85k|        *settings_file_path = loader_instance_heap_calloc(inst, path_len, VK_SYSTEM_ALLOCATION_SCOPE_COMMAND);
  461|  5.85k|        if (NULL == *settings_file_path) {
  ------------------
  |  Branch (461:13): [True: 0, False: 5.85k]
  ------------------
  462|      0|            return VK_ERROR_OUT_OF_HOST_MEMORY;
  463|      0|        }
  464|  5.85k|        loader_strncpy(*settings_file_path, path_len, base + start, segment_len);
  465|  5.85k|        loader_strncat(*settings_file_path, path_len, suffix, suffix_len);
  466|       |
  467|  5.85k|        if (loader_platform_file_exists(*settings_file_path)) {
  ------------------
  |  Branch (467:13): [True: 2.24k, False: 3.60k]
  ------------------
  468|  2.24k|            return VK_SUCCESS;
  469|  2.24k|        }
  470|  3.60k|        loader_instance_heap_free(inst, *settings_file_path);
  471|  3.60k|        *settings_file_path = NULL;
  472|  3.60k|    }
  473|       |
  474|  3.41k|    return VK_ERROR_INITIALIZATION_FAILED;
  475|  5.65k|}
get_unix_settings_path:
  478|  2.43k|VkResult get_unix_settings_path(const struct loader_instance* inst, char** settings_file_path) {
  479|       |    // First, get XDG env-vars we use. Don't need to worry about free'ing because on linux getenv is non-allocating
  480|  2.43k|    char* xdg_config_home = loader_secure_getenv("XDG_CONFIG_HOME", inst);
  481|  2.43k|    char* xdg_config_dirs = loader_secure_getenv("XDG_CONFIG_DIRS", inst);
  482|  2.43k|    char* xdg_data_home = loader_secure_getenv("XDG_DATA_HOME", inst);
  483|  2.43k|    char* xdg_data_dirs = loader_secure_getenv("XDG_DATA_DIRS", inst);
  484|       |
  485|       |    // Use fallback directories for xdg_config_dirs and xdg_data_dirs if they are NULL.
  486|  2.43k|#if !defined(__Fuchsia__) && !defined(__QNX__)
  487|  2.43k|    if (NULL == xdg_config_dirs || '\0' == xdg_config_dirs[0]) {
  ------------------
  |  Branch (487:9): [True: 2.43k, False: 0]
  |  Branch (487:36): [True: 0, False: 0]
  ------------------
  488|  2.43k|        xdg_config_dirs = FALLBACK_CONFIG_DIRS;
  489|  2.43k|    }
  490|  2.43k|#endif
  491|       |
  492|  2.43k|#if !defined(__Fuchsia__) && !defined(__QNX__)
  493|  2.43k|    if (NULL == xdg_data_dirs || '\0' == xdg_data_dirs[0]) {
  ------------------
  |  Branch (493:9): [True: 2.43k, False: 0]
  |  Branch (493:34): [True: 0, False: 0]
  ------------------
  494|  2.43k|        xdg_data_dirs = FALLBACK_DATA_DIRS;
  495|  2.43k|    }
  496|  2.43k|#endif
  497|       |
  498|  2.43k|    VkResult res = check_if_settings_path_exists(
  499|  2.43k|        inst, xdg_config_home, "/" VULKAN_DIR "/loader_settings.d/" VK_LOADER_SETTINGS_FILENAME, settings_file_path);
  ------------------
  |  |  145|  2.43k|#define VK_LOADER_SETTINGS_FILENAME "vk_loader_settings.json"
  ------------------
  500|  2.43k|    if (res == VK_SUCCESS) {
  ------------------
  |  Branch (500:9): [True: 0, False: 2.43k]
  ------------------
  501|      0|        return res;
  502|      0|    }
  503|       |
  504|  2.43k|    res = check_if_settings_path_exists(inst, xdg_data_home, "/" VULKAN_DIR "/loader_settings.d/" VK_LOADER_SETTINGS_FILENAME,
  ------------------
  |  |  145|  2.43k|#define VK_LOADER_SETTINGS_FILENAME "vk_loader_settings.json"
  ------------------
  505|  2.43k|                                        settings_file_path);
  506|  2.43k|    if (res == VK_SUCCESS) {
  ------------------
  |  Branch (506:9): [True: 0, False: 2.43k]
  ------------------
  507|      0|        return res;
  508|      0|    }
  509|       |
  510|       |    // Check home if either xdg_config_home or xdg_data_home wasn't set
  511|  2.43k|    char* home = loader_secure_getenv("HOME", inst);
  512|  2.43k|    if (home != NULL) {
  ------------------
  |  Branch (512:9): [True: 2.43k, False: 0]
  ------------------
  513|  2.43k|        if (NULL == xdg_config_home || '\0' == xdg_config_home[0]) {
  ------------------
  |  Branch (513:13): [True: 2.43k, False: 0]
  |  Branch (513:40): [True: 0, False: 0]
  ------------------
  514|  2.43k|            res = check_if_settings_path_exists(
  515|  2.43k|                inst, home, "/.config/" VULKAN_DIR "/loader_settings.d/" VK_LOADER_SETTINGS_FILENAME, settings_file_path);
  ------------------
  |  |  145|  2.43k|#define VK_LOADER_SETTINGS_FILENAME "vk_loader_settings.json"
  ------------------
  516|  2.43k|            if (res == VK_SUCCESS) {
  ------------------
  |  Branch (516:17): [True: 0, False: 2.43k]
  ------------------
  517|      0|                return res;
  518|      0|            }
  519|  2.43k|        }
  520|  2.43k|        if (NULL == xdg_data_home || '\0' == xdg_data_home[0]) {
  ------------------
  |  Branch (520:13): [True: 2.43k, False: 0]
  |  Branch (520:38): [True: 0, False: 0]
  ------------------
  521|  2.43k|            res = check_if_settings_path_exists(
  522|  2.43k|                inst, home, "/.local/share/" VULKAN_DIR "/loader_settings.d/" VK_LOADER_SETTINGS_FILENAME, settings_file_path);
  ------------------
  |  |  145|  2.43k|#define VK_LOADER_SETTINGS_FILENAME "vk_loader_settings.json"
  ------------------
  523|  2.43k|            if (res == VK_SUCCESS) {
  ------------------
  |  Branch (523:17): [True: 2.24k, False: 195]
  ------------------
  524|  2.24k|                return res;
  525|  2.24k|            }
  526|  2.43k|        }
  527|  2.43k|    }
  528|       |
  529|    195|    res = check_if_settings_path_exists(inst, xdg_config_dirs, "/" VULKAN_DIR "/loader_settings.d/" VK_LOADER_SETTINGS_FILENAME,
  ------------------
  |  |  145|    195|#define VK_LOADER_SETTINGS_FILENAME "vk_loader_settings.json"
  ------------------
  530|    195|                                        settings_file_path);
  531|    195|    if (res == VK_SUCCESS) {
  ------------------
  |  Branch (531:9): [True: 0, False: 195]
  ------------------
  532|      0|        return res;
  533|      0|    }
  534|       |
  535|    195|    res = check_if_settings_path_exists(inst, SYSCONFDIR, "/" VULKAN_DIR "/loader_settings.d/" VK_LOADER_SETTINGS_FILENAME,
  ------------------
  |  |  145|    195|#define VK_LOADER_SETTINGS_FILENAME "vk_loader_settings.json"
  ------------------
  536|    195|                                        settings_file_path);
  537|    195|    if (res == VK_SUCCESS) {
  ------------------
  |  Branch (537:9): [True: 0, False: 195]
  ------------------
  538|      0|        return res;
  539|      0|    }
  540|    195|#if defined(EXTRASYSCONFDIR)
  541|       |
  542|    195|    res = check_if_settings_path_exists(inst, EXTRASYSCONFDIR, "/" VULKAN_DIR "/loader_settings.d/" VK_LOADER_SETTINGS_FILENAME,
  ------------------
  |  |  145|    195|#define VK_LOADER_SETTINGS_FILENAME "vk_loader_settings.json"
  ------------------
  543|    195|                                        settings_file_path);
  544|    195|    if (res == VK_SUCCESS) {
  ------------------
  |  Branch (544:9): [True: 0, False: 195]
  ------------------
  545|      0|        return res;
  546|      0|    }
  547|    195|#endif
  548|    195|    res = check_if_settings_path_exists(inst, xdg_data_dirs, "/" VULKAN_DIR "/loader_settings.d/" VK_LOADER_SETTINGS_FILENAME,
  ------------------
  |  |  145|    195|#define VK_LOADER_SETTINGS_FILENAME "vk_loader_settings.json"
  ------------------
  549|    195|                                        settings_file_path);
  550|    195|    if (res == VK_SUCCESS) {
  ------------------
  |  Branch (550:9): [True: 0, False: 195]
  ------------------
  551|      0|        return res;
  552|      0|    }
  553|       |
  554|    195|    return VK_ERROR_INITIALIZATION_FAILED;
  555|    195|}
check_if_layer_configurations_are_equal:
  558|      5|bool check_if_layer_configurations_are_equal(loader_settings_layer_configuration* a, loader_settings_layer_configuration* b) {
  559|      5|    if (!a->name || !b->name || 0 != strcmp(a->name, b->name)) {
  ------------------
  |  Branch (559:9): [True: 0, False: 5]
  |  Branch (559:21): [True: 0, False: 5]
  |  Branch (559:33): [True: 1, False: 4]
  ------------------
  560|      1|        return false;
  561|      1|    }
  562|      4|    if (!a->path || !b->path || 0 != strcmp(a->path, b->path)) {
  ------------------
  |  Branch (562:9): [True: 0, False: 4]
  |  Branch (562:21): [True: 0, False: 4]
  |  Branch (562:33): [True: 0, False: 4]
  ------------------
  563|      0|        return false;
  564|      0|    }
  565|      4|    return a->control == b->control && a->treat_as_implicit_manifest == b->treat_as_implicit_manifest;
  ------------------
  |  Branch (565:12): [True: 4, False: 0]
  |  Branch (565:40): [True: 4, False: 0]
  ------------------
  566|      4|}
check_if_settings_are_equal:
  588|  2.06k|bool check_if_settings_are_equal(loader_settings* a, loader_settings* b) {
  589|       |    // If either pointer is null, return true
  590|  2.06k|    if (NULL == a || NULL == b) return false;
  ------------------
  |  Branch (590:9): [True: 0, False: 2.06k]
  |  Branch (590:22): [True: 0, False: 2.06k]
  ------------------
  591|  2.06k|    bool are_equal = true;
  592|  2.06k|    are_equal &= a->settings_active == b->settings_active;
  593|  2.06k|    are_equal &= a->has_unordered_layer_location == b->has_unordered_layer_location;
  594|  2.06k|    are_equal &= a->debug_level == b->debug_level;
  595|  2.06k|    are_equal &= a->layer_configurations_active == b->layer_configurations_active;
  596|  2.06k|    are_equal &= a->layer_configuration_count == b->layer_configuration_count;
  597|  2.06k|    are_equal &= a->additional_drivers_use_exclusively == b->additional_drivers_use_exclusively;
  598|  2.06k|    are_equal &= a->additional_driver_count == b->additional_driver_count;
  599|  2.06k|    are_equal &= a->device_configurations_active == b->device_configurations_active;
  600|  2.06k|    are_equal &= a->device_configuration_count == b->device_configuration_count;
  601|  2.06k|    if (!are_equal) return false;
  ------------------
  |  Branch (601:9): [True: 36, False: 2.02k]
  ------------------
  602|  2.03k|    for (uint32_t i = 0; i < a->layer_configuration_count && i < b->layer_configuration_count; i++) {
  ------------------
  |  Branch (602:26): [True: 5, False: 2.02k]
  |  Branch (602:62): [True: 5, False: 0]
  ------------------
  603|      5|        are_equal &= check_if_layer_configurations_are_equal(&a->layer_configurations[i], &b->layer_configurations[i]);
  604|      5|    }
  605|  2.02k|    for (uint32_t i = 0; i < a->additional_driver_count && i < b->additional_driver_count; i++) {
  ------------------
  |  Branch (605:26): [True: 0, False: 2.02k]
  |  Branch (605:60): [True: 0, False: 0]
  ------------------
  606|      0|        are_equal &= check_if_driver_configurations_are_equal(&a->additional_drivers[i], &b->additional_drivers[i]);
  607|      0|    }
  608|  2.02k|    for (uint32_t i = 0; i < a->device_configuration_count && i < b->device_configuration_count; i++) {
  ------------------
  |  Branch (608:26): [True: 0, False: 2.02k]
  |  Branch (608:63): [True: 0, False: 0]
  ------------------
  609|      0|        are_equal &= check_if_device_configurations_are_equal(&a->device_configurations[i], &b->device_configurations[i]);
  610|      0|    }
  611|  2.02k|    return are_equal;
  612|  2.06k|}
log_settings:
  614|     37|void log_settings(const struct loader_instance* inst, loader_settings* settings) {
  615|     37|    if (settings == NULL) {
  ------------------
  |  Branch (615:9): [True: 0, False: 37]
  ------------------
  616|      0|        return;
  617|      0|    }
  618|     37|    loader_log(inst, VULKAN_LOADER_INFO_BIT, 0, "Using layer configurations found in loader settings from %s",
  619|     37|               settings->settings_file_path);
  620|       |
  621|     37|    char cmd_line_msg[64] = {0};
  622|     37|    size_t cmd_line_size = sizeof(cmd_line_msg);
  623|       |
  624|     37|    cmd_line_msg[0] = '\0';
  625|       |
  626|     37|    generate_debug_flag_str(settings->debug_level, cmd_line_size, cmd_line_msg);
  627|     37|    if (strlen(cmd_line_msg)) {
  ------------------
  |  Branch (627:9): [True: 5, False: 32]
  ------------------
  628|      5|        loader_log(inst, VULKAN_LOADER_DEBUG_BIT, 0, "Loader Settings Filters for Logging to Standard Error: %s", cmd_line_msg);
  629|      5|    }
  630|     37|    if (settings->layer_configurations_active) {
  ------------------
  |  Branch (630:9): [True: 14, False: 23]
  ------------------
  631|     14|        loader_log(inst, VULKAN_LOADER_DEBUG_BIT, 0, "Layer Configurations count = %d", settings->layer_configuration_count);
  632|     34|        for (uint32_t i = 0; i < settings->layer_configuration_count; i++) {
  ------------------
  |  Branch (632:30): [True: 20, False: 14]
  ------------------
  633|     20|            loader_log(inst, VULKAN_LOADER_DEBUG_BIT, 0, "---- Layer Configuration [%d] ----", i);
  634|     20|            if (settings->layer_configurations[i].control != LOADER_SETTINGS_LAYER_UNORDERED_LAYER_LOCATION) {
  ------------------
  |  Branch (634:17): [True: 18, False: 2]
  ------------------
  635|     18|                loader_log(inst, VULKAN_LOADER_DEBUG_BIT, 0, "Name: %s", settings->layer_configurations[i].name);
  636|     18|                loader_log(inst, VULKAN_LOADER_DEBUG_BIT, 0, "Path: %s", settings->layer_configurations[i].path);
  637|     18|                loader_log(inst, VULKAN_LOADER_DEBUG_BIT, 0, "Layer Type: %s",
  638|     18|                           settings->layer_configurations[i].treat_as_implicit_manifest ? "Implicit" : "Explicit");
  ------------------
  |  Branch (638:28): [True: 0, False: 18]
  ------------------
  639|     18|            }
  640|     20|            loader_log(inst, VULKAN_LOADER_DEBUG_BIT, 0, "Control: %s",
  641|     20|                       loader_settings_layer_control_to_string(settings->layer_configurations[i].control));
  642|     20|        }
  643|     14|    }
  644|     37|    if (settings->additional_driver_count > 0) {
  ------------------
  |  Branch (644:9): [True: 0, False: 37]
  ------------------
  645|      0|        loader_log(inst, VULKAN_LOADER_DEBUG_BIT, 0, "----");
  646|      0|        loader_log(inst, VULKAN_LOADER_DEBUG_BIT, 0, "Use Additional Drivers Exclusively = %s",
  647|      0|                   settings->additional_drivers_use_exclusively ? "true" : "false");
  ------------------
  |  Branch (647:20): [True: 0, False: 0]
  ------------------
  648|      0|        loader_log(inst, VULKAN_LOADER_DEBUG_BIT, 0, "Additional Driver Configurations count = %d",
  649|      0|                   settings->additional_driver_count);
  650|      0|        for (uint32_t i = 0; i < settings->additional_driver_count; i++) {
  ------------------
  |  Branch (650:30): [True: 0, False: 0]
  ------------------
  651|      0|            loader_log(inst, VULKAN_LOADER_DEBUG_BIT, 0, "---- Driver Configuration [%d] ----", i);
  652|      0|            loader_log(inst, VULKAN_LOADER_DEBUG_BIT, 0, "Path: %s", settings->additional_drivers[i].path);
  653|      0|        }
  654|      0|    }
  655|     37|    if (settings->device_configurations_active) {
  ------------------
  |  Branch (655:9): [True: 0, False: 37]
  ------------------
  656|      0|        loader_log(inst, VULKAN_LOADER_DEBUG_BIT, 0, "----");
  657|      0|        loader_log(inst, VULKAN_LOADER_DEBUG_BIT, 0, "Device Configurations count = %d", settings->device_configuration_count);
  658|      0|        for (uint32_t i = 0; i < settings->device_configuration_count; i++) {
  ------------------
  |  Branch (658:30): [True: 0, False: 0]
  ------------------
  659|      0|            loader_log(inst, VULKAN_LOADER_DEBUG_BIT, 0, "---- Device Configuration [%d] ----", i);
  660|      0|            char device_uuid_str[UUID_STR_LEN] = {0};
  661|      0|            loader_log_generate_uuid_string(settings->device_configurations[i].deviceUUID, device_uuid_str);
  662|      0|            char driver_uuid_str[UUID_STR_LEN] = {0};
  663|      0|            loader_log_generate_uuid_string(settings->device_configurations[i].driverUUID, driver_uuid_str);
  664|      0|            loader_log(inst, VULKAN_LOADER_DEBUG_BIT, 0, "deviceUUID: %s", device_uuid_str);
  665|      0|            loader_log(inst, VULKAN_LOADER_DEBUG_BIT, 0, "driverUUID: %s", driver_uuid_str);
  666|      0|            loader_log(inst, VULKAN_LOADER_DEBUG_BIT, 0, "driverVersion: %d", settings->device_configurations[i].driverVersion);
  667|      0|            if ('\0' != settings->device_configurations[i].deviceName[0]) {
  ------------------
  |  Branch (667:17): [True: 0, False: 0]
  ------------------
  668|      0|                loader_log(inst, VULKAN_LOADER_DEBUG_BIT, 0, "deviceName: %s", settings->device_configurations[i].deviceName);
  669|      0|            }
  670|      0|            if ('\0' != settings->device_configurations[i].driverName[0]) {
  ------------------
  |  Branch (670:17): [True: 0, False: 0]
  ------------------
  671|      0|                loader_log(inst, VULKAN_LOADER_DEBUG_BIT, 0, "driverName: %s", settings->device_configurations[i].driverName);
  672|      0|            }
  673|      0|        }
  674|      0|    }
  675|     37|    loader_log(inst, VULKAN_LOADER_DEBUG_BIT, 0, "---------------------------------");
  676|     37|}
get_loader_settings:
  681|  2.43k|VkResult get_loader_settings(const struct loader_instance* inst, loader_settings* loader_settings) {
  682|  2.43k|    VkResult res = VK_SUCCESS;
  683|  2.43k|    cJSON* json = NULL;
  684|  2.43k|    char* file_format_version_string = NULL;
  685|  2.43k|    char* settings_file_path = NULL;
  686|       |#if defined(WIN32)
  687|       |    res = windows_get_loader_settings_file_path(inst, &settings_file_path);
  688|       |    if (res != VK_SUCCESS) {
  689|       |        loader_log(inst, VULKAN_LOADER_INFO_BIT, 0,
  690|       |                   "No valid vk_loader_settings.json file found, no loader settings will be active");
  691|       |        goto out;
  692|       |    }
  693|       |
  694|       |#elif COMMON_UNIX_PLATFORMS
  695|       |    res = get_unix_settings_path(inst, &settings_file_path);
  696|  2.43k|    if (res != VK_SUCCESS) {
  ------------------
  |  Branch (696:9): [True: 195, False: 2.24k]
  ------------------
  697|    195|        loader_log(inst, VULKAN_LOADER_INFO_BIT, 0,
  698|    195|                   "No valid vk_loader_settings.json file found, no loader settings will be active");
  699|    195|        goto out;
  700|    195|    }
  701|       |#else
  702|       |#warning "Unsupported platform - must specify platform specific location for vk_loader_settings.json"
  703|       |#endif
  704|       |
  705|  2.24k|    res = loader_get_json(inst, settings_file_path, &json);
  706|       |    // Make sure sure the top level json value is an object
  707|  2.24k|    if (res != VK_SUCCESS || NULL == json || json->type != cJSON_Object) {
  ------------------
  |  |  103|    484|#define cJSON_Object (1 << 6)
  ------------------
  |  Branch (707:9): [True: 43, False: 2.20k]
  |  Branch (707:30): [True: 1.71k, False: 484]
  |  Branch (707:46): [True: 222, False: 262]
  ------------------
  708|  1.98k|        goto out;
  709|  1.98k|    }
  710|       |
  711|    262|    res = loader_parse_json_string(json, "file_format_version", &file_format_version_string);
  712|    262|    if (res != VK_SUCCESS) {
  ------------------
  |  Branch (712:9): [True: 13, False: 249]
  ------------------
  713|     13|        if (res != VK_ERROR_OUT_OF_HOST_MEMORY) {
  ------------------
  |  Branch (713:13): [True: 13, False: 0]
  ------------------
  714|     13|            loader_log(
  715|     13|                inst, VULKAN_LOADER_DEBUG_BIT, 0,
  716|     13|                "Loader settings file from %s missing required field file_format_version - no loader settings will be active",
  717|     13|                settings_file_path);
  718|     13|        }
  719|     13|        goto out;
  720|     13|    }
  721|       |
  722|       |    // Because the file may contain either a "settings_array" or a single "settings" object, we need to create a cJSON so that we
  723|       |    // can iterate on both cases with common code
  724|    249|    cJSON settings_iter_parent = {0};
  725|       |
  726|    249|    cJSON* settings_array = loader_cJSON_GetObjectItem(json, "settings_array");
  727|    249|    cJSON* single_settings_object = loader_cJSON_GetObjectItem(json, "settings");
  728|    249|    if (NULL != settings_array) {
  ------------------
  |  Branch (728:9): [True: 90, False: 159]
  ------------------
  729|     90|        memcpy(&settings_iter_parent, settings_array, sizeof(cJSON));
  730|    159|    } else if (NULL != single_settings_object) {
  ------------------
  |  Branch (730:16): [True: 33, False: 126]
  ------------------
  731|     33|        settings_iter_parent.child = single_settings_object;
  732|    126|    } else {
  733|    126|        loader_log(inst, VULKAN_LOADER_DEBUG_BIT, 0,
  734|    126|                   "Loader settings file from %s missing required settings objects: Either one of the \"settings\" or "
  735|    126|                   "\"settings_array\" objects must be present - no loader settings will be active",
  736|    126|                   settings_file_path);
  737|    126|        res = VK_ERROR_INITIALIZATION_FAILED;
  738|    126|        goto out;
  739|    126|    }
  740|       |
  741|       |    // Corresponds to the settings object that has no app keys
  742|    123|    cJSON* global_settings = NULL;
  743|       |    // Corresponds to the settings object which has a matching app key
  744|    123|    cJSON* settings_to_use = NULL;
  745|       |
  746|    123|    char current_process_path[1024];
  747|    123|    bool valid_exe_path = NULL != loader_platform_executable_path(current_process_path, 1024);
  748|       |
  749|    123|    cJSON* settings_object_iter = NULL;
  750|    190|    cJSON_ArrayForEach(settings_object_iter, &settings_iter_parent) {
  ------------------
  |  |  213|    305|    for (element = (array != NULL) ? (array)->child : NULL; element != NULL; element = element->next)
  |  |  ------------------
  |  |  |  Branch (213:20): [True: 123, Folded]
  |  |  |  Branch (213:61): [True: 190, False: 115]
  |  |  ------------------
  ------------------
  751|    190|        if (settings_object_iter->type != cJSON_Object) {
  ------------------
  |  |  103|    190|#define cJSON_Object (1 << 6)
  ------------------
  |  Branch (751:13): [True: 8, False: 182]
  ------------------
  752|      8|            loader_log(inst, VULKAN_LOADER_DEBUG_BIT, 0,
  753|      8|                       "Loader settings file from %s has a settings element that is not an object", settings_file_path);
  754|      8|            break;
  755|      8|        }
  756|       |
  757|    182|        cJSON* app_keys = loader_cJSON_GetObjectItem(settings_object_iter, "app_keys");
  758|    182|        if (NULL == app_keys) {
  ------------------
  |  Branch (758:13): [True: 156, False: 26]
  ------------------
  759|       |            // use the first 'global' settings that has no app keys as the global one
  760|    156|            if (global_settings == NULL) {
  ------------------
  |  Branch (760:17): [True: 92, False: 64]
  ------------------
  761|     92|                global_settings = settings_object_iter;
  762|     92|            }
  763|    156|            continue;
  764|    156|        }
  765|       |        // No sense iterating if we couldn't get the executable path
  766|     26|        if (!valid_exe_path) {
  ------------------
  |  Branch (766:13): [True: 0, False: 26]
  ------------------
  767|      0|            break;
  768|      0|        }
  769|     26|        cJSON* app_key = NULL;
  770|     79|        cJSON_ArrayForEach(app_key, app_keys) {
  ------------------
  |  |  213|    105|    for (element = (array != NULL) ? (array)->child : NULL; element != NULL; element = element->next)
  |  |  ------------------
  |  |  |  Branch (213:20): [True: 26, False: 0]
  |  |  |  Branch (213:61): [True: 79, False: 26]
  |  |  ------------------
  ------------------
  771|     79|            char* app_key_str = loader_cJSON_GetStringValue(app_key);
  772|     79|            if (app_key_str && strcmp(current_process_path, app_key_str) == 0) {
  ------------------
  |  Branch (772:17): [True: 63, False: 16]
  |  Branch (772:32): [True: 0, False: 63]
  ------------------
  773|      0|                settings_to_use = settings_object_iter;
  774|      0|                break;
  775|      0|            }
  776|     79|        }
  777|       |
  778|       |        // Break if we have found a matching current_process_path
  779|     26|        if (NULL != settings_to_use) {
  ------------------
  |  Branch (779:13): [True: 0, False: 26]
  ------------------
  780|      0|            break;
  781|      0|        }
  782|     26|    }
  783|       |
  784|       |    // No app specific settings match - either use global settings or exit
  785|    123|    if (settings_to_use == NULL) {
  ------------------
  |  Branch (785:9): [True: 123, False: 0]
  ------------------
  786|    123|        if (global_settings == NULL) {
  ------------------
  |  Branch (786:13): [True: 31, False: 92]
  ------------------
  787|     31|            loader_log(inst, VULKAN_LOADER_DEBUG_BIT, 0,
  788|     31|                       "Loader settings file from %s missing global settings and none of the app specific settings matched the "
  789|     31|                       "current application - no loader settings will be active",
  790|     31|                       settings_file_path);
  791|     31|            goto out;  // No global settings were found - exit
  792|     92|        } else {
  793|     92|            settings_to_use = global_settings;  // Global settings are present - use it
  794|     92|        }
  795|    123|    }
  796|       |
  797|       |    // optional
  798|     92|    cJSON* stderr_filter = loader_cJSON_GetObjectItem(settings_to_use, "stderr_log");
  799|     92|    if (NULL != stderr_filter) {
  ------------------
  |  Branch (799:9): [True: 34, False: 58]
  ------------------
  800|     34|        struct loader_string_list stderr_log = {0};
  801|     34|        VkResult stderr_log_result = VK_SUCCESS;
  802|     34|        stderr_log_result = loader_parse_json_array_of_strings(inst, settings_to_use, "stderr_log", &stderr_log);
  803|     34|        if (VK_ERROR_OUT_OF_HOST_MEMORY == stderr_log_result) {
  ------------------
  |  Branch (803:13): [True: 0, False: 34]
  ------------------
  804|      0|            res = VK_ERROR_OUT_OF_HOST_MEMORY;
  805|      0|            goto out;
  806|      0|        }
  807|       |        // NOLINTNEXTLINE(clang-analyzer-optin.core.EnumCastOutOfRange) - 0xFF is a valid bitwise-OR of all flags (the "all" filter)
  808|     34|        loader_settings->debug_level = parse_log_filters_from_strings(&stderr_log);
  809|     34|        free_string_list(inst, &stderr_log);
  810|     34|    }
  811|       |
  812|       |    // optional
  813|     92|    cJSON* logs_to_use = loader_cJSON_GetObjectItem(settings_to_use, "log_locations");
  814|     92|    if (NULL != logs_to_use) {
  ------------------
  |  Branch (814:9): [True: 1, False: 91]
  ------------------
  815|      1|        cJSON* log_element = NULL;
  816|      3|        cJSON_ArrayForEach(log_element, logs_to_use) {
  ------------------
  |  |  213|      4|    for (element = (array != NULL) ? (array)->child : NULL; element != NULL; element = element->next)
  |  |  ------------------
  |  |  |  Branch (213:20): [True: 1, False: 0]
  |  |  |  Branch (213:61): [True: 3, False: 1]
  |  |  ------------------
  ------------------
  817|       |            // bool is_valid = true;
  818|      3|            struct loader_string_list log_destinations = {0};
  819|      3|            VkResult parse_dest_res = loader_parse_json_array_of_strings(inst, log_element, "destinations", &log_destinations);
  820|      3|            if (parse_dest_res != VK_SUCCESS) {
  ------------------
  |  Branch (820:17): [True: 3, False: 0]
  ------------------
  821|       |                // is_valid = false;
  822|      3|            }
  823|      3|            free_string_list(inst, &log_destinations);
  824|      3|            struct loader_string_list log_filters = {0};
  825|      3|            VkResult parse_filters_res = loader_parse_json_array_of_strings(inst, log_element, "filters", &log_filters);
  826|      3|            if (parse_filters_res != VK_SUCCESS) {
  ------------------
  |  Branch (826:17): [True: 3, False: 0]
  ------------------
  827|       |                // is_valid = false;
  828|      3|            }
  829|      3|            free_string_list(inst, &log_filters);
  830|      3|        }
  831|      1|    }
  832|       |
  833|     92|    VkResult layer_configurations_res = parse_layer_configurations(inst, settings_to_use, loader_settings);
  834|     92|    if (VK_ERROR_OUT_OF_HOST_MEMORY == layer_configurations_res) {
  ------------------
  |  Branch (834:9): [True: 0, False: 92]
  ------------------
  835|      0|        res = layer_configurations_res;
  836|      0|        goto out;
  837|      0|    }
  838|       |
  839|       |    // Determine if there exists a layer configuration indicating where to put layers not contained in the settings file
  840|       |    // LOADER_SETTINGS_LAYER_UNORDERED_LAYER_LOCATION
  841|    114|    for (uint32_t i = 0; i < loader_settings->layer_configuration_count; i++) {
  ------------------
  |  Branch (841:26): [True: 24, False: 90]
  ------------------
  842|     24|        if (loader_settings->layer_configurations[i].control == LOADER_SETTINGS_LAYER_UNORDERED_LAYER_LOCATION) {
  ------------------
  |  Branch (842:13): [True: 2, False: 22]
  ------------------
  843|      2|            loader_settings->has_unordered_layer_location = true;
  844|      2|            break;
  845|      2|        }
  846|     24|    }
  847|       |
  848|     92|    VkResult additional_drivers_res = parse_additional_drivers(inst, settings_to_use, loader_settings);
  849|     92|    if (VK_ERROR_OUT_OF_HOST_MEMORY == additional_drivers_res) {
  ------------------
  |  Branch (849:9): [True: 0, False: 92]
  ------------------
  850|      0|        res = additional_drivers_res;
  851|      0|        goto out;
  852|      0|    }
  853|       |
  854|     92|    VkResult device_configurations_res = parse_device_configurations(inst, settings_to_use, loader_settings);
  855|     92|    if (VK_ERROR_OUT_OF_HOST_MEMORY == device_configurations_res) {
  ------------------
  |  Branch (855:9): [True: 0, False: 92]
  ------------------
  856|      0|        res = device_configurations_res;
  857|      0|        goto out;
  858|      0|    }
  859|       |
  860|       |    // Only consider the settings active if there is at least one "setting" active.
  861|       |    // Those are either logging, layers, additional_drivers, or device_configurations.
  862|     92|    if (loader_settings->debug_level != 0 || loader_settings->layer_configurations_active ||
  ------------------
  |  Branch (862:9): [True: 5, False: 87]
  |  Branch (862:46): [True: 15, False: 72]
  ------------------
  863|     72|        loader_settings->additional_driver_count != 0 || loader_settings->device_configurations_active) {
  ------------------
  |  Branch (863:9): [True: 0, False: 72]
  |  Branch (863:58): [True: 0, False: 72]
  ------------------
  864|     20|        loader_settings->settings_file_path = settings_file_path;
  865|     20|        settings_file_path = NULL;
  866|     20|        loader_settings->settings_active = true;
  867|     72|    } else {
  868|     72|        loader_log(inst, VULKAN_LOADER_INFO_BIT, 0,
  869|     72|                   "vk_loader_settings.json file found at \"%s\" but did not contain any valid settings.", settings_file_path);
  870|     72|    }
  871|  2.43k|out:
  872|  2.43k|    if (NULL != json) {
  ------------------
  |  Branch (872:9): [True: 484, False: 1.95k]
  ------------------
  873|    484|        loader_cJSON_Delete(json);
  874|    484|    }
  875|       |
  876|  2.43k|    loader_instance_heap_free(inst, settings_file_path);
  877|       |
  878|  2.43k|    loader_instance_heap_free(inst, file_format_version_string);
  879|  2.43k|    return res;
  880|     92|}
update_global_loader_settings:
  882|  2.43k|TEST_FUNCTION_EXPORT VkResult update_global_loader_settings(void) {
  883|  2.43k|    loader_settings settings = {0};
  884|  2.43k|    VkResult res = get_loader_settings(NULL, &settings);
  885|  2.43k|    loader_platform_thread_lock_mutex(&global_loader_settings_lock);
  886|       |
  887|  2.43k|    if (res == VK_SUCCESS) {
  ------------------
  |  Branch (887:9): [True: 2.06k, False: 377]
  ------------------
  888|  2.06k|        if (!check_if_settings_are_equal(&settings, &global_loader_settings)) {
  ------------------
  |  Branch (888:13): [True: 37, False: 2.02k]
  ------------------
  889|     37|            log_settings(NULL, &settings);
  890|     37|        }
  891|  2.06k|        free_loader_settings(NULL, &global_loader_settings);
  892|  2.06k|        memcpy(&global_loader_settings, &settings, sizeof(loader_settings));
  893|  2.06k|        if (global_loader_settings.settings_active && global_loader_settings.debug_level > 0) {
  ------------------
  |  Branch (893:13): [True: 20, False: 2.04k]
  |  Branch (893:55): [True: 5, False: 15]
  ------------------
  894|      5|            loader_set_global_debug_level(global_loader_settings.debug_level);
  895|      5|        }
  896|  2.06k|    }
  897|  2.43k|    loader_platform_thread_unlock_mutex(&global_loader_settings_lock);
  898|  2.43k|    return res;
  899|  2.43k|}
init_global_loader_settings:
  901|      2|void init_global_loader_settings(void) {
  902|      2|    loader_platform_thread_create_mutex(&global_loader_settings_lock);
  903|       |    // Free out the global settings in case the process was loaded & unloaded
  904|       |    free_loader_settings(NULL, &global_loader_settings);
  905|      2|}
get_current_settings_and_lock:
  921|  4.87k|const loader_settings* get_current_settings_and_lock(const struct loader_instance* inst) {
  922|  4.87k|    if (inst) {
  ------------------
  |  Branch (922:9): [True: 0, False: 4.87k]
  ------------------
  923|      0|        return &inst->settings;
  924|      0|    }
  925|  4.87k|    loader_platform_thread_lock_mutex(&global_loader_settings_lock);
  926|  4.87k|    return &global_loader_settings;
  927|  4.87k|}
release_current_settings_lock:
  929|  4.87k|void release_current_settings_lock(const struct loader_instance* inst) {
  930|  4.87k|    if (inst == NULL) {
  ------------------
  |  Branch (930:9): [True: 4.87k, False: 0]
  ------------------
  931|  4.87k|        loader_platform_thread_unlock_mutex(&global_loader_settings_lock);
  932|  4.87k|    }
  933|  4.87k|}
get_settings_layers:
  936|  4.87k|                                                  bool* should_search_for_other_layers) {
  937|  4.87k|    VkResult res = VK_SUCCESS;
  938|  4.87k|    *should_search_for_other_layers = true;  // default to true
  939|       |
  940|  4.87k|    const loader_settings* settings = get_current_settings_and_lock(inst);
  941|       |
  942|  4.87k|    if (NULL == settings || !settings->settings_active || !settings->layer_configurations_active) {
  ------------------
  |  Branch (942:9): [True: 0, False: 4.87k]
  |  Branch (942:29): [True: 4.82k, False: 50]
  |  Branch (942:59): [True: 12, False: 38]
  ------------------
  943|  4.83k|        goto out;
  944|  4.83k|    }
  945|       |
  946|       |    // Assume the list doesn't contain LOADER_SETTINGS_LAYER_UNORDERED_LAYER_LOCATION at first
  947|     38|    *should_search_for_other_layers = false;
  948|       |
  949|    102|    for (uint32_t i = 0; i < settings->layer_configuration_count; i++) {
  ------------------
  |  Branch (949:26): [True: 64, False: 38]
  ------------------
  950|     64|        loader_settings_layer_configuration* layer_config = &settings->layer_configurations[i];
  951|       |
  952|       |        // If we encountered a layer that should be forced off, we add it to the settings_layers list but only
  953|       |        // with the data required to compare it with layers not in the settings file (aka name and manifest path)
  954|     64|        if (layer_config->control == LOADER_SETTINGS_LAYER_CONTROL_OFF) {
  ------------------
  |  Branch (954:13): [True: 28, False: 36]
  ------------------
  955|     28|            struct loader_layer_properties props = {0};
  956|     28|            props.settings_control_value = LOADER_SETTINGS_LAYER_CONTROL_OFF;
  957|     28|            loader_strncpy(props.info.layerName, VK_MAX_EXTENSION_NAME_SIZE, layer_config->name, VK_MAX_EXTENSION_NAME_SIZE);
  958|     28|            props.info.layerName[VK_MAX_EXTENSION_NAME_SIZE - 1] = '\0';
  959|     28|            res = loader_copy_to_new_str(inst, layer_config->path, &props.manifest_file_name);
  960|     28|            if (VK_ERROR_OUT_OF_HOST_MEMORY == res) {
  ------------------
  |  Branch (960:17): [True: 0, False: 28]
  ------------------
  961|      0|                goto out;
  962|      0|            }
  963|     28|            res = loader_append_layer_property(inst, settings_layers, &props);
  964|     28|            if (VK_ERROR_OUT_OF_HOST_MEMORY == res) {
  ------------------
  |  Branch (964:17): [True: 0, False: 28]
  ------------------
  965|      0|                loader_free_layer_properties(inst, &props);
  966|      0|                goto out;
  967|      0|            }
  968|     28|            continue;
  969|     28|        }
  970|       |
  971|       |        // The special layer location that indicates where unordered layers should go only should have the
  972|       |        // settings_control_value set - everything else should be NULL
  973|     36|        if (layer_config->control == LOADER_SETTINGS_LAYER_UNORDERED_LAYER_LOCATION) {
  ------------------
  |  Branch (973:13): [True: 8, False: 28]
  ------------------
  974|      8|            struct loader_layer_properties props = {0};
  975|      8|            props.settings_control_value = LOADER_SETTINGS_LAYER_UNORDERED_LAYER_LOCATION;
  976|      8|            res = loader_append_layer_property(inst, settings_layers, &props);
  977|      8|            if (VK_ERROR_OUT_OF_HOST_MEMORY == res) {
  ------------------
  |  Branch (977:17): [True: 0, False: 8]
  ------------------
  978|      0|                loader_free_layer_properties(inst, &props);
  979|      0|                goto out;
  980|      0|            }
  981|      8|            *should_search_for_other_layers = true;
  982|      8|            continue;
  983|      8|        }
  984|       |
  985|     28|        if (layer_config->path == NULL) {
  ------------------
  |  Branch (985:13): [True: 0, False: 28]
  ------------------
  986|      0|            continue;
  987|      0|        }
  988|       |
  989|     28|        if (!is_json(layer_config->path, strlen(layer_config->path))) {
  ------------------
  |  Branch (989:13): [True: 26, False: 2]
  ------------------
  990|     26|            continue;
  991|     26|        }
  992|       |
  993|      2|        cJSON* json = NULL;
  994|      2|        VkResult local_res = loader_get_json(inst, layer_config->path, &json);
  995|      2|        if (VK_ERROR_OUT_OF_HOST_MEMORY == local_res) {
  ------------------
  |  Branch (995:13): [True: 0, False: 2]
  ------------------
  996|      0|            res = VK_ERROR_OUT_OF_HOST_MEMORY;
  997|      0|            goto out;
  998|      2|        } else if (VK_SUCCESS != local_res || NULL == json) {
  ------------------
  |  Branch (998:20): [True: 2, False: 0]
  |  Branch (998:47): [True: 0, False: 0]
  ------------------
  999|      2|            continue;
 1000|      2|        }
 1001|       |
 1002|       |        // Makes it possible to know if a new layer was added or not, since the only return value is VkResult
 1003|      0|        uint32_t count_before_adding = settings_layers->count;
 1004|       |
 1005|      0|        local_res =
 1006|      0|            loader_add_layer_properties(inst, settings_layers, json, layer_config->treat_as_implicit_manifest, layer_config->path);
 1007|      0|        loader_cJSON_Delete(json);
 1008|       |
 1009|       |        // If the error is anything other than out of memory we still want to try to load the other layers
 1010|      0|        if (VK_ERROR_OUT_OF_HOST_MEMORY == local_res) {
  ------------------
  |  Branch (1010:13): [True: 0, False: 0]
  ------------------
 1011|      0|            res = VK_ERROR_OUT_OF_HOST_MEMORY;
 1012|      0|            goto out;
 1013|      0|        } else if (local_res != VK_SUCCESS || count_before_adding == settings_layers->count) {
  ------------------
  |  Branch (1013:20): [True: 0, False: 0]
  |  Branch (1013:47): [True: 0, False: 0]
  ------------------
 1014|       |            // Indicates something was wrong with the layer, can't add it to the list
 1015|      0|            continue;
 1016|      0|        }
 1017|       |
 1018|      0|        for (uint32_t j = count_before_adding; j < settings_layers->count; j++) {
  ------------------
  |  Branch (1018:48): [True: 0, False: 0]
  ------------------
 1019|      0|            struct loader_layer_properties* newly_added_layer = &settings_layers->list[j];
 1020|      0|            newly_added_layer->settings_control_value = layer_config->control;
 1021|       |            // If the manifest file found has a name that differs from the one in the settings, remove this layer from
 1022|       |            // consideration
 1023|      0|            if (strncmp(newly_added_layer->info.layerName, layer_config->name, VK_MAX_EXTENSION_NAME_SIZE) != 0) {
  ------------------
  |  Branch (1023:17): [True: 0, False: 0]
  ------------------
 1024|      0|                loader_remove_layer_in_list(inst, settings_layers, j);
 1025|      0|                j--;
 1026|      0|                continue;
 1027|      0|            }
 1028|      0|            bool should_remove = false;
 1029|       |            // Make sure the layer isn't already in the list
 1030|      0|            for (uint32_t k = 0; k < j; k++) {
  ------------------
  |  Branch (1030:34): [True: 0, False: 0]
  ------------------
 1031|      0|                if (0 == strncmp(settings_layers->list[k].info.layerName, newly_added_layer->info.layerName,
  ------------------
  |  Branch (1031:21): [True: 0, False: 0]
  ------------------
 1032|      0|                                 VK_MAX_EXTENSION_NAME_SIZE)) {
 1033|      0|                    if (0 == (newly_added_layer->type_flags & VK_LAYER_TYPE_FLAG_META_LAYER) &&
  ------------------
  |  Branch (1033:25): [True: 0, False: 0]
  ------------------
 1034|      0|                        settings_layers->list[k].lib_name != NULL && newly_added_layer->lib_name != NULL &&
  ------------------
  |  Branch (1034:25): [True: 0, False: 0]
  |  Branch (1034:70): [True: 0, False: 0]
  ------------------
 1035|      0|                        strcmp(settings_layers->list[k].lib_name, newly_added_layer->lib_name) == 0) {
  ------------------
  |  Branch (1035:25): [True: 0, False: 0]
  ------------------
 1036|      0|                        should_remove = true;
 1037|      0|                        break;
 1038|      0|                    }
 1039|      0|                }
 1040|      0|            }
 1041|      0|            if (should_remove) {
  ------------------
  |  Branch (1041:17): [True: 0, False: 0]
  ------------------
 1042|      0|                loader_remove_layer_in_list(inst, settings_layers, j);
 1043|      0|                j--;
 1044|      0|            }
 1045|      0|        }
 1046|      0|    }
 1047|       |
 1048|  4.87k|out:
 1049|  4.87k|    release_current_settings_lock(inst);
 1050|  4.87k|    return res;
 1051|     38|}
combine_settings_layers_with_regular_layers:
 1085|  4.84k|                                                     struct loader_layer_list* output_layers) {
 1086|  4.84k|    VkResult res = VK_SUCCESS;
 1087|  4.84k|    bool has_unordered_layer_location = false;
 1088|  4.84k|    uint32_t unordered_layer_location_index = 0;
 1089|       |    // Location to put layers that aren't known to the settings file
 1090|       |    // Find it here so we dont have to pass in a loader_settings struct
 1091|  4.85k|    for (uint32_t i = 0; i < settings_layers->count; i++) {
  ------------------
  |  Branch (1091:26): [True: 11, False: 4.84k]
  ------------------
 1092|     11|        if (settings_layers->list[i].settings_control_value == LOADER_SETTINGS_LAYER_UNORDERED_LAYER_LOCATION) {
  ------------------
  |  Branch (1092:13): [True: 4, False: 7]
  ------------------
 1093|      4|            has_unordered_layer_location = true;
 1094|      4|            unordered_layer_location_index = i;
 1095|      4|            break;
 1096|      4|        }
 1097|     11|    }
 1098|       |
 1099|  4.84k|    if (settings_layers->count == 0 && regular_layers->count == 0) {
  ------------------
  |  Branch (1099:9): [True: 4.84k, False: 4]
  |  Branch (1099:40): [True: 4.80k, False: 34]
  ------------------
 1100|       |        // No layers to combine
 1101|  4.80k|        goto out;
 1102|  4.80k|    } else if (settings_layers->count == 0) {
  ------------------
  |  Branch (1102:16): [True: 34, False: 4]
  ------------------
 1103|       |        // No settings layers - just copy regular to output_layers - memset regular layers to prevent double frees
 1104|     34|        *output_layers = *regular_layers;
 1105|     34|        memset(regular_layers, 0, sizeof(struct loader_layer_list));
 1106|     34|        goto out;
 1107|     34|    } else if (regular_layers->count == 0 || !has_unordered_layer_location) {
  ------------------
  |  Branch (1107:16): [True: 4, False: 0]
  |  Branch (1107:46): [True: 0, False: 0]
  ------------------
 1108|       |        // No regular layers or has_unordered_layer_location is false - just copy settings to output_layers -
 1109|       |        // memset settings layers to prevent double frees
 1110|      4|        *output_layers = *settings_layers;
 1111|      4|        memset(settings_layers, 0, sizeof(struct loader_layer_list));
 1112|      4|        goto out;
 1113|      4|    }
 1114|       |
 1115|      0|    res = loader_init_generic_list(inst, (struct loader_generic_list*)output_layers,
 1116|      0|                                   (settings_layers->count + regular_layers->count) * sizeof(struct loader_layer_properties));
 1117|      0|    if (VK_SUCCESS != res) {
  ------------------
  |  Branch (1117:9): [True: 0, False: 0]
  ------------------
 1118|      0|        goto out;
 1119|      0|    }
 1120|       |
 1121|       |    // Insert the settings layers into output_layers up to unordered_layer_index
 1122|      0|    for (uint32_t i = 0; i < unordered_layer_location_index; i++) {
  ------------------
  |  Branch (1122:26): [True: 0, False: 0]
  ------------------
 1123|      0|        if (!check_if_layer_is_in_list(output_layers, &settings_layers->list[i], true)) {
  ------------------
  |  Branch (1123:13): [True: 0, False: 0]
  ------------------
 1124|      0|            res = loader_append_layer_property(inst, output_layers, &settings_layers->list[i]);
 1125|      0|            if (VK_SUCCESS != res) {
  ------------------
  |  Branch (1125:17): [True: 0, False: 0]
  ------------------
 1126|      0|                goto out;
 1127|      0|            }
 1128|      0|        }
 1129|      0|    }
 1130|       |
 1131|      0|    for (uint32_t i = 0; i < regular_layers->count; i++) {
  ------------------
  |  Branch (1131:26): [True: 0, False: 0]
  ------------------
 1132|       |        // Check if its already been put in the output_layers list as well as the remaining settings_layers
 1133|      0|        bool regular_layer_is_ordered = check_if_layer_is_in_list(output_layers, &regular_layers->list[i], false) ||
  ------------------
  |  Branch (1133:41): [True: 0, False: 0]
  ------------------
 1134|      0|                                        check_if_layer_is_in_list(settings_layers, &regular_layers->list[i], false);
  ------------------
  |  Branch (1134:41): [True: 0, False: 0]
  ------------------
 1135|       |        // If it isn't found, add it
 1136|      0|        if (!regular_layer_is_ordered) {
  ------------------
  |  Branch (1136:13): [True: 0, False: 0]
  ------------------
 1137|      0|            res = loader_append_layer_property(inst, output_layers, &regular_layers->list[i]);
 1138|      0|            if (VK_SUCCESS != res) {
  ------------------
  |  Branch (1138:17): [True: 0, False: 0]
  ------------------
 1139|      0|                goto out;
 1140|      0|            }
 1141|      0|        } else {
 1142|       |            // layer is already ordered and can be safely freed
 1143|      0|            loader_free_layer_properties(inst, &regular_layers->list[i]);
 1144|      0|        }
 1145|      0|    }
 1146|       |
 1147|       |    // Insert the rest of the settings layers into combined_layers from  unordered_layer_index to the end
 1148|       |    // start at one after the unordered_layer_index
 1149|      0|    for (uint32_t i = unordered_layer_location_index + 1; i < settings_layers->count; i++) {
  ------------------
  |  Branch (1149:59): [True: 0, False: 0]
  ------------------
 1150|      0|        if (!check_if_layer_is_in_list(output_layers, &settings_layers->list[i], true)) {
  ------------------
  |  Branch (1150:13): [True: 0, False: 0]
  ------------------
 1151|      0|            res = loader_append_layer_property(inst, output_layers, &settings_layers->list[i]);
 1152|      0|            if (VK_SUCCESS != res) {
  ------------------
  |  Branch (1152:17): [True: 0, False: 0]
  ------------------
 1153|      0|                goto out;
 1154|      0|            }
 1155|      0|        }
 1156|      0|    }
 1157|       |
 1158|  4.84k|out:
 1159|  4.84k|    if (res != VK_SUCCESS) {
  ------------------
  |  Branch (1159:9): [True: 0, False: 4.84k]
  ------------------
 1160|      0|        loader_delete_layer_list_and_properties(inst, output_layers);
 1161|      0|    }
 1162|       |
 1163|  4.84k|    return res;
 1164|      0|}

vkEnumerateInstanceExtensionProperties:
  164|  2.43k|                                                                                    VkExtensionProperties *pProperties) {
  165|  2.43k|    LOADER_PLATFORM_THREAD_ONCE(&once_init, loader_initialize);
  166|       |
  167|  2.43k|    update_global_loader_settings();
  168|       |
  169|       |    // We know we need to call at least the terminator
  170|  2.43k|    VkResult res = VK_SUCCESS;
  171|  2.43k|    VkEnumerateInstanceExtensionPropertiesChain chain_tail = {
  172|  2.43k|        .header =
  173|  2.43k|            {
  174|  2.43k|                .type = VK_CHAIN_TYPE_ENUMERATE_INSTANCE_EXTENSION_PROPERTIES,
  175|  2.43k|                .version = VK_CURRENT_CHAIN_VERSION,
  176|  2.43k|                .size = sizeof(chain_tail),
  177|  2.43k|            },
  178|  2.43k|        .pfnNextLayer = &terminator_pre_instance_EnumerateInstanceExtensionProperties,
  179|  2.43k|        .pNextLink = NULL,
  180|  2.43k|    };
  181|  2.43k|    VkEnumerateInstanceExtensionPropertiesChain *chain_head = &chain_tail;
  182|       |
  183|       |    // Get the implicit layers
  184|  2.43k|    struct loader_layer_list layers = {0};
  185|  2.43k|    memset(&layers, 0, sizeof(layers));
  186|  2.43k|    struct loader_envvar_all_filters layer_filters = {0};
  187|       |
  188|  2.43k|    res = parse_layer_environment_var_filters(NULL, &layer_filters);
  189|  2.43k|    if (VK_SUCCESS != res) {
  ------------------
  |  Branch (189:9): [True: 0, False: 2.43k]
  ------------------
  190|      0|        return res;
  191|      0|    }
  192|       |
  193|  2.43k|    res = loader_scan_for_implicit_layers(NULL, &layers, &layer_filters);
  194|  2.43k|    if (VK_SUCCESS != res) {
  ------------------
  |  Branch (194:9): [True: 0, False: 2.43k]
  ------------------
  195|      0|        return res;
  196|      0|    }
  197|       |
  198|       |    // Prepend layers onto the chain if they implement this entry point
  199|  2.45k|    for (uint32_t i = 0; i < layers.count; ++i) {
  ------------------
  |  Branch (199:26): [True: 12, False: 2.43k]
  ------------------
  200|       |        // Skip this layer if it doesn't expose the entry-point
  201|     12|        if (NULL == layers.list[i].pre_instance_functions.enumerate_instance_extension_properties) {
  ------------------
  |  Branch (201:13): [True: 12, False: 0]
  ------------------
  202|     12|            continue;
  203|     12|        }
  204|       |
  205|      0|        loader_open_layer_file(NULL, &layers.list[i]);
  206|      0|        if (layers.list[i].lib_handle == NULL) {
  ------------------
  |  Branch (206:13): [True: 0, False: 0]
  ------------------
  207|      0|            continue;
  208|      0|        }
  209|       |
  210|      0|        void *pfn = loader_platform_get_proc_address(layers.list[i].lib_handle,
  211|      0|                                                     layers.list[i].pre_instance_functions.enumerate_instance_extension_properties);
  212|      0|        if (pfn == NULL) {
  ------------------
  |  Branch (212:13): [True: 0, False: 0]
  ------------------
  213|      0|            loader_log(NULL, VULKAN_LOADER_WARN_BIT | VULKAN_LOADER_LAYER_BIT, 0,
  214|      0|                       "%s: Unable to resolve symbol \"%s\" in implicit layer library \"%s\"", __FUNCTION__,
  215|      0|                       layers.list[i].pre_instance_functions.enumerate_instance_extension_properties, layers.list[i].lib_name);
  216|      0|            continue;
  217|      0|        }
  218|       |
  219|      0|        VkEnumerateInstanceExtensionPropertiesChain *chain_link =
  220|      0|            loader_alloc(NULL, sizeof(VkEnumerateInstanceExtensionPropertiesChain), VK_SYSTEM_ALLOCATION_SCOPE_COMMAND);
  221|      0|        if (chain_link == NULL) {
  ------------------
  |  Branch (221:13): [True: 0, False: 0]
  ------------------
  222|      0|            res = VK_ERROR_OUT_OF_HOST_MEMORY;
  223|      0|            break;
  224|      0|        }
  225|      0|        memset(chain_link, 0, sizeof(VkEnumerateInstanceLayerPropertiesChain));
  226|      0|        chain_link->header.type = VK_CHAIN_TYPE_ENUMERATE_INSTANCE_EXTENSION_PROPERTIES;
  227|      0|        chain_link->header.version = VK_CURRENT_CHAIN_VERSION;
  228|      0|        chain_link->header.size = sizeof(*chain_link);
  229|      0|        chain_link->pfnNextLayer = pfn;
  230|      0|        chain_link->pNextLink = chain_head;
  231|       |
  232|      0|        chain_head = chain_link;
  233|      0|    }
  234|       |
  235|       |    // Call down the chain
  236|  2.43k|    if (res == VK_SUCCESS) {
  ------------------
  |  Branch (236:9): [True: 2.43k, False: 0]
  ------------------
  237|  2.43k|        res = chain_head->pfnNextLayer(chain_head->pNextLink, pLayerName, pPropertyCount, pProperties);
  238|  2.43k|    }
  239|       |
  240|       |    // Free up the layers
  241|  2.43k|    loader_delete_layer_list_and_properties(NULL, &layers);
  242|       |
  243|       |    // Tear down the chain
  244|  2.43k|    while (chain_head != &chain_tail) {
  ------------------
  |  Branch (244:12): [True: 0, False: 2.43k]
  ------------------
  245|      0|        VkEnumerateInstanceExtensionPropertiesChain *holder = chain_head;
  246|      0|        chain_head = (VkEnumerateInstanceExtensionPropertiesChain *)chain_head->pNextLink;
  247|      0|        loader_free(NULL, holder);
  248|      0|    }
  249|       |
  250|  2.43k|    return res;
  251|  2.43k|}

loader.c:loader_strncpy:
  467|  22.5k|static inline char *loader_strncpy(char *dest, size_t dest_sz, const char *src, size_t count) {
  468|  22.5k|    (void)dest_sz;
  469|  22.5k|    return strncpy(dest, src, count);
  470|  22.5k|}
loader.c:thread_safe_strtok:
  460|  4.32k|static inline void *thread_safe_strtok(char *str, const char *delim, char **saveptr) { return strtok_r(str, delim, saveptr); }
loader.c:loader_platform_thread_create_mutex:
  450|      4|static inline void loader_platform_thread_create_mutex(loader_platform_thread_mutex *pMutex) {
  451|      4|    pthread_mutexattr_t attr;
  452|      4|    pthread_mutexattr_init(&attr);
  453|      4|    pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);
  454|      4|    pthread_mutex_init(pMutex, &attr);
  455|      4|}
loader.c:loader_platform_is_path_absolute:
  296|    366|static inline bool loader_platform_is_path_absolute(const char *path) {
  297|    366|    if (path[0] == '/') return true;
  ------------------
  |  Branch (297:9): [True: 0, False: 366]
  ------------------
  298|    366|    return false;
  299|    366|}
loader.c:loader_platform_is_path:
  252|  13.0k|static inline bool loader_platform_is_path(const char *path) { return strchr(path, DIRECTORY_SYMBOL) != NULL; }
  ------------------
  |  |  155|  13.0k|#define DIRECTORY_SYMBOL '/'
  ------------------
loader.c:loader_platform_file_exists:
  289|  13.0k|static inline bool loader_platform_file_exists(const char *path) {
  290|  13.0k|    if (access(path, F_OK)) return false;
  ------------------
  |  Branch (290:9): [True: 47, False: 13.0k]
  ------------------
  291|  13.0k|    return true;
  292|  13.0k|}
loader.c:loader_platform_executable_path:
  307|  4.84k|static inline char *loader_platform_executable_path(char *buffer, size_t size) {
  308|  4.84k|    ssize_t count = readlink("/proc/self/exe", buffer, size);
  309|  4.84k|    if (count == -1) return NULL;
  ------------------
  |  Branch (309:9): [True: 0, False: 4.84k]
  ------------------
  310|  4.84k|    if (count == 0) return NULL;
  ------------------
  |  Branch (310:9): [True: 0, False: 4.84k]
  ------------------
  311|       |    // readlink does not append a null terminator and returns up to size bytes, so a target of size or more
  312|       |    // would leave no room for the terminator and buffer[count] would write past the end.
  313|  4.84k|    if ((size_t)count >= size) return NULL;
  ------------------
  |  Branch (313:9): [True: 0, False: 4.84k]
  ------------------
  314|  4.84k|    buffer[count] = '\0';
  315|  4.84k|    return buffer;
  316|  4.84k|}
loader_environment.c:thread_safe_strtok:
  460|  9.75k|static inline void *thread_safe_strtok(char *str, const char *delim, char **saveptr) { return strtok_r(str, delim, saveptr); }
loader_environment.c:loader_strncpy:
  467|  4.87k|static inline char *loader_strncpy(char *dest, size_t dest_sz, const char *src, size_t count) {
  468|  4.87k|    (void)dest_sz;
  469|  4.87k|    return strncpy(dest, src, count);
  470|  4.87k|}
log.c:loader_strncat:
  463|  72.5k|static inline char *loader_strncat(char *dest, size_t dest_sz, const char *src, size_t count) {
  464|  72.5k|    (void)dest_sz;
  465|  72.5k|    return strncat(dest, src, count);
  466|  72.5k|}
settings.c:loader_strncpy:
  467|  5.87k|static inline char *loader_strncpy(char *dest, size_t dest_sz, const char *src, size_t count) {
  468|  5.87k|    (void)dest_sz;
  469|  5.87k|    return strncpy(dest, src, count);
  470|  5.87k|}
settings.c:loader_strncat:
  463|  5.85k|static inline char *loader_strncat(char *dest, size_t dest_sz, const char *src, size_t count) {
  464|  5.85k|    (void)dest_sz;
  465|  5.85k|    return strncat(dest, src, count);
  466|  5.85k|}
settings.c:loader_platform_file_exists:
  289|  5.85k|static inline bool loader_platform_file_exists(const char *path) {
  290|  5.85k|    if (access(path, F_OK)) return false;
  ------------------
  |  Branch (290:9): [True: 3.60k, False: 2.24k]
  ------------------
  291|  2.24k|    return true;
  292|  5.85k|}
settings.c:loader_platform_executable_path:
  307|    123|static inline char *loader_platform_executable_path(char *buffer, size_t size) {
  308|    123|    ssize_t count = readlink("/proc/self/exe", buffer, size);
  309|    123|    if (count == -1) return NULL;
  ------------------
  |  Branch (309:9): [True: 0, False: 123]
  ------------------
  310|    123|    if (count == 0) return NULL;
  ------------------
  |  Branch (310:9): [True: 0, False: 123]
  ------------------
  311|       |    // readlink does not append a null terminator and returns up to size bytes, so a target of size or more
  312|       |    // would leave no room for the terminator and buffer[count] would write past the end.
  313|    123|    if ((size_t)count >= size) return NULL;
  ------------------
  |  Branch (313:9): [True: 0, False: 123]
  ------------------
  314|    123|    buffer[count] = '\0';
  315|    123|    return buffer;
  316|    123|}
settings.c:loader_platform_thread_lock_mutex:
  456|  7.31k|static inline void loader_platform_thread_lock_mutex(loader_platform_thread_mutex *pMutex) { pthread_mutex_lock(pMutex); }
settings.c:loader_platform_thread_unlock_mutex:
  457|  7.31k|static inline void loader_platform_thread_unlock_mutex(loader_platform_thread_mutex *pMutex) { pthread_mutex_unlock(pMutex); }
settings.c:loader_platform_thread_create_mutex:
  450|      2|static inline void loader_platform_thread_create_mutex(loader_platform_thread_mutex *pMutex) {
  451|      2|    pthread_mutexattr_t attr;
  452|      2|    pthread_mutexattr_init(&attr);
  453|      2|    pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);
  454|      2|    pthread_mutex_init(pMutex, &attr);
  455|      2|}

wsi_unsupported_instance_extension:
  280|      4|bool wsi_unsupported_instance_extension(const VkExtensionProperties *ext_prop) {
  281|       |#if !defined(VK_USE_PLATFORM_WAYLAND_KHR)
  282|       |    if (!strcmp(ext_prop->extensionName, "VK_KHR_wayland_surface")) return true;
  283|       |#endif  // VK_USE_PLATFORM_WAYLAND_KHR
  284|       |#if !defined(VK_USE_PLATFORM_XCB_KHR)
  285|       |    if (!strcmp(ext_prop->extensionName, "VK_KHR_xcb_surface")) return true;
  286|       |#endif  // VK_USE_PLATFORM_XCB_KHR
  287|       |#if !defined(VK_USE_PLATFORM_XLIB_KHR)
  288|       |    if (!strcmp(ext_prop->extensionName, "VK_KHR_xlib_surface")) return true;
  289|       |#endif  // VK_USE_PLATFORM_XLIB_KHR
  290|      4|#if !defined(VK_USE_PLATFORM_DIRECTFB_EXT)
  291|      4|    if (!strcmp(ext_prop->extensionName, "VK_EXT_directfb_surface")) return true;
  ------------------
  |  Branch (291:9): [True: 0, False: 4]
  ------------------
  292|      4|#endif  // VK_USE_PLATFORM_DIRECTFB_EXT
  293|      4|#if !defined(VK_USE_PLATFORM_SCREEN_QNX)
  294|      4|    if (!strcmp(ext_prop->extensionName, "VK_QNX_screen_surface")) return true;
  ------------------
  |  Branch (294:9): [True: 0, False: 4]
  ------------------
  295|      4|#endif  // VK_USE_PLATFORM_SCREEN_QNX
  296|       |
  297|      4|    return false;
  298|      4|}

