fuzz_init:
   25|  6.58k|void fuzz_init(const uint8_t *data, size_t size) {
   26|  6.58k|    global_fuzz_data = (uint8_t *)data;
   27|  6.58k|    global_size = size;
   28|       |    
   29|  6.58k|    callback1 = NULL;
   30|  6.58k|    callback2 = NULL;
   31|  6.58k|    callback3 = NULL;
   32|       |    callback4 = NULL;
   33|  6.58k|}
create_callback_file:
   36|  5.80k|void create_callback_file(const char *filename) {
   37|  5.80k|  fprintf(stderr, "create_callback_file: Creating file %s\n", filename);
   38|  5.80k|  FILE *fp = fopen(filename, "wb");
   39|  5.80k|  if (!fp) {
  ------------------
  |  Branch (39:7): [True: 598, False: 5.21k]
  ------------------
   40|    598|    return;
   41|    598|  }
   42|  5.21k|  fwrite(global_fuzz_data, global_size, 1, fp);
   43|  5.21k|  fclose(fp);
   44|       |
   45|  5.21k|  if (callback1 == NULL) {
  ------------------
  |  Branch (45:7): [True: 2.17k, False: 3.03k]
  ------------------
   46|  2.17k|    callback1 = strdup(filename);
   47|  3.03k|  } else if (callback2 == NULL) {
  ------------------
  |  Branch (47:14): [True: 1.39k, False: 1.63k]
  ------------------
   48|  1.39k|    callback2 = strdup(filename);
   49|  1.63k|  } else if (callback3 == NULL) {
  ------------------
  |  Branch (49:14): [True: 892, False: 747]
  ------------------
   50|    892|    callback3 = strdup(filename);
   51|    892|  } else if (callback4 == NULL) {
  ------------------
  |  Branch (51:14): [True: 224, False: 523]
  ------------------
   52|    224|    callback4 = strdup(filename);
   53|    523|  } else {
   54|       |    fprintf(stderr, "create_callback_file: Too many callbacks created, ignoring %s\n", filename);
   55|    523|  }
   56|  5.21k|}
fuzz_cleanup:
   62|  6.58k|void fuzz_cleanup() {
   63|  6.58k|  if (callback1) {
  ------------------
  |  Branch (63:7): [True: 2.17k, False: 4.41k]
  ------------------
   64|  2.17k| unlink(callback1);    
   65|  2.17k|    free(callback1);
   66|       |   
   67|  2.17k|    callback1 = NULL;
   68|  2.17k|  }
   69|  6.58k|  if (callback2) {
  ------------------
  |  Branch (69:7): [True: 1.39k, False: 5.19k]
  ------------------
   70|  1.39k| unlink(callback2);    
   71|  1.39k|    free(callback2);
   72|  1.39k|    callback2 = NULL;
   73|  1.39k|  }
   74|  6.58k|  if (callback3) {
  ------------------
  |  Branch (74:7): [True: 892, False: 5.69k]
  ------------------
   75|    892| unlink(callback3);      
   76|    892|    free(callback3);
   77|    892|    callback3 = NULL;
   78|    892|  }
   79|  6.58k|  if (callback4) {
  ------------------
  |  Branch (79:7): [True: 224, False: 6.36k]
  ------------------
   80|    224|     unlink(callback4);
   81|    224|    free(callback4);
   82|       |    callback4 = NULL;
   83|    224|  }
   84|  6.58k|}

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|  system("mkdir -p $HOME/.local/share/vulkan/icd.d");
   27|      2|  return 0;
   28|      2|}
create_config_file:
   33|  19.7k|int create_config_file(const char* config_path, const char* config_filename, const uint8_t* data, size_t size) {
   34|  19.7k|  char filename[512];
   35|  19.7k|  char path[256];
   36|       |  // char command[256];
   37|       |
   38|  19.7k|  sprintf(path, "%s/%s", getenv("HOME"), config_path);
   39|       |  //sprintf(command, "mkdir -p %s", path);
   40|       |
   41|       |  //system(command);
   42|       |
   43|  19.7k|  sprintf(filename, "%s/%s", path, config_filename);
   44|       |
   45|  19.7k|  FILE *fp = fopen(filename, "wb");
   46|  19.7k|  if (!fp) {
  ------------------
  |  Branch (46:7): [True: 0, False: 19.7k]
  ------------------
   47|      0|    return 1;
   48|      0|  }
   49|  19.7k|  fwrite(data, size, 1, fp);
   50|  19.7k|  fclose(fp);
   51|       |
   52|  19.7k|  return 0;
   53|  19.7k|}
remove_config_file:
   58|  19.7k|void remove_config_file(const char* config_path, const char* config_filename) {
   59|  19.7k|  char filename[512];
   60|  19.7k|  sprintf(filename, "%s/%s/%s", getenv("HOME"), config_path, config_filename);
   61|  19.7k|  unlink(filename);
   62|  19.7k|}
LLVMFuzzerTestOneInput:
   67|  6.61k|int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
   68|  6.61k|  if (size < 3*sizeof(size_t)) {
  ------------------
  |  Branch (68:7): [True: 8, False: 6.60k]
  ------------------
   69|      8|    return 0;
   70|      8|  }
   71|       |
   72|       |  // Split the loaders into two different parts so the files
   73|       |  // are independently seeded with fuzz data.
   74|  6.60k|  size_t first_size = (*(size_t*)data) % 40000;
   75|  6.60k|  size_t second_size = (*(size_t*)(data + sizeof(size_t))) % 40000;
   76|  6.60k|  size_t third_size = (*(size_t*)(data + 2*sizeof(size_t))) % 40000;
   77|       |
   78|  6.60k|  data += 3*sizeof(size_t); // Move past the first two integers
   79|  6.60k|  size -= 3*sizeof(size_t); // Adjust size to account for the first two integers
   80|  6.60k|  size_t total_size_needed = first_size + second_size + third_size;
   81|  6.60k|  if (size <= total_size_needed) {
  ------------------
  |  Branch (81:7): [True: 18, False: 6.58k]
  ------------------
   82|     18|    return 0;
   83|     18|  }
   84|  6.58k|  int result = create_config_file(".local/share/vulkan/implicit_layer.d", "complex_layer.json", data, first_size);
   85|  6.58k|  if (result) {
  ------------------
  |  Branch (85:7): [True: 0, False: 6.58k]
  ------------------
   86|      0|    return 0;
   87|      0|  }
   88|       |
   89|  6.58k|  data += first_size;
   90|  6.58k|  size -= first_size;
   91|  6.58k|  result = create_config_file(".local/share/vulkan/loader_settings.d", "vk_loader_settings.json", data, second_size);
   92|  6.58k|  if (result) {
  ------------------
  |  Branch (92:7): [True: 0, False: 6.58k]
  ------------------
   93|      0|    return 0;
   94|      0|  }
   95|       |
   96|  6.58k|  data += second_size;
   97|  6.58k|  size -= second_size;
   98|  6.58k|  result = create_config_file(".local/share/vulkan/loader_settings.d", "icd_test.json", data, third_size);
   99|  6.58k|  if (result) {
  ------------------
  |  Branch (99:7): [True: 0, False: 6.58k]
  ------------------
  100|      0|    return 0;
  101|      0|  }
  102|  6.58k|  data += third_size;
  103|  6.58k|  size -= third_size;
  104|       |
  105|  6.58k|  fuzz_init(data, size);
  106|       |
  107|  6.58k|  setenv("VK_LOADER_LAYERS_ENABLE", "all", 1);
  108|       |
  109|       |
  110|  6.58k|  VkInstance inst = {0};
  111|  6.58k|  char *instance_layers[] = {
  112|  6.58k|    "VK_LAYER_KHRONOS_validation",
  113|  6.58k|    "VK_LAYER_test_layer_1",
  114|  6.58k|    "VK_LAYER_test_layer_2"
  115|  6.58k|  };
  116|  6.58k|  const VkApplicationInfo app = {
  117|  6.58k|      .sType = VK_STRUCTURE_TYPE_APPLICATION_INFO,
  118|  6.58k|      .pNext = NULL,
  119|  6.58k|      .pApplicationName = "TEST_APP",
  120|  6.58k|      .applicationVersion = 0,
  121|  6.58k|      .pEngineName = "TEST_ENGINE",
  122|  6.58k|      .engineVersion = 0,
  123|  6.58k|      .apiVersion = VK_API_VERSION_1_0,
  ------------------
  |  |   81|  6.58k|#define VK_API_VERSION_1_0 VK_MAKE_API_VERSION(0, 1, 0, 0)// Patch version should always be set to 0
  |  |  ------------------
  |  |  |  |   60|  6.58k|    ((((uint32_t)(variant)) << 29U) | (((uint32_t)(major)) << 22U) | (((uint32_t)(minor)) << 12U) | ((uint32_t)(patch)))
  |  |  ------------------
  ------------------
  124|  6.58k|  };
  125|  6.58k|  VkInstanceCreateInfo inst_info = {
  126|  6.58k|      .sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO,
  127|  6.58k|      .pNext = NULL,
  128|  6.58k|      .pApplicationInfo = &app,
  129|  6.58k|      .enabledLayerCount = 1,
  130|  6.58k|      .ppEnabledLayerNames = (const char *const *)instance_layers,
  131|  6.58k|      .enabledExtensionCount = 0,
  132|  6.58k|      .ppEnabledExtensionNames = NULL,
  133|  6.58k|  };
  134|  6.58k|  VkResult err = vkCreateInstance(&inst_info, NULL, &inst);
  135|  6.58k|  if (err != VK_SUCCESS) {
  ------------------
  |  Branch (135:7): [True: 6.58k, False: 0]
  ------------------
  136|  6.58k|    goto out;
  137|  6.58k|  }
  138|      0|  else {
  139|       |
  140|      0|  }
  141|       |
  142|      0|  vkDestroyInstance(inst, NULL);
  143|       |
  144|  6.58k|out:
  145|       |  // Clean up config files
  146|  6.58k|  remove_config_file(".local/share/vulkan/implicit_layer.d", "complex_layer.json");
  147|  6.58k|  remove_config_file(".local/share/vulkan/loader_settings.d", "vk_loader_settings.json");
  148|  6.58k|  remove_config_file(".local/share/vulkan/icd.d", "icd_test.json");
  149|       |
  150|       |
  151|  6.58k|  fuzz_cleanup();
  152|       |
  153|  6.58k|  return 0;
  154|      0|}

loader_alloc:
   34|      2|void *loader_alloc(const VkAllocationCallbacks *pAllocator, size_t size, VkSystemAllocationScope allocation_scope) {
   35|      2|    void *pMemory = NULL;
   36|       |#if (DEBUG_DISABLE_APP_ALLOCATORS == 1)
   37|       |    {
   38|       |#else
   39|      2|    if (pAllocator && pAllocator->pfnAllocation) {
  ------------------
  |  Branch (39:9): [True: 2, False: 0]
  |  Branch (39:23): [True: 0, False: 2]
  ------------------
   40|       |        // These are internal structures, so it's best to align everything to
   41|       |        // the largest unit size which is the size of a uint64_t.
   42|      0|        pMemory = pAllocator->pfnAllocation(pAllocator->pUserData, size, sizeof(uint64_t), allocation_scope);
   43|      2|    } else {
   44|      2|#endif
   45|      2|        pMemory = malloc(size);
   46|      2|    }
   47|       |
   48|      2|    return pMemory;
   49|      2|}
loader_calloc:
   51|  14.0M|void *loader_calloc(const VkAllocationCallbacks *pAllocator, size_t size, VkSystemAllocationScope allocation_scope) {
   52|  14.0M|    void *pMemory = NULL;
   53|       |#if (DEBUG_DISABLE_APP_ALLOCATORS == 1)
   54|       |    {
   55|       |#else
   56|  14.0M|    if (pAllocator && pAllocator->pfnAllocation) {
  ------------------
  |  Branch (56:9): [True: 14.0M, False: 6.58k]
  |  Branch (56:23): [True: 0, False: 14.0M]
  ------------------
   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|  14.0M|    } else {
   64|  14.0M|#endif
   65|  14.0M|        pMemory = calloc(1, size);
   66|  14.0M|    }
   67|       |
   68|  14.0M|    return pMemory;
   69|  14.0M|}
loader_free:
   71|  21.0M|void loader_free(const VkAllocationCallbacks *pAllocator, void *pMemory) {
   72|  21.0M|    if (pMemory != NULL) {
  ------------------
  |  Branch (72:9): [True: 14.0M, False: 7.05M]
  ------------------
   73|       |#if (DEBUG_DISABLE_APP_ALLOCATORS == 1)
   74|       |        {
   75|       |#else
   76|  14.0M|        if (pAllocator && pAllocator->pfnFree) {
  ------------------
  |  Branch (76:13): [True: 14.0M, False: 0]
  |  Branch (76:27): [True: 0, False: 14.0M]
  ------------------
   77|      0|            pAllocator->pfnFree(pAllocator->pUserData, pMemory);
   78|  14.0M|        } else {
   79|  14.0M|#endif
   80|  14.0M|            free(pMemory);
   81|  14.0M|        }
   82|  14.0M|    }
   83|  21.0M|}
loader_realloc:
   86|   298k|                     VkSystemAllocationScope allocation_scope) {
   87|   298k|    void *pNewMem = NULL;
   88|   298k|    if (pMemory == NULL || orig_size == 0) {
  ------------------
  |  Branch (88:9): [True: 0, False: 298k]
  |  Branch (88:28): [True: 0, False: 298k]
  ------------------
   89|      0|        pNewMem = loader_alloc(pAllocator, size, allocation_scope);
   90|   298k|    } else if (size == 0) {
  ------------------
  |  Branch (90:16): [True: 0, False: 298k]
  ------------------
   91|      0|        loader_free(pAllocator, pMemory);
   92|       |#if (DEBUG_DISABLE_APP_ALLOCATORS == 1)
   93|       |#else
   94|   298k|    } else if (pAllocator && pAllocator->pfnReallocation) {
  ------------------
  |  Branch (94:16): [True: 298k, False: 0]
  |  Branch (94:30): [True: 0, False: 298k]
  ------------------
   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|   298k|    } else {
  100|   298k|        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|   298k|        if (NULL != pNewMem && size > orig_size) {
  ------------------
  |  Branch (103:13): [True: 298k, False: 0]
  |  Branch (103:32): [True: 3.38k, False: 294k]
  ------------------
  104|  3.38k|            memset((uint8_t *)pNewMem + orig_size, 0, size - orig_size);
  105|  3.38k|        }
  106|   298k|    }
  107|   298k|    return pNewMem;
  108|   298k|}
loader_instance_heap_alloc:
  110|      2|void *loader_instance_heap_alloc(const struct loader_instance *inst, size_t size, VkSystemAllocationScope allocation_scope) {
  111|      2|    return loader_alloc(inst ? &inst->alloc_callbacks : NULL, size, allocation_scope);
  ------------------
  |  Branch (111:25): [True: 2, False: 0]
  ------------------
  112|      2|}
loader_instance_heap_calloc:
  114|   852k|void *loader_instance_heap_calloc(const struct loader_instance *inst, size_t size, VkSystemAllocationScope allocation_scope) {
  115|   852k|    return loader_calloc(inst ? &inst->alloc_callbacks : NULL, size, allocation_scope);
  ------------------
  |  Branch (115:26): [True: 852k, False: 0]
  ------------------
  116|   852k|}
loader_instance_heap_free:
  118|  8.21M|void loader_instance_heap_free(const struct loader_instance *inst, void *pMemory) {
  119|  8.21M|    loader_free(inst ? &inst->alloc_callbacks : NULL, pMemory);
  ------------------
  |  Branch (119:17): [True: 8.21M, False: 2]
  ------------------
  120|  8.21M|}
loader_instance_heap_realloc:
  122|  1.38k|                                   VkSystemAllocationScope allocation_scope) {
  123|  1.38k|    return loader_realloc(inst ? &inst->alloc_callbacks : NULL, pMemory, orig_size, size, allocation_scope);
  ------------------
  |  Branch (123:27): [True: 1.38k, False: 0]
  ------------------
  124|  1.38k|}

loader_cJSON_GetStringValue:
   98|  1.35M|CJSON_PUBLIC(char *) loader_cJSON_GetStringValue(const cJSON *const item) {
   99|  1.35M|    if (!loader_cJSON_IsString(item)) {
  ------------------
  |  Branch (99:9): [True: 320k, False: 1.03M]
  ------------------
  100|   320k|        return NULL;
  101|   320k|    }
  102|       |
  103|  1.03M|    return item->valuestring;
  104|  1.35M|}
loader_cJSON_Delete:
  151|  1.00M|TEST_FUNCTION_EXPORT CJSON_PUBLIC(void) loader_cJSON_Delete(cJSON *item) {
  152|  1.00M|    cJSON *next = NULL;
  153|  5.97M|    while (item != NULL) {
  ------------------
  |  Branch (153:12): [True: 4.97M, False: 1.00M]
  ------------------
  154|  4.97M|        next = item->next;
  155|  4.97M|        if (!(item->type & cJSON_IsReference) && (item->child != NULL)) {
  ------------------
  |  |  106|  4.97M|#define cJSON_IsReference 256
  ------------------
  |  Branch (155:13): [True: 4.97M, False: 0]
  |  Branch (155:50): [True: 733k, False: 4.24M]
  ------------------
  156|   733k|            loader_cJSON_Delete(item->child);
  157|   733k|        }
  158|  4.97M|        if (!(item->type & cJSON_IsReference) && (item->valuestring != NULL)) {
  ------------------
  |  |  106|  4.97M|#define cJSON_IsReference 256
  ------------------
  |  Branch (158:13): [True: 4.97M, False: 0]
  |  Branch (158:50): [True: 3.89M, False: 1.08M]
  ------------------
  159|  3.89M|            loader_free(item->pAllocator, item->valuestring);
  160|  3.89M|            item->valuestring = NULL;
  161|  3.89M|        }
  162|  4.97M|        if (!(item->type & cJSON_StringIsConst) && (item->string != NULL)) {
  ------------------
  |  |  107|  4.97M|#define cJSON_StringIsConst 512
  ------------------
  |  Branch (162:13): [True: 4.97M, False: 0]
  |  Branch (162:52): [True: 3.94M, False: 1.03M]
  ------------------
  163|  3.94M|            loader_free(item->pAllocator, item->string);
  164|       |            item->string = NULL;
  165|  3.94M|        }
  166|  4.97M|        loader_free(item->pAllocator, item);
  167|  4.97M|        item = next;
  168|  4.97M|    }
  169|  1.00M|}
loader_cJSON_ParseWithLengthOpts:
  848|  23.7k|                                 const char **return_parse_end, cJSON_bool require_null_terminated, bool *out_of_memory) {
  849|  23.7k|    parse_buffer buffer = {0, 0, 0, 0, 0};
  850|  23.7k|    cJSON *item = NULL;
  851|       |
  852|       |    /* reset error position */
  853|       |    // global_error.json = NULL;
  854|       |    // global_error.position = 0;
  855|       |
  856|  23.7k|    if (value == NULL || 0 == buffer_length) {
  ------------------
  |  Branch (856:9): [True: 0, False: 23.7k]
  |  Branch (856:26): [True: 0, False: 23.7k]
  ------------------
  857|      0|        goto fail;
  858|      0|    }
  859|       |
  860|  23.7k|    buffer.content = (const unsigned char *)value;
  861|  23.7k|    buffer.length = buffer_length;
  862|  23.7k|    buffer.offset = 0;
  863|  23.7k|    buffer.pAllocator = pAllocator;
  864|       |
  865|  23.7k|    item = cJSON_New_Item(pAllocator);
  866|  23.7k|    if (item == NULL) /* memory fail */
  ------------------
  |  Branch (866:9): [True: 0, False: 23.7k]
  ------------------
  867|      0|    {
  868|      0|        *out_of_memory = true;
  ------------------
  |  |   67|      0|#define true ((cJSON_bool)1)
  ------------------
  869|      0|        goto fail;
  870|      0|    }
  871|       |
  872|  23.7k|    if (!parse_value(item, buffer_skip_whitespace(skip_utf8_bom(&buffer)), out_of_memory)) {
  ------------------
  |  Branch (872:9): [True: 9.22k, False: 14.5k]
  ------------------
  873|       |        /* parse failure. ep is set. */
  874|  9.22k|        goto fail;
  875|  9.22k|    }
  876|       |
  877|       |    /* if we require null-terminated JSON without appended garbage, skip and then check for a null terminator */
  878|  14.5k|    if (require_null_terminated) {
  ------------------
  |  Branch (878:9): [True: 0, False: 14.5k]
  ------------------
  879|      0|        buffer_skip_whitespace(&buffer);
  880|      0|        if ((buffer.offset >= buffer.length) || buffer_at_offset(&buffer)[0] != '\0') {
  ------------------
  |  |  195|      0|#define buffer_at_offset(buffer) ((buffer)->content + (buffer)->offset)
  ------------------
  |  Branch (880:13): [True: 0, False: 0]
  |  Branch (880:49): [True: 0, False: 0]
  ------------------
  881|      0|            goto fail;
  882|      0|        }
  883|      0|    }
  884|  14.5k|    if (return_parse_end) {
  ------------------
  |  Branch (884:9): [True: 0, False: 14.5k]
  ------------------
  885|      0|        *return_parse_end = (const char *)buffer_at_offset(&buffer);
  ------------------
  |  |  195|      0|#define buffer_at_offset(buffer) ((buffer)->content + (buffer)->offset)
  ------------------
  886|      0|    }
  887|       |
  888|  14.5k|    return item;
  889|       |
  890|  9.22k|fail:
  891|  9.22k|    if (item != NULL) {
  ------------------
  |  Branch (891:9): [True: 9.22k, False: 0]
  ------------------
  892|  9.22k|        loader_cJSON_Delete(item);
  893|  9.22k|    }
  894|       |
  895|  9.22k|    if (value != NULL) {
  ------------------
  |  Branch (895:9): [True: 9.22k, False: 0]
  ------------------
  896|  9.22k|        error local_error;
  897|  9.22k|        local_error.json = (const unsigned char *)value;
  898|  9.22k|        local_error.position = 0;
  899|       |
  900|  9.22k|        if (buffer.offset < buffer.length) {
  ------------------
  |  Branch (900:13): [True: 9.01k, False: 212]
  ------------------
  901|  9.01k|            local_error.position = buffer.offset;
  902|  9.01k|        } else if (buffer.length > 0) {
  ------------------
  |  Branch (902:20): [True: 212, False: 0]
  ------------------
  903|    212|            local_error.position = buffer.length - 1;
  904|    212|        }
  905|       |
  906|  9.22k|        if (return_parse_end != NULL) {
  ------------------
  |  Branch (906:13): [True: 0, False: 9.22k]
  ------------------
  907|      0|            *return_parse_end = (const char *)local_error.json + local_error.position;
  908|      0|        }
  909|       |
  910|       |        // global_error = local_error;
  911|  9.22k|    }
  912|       |
  913|       |    return NULL;
  914|  14.5k|}
loader_cJSON_ParseWithLength:
  923|  23.7k|                             bool *out_of_memory) {
  924|  23.7k|    return loader_cJSON_ParseWithLengthOpts(pAllocator, value, buffer_length, 0, 0, out_of_memory);
  925|  23.7k|}
loader_cJSON_Print:
  977|   294k|TEST_FUNCTION_EXPORT CJSON_PUBLIC(char *) loader_cJSON_Print(const cJSON *item, bool *out_of_memory) {
  978|   294k|    return (char *)print(item, true, out_of_memory);
  ------------------
  |  |   67|   294k|#define true ((cJSON_bool)1)
  ------------------
  979|   294k|}
loader_cJSON_PrintPreallocated:
 1014|   709k|    loader_cJSON_PrintPreallocated(cJSON *item, char *buffer, const int length, const cJSON_bool format) {
 1015|   709k|    printbuffer p = {0, 0, 0, 0, 0, 0, 0};
 1016|       |
 1017|   709k|    if ((length < 0) || (buffer == NULL)) {
  ------------------
  |  Branch (1017:9): [True: 0, False: 709k]
  |  Branch (1017:25): [True: 0, False: 709k]
  ------------------
 1018|      0|        return false;
  ------------------
  |  |   72|      0|#define false ((cJSON_bool)0)
  ------------------
 1019|      0|    }
 1020|       |
 1021|   709k|    p.buffer = (unsigned char *)buffer;
 1022|   709k|    p.length = (size_t)length;
 1023|   709k|    p.offset = 0;
 1024|   709k|    p.noalloc = true;
  ------------------
  |  |   67|   709k|#define true ((cJSON_bool)1)
  ------------------
 1025|   709k|    p.format = format;
 1026|   709k|    p.pAllocator = item->pAllocator;
 1027|   709k|    bool out_of_memory = false;
  ------------------
  |  |   72|   709k|#define false ((cJSON_bool)0)
  ------------------
 1028|   709k|    return print_value(item, &p, &out_of_memory);
 1029|   709k|}
loader_cJSON_GetArraySize:
 1489|  52.1k|CJSON_PUBLIC(int) loader_cJSON_GetArraySize(const cJSON *array) {
 1490|  52.1k|    cJSON *child = NULL;
 1491|  52.1k|    size_t size = 0;
 1492|       |
 1493|  52.1k|    if (array == NULL) {
  ------------------
  |  Branch (1493:9): [True: 0, False: 52.1k]
  ------------------
 1494|      0|        return 0;
 1495|      0|    }
 1496|       |
 1497|  52.1k|    child = array->child;
 1498|       |
 1499|   146k|    while (child != NULL) {
  ------------------
  |  Branch (1499:12): [True: 94.3k, False: 52.1k]
  ------------------
 1500|  94.3k|        size++;
 1501|  94.3k|        child = child->next;
 1502|  94.3k|    }
 1503|       |
 1504|       |    /* FIXME: Can overflow here. Cannot be fixed without breaking the API */
 1505|       |
 1506|  52.1k|    return (int)size;
 1507|  52.1k|}
loader_cJSON_GetObjectItem:
 1559|  4.12M|CJSON_PUBLIC(cJSON *) loader_cJSON_GetObjectItem(const cJSON *const object, const char *const string) {
 1560|  4.12M|    return get_object_item(object, string, false);
  ------------------
  |  |   72|  4.12M|#define false ((cJSON_bool)0)
  ------------------
 1561|  4.12M|}
loader_cJSON_IsString:
 1702|  1.35M|CJSON_PUBLIC(cJSON_bool) loader_cJSON_IsString(const cJSON *const item) {
 1703|  1.35M|    if (item == NULL) {
  ------------------
  |  Branch (1703:9): [True: 319k, False: 1.03M]
  ------------------
 1704|   319k|        return false;
  ------------------
  |  |   72|   319k|#define false ((cJSON_bool)0)
  ------------------
 1705|   319k|    }
 1706|       |
 1707|  1.03M|    return (item->type & 0xFF) == cJSON_String;
  ------------------
  |  |  101|  1.03M|#define cJSON_String (1 << 4)
  ------------------
 1708|  1.35M|}
cJSON.c:cJSON_New_Item:
  142|  4.97M|static cJSON *cJSON_New_Item(const VkAllocationCallbacks *pAllocator) {
  143|  4.97M|    cJSON *node = (cJSON *)loader_calloc(pAllocator, sizeof(cJSON), VK_SYSTEM_ALLOCATION_SCOPE_COMMAND);
  144|  4.97M|    if (NULL != node) {
  ------------------
  |  Branch (144:9): [True: 4.97M, False: 0]
  ------------------
  145|  4.97M|        node->pAllocator = pAllocator;
  146|  4.97M|    }
  147|  4.97M|    return node;
  148|  4.97M|}
cJSON.c:buffer_skip_whitespace:
  796|  18.5M|static parse_buffer *buffer_skip_whitespace(parse_buffer *const buffer) {
  797|  18.5M|    if ((buffer == NULL) || (buffer->content == NULL)) {
  ------------------
  |  Branch (797:9): [True: 0, False: 18.5M]
  |  Branch (797:29): [True: 0, False: 18.5M]
  ------------------
  798|      0|        return NULL;
  799|      0|    }
  800|       |
  801|  18.5M|    if (cannot_access_at_index(buffer, 0)) {
  ------------------
  |  |  193|  18.5M|#define cannot_access_at_index(buffer, index) (!can_access_at_index(buffer, index))
  |  |  ------------------
  |  |  |  |  192|  18.5M|#define can_access_at_index(buffer, index) ((buffer != NULL) && (((buffer)->offset + index) < (buffer)->length))
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (192:45): [True: 18.5M, False: 0]
  |  |  |  |  |  Branch (192:65): [True: 18.5M, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  802|      0|        return buffer;
  803|      0|    }
  804|       |
  805|  42.0M|    while (can_access_at_index(buffer, 0) && (buffer_at_offset(buffer)[0] <= 32)) {
  ------------------
  |  |  192|  84.0M|#define can_access_at_index(buffer, index) ((buffer != NULL) && (((buffer)->offset + index) < (buffer)->length))
  |  |  ------------------
  |  |  |  Branch (192:45): [True: 42.0M, False: 0]
  |  |  |  Branch (192:65): [True: 42.0M, False: 4.67k]
  |  |  ------------------
  ------------------
                  while (can_access_at_index(buffer, 0) && (buffer_at_offset(buffer)[0] <= 32)) {
  ------------------
  |  |  195|  42.0M|#define buffer_at_offset(buffer) ((buffer)->content + (buffer)->offset)
  ------------------
  |  Branch (805:46): [True: 23.4M, False: 18.5M]
  ------------------
  806|  23.4M|        buffer->offset++;
  807|  23.4M|    }
  808|       |
  809|  18.5M|    if (buffer->offset == buffer->length) {
  ------------------
  |  Branch (809:9): [True: 4.67k, False: 18.5M]
  ------------------
  810|  4.67k|        buffer->offset--;
  811|  4.67k|    }
  812|       |
  813|  18.5M|    return buffer;
  814|  18.5M|}
cJSON.c:skip_utf8_bom:
  817|  23.7k|static parse_buffer *skip_utf8_bom(parse_buffer *const buffer) {
  818|  23.7k|    if ((buffer == NULL) || (buffer->content == NULL) || (buffer->offset != 0)) {
  ------------------
  |  Branch (818:9): [True: 0, False: 23.7k]
  |  Branch (818:29): [True: 0, False: 23.7k]
  |  Branch (818:58): [True: 0, False: 23.7k]
  ------------------
  819|      0|        return NULL;
  820|      0|    }
  821|       |
  822|  23.7k|    if (can_access_at_index(buffer, 4) && (strncmp((const char *)buffer_at_offset(buffer), "\xEF\xBB\xBF", 3) == 0)) {
  ------------------
  |  |  192|  47.5k|#define can_access_at_index(buffer, index) ((buffer != NULL) && (((buffer)->offset + index) < (buffer)->length))
  |  |  ------------------
  |  |  |  Branch (192:45): [True: 23.7k, False: 0]
  |  |  |  Branch (192:65): [True: 17.6k, False: 6.11k]
  |  |  ------------------
  ------------------
                  if (can_access_at_index(buffer, 4) && (strncmp((const char *)buffer_at_offset(buffer), "\xEF\xBB\xBF", 3) == 0)) {
  ------------------
  |  |  195|  17.6k|#define buffer_at_offset(buffer) ((buffer)->content + (buffer)->offset)
  ------------------
  |  Branch (822:43): [True: 123, False: 17.5k]
  ------------------
  823|    123|        buffer->offset += 3;
  824|    123|    }
  825|       |
  826|  23.7k|    return buffer;
  827|  23.7k|}
cJSON.c:print:
  929|   294k|static unsigned char *print(const cJSON *const item, cJSON_bool format, bool *out_of_memory) {
  930|   294k|    static const size_t default_buffer_size = 256;
  931|   294k|    printbuffer buffer[1];
  932|   294k|    unsigned char *printed = NULL;
  933|       |
  934|   294k|    memset(buffer, 0, sizeof(buffer));
  935|       |
  936|       |    /* create buffer */
  937|   294k|    buffer->buffer = (unsigned char *)loader_calloc(item->pAllocator, default_buffer_size, VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE);
  938|   294k|    buffer->length = default_buffer_size;
  939|   294k|    buffer->format = format;
  940|   294k|    buffer->pAllocator = item->pAllocator;
  941|   294k|    if (buffer->buffer == NULL) {
  ------------------
  |  Branch (941:9): [True: 0, False: 294k]
  ------------------
  942|      0|        *out_of_memory = true;
  ------------------
  |  |   67|      0|#define true ((cJSON_bool)1)
  ------------------
  943|      0|        goto fail;
  944|      0|    }
  945|       |
  946|       |    /* print the value */
  947|   294k|    if (!print_value(item, buffer, out_of_memory)) {
  ------------------
  |  Branch (947:9): [True: 0, False: 294k]
  ------------------
  948|      0|        goto fail;
  949|      0|    }
  950|   294k|    update_offset(buffer);
  951|       |
  952|   294k|    printed = (unsigned char *)loader_realloc(item->pAllocator, buffer->buffer, buffer->length, buffer->offset + 1,
  953|   294k|                                              VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE);
  954|   294k|    if (printed == NULL) {
  ------------------
  |  Branch (954:9): [True: 0, False: 294k]
  ------------------
  955|      0|        *out_of_memory = true;
  ------------------
  |  |   67|      0|#define true ((cJSON_bool)1)
  ------------------
  956|      0|        goto fail;
  957|      0|    }
  958|   294k|    buffer->buffer = NULL;
  959|       |
  960|   294k|    return printed;
  961|       |
  962|      0|fail:
  963|      0|    if (buffer->buffer != NULL) {
  ------------------
  |  Branch (963:9): [True: 0, False: 0]
  ------------------
  964|      0|        loader_free(item->pAllocator, buffer->buffer);
  965|      0|        buffer->buffer = NULL;
  966|      0|    }
  967|       |
  968|      0|    if (printed != NULL) {
  ------------------
  |  Branch (968:9): [True: 0, False: 0]
  ------------------
  969|      0|        loader_free(item->pAllocator, printed);
  970|      0|        printed = NULL;
  971|      0|    }
  972|       |
  973|       |    return NULL;
  974|   294k|}
cJSON.c:update_offset:
  355|   294k|static void update_offset(printbuffer *const buffer) {
  356|   294k|    const unsigned char *buffer_pointer = NULL;
  357|   294k|    if ((buffer == NULL) || (buffer->buffer == NULL)) {
  ------------------
  |  Branch (357:9): [True: 0, False: 294k]
  |  Branch (357:29): [True: 0, False: 294k]
  ------------------
  358|      0|        return;
  359|      0|    }
  360|   294k|    buffer_pointer = buffer->buffer + buffer->offset;
  361|       |
  362|   294k|    buffer->offset += strlen((const char *)buffer_pointer);
  363|   294k|}
cJSON.c:parse_value:
 1032|  4.97M|static cJSON_bool parse_value(cJSON *const item, parse_buffer *const input_buffer, bool *out_of_memory) {
 1033|  4.97M|    if ((input_buffer == NULL) || (input_buffer->content == NULL)) {
  ------------------
  |  Branch (1033:9): [True: 0, False: 4.97M]
  |  Branch (1033:35): [True: 0, False: 4.97M]
  ------------------
 1034|      0|        return false; /* no input */
  ------------------
  |  |   72|      0|#define false ((cJSON_bool)0)
  ------------------
 1035|      0|    }
 1036|       |
 1037|       |    /* parse the different types of values */
 1038|       |    /* null */
 1039|  4.97M|    if (can_read(input_buffer, 4) && (strncmp((const char *)buffer_at_offset(input_buffer), "null", 4) == 0)) {
  ------------------
  |  |  190|  9.95M|#define can_read(buffer, size) ((buffer != NULL) && (((buffer)->offset + size) <= (buffer)->length))
  |  |  ------------------
  |  |  |  Branch (190:33): [True: 4.97M, False: 0]
  |  |  |  Branch (190:53): [True: 4.96M, False: 7.77k]
  |  |  ------------------
  ------------------
                  if (can_read(input_buffer, 4) && (strncmp((const char *)buffer_at_offset(input_buffer), "null", 4) == 0)) {
  ------------------
  |  |  195|  4.96M|#define buffer_at_offset(buffer) ((buffer)->content + (buffer)->offset)
  ------------------
  |  Branch (1039:38): [True: 349, False: 4.96M]
  ------------------
 1040|    349|        item->type = cJSON_NULL;
  ------------------
  |  |   99|    349|#define cJSON_NULL (1 << 2)
  ------------------
 1041|    349|        input_buffer->offset += 4;
 1042|    349|        return true;
  ------------------
  |  |   67|    349|#define true ((cJSON_bool)1)
  ------------------
 1043|    349|    }
 1044|       |    /* false */
 1045|  4.97M|    if (can_read(input_buffer, 5) && (strncmp((const char *)buffer_at_offset(input_buffer), "false", 5) == 0)) {
  ------------------
  |  |  190|  9.95M|#define can_read(buffer, size) ((buffer != NULL) && (((buffer)->offset + size) <= (buffer)->length))
  |  |  ------------------
  |  |  |  Branch (190:33): [True: 4.97M, False: 0]
  |  |  |  Branch (190:53): [True: 4.96M, False: 8.26k]
  |  |  ------------------
  ------------------
                  if (can_read(input_buffer, 5) && (strncmp((const char *)buffer_at_offset(input_buffer), "false", 5) == 0)) {
  ------------------
  |  |  195|  4.96M|#define buffer_at_offset(buffer) ((buffer)->content + (buffer)->offset)
  ------------------
  |  Branch (1045:38): [True: 88, False: 4.96M]
  ------------------
 1046|     88|        item->type = cJSON_False;
  ------------------
  |  |   97|     88|#define cJSON_False (1 << 0)
  ------------------
 1047|     88|        input_buffer->offset += 5;
 1048|     88|        return true;
  ------------------
  |  |   67|     88|#define true ((cJSON_bool)1)
  ------------------
 1049|     88|    }
 1050|       |    /* true */
 1051|  4.97M|    if (can_read(input_buffer, 4) && (strncmp((const char *)buffer_at_offset(input_buffer), "true", 4) == 0)) {
  ------------------
  |  |  190|  9.95M|#define can_read(buffer, size) ((buffer != NULL) && (((buffer)->offset + size) <= (buffer)->length))
  |  |  ------------------
  |  |  |  Branch (190:33): [True: 4.97M, False: 0]
  |  |  |  Branch (190:53): [True: 4.96M, False: 7.77k]
  |  |  ------------------
  ------------------
                  if (can_read(input_buffer, 4) && (strncmp((const char *)buffer_at_offset(input_buffer), "true", 4) == 0)) {
  ------------------
  |  |  195|  4.96M|#define buffer_at_offset(buffer) ((buffer)->content + (buffer)->offset)
  ------------------
  |  Branch (1051:38): [True: 16.3k, False: 4.95M]
  ------------------
 1052|  16.3k|        item->type = cJSON_True;
  ------------------
  |  |   98|  16.3k|#define cJSON_True (1 << 1)
  ------------------
 1053|  16.3k|        item->valueint = 1;
 1054|  16.3k|        input_buffer->offset += 4;
 1055|  16.3k|        return true;
  ------------------
  |  |   67|  16.3k|#define true ((cJSON_bool)1)
  ------------------
 1056|  16.3k|    }
 1057|       |    /* string */
 1058|  4.95M|    if (can_access_at_index(input_buffer, 0) && (buffer_at_offset(input_buffer)[0] == '\"')) {
  ------------------
  |  |  192|  9.91M|#define can_access_at_index(buffer, index) ((buffer != NULL) && (((buffer)->offset + index) < (buffer)->length))
  |  |  ------------------
  |  |  |  Branch (192:45): [True: 4.95M, False: 0]
  |  |  |  Branch (192:65): [True: 4.95M, False: 0]
  |  |  ------------------
  ------------------
                  if (can_access_at_index(input_buffer, 0) && (buffer_at_offset(input_buffer)[0] == '\"')) {
  ------------------
  |  |  195|  4.95M|#define buffer_at_offset(buffer) ((buffer)->content + (buffer)->offset)
  ------------------
  |  Branch (1058:49): [True: 3.89M, False: 1.06M]
  ------------------
 1059|  3.89M|        return parse_string(item, input_buffer, out_of_memory);
 1060|  3.89M|    }
 1061|       |    /* number */
 1062|  1.06M|    if (can_access_at_index(input_buffer, 0) &&
  ------------------
  |  |  192|  2.13M|#define can_access_at_index(buffer, index) ((buffer != NULL) && (((buffer)->offset + index) < (buffer)->length))
  |  |  ------------------
  |  |  |  Branch (192:45): [True: 1.06M, False: 0]
  |  |  |  Branch (192:65): [True: 1.06M, False: 0]
  |  |  ------------------
  ------------------
 1063|  1.06M|        ((buffer_at_offset(input_buffer)[0] == '-') ||
  ------------------
  |  |  195|  1.06M|#define buffer_at_offset(buffer) ((buffer)->content + (buffer)->offset)
  ------------------
  |  Branch (1063:10): [True: 14.6k, False: 1.05M]
  ------------------
 1064|  1.05M|         ((buffer_at_offset(input_buffer)[0] >= '0') && (buffer_at_offset(input_buffer)[0] <= '9')))) {
  ------------------
  |  |  195|  1.05M|#define buffer_at_offset(buffer) ((buffer)->content + (buffer)->offset)
  ------------------
                       ((buffer_at_offset(input_buffer)[0] >= '0') && (buffer_at_offset(input_buffer)[0] <= '9')))) {
  ------------------
  |  |  195|  1.04M|#define buffer_at_offset(buffer) ((buffer)->content + (buffer)->offset)
  ------------------
  |  Branch (1064:11): [True: 1.04M, False: 4.10k]
  |  Branch (1064:57): [True: 42.1k, False: 1.00M]
  ------------------
 1065|  56.8k|        return parse_number(item, input_buffer);
 1066|  56.8k|    }
 1067|       |    /* array */
 1068|  1.00M|    if (can_access_at_index(input_buffer, 0) && (buffer_at_offset(input_buffer)[0] == '[')) {
  ------------------
  |  |  192|  2.01M|#define can_access_at_index(buffer, index) ((buffer != NULL) && (((buffer)->offset + index) < (buffer)->length))
  |  |  ------------------
  |  |  |  Branch (192:45): [True: 1.00M, False: 0]
  |  |  |  Branch (192:65): [True: 1.00M, False: 0]
  |  |  ------------------
  ------------------
                  if (can_access_at_index(input_buffer, 0) && (buffer_at_offset(input_buffer)[0] == '[')) {
  ------------------
  |  |  195|  1.00M|#define buffer_at_offset(buffer) ((buffer)->content + (buffer)->offset)
  ------------------
  |  Branch (1068:49): [True: 353k, False: 655k]
  ------------------
 1069|   353k|        return parse_array(item, input_buffer, out_of_memory);
 1070|   353k|    }
 1071|       |    /* object */
 1072|   655k|    if (can_access_at_index(input_buffer, 0) && (buffer_at_offset(input_buffer)[0] == '{')) {
  ------------------
  |  |  192|  1.31M|#define can_access_at_index(buffer, index) ((buffer != NULL) && (((buffer)->offset + index) < (buffer)->length))
  |  |  ------------------
  |  |  |  Branch (192:45): [True: 655k, False: 0]
  |  |  |  Branch (192:65): [True: 655k, False: 0]
  |  |  ------------------
  ------------------
                  if (can_access_at_index(input_buffer, 0) && (buffer_at_offset(input_buffer)[0] == '{')) {
  ------------------
  |  |  195|   655k|#define buffer_at_offset(buffer) ((buffer)->content + (buffer)->offset)
  ------------------
  |  Branch (1072:49): [True: 648k, False: 6.67k]
  ------------------
 1073|   648k|        return parse_object(item, input_buffer, out_of_memory);
 1074|   648k|    }
 1075|       |
 1076|  6.67k|    return false;
  ------------------
  |  |   72|  6.67k|#define false ((cJSON_bool)0)
  ------------------
 1077|   655k|}
cJSON.c:parse_string:
  557|  7.83M|static cJSON_bool parse_string(cJSON *const item, parse_buffer *const input_buffer, bool *out_of_memory) {
  558|  7.83M|    const unsigned char *input_pointer = buffer_at_offset(input_buffer) + 1;
  ------------------
  |  |  195|  7.83M|#define buffer_at_offset(buffer) ((buffer)->content + (buffer)->offset)
  ------------------
  559|  7.83M|    const unsigned char *input_end = buffer_at_offset(input_buffer) + 1;
  ------------------
  |  |  195|  7.83M|#define buffer_at_offset(buffer) ((buffer)->content + (buffer)->offset)
  ------------------
  560|  7.83M|    unsigned char *output_pointer = NULL;
  561|  7.83M|    unsigned char *output = NULL;
  562|       |
  563|       |    /* not a string */
  564|  7.83M|    if (buffer_at_offset(input_buffer)[0] != '\"') {
  ------------------
  |  |  195|  7.83M|#define buffer_at_offset(buffer) ((buffer)->content + (buffer)->offset)
  ------------------
  |  Branch (564:9): [True: 329, False: 7.83M]
  ------------------
  565|    329|        goto fail;
  566|    329|    }
  567|       |
  568|  7.83M|    {
  569|       |        /* calculate approximate size of the output (overestimate) */
  570|  7.83M|        size_t allocation_length = 0;
  571|  7.83M|        size_t skipped_bytes = 0;
  572|   141M|        while (((size_t)(input_end - input_buffer->content) < input_buffer->length) && (*input_end != '\"')) {
  ------------------
  |  Branch (572:16): [True: 141M, False: 357]
  |  Branch (572:88): [True: 133M, False: 7.83M]
  ------------------
  573|       |            /* is escape sequence */
  574|   133M|            if (input_end[0] == '\\') {
  ------------------
  |  Branch (574:17): [True: 681k, False: 133M]
  ------------------
  575|   681k|                if ((size_t)(input_end + 1 - input_buffer->content) >= input_buffer->length) {
  ------------------
  |  Branch (575:21): [True: 0, False: 681k]
  ------------------
  576|       |                    /* prevent buffer overflow when last input character is a backslash */
  577|      0|                    goto fail;
  578|      0|                }
  579|   681k|                skipped_bytes++;
  580|   681k|                input_end++;
  581|   681k|            }
  582|   133M|            input_end++;
  583|   133M|        }
  584|  7.83M|        if (((size_t)(input_end - input_buffer->content) >= input_buffer->length) || (*input_end != '\"')) {
  ------------------
  |  Branch (584:13): [True: 357, False: 7.83M]
  |  Branch (584:86): [True: 0, False: 7.83M]
  ------------------
  585|    357|            goto fail; /* string ended unexpectedly */
  586|    357|        }
  587|       |
  588|       |        /* This is at most how much we need for the output */
  589|  7.83M|        allocation_length = (size_t)(input_end - buffer_at_offset(input_buffer)) - skipped_bytes;
  ------------------
  |  |  195|  7.83M|#define buffer_at_offset(buffer) ((buffer)->content + (buffer)->offset)
  ------------------
  590|  7.83M|        output = (unsigned char *)loader_calloc(input_buffer->pAllocator, allocation_length + sizeof(""),
  591|  7.83M|                                                VK_SYSTEM_ALLOCATION_SCOPE_COMMAND);
  592|  7.83M|        if (output == NULL) {
  ------------------
  |  Branch (592:13): [True: 0, False: 7.83M]
  ------------------
  593|      0|            *out_of_memory = true;
  ------------------
  |  |   67|      0|#define true ((cJSON_bool)1)
  ------------------
  594|      0|            goto fail; /* allocation failure */
  595|      0|        }
  596|  7.83M|    }
  597|       |
  598|  7.83M|    output_pointer = output;
  599|       |    /* loop through the string literal */
  600|   124M|    while (input_pointer < input_end) {
  ------------------
  |  Branch (600:12): [True: 116M, False: 7.83M]
  ------------------
  601|   116M|        if (*input_pointer != '\\') {
  ------------------
  |  Branch (601:13): [True: 115M, False: 546k]
  ------------------
  602|   115M|            *output_pointer++ = *input_pointer++;
  603|   115M|        }
  604|       |        /* escape sequence */
  605|   546k|        else {
  606|   546k|            unsigned char sequence_length = 2;
  607|   546k|            if ((input_end - input_pointer) < 1) {
  ------------------
  |  Branch (607:17): [True: 0, False: 546k]
  ------------------
  608|      0|                goto fail;
  609|      0|            }
  610|       |
  611|   546k|            switch (input_pointer[1]) {
  612|  1.95k|                case 'b':
  ------------------
  |  Branch (612:17): [True: 1.95k, False: 544k]
  ------------------
  613|  1.95k|                    *output_pointer++ = '\b';
  614|  1.95k|                    break;
  615|    381|                case 'f':
  ------------------
  |  Branch (615:17): [True: 381, False: 546k]
  ------------------
  616|    381|                    *output_pointer++ = '\f';
  617|    381|                    break;
  618|  4.33k|                case 'n':
  ------------------
  |  Branch (618:17): [True: 4.33k, False: 542k]
  ------------------
  619|  4.33k|                    *output_pointer++ = '\n';
  620|  4.33k|                    break;
  621|  5.90k|                case 'r':
  ------------------
  |  Branch (621:17): [True: 5.90k, False: 540k]
  ------------------
  622|  5.90k|                    *output_pointer++ = '\r';
  623|  5.90k|                    break;
  624|  1.01k|                case 't':
  ------------------
  |  Branch (624:17): [True: 1.01k, False: 545k]
  ------------------
  625|  1.01k|                    *output_pointer++ = '\t';
  626|  1.01k|                    break;
  627|    613|                case '\"':
  ------------------
  |  Branch (627:17): [True: 613, False: 545k]
  ------------------
  628|  16.5k|                case '\\':
  ------------------
  |  Branch (628:17): [True: 15.9k, False: 530k]
  ------------------
  629|  35.5k|                case '/':
  ------------------
  |  Branch (629:17): [True: 18.9k, False: 527k]
  ------------------
  630|  35.5k|                    *output_pointer++ = input_pointer[1];
  631|  35.5k|                    break;
  632|       |
  633|       |                /* UTF-16 literal */
  634|   497k|                case 'u':
  ------------------
  |  Branch (634:17): [True: 497k, False: 49.2k]
  ------------------
  635|   497k|                    sequence_length = utf16_literal_to_utf8(input_pointer, input_end, &output_pointer);
  636|   497k|                    if (sequence_length == 0) {
  ------------------
  |  Branch (636:25): [True: 921, False: 496k]
  ------------------
  637|       |                        /* failed to convert UTF16-literal to UTF-8 */
  638|    921|                        goto fail;
  639|    921|                    }
  640|   496k|                    break;
  641|       |
  642|   496k|                default:
  ------------------
  |  Branch (642:17): [True: 116, False: 546k]
  ------------------
  643|    116|                    goto fail;
  644|   546k|            }
  645|   545k|            input_pointer += sequence_length;
  646|   545k|        }
  647|   116M|    }
  648|       |
  649|       |    /* zero terminate the output */
  650|  7.83M|    *output_pointer = '\0';
  651|       |
  652|  7.83M|    item->type = cJSON_String;
  ------------------
  |  |  101|  7.83M|#define cJSON_String (1 << 4)
  ------------------
  653|  7.83M|    item->valuestring = (char *)output;
  654|       |
  655|  7.83M|    input_buffer->offset = (size_t)(input_end - input_buffer->content);
  656|  7.83M|    input_buffer->offset++;
  657|       |
  658|  7.83M|    return true;
  ------------------
  |  |   67|  7.83M|#define true ((cJSON_bool)1)
  ------------------
  659|       |
  660|  1.72k|fail:
  661|  1.72k|    if (output != NULL) {
  ------------------
  |  Branch (661:9): [True: 1.03k, False: 686]
  ------------------
  662|  1.03k|        loader_free(input_buffer->pAllocator, output);
  663|  1.03k|        output = NULL;
  664|  1.03k|    }
  665|       |
  666|  1.72k|    if (input_pointer != NULL) {
  ------------------
  |  Branch (666:9): [True: 1.72k, False: 0]
  ------------------
  667|  1.72k|        input_buffer->offset = (size_t)(input_pointer - input_buffer->content);
  668|  1.72k|    }
  669|       |
  670|  1.72k|    return false;
  ------------------
  |  |   72|  1.72k|#define false ((cJSON_bool)0)
  ------------------
  671|  7.83M|}
cJSON.c:utf16_literal_to_utf8:
  459|   497k|                                           unsigned char **output_pointer) {
  460|   497k|    long unsigned int codepoint = 0;
  461|   497k|    unsigned int first_code = 0;
  462|   497k|    const unsigned char *first_sequence = input_pointer;
  463|   497k|    unsigned char utf8_length = 0;
  464|   497k|    unsigned char utf8_position = 0;
  465|   497k|    unsigned char sequence_length = 0;
  466|   497k|    unsigned char first_byte_mark = 0;
  467|       |
  468|   497k|    if ((input_end - first_sequence) < 6) {
  ------------------
  |  Branch (468:9): [True: 108, False: 497k]
  ------------------
  469|       |        /* input ends unexpectedly */
  470|    108|        goto fail;
  471|    108|    }
  472|       |
  473|       |    /* get the first utf16 sequence */
  474|   497k|    first_code = parse_hex4(first_sequence + 2);
  475|       |
  476|       |    /* check that the code is valid */
  477|   497k|    if (((first_code >= 0xDC00) && (first_code <= 0xDFFF))) {
  ------------------
  |  Branch (477:10): [True: 244k, False: 252k]
  |  Branch (477:36): [True: 336, False: 244k]
  ------------------
  478|    336|        goto fail;
  479|    336|    }
  480|       |
  481|       |    /* UTF16 surrogate pair */
  482|   496k|    if ((first_code >= 0xD800) && (first_code <= 0xDBFF)) {
  ------------------
  |  Branch (482:9): [True: 245k, False: 251k]
  |  Branch (482:35): [True: 1.11k, False: 244k]
  ------------------
  483|  1.11k|        const unsigned char *second_sequence = first_sequence + 6;
  484|  1.11k|        unsigned int second_code = 0;
  485|  1.11k|        sequence_length = 12; /* \uXXXX\uXXXX */
  486|       |
  487|  1.11k|        if ((input_end - second_sequence) < 6) {
  ------------------
  |  Branch (487:13): [True: 161, False: 954]
  ------------------
  488|       |            /* input ends unexpectedly */
  489|    161|            goto fail;
  490|    161|        }
  491|       |
  492|    954|        if ((second_sequence[0] != '\\') || (second_sequence[1] != 'u')) {
  ------------------
  |  Branch (492:13): [True: 61, False: 893]
  |  Branch (492:45): [True: 81, False: 812]
  ------------------
  493|       |            /* missing second half of the surrogate pair */
  494|    142|            goto fail;
  495|    142|        }
  496|       |
  497|       |        /* get the second utf16 sequence */
  498|    812|        second_code = parse_hex4(second_sequence + 2);
  499|       |        /* check that the code is valid */
  500|    812|        if ((second_code < 0xDC00) || (second_code > 0xDFFF)) {
  ------------------
  |  Branch (500:13): [True: 96, False: 716]
  |  Branch (500:39): [True: 78, False: 638]
  ------------------
  501|       |            /* invalid second half of the surrogate pair */
  502|    174|            goto fail;
  503|    174|        }
  504|       |
  505|       |        /* calculate the unicode codepoint from the surrogate pair */
  506|    638|        codepoint = 0x10000 + (((first_code & 0x3FF) << 10) | (second_code & 0x3FF));
  507|   495k|    } else {
  508|   495k|        sequence_length = 6; /* \uXXXX */
  509|   495k|        codepoint = first_code;
  510|   495k|    }
  511|       |
  512|       |    /* encode as UTF-8
  513|       |     * takes at maximum 4 bytes to encode:
  514|       |     * 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx */
  515|   496k|    if (codepoint < 0x80) {
  ------------------
  |  Branch (515:9): [True: 178k, False: 317k]
  ------------------
  516|       |        /* normal ascii, encoding 0xxxxxxx */
  517|   178k|        utf8_length = 1;
  518|   317k|    } else if (codepoint < 0x800) {
  ------------------
  |  Branch (518:16): [True: 66.1k, False: 251k]
  ------------------
  519|       |        /* two bytes, encoding 110xxxxx 10xxxxxx */
  520|  66.1k|        utf8_length = 2;
  521|  66.1k|        first_byte_mark = 0xC0; /* 11000000 */
  522|   251k|    } else if (codepoint < 0x10000) {
  ------------------
  |  Branch (522:16): [True: 251k, False: 638]
  ------------------
  523|       |        /* three bytes, encoding 1110xxxx 10xxxxxx 10xxxxxx */
  524|   251k|        utf8_length = 3;
  525|   251k|        first_byte_mark = 0xE0; /* 11100000 */
  526|   251k|    } else if (codepoint <= 0x10FFFF) {
  ------------------
  |  Branch (526:16): [True: 638, False: 0]
  ------------------
  527|       |        /* four bytes, encoding 1110xxxx 10xxxxxx 10xxxxxx 10xxxxxx */
  528|    638|        utf8_length = 4;
  529|    638|        first_byte_mark = 0xF0; /* 11110000 */
  530|    638|    } else {
  531|       |        /* invalid unicode codepoint */
  532|      0|        goto fail;
  533|      0|    }
  534|       |
  535|       |    /* encode as utf8 */
  536|  1.06M|    for (utf8_position = (unsigned char)(utf8_length - 1); utf8_position > 0; utf8_position--) {
  ------------------
  |  Branch (536:60): [True: 570k, False: 496k]
  ------------------
  537|       |        /* 10xxxxxx */
  538|   570k|        (*output_pointer)[utf8_position] = (unsigned char)((codepoint | 0x80) & 0xBF);
  539|   570k|        codepoint >>= 6;
  540|   570k|    }
  541|       |    /* encode first byte */
  542|   496k|    if (utf8_length > 1) {
  ------------------
  |  Branch (542:9): [True: 317k, False: 178k]
  ------------------
  543|   317k|        (*output_pointer)[0] = (unsigned char)((codepoint | first_byte_mark) & 0xFF);
  544|   317k|    } else {
  545|   178k|        (*output_pointer)[0] = (unsigned char)(codepoint & 0x7F);
  546|   178k|    }
  547|       |
  548|   496k|    *output_pointer += utf8_length;
  549|       |
  550|   496k|    return sequence_length;
  551|       |
  552|    921|fail:
  553|    921|    return 0;
  554|   496k|}
cJSON.c:parse_hex4:
  430|   497k|static unsigned parse_hex4(const unsigned char *const input) {
  431|   497k|    unsigned int h = 0;
  432|   497k|    size_t i = 0;
  433|       |
  434|  2.14M|    for (i = 0; i < 4; i++) {
  ------------------
  |  Branch (434:17): [True: 1.80M, False: 343k]
  ------------------
  435|       |        /* parse digit */
  436|  1.80M|        if ((input[i] >= '0') && (input[i] <= '9')) {
  ------------------
  |  Branch (436:13): [True: 1.77M, False: 35.4k]
  |  Branch (436:34): [True: 1.22M, False: 549k]
  ------------------
  437|  1.22M|            h += (unsigned int)input[i] - '0';
  438|  1.22M|        } else if ((input[i] >= 'A') && (input[i] <= 'F')) {
  ------------------
  |  Branch (438:20): [True: 536k, False: 48.3k]
  |  Branch (438:41): [True: 31.8k, False: 504k]
  ------------------
  439|  31.8k|            h += (unsigned int)10 + input[i] - 'A';
  440|   552k|        } else if ((input[i] >= 'a') && (input[i] <= 'f')) {
  ------------------
  |  Branch (440:20): [True: 442k, False: 110k]
  |  Branch (440:41): [True: 398k, False: 44.3k]
  ------------------
  441|   398k|            h += (unsigned int)10 + input[i] - 'a';
  442|   398k|        } else /* invalid */
  443|   154k|        {
  444|   154k|            return 0;
  445|   154k|        }
  446|       |
  447|  1.65M|        if (i < 3) {
  ------------------
  |  Branch (447:13): [True: 1.30M, False: 343k]
  ------------------
  448|       |            /* shift left to make place for the next nibble */
  449|  1.30M|            h = h << 4;
  450|  1.30M|        }
  451|  1.65M|    }
  452|       |
  453|   343k|    return h;
  454|   497k|}
cJSON.c:parse_number:
  198|  56.8k|static cJSON_bool parse_number(cJSON *const item, parse_buffer *const input_buffer) {
  199|  56.8k|    double number = 0;
  200|  56.8k|    unsigned char *after_end = NULL;
  201|  56.8k|    unsigned char *number_c_string;
  202|  56.8k|    unsigned char decimal_point = get_decimal_point();
  203|  56.8k|    size_t i = 0;
  204|  56.8k|    size_t number_string_length = 0;
  205|  56.8k|    cJSON_bool has_decimal_point = false;
  ------------------
  |  |   72|  56.8k|#define false ((cJSON_bool)0)
  ------------------
  206|       |
  207|  56.8k|    if ((input_buffer == NULL) || (input_buffer->content == NULL)) {
  ------------------
  |  Branch (207:9): [True: 0, False: 56.8k]
  |  Branch (207:35): [True: 0, False: 56.8k]
  ------------------
  208|      0|        return false;
  ------------------
  |  |   72|      0|#define false ((cJSON_bool)0)
  ------------------
  209|      0|    }
  210|       |
  211|       |    /* copy the number into a temporary buffer and replace '.' with the decimal point
  212|       |     * of the current locale (for strtod)
  213|       |     * This also takes care of '\0' not necessarily being available for marking the end of the input */
  214|   276k|    for (i = 0; can_access_at_index(input_buffer, i); i++) {
  ------------------
  |  |  192|   276k|#define can_access_at_index(buffer, index) ((buffer != NULL) && (((buffer)->offset + index) < (buffer)->length))
  |  |  ------------------
  |  |  |  Branch (192:45): [True: 276k, False: 0]
  |  |  |  Branch (192:65): [True: 276k, False: 0]
  |  |  ------------------
  ------------------
  215|   276k|        switch (buffer_at_offset(input_buffer)[i]) {
  ------------------
  |  |  195|   276k|#define buffer_at_offset(buffer) ((buffer)->content + (buffer)->offset)
  ------------------
  216|  19.4k|            case '0':
  ------------------
  |  Branch (216:13): [True: 19.4k, False: 256k]
  ------------------
  217|  49.0k|            case '1':
  ------------------
  |  Branch (217:13): [True: 29.5k, False: 246k]
  ------------------
  218|  79.5k|            case '2':
  ------------------
  |  Branch (218:13): [True: 30.4k, False: 245k]
  ------------------
  219|  88.8k|            case '3':
  ------------------
  |  Branch (219:13): [True: 9.30k, False: 266k]
  ------------------
  220|   102k|            case '4':
  ------------------
  |  Branch (220:13): [True: 13.6k, False: 262k]
  ------------------
  221|   122k|            case '5':
  ------------------
  |  Branch (221:13): [True: 20.0k, False: 255k]
  ------------------
  222|   130k|            case '6':
  ------------------
  |  Branch (222:13): [True: 8.09k, False: 267k]
  ------------------
  223|   157k|            case '7':
  ------------------
  |  Branch (223:13): [True: 27.0k, False: 248k]
  ------------------
  224|   185k|            case '8':
  ------------------
  |  Branch (224:13): [True: 27.8k, False: 248k]
  ------------------
  225|   193k|            case '9':
  ------------------
  |  Branch (225:13): [True: 7.59k, False: 268k]
  ------------------
  226|   193k|            case '+':
  ------------------
  |  Branch (226:13): [True: 289, False: 275k]
  ------------------
  227|   209k|            case '-':
  ------------------
  |  Branch (227:13): [True: 16.0k, False: 260k]
  ------------------
  228|   211k|            case 'e':
  ------------------
  |  Branch (228:13): [True: 2.45k, False: 273k]
  ------------------
  229|   216k|            case 'E':
  ------------------
  |  Branch (229:13): [True: 5.00k, False: 271k]
  ------------------
  230|   216k|                number_string_length++;
  231|   216k|                break;
  232|       |
  233|  2.33k|            case '.':
  ------------------
  |  Branch (233:13): [True: 2.33k, False: 273k]
  ------------------
  234|  2.33k|                number_string_length++;
  235|  2.33k|                has_decimal_point = true;
  ------------------
  |  |   67|  2.33k|#define true ((cJSON_bool)1)
  ------------------
  236|  2.33k|                break;
  237|       |
  238|  56.8k|            default:
  ------------------
  |  Branch (238:13): [True: 56.8k, False: 219k]
  ------------------
  239|  56.8k|                goto loop_end;
  240|   276k|        }
  241|   276k|    }
  242|  56.8k|loop_end:
  243|       |    /* malloc for temporary buffer, add 1 for '\0' */
  244|  56.8k|    number_c_string =
  245|  56.8k|        (unsigned char *)loader_calloc(input_buffer->pAllocator, number_string_length + 1, VK_SYSTEM_ALLOCATION_SCOPE_COMMAND);
  246|  56.8k|    if (number_c_string == NULL) {
  ------------------
  |  Branch (246:9): [True: 0, False: 56.8k]
  ------------------
  247|      0|        return false; /* allocation failure */
  ------------------
  |  |   72|      0|#define false ((cJSON_bool)0)
  ------------------
  248|      0|    }
  249|       |
  250|  56.8k|    memcpy(number_c_string, buffer_at_offset(input_buffer), number_string_length);
  ------------------
  |  |  195|  56.8k|#define buffer_at_offset(buffer) ((buffer)->content + (buffer)->offset)
  ------------------
  251|  56.8k|    number_c_string[number_string_length] = '\0';
  252|       |
  253|  56.8k|    if (has_decimal_point) {
  ------------------
  |  Branch (253:9): [True: 2.06k, False: 54.7k]
  ------------------
  254|  23.7k|        for (i = 0; i < number_string_length; i++) {
  ------------------
  |  Branch (254:21): [True: 21.6k, False: 2.06k]
  ------------------
  255|  21.6k|            if (number_c_string[i] == '.') {
  ------------------
  |  Branch (255:17): [True: 2.33k, False: 19.3k]
  ------------------
  256|       |                /* replace '.' with the decimal point of the current locale (for strtod) */
  257|  2.33k|                number_c_string[i] = decimal_point;
  258|  2.33k|            }
  259|  21.6k|        }
  260|  2.06k|    }
  261|       |
  262|  56.8k|    number = strtod((const char *)number_c_string, (char **)&after_end);
  263|  56.8k|    if (number_c_string == after_end) {
  ------------------
  |  Branch (263:9): [True: 80, False: 56.7k]
  ------------------
  264|       |        /* free the temporary buffer */
  265|     80|        loader_free(input_buffer->pAllocator, number_c_string);
  266|     80|        return false; /* parse_error */
  ------------------
  |  |   72|     80|#define false ((cJSON_bool)0)
  ------------------
  267|     80|    }
  268|       |
  269|  56.7k|    item->valuedouble = number;
  270|       |
  271|       |    /* use saturation in case of overflow */
  272|  56.7k|    if (number >= INT_MAX) {
  ------------------
  |  Branch (272:9): [True: 2.91k, False: 53.8k]
  ------------------
  273|  2.91k|        item->valueint = INT_MAX;
  274|  53.8k|    } else if (number <= (double)INT_MIN) {
  ------------------
  |  Branch (274:16): [True: 3.28k, False: 50.5k]
  ------------------
  275|  3.28k|        item->valueint = INT_MIN;
  276|  50.5k|    } else {
  277|  50.5k|        item->valueint = (int)number;
  278|  50.5k|    }
  279|       |
  280|  56.7k|    item->type = cJSON_Number;
  ------------------
  |  |  100|  56.7k|#define cJSON_Number (1 << 3)
  ------------------
  281|       |
  282|  56.7k|    input_buffer->offset += (size_t)(after_end - number_c_string);
  283|       |    /* free the temporary buffer */
  284|  56.7k|    loader_free(input_buffer->pAllocator, number_c_string);
  285|  56.7k|    return true;
  ------------------
  |  |   67|  56.7k|#define true ((cJSON_bool)1)
  ------------------
  286|  56.8k|}
cJSON.c:get_decimal_point:
  172|  56.8k|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|  56.8k|    return '.';
  178|  56.8k|#endif
  179|  56.8k|}
cJSON.c:parse_array:
 1145|   353k|static cJSON_bool parse_array(cJSON *const item, parse_buffer *const input_buffer, bool *out_of_memory) {
 1146|   353k|    cJSON *head = NULL; /* head of the linked list */
 1147|   353k|    cJSON *current_item = NULL;
 1148|       |
 1149|   353k|    if (input_buffer->depth >= CJSON_NESTING_LIMIT) {
  ------------------
  |  |  138|   353k|#define CJSON_NESTING_LIMIT 1000
  ------------------
  |  Branch (1149:9): [True: 94, False: 353k]
  ------------------
 1150|     94|        return false; /* to deeply nested */
  ------------------
  |  |   72|     94|#define false ((cJSON_bool)0)
  ------------------
 1151|     94|    }
 1152|   353k|    input_buffer->depth++;
 1153|       |
 1154|   353k|    if (buffer_at_offset(input_buffer)[0] != '[') {
  ------------------
  |  |  195|   353k|#define buffer_at_offset(buffer) ((buffer)->content + (buffer)->offset)
  ------------------
  |  Branch (1154:9): [True: 0, False: 353k]
  ------------------
 1155|       |        /* not an array */
 1156|      0|        goto fail;
 1157|      0|    }
 1158|       |
 1159|   353k|    input_buffer->offset++;
 1160|   353k|    buffer_skip_whitespace(input_buffer);
 1161|   353k|    if (can_access_at_index(input_buffer, 0) && (buffer_at_offset(input_buffer)[0] == ']')) {
  ------------------
  |  |  192|   706k|#define can_access_at_index(buffer, index) ((buffer != NULL) && (((buffer)->offset + index) < (buffer)->length))
  |  |  ------------------
  |  |  |  Branch (192:45): [True: 353k, False: 0]
  |  |  |  Branch (192:65): [True: 353k, False: 0]
  |  |  ------------------
  ------------------
                  if (can_access_at_index(input_buffer, 0) && (buffer_at_offset(input_buffer)[0] == ']')) {
  ------------------
  |  |  195|   353k|#define buffer_at_offset(buffer) ((buffer)->content + (buffer)->offset)
  ------------------
  |  Branch (1161:49): [True: 7.17k, False: 346k]
  ------------------
 1162|       |        /* empty array */
 1163|  7.17k|        goto success;
 1164|  7.17k|    }
 1165|       |
 1166|       |    /* check if we skipped to the end of the buffer */
 1167|   346k|    if (cannot_access_at_index(input_buffer, 0)) {
  ------------------
  |  |  193|   346k|#define cannot_access_at_index(buffer, index) (!can_access_at_index(buffer, index))
  |  |  ------------------
  |  |  |  |  192|   346k|#define can_access_at_index(buffer, index) ((buffer != NULL) && (((buffer)->offset + index) < (buffer)->length))
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (192:45): [True: 346k, False: 0]
  |  |  |  |  |  Branch (192:65): [True: 346k, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1168|      0|        input_buffer->offset--;
 1169|      0|        goto fail;
 1170|      0|    }
 1171|       |
 1172|       |    /* step back to character in front of the first element */
 1173|   346k|    input_buffer->offset--;
 1174|       |    /* loop through the comma separated array elements */
 1175|  1.01M|    do {
 1176|       |        /* allocate next item */
 1177|  1.01M|        cJSON *new_item = cJSON_New_Item(input_buffer->pAllocator);
 1178|  1.01M|        if (new_item == NULL) {
  ------------------
  |  Branch (1178:13): [True: 0, False: 1.01M]
  ------------------
 1179|      0|            *out_of_memory = true;
  ------------------
  |  |   67|      0|#define true ((cJSON_bool)1)
  ------------------
 1180|      0|            goto fail; /* allocation failure */
 1181|      0|        }
 1182|       |
 1183|       |        /* attach next item to list */
 1184|  1.01M|        if (head == NULL) {
  ------------------
  |  Branch (1184:13): [True: 346k, False: 665k]
  ------------------
 1185|       |            /* start the linked list */
 1186|   346k|            current_item = head = new_item;
 1187|   665k|        } else {
 1188|       |            /* add to the end and advance */
 1189|   665k|            current_item->next = new_item;
 1190|   665k|            new_item->prev = current_item;
 1191|   665k|            current_item = new_item;
 1192|   665k|        }
 1193|       |
 1194|       |        /* parse next value */
 1195|  1.01M|        input_buffer->offset++;
 1196|  1.01M|        buffer_skip_whitespace(input_buffer);
 1197|  1.01M|        if (!parse_value(current_item, input_buffer, out_of_memory)) {
  ------------------
  |  Branch (1197:13): [True: 241k, False: 770k]
  ------------------
 1198|   241k|            goto fail; /* failed to parse value */
 1199|   241k|        }
 1200|   770k|        buffer_skip_whitespace(input_buffer);
 1201|   770k|    } while (can_access_at_index(input_buffer, 0) && (buffer_at_offset(input_buffer)[0] == ','));
  ------------------
  |  |  192|  1.54M|#define can_access_at_index(buffer, index) ((buffer != NULL) && (((buffer)->offset + index) < (buffer)->length))
  |  |  ------------------
  |  |  |  Branch (192:45): [True: 770k, False: 0]
  |  |  |  Branch (192:65): [True: 770k, False: 0]
  |  |  ------------------
  ------------------
                  } while (can_access_at_index(input_buffer, 0) && (buffer_at_offset(input_buffer)[0] == ','));
  ------------------
  |  |  195|   770k|#define buffer_at_offset(buffer) ((buffer)->content + (buffer)->offset)
  ------------------
  |  Branch (1201:54): [True: 665k, False: 105k]
  ------------------
 1202|       |
 1203|   105k|    if (cannot_access_at_index(input_buffer, 0) || buffer_at_offset(input_buffer)[0] != ']') {
  ------------------
  |  |  193|   210k|#define cannot_access_at_index(buffer, index) (!can_access_at_index(buffer, index))
  |  |  ------------------
  |  |  |  |  192|   105k|#define can_access_at_index(buffer, index) ((buffer != NULL) && (((buffer)->offset + index) < (buffer)->length))
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (192:45): [True: 105k, False: 0]
  |  |  |  |  |  Branch (192:65): [True: 105k, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
                  if (cannot_access_at_index(input_buffer, 0) || buffer_at_offset(input_buffer)[0] != ']') {
  ------------------
  |  |  195|   105k|#define buffer_at_offset(buffer) ((buffer)->content + (buffer)->offset)
  ------------------
  |  Branch (1203:52): [True: 243, False: 104k]
  ------------------
 1204|    243|        goto fail; /* expected end of array */
 1205|    243|    }
 1206|       |
 1207|   112k|success:
 1208|   112k|    input_buffer->depth--;
 1209|       |
 1210|   112k|    if (head != NULL) {
  ------------------
  |  Branch (1210:9): [True: 104k, False: 7.17k]
  ------------------
 1211|   104k|        head->prev = current_item;
 1212|   104k|    }
 1213|       |
 1214|   112k|    item->type = cJSON_Array;
  ------------------
  |  |  102|   112k|#define cJSON_Array (1 << 5)
  ------------------
 1215|   112k|    item->child = head;
 1216|       |
 1217|   112k|    input_buffer->offset++;
 1218|       |
 1219|   112k|    return true;
  ------------------
  |  |   67|   112k|#define true ((cJSON_bool)1)
  ------------------
 1220|       |
 1221|   241k|fail:
 1222|   241k|    if (head != NULL) {
  ------------------
  |  Branch (1222:9): [True: 241k, False: 0]
  ------------------
 1223|   241k|        loader_cJSON_Delete(head);
 1224|   241k|    }
 1225|       |
 1226|   241k|    return false;
  ------------------
  |  |   72|   241k|#define false ((cJSON_bool)0)
  ------------------
 1227|   105k|}
cJSON.c:parse_object:
 1287|   648k|static cJSON_bool parse_object(cJSON *const item, parse_buffer *const input_buffer, bool *out_of_memory) {
 1288|   648k|    cJSON *head = NULL; /* linked list head */
 1289|   648k|    cJSON *current_item = NULL;
 1290|       |
 1291|   648k|    if (input_buffer->depth >= CJSON_NESTING_LIMIT) {
  ------------------
  |  |  138|   648k|#define CJSON_NESTING_LIMIT 1000
  ------------------
  |  Branch (1291:9): [True: 111, False: 648k]
  ------------------
 1292|    111|        return false; /* to deeply nested */
  ------------------
  |  |   72|    111|#define false ((cJSON_bool)0)
  ------------------
 1293|    111|    }
 1294|   648k|    input_buffer->depth++;
 1295|       |
 1296|   648k|    if (cannot_access_at_index(input_buffer, 0) || (buffer_at_offset(input_buffer)[0] != '{')) {
  ------------------
  |  |  193|  1.29M|#define cannot_access_at_index(buffer, index) (!can_access_at_index(buffer, index))
  |  |  ------------------
  |  |  |  |  192|   648k|#define can_access_at_index(buffer, index) ((buffer != NULL) && (((buffer)->offset + index) < (buffer)->length))
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (192:45): [True: 648k, False: 0]
  |  |  |  |  |  Branch (192:65): [True: 648k, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
                  if (cannot_access_at_index(input_buffer, 0) || (buffer_at_offset(input_buffer)[0] != '{')) {
  ------------------
  |  |  195|   648k|#define buffer_at_offset(buffer) ((buffer)->content + (buffer)->offset)
  ------------------
  |  Branch (1296:52): [True: 0, False: 648k]
  ------------------
 1297|      0|        goto fail; /* not an object */
 1298|      0|    }
 1299|       |
 1300|   648k|    input_buffer->offset++;
 1301|   648k|    buffer_skip_whitespace(input_buffer);
 1302|   648k|    if (can_access_at_index(input_buffer, 0) && (buffer_at_offset(input_buffer)[0] == '}')) {
  ------------------
  |  |  192|  1.29M|#define can_access_at_index(buffer, index) ((buffer != NULL) && (((buffer)->offset + index) < (buffer)->length))
  |  |  ------------------
  |  |  |  Branch (192:45): [True: 648k, False: 0]
  |  |  |  Branch (192:65): [True: 648k, False: 0]
  |  |  ------------------
  ------------------
                  if (can_access_at_index(input_buffer, 0) && (buffer_at_offset(input_buffer)[0] == '}')) {
  ------------------
  |  |  195|   648k|#define buffer_at_offset(buffer) ((buffer)->content + (buffer)->offset)
  ------------------
  |  Branch (1302:49): [True: 16.6k, False: 631k]
  ------------------
 1303|  16.6k|        goto success; /* empty object */
 1304|  16.6k|    }
 1305|       |
 1306|       |    /* check if we skipped to the end of the buffer */
 1307|   631k|    if (cannot_access_at_index(input_buffer, 0)) {
  ------------------
  |  |  193|   631k|#define cannot_access_at_index(buffer, index) (!can_access_at_index(buffer, index))
  |  |  ------------------
  |  |  |  |  192|   631k|#define can_access_at_index(buffer, index) ((buffer != NULL) && (((buffer)->offset + index) < (buffer)->length))
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (192:45): [True: 631k, False: 0]
  |  |  |  |  |  Branch (192:65): [True: 631k, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1308|      0|        input_buffer->offset--;
 1309|      0|        goto fail;
 1310|      0|    }
 1311|       |
 1312|       |    /* step back to character in front of the first element */
 1313|   631k|    input_buffer->offset--;
 1314|       |    /* loop through the comma separated array elements */
 1315|  3.94M|    do {
 1316|       |        /* allocate next item */
 1317|  3.94M|        cJSON *new_item = cJSON_New_Item(input_buffer->pAllocator);
 1318|  3.94M|        if (new_item == NULL) {
  ------------------
  |  Branch (1318:13): [True: 0, False: 3.94M]
  ------------------
 1319|      0|            *out_of_memory = true;
  ------------------
  |  |   67|      0|#define true ((cJSON_bool)1)
  ------------------
 1320|      0|            goto fail; /* allocation failure */
 1321|      0|        }
 1322|       |
 1323|       |        /* attach next item to list */
 1324|  3.94M|        if (head == NULL) {
  ------------------
  |  Branch (1324:13): [True: 631k, False: 3.30M]
  ------------------
 1325|       |            /* start the linked list */
 1326|   631k|            current_item = head = new_item;
 1327|  3.30M|        } else {
 1328|       |            /* add to the end and advance */
 1329|  3.30M|            current_item->next = new_item;
 1330|  3.30M|            new_item->prev = current_item;
 1331|  3.30M|            current_item = new_item;
 1332|  3.30M|        }
 1333|       |
 1334|  3.94M|        if (cannot_access_at_index(input_buffer, 1)) {
  ------------------
  |  |  193|  3.94M|#define cannot_access_at_index(buffer, index) (!can_access_at_index(buffer, index))
  |  |  ------------------
  |  |  |  |  192|  3.94M|#define can_access_at_index(buffer, index) ((buffer != NULL) && (((buffer)->offset + index) < (buffer)->length))
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (192:45): [True: 3.94M, False: 0]
  |  |  |  |  |  Branch (192:65): [True: 3.94M, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1335|      0|            goto fail; /* nothing comes after the comma */
 1336|      0|        }
 1337|       |
 1338|       |        /* parse the name of the child */
 1339|  3.94M|        input_buffer->offset++;
 1340|  3.94M|        buffer_skip_whitespace(input_buffer);
 1341|  3.94M|        if (!parse_string(current_item, input_buffer, out_of_memory)) {
  ------------------
  |  Branch (1341:13): [True: 697, False: 3.94M]
  ------------------
 1342|    697|            goto fail; /* failed to parse name */
 1343|    697|        }
 1344|  3.94M|        buffer_skip_whitespace(input_buffer);
 1345|       |
 1346|       |        /* swap valuestring and string, because we parsed the name */
 1347|  3.94M|        current_item->string = current_item->valuestring;
 1348|  3.94M|        current_item->valuestring = NULL;
 1349|       |
 1350|  3.94M|        if (cannot_access_at_index(input_buffer, 0) || (buffer_at_offset(input_buffer)[0] != ':')) {
  ------------------
  |  |  193|  7.88M|#define cannot_access_at_index(buffer, index) (!can_access_at_index(buffer, index))
  |  |  ------------------
  |  |  |  |  192|  3.94M|#define can_access_at_index(buffer, index) ((buffer != NULL) && (((buffer)->offset + index) < (buffer)->length))
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (192:45): [True: 3.94M, False: 0]
  |  |  |  |  |  Branch (192:65): [True: 3.94M, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
                      if (cannot_access_at_index(input_buffer, 0) || (buffer_at_offset(input_buffer)[0] != ':')) {
  ------------------
  |  |  195|  3.94M|#define buffer_at_offset(buffer) ((buffer)->content + (buffer)->offset)
  ------------------
  |  Branch (1350:56): [True: 175, False: 3.94M]
  ------------------
 1351|    175|            goto fail; /* invalid object */
 1352|    175|        }
 1353|       |
 1354|       |        /* parse the value */
 1355|  3.94M|        input_buffer->offset++;
 1356|  3.94M|        buffer_skip_whitespace(input_buffer);
 1357|  3.94M|        if (!parse_value(current_item, input_buffer, out_of_memory)) {
  ------------------
  |  Branch (1357:13): [True: 1.87k, False: 3.93M]
  ------------------
 1358|  1.87k|            goto fail; /* failed to parse value */
 1359|  1.87k|        }
 1360|  3.93M|        buffer_skip_whitespace(input_buffer);
 1361|  3.93M|    } while (can_access_at_index(input_buffer, 0) && (buffer_at_offset(input_buffer)[0] == ','));
  ------------------
  |  |  192|  7.87M|#define can_access_at_index(buffer, index) ((buffer != NULL) && (((buffer)->offset + index) < (buffer)->length))
  |  |  ------------------
  |  |  |  Branch (192:45): [True: 3.93M, False: 0]
  |  |  |  Branch (192:65): [True: 3.93M, False: 0]
  |  |  ------------------
  ------------------
                  } while (can_access_at_index(input_buffer, 0) && (buffer_at_offset(input_buffer)[0] == ','));
  ------------------
  |  |  195|  3.93M|#define buffer_at_offset(buffer) ((buffer)->content + (buffer)->offset)
  ------------------
  |  Branch (1361:54): [True: 3.30M, False: 629k]
  ------------------
 1362|       |
 1363|   629k|    if (cannot_access_at_index(input_buffer, 0) || (buffer_at_offset(input_buffer)[0] != '}')) {
  ------------------
  |  |  193|  1.25M|#define cannot_access_at_index(buffer, index) (!can_access_at_index(buffer, index))
  |  |  ------------------
  |  |  |  |  192|   629k|#define can_access_at_index(buffer, index) ((buffer != NULL) && (((buffer)->offset + index) < (buffer)->length))
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (192:45): [True: 629k, False: 0]
  |  |  |  |  |  Branch (192:65): [True: 629k, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
                  if (cannot_access_at_index(input_buffer, 0) || (buffer_at_offset(input_buffer)[0] != '}')) {
  ------------------
  |  |  195|   629k|#define buffer_at_offset(buffer) ((buffer)->content + (buffer)->offset)
  ------------------
  |  Branch (1363:52): [True: 125, False: 629k]
  ------------------
 1364|    125|        goto fail; /* expected end of object */
 1365|    125|    }
 1366|       |
 1367|   645k|success:
 1368|   645k|    input_buffer->depth--;
 1369|       |
 1370|   645k|    if (head != NULL) {
  ------------------
  |  Branch (1370:9): [True: 629k, False: 16.6k]
  ------------------
 1371|   629k|        head->prev = current_item;
 1372|   629k|    }
 1373|       |
 1374|   645k|    item->type = cJSON_Object;
  ------------------
  |  |  103|   645k|#define cJSON_Object (1 << 6)
  ------------------
 1375|   645k|    item->child = head;
 1376|       |
 1377|   645k|    input_buffer->offset++;
 1378|   645k|    return true;
  ------------------
  |  |   67|   645k|#define true ((cJSON_bool)1)
  ------------------
 1379|       |
 1380|  2.87k|fail:
 1381|  2.87k|    if (head != NULL) {
  ------------------
  |  Branch (1381:9): [True: 2.87k, False: 0]
  ------------------
 1382|  2.87k|        loader_cJSON_Delete(head);
 1383|  2.87k|    }
 1384|       |
 1385|  2.87k|    return false;
  ------------------
  |  |   72|  2.87k|#define false ((cJSON_bool)0)
  ------------------
 1386|   629k|}
cJSON.c:print_value:
 1080|  1.00M|static cJSON_bool print_value(const cJSON *const item, printbuffer *const output_buffer, bool *out_of_memory) {
 1081|  1.00M|    unsigned char *output = NULL;
 1082|       |
 1083|  1.00M|    if ((item == NULL) || (output_buffer == NULL)) {
  ------------------
  |  Branch (1083:9): [True: 0, False: 1.00M]
  |  Branch (1083:27): [True: 0, False: 1.00M]
  ------------------
 1084|      0|        return false;
  ------------------
  |  |   72|      0|#define false ((cJSON_bool)0)
  ------------------
 1085|      0|    }
 1086|       |
 1087|  1.00M|    switch ((item->type) & 0xFF) {
 1088|      0|        case cJSON_NULL:
  ------------------
  |  |   99|      0|#define cJSON_NULL (1 << 2)
  ------------------
  |  Branch (1088:9): [True: 0, False: 1.00M]
  ------------------
 1089|      0|            output = ensure(output_buffer, 5, out_of_memory);
 1090|      0|            if (output == NULL) {
  ------------------
  |  Branch (1090:17): [True: 0, False: 0]
  ------------------
 1091|      0|                return false;
  ------------------
  |  |   72|      0|#define false ((cJSON_bool)0)
  ------------------
 1092|      0|            }
 1093|      0|            strcpy((char *)output, "null");
 1094|      0|            return true;
  ------------------
  |  |   67|      0|#define true ((cJSON_bool)1)
  ------------------
 1095|       |
 1096|      0|        case cJSON_False:
  ------------------
  |  |   97|      0|#define cJSON_False (1 << 0)
  ------------------
  |  Branch (1096:9): [True: 0, False: 1.00M]
  ------------------
 1097|      0|            output = ensure(output_buffer, 6, out_of_memory);
 1098|      0|            if (output == NULL) {
  ------------------
  |  Branch (1098:17): [True: 0, False: 0]
  ------------------
 1099|      0|                return false;
  ------------------
  |  |   72|      0|#define false ((cJSON_bool)0)
  ------------------
 1100|      0|            }
 1101|      0|            strcpy((char *)output, "false");
 1102|      0|            return true;
  ------------------
  |  |   67|      0|#define true ((cJSON_bool)1)
  ------------------
 1103|       |
 1104|      0|        case cJSON_True:
  ------------------
  |  |   98|      0|#define cJSON_True (1 << 1)
  ------------------
  |  Branch (1104:9): [True: 0, False: 1.00M]
  ------------------
 1105|      0|            output = ensure(output_buffer, 5, out_of_memory);
 1106|      0|            if (output == NULL) {
  ------------------
  |  Branch (1106:17): [True: 0, False: 0]
  ------------------
 1107|      0|                return false;
  ------------------
  |  |   72|      0|#define false ((cJSON_bool)0)
  ------------------
 1108|      0|            }
 1109|      0|            strcpy((char *)output, "true");
 1110|      0|            return true;
  ------------------
  |  |   67|      0|#define true ((cJSON_bool)1)
  ------------------
 1111|       |
 1112|      0|        case cJSON_Number:
  ------------------
  |  |  100|      0|#define cJSON_Number (1 << 3)
  ------------------
  |  Branch (1112:9): [True: 0, False: 1.00M]
  ------------------
 1113|      0|            return print_number(item, output_buffer, out_of_memory);
 1114|       |
 1115|      0|        case cJSON_Raw: {
  ------------------
  |  |  104|      0|#define cJSON_Raw (1 << 7) /* raw json */
  ------------------
  |  Branch (1115:9): [True: 0, False: 1.00M]
  ------------------
 1116|      0|            size_t raw_length = 0;
 1117|      0|            if (item->valuestring == NULL) {
  ------------------
  |  Branch (1117:17): [True: 0, False: 0]
  ------------------
 1118|      0|                return false;
  ------------------
  |  |   72|      0|#define false ((cJSON_bool)0)
  ------------------
 1119|      0|            }
 1120|       |
 1121|      0|            raw_length = strlen(item->valuestring) + sizeof("");
 1122|      0|            output = ensure(output_buffer, raw_length, out_of_memory);
 1123|      0|            if (output == NULL) {
  ------------------
  |  Branch (1123:17): [True: 0, False: 0]
  ------------------
 1124|      0|                return false;
  ------------------
  |  |   72|      0|#define false ((cJSON_bool)0)
  ------------------
 1125|      0|            }
 1126|      0|            memcpy(output, item->valuestring, raw_length);
 1127|      0|            return true;
  ------------------
  |  |   67|      0|#define true ((cJSON_bool)1)
  ------------------
 1128|      0|        }
 1129|       |
 1130|  1.00M|        case cJSON_String:
  ------------------
  |  |  101|  1.00M|#define cJSON_String (1 << 4)
  ------------------
  |  Branch (1130:9): [True: 1.00M, False: 0]
  ------------------
 1131|  1.00M|            return print_string(item, output_buffer, out_of_memory);
 1132|       |
 1133|      0|        case cJSON_Array:
  ------------------
  |  |  102|      0|#define cJSON_Array (1 << 5)
  ------------------
  |  Branch (1133:9): [True: 0, False: 1.00M]
  ------------------
 1134|      0|            return print_array(item, output_buffer, out_of_memory);
 1135|       |
 1136|      0|        case cJSON_Object:
  ------------------
  |  |  103|      0|#define cJSON_Object (1 << 6)
  ------------------
  |  Branch (1136:9): [True: 0, False: 1.00M]
  ------------------
 1137|      0|            return print_object(item, output_buffer, out_of_memory);
 1138|       |
 1139|      0|        default:
  ------------------
  |  Branch (1139:9): [True: 0, False: 1.00M]
  ------------------
 1140|      0|            return false;
  ------------------
  |  |   72|      0|#define false ((cJSON_bool)0)
  ------------------
 1141|  1.00M|    }
 1142|  1.00M|}
cJSON.c:ensure:
  299|  1.00M|static unsigned char *ensure(printbuffer *const p, size_t needed, bool *out_of_memory) {
  300|  1.00M|    unsigned char *newbuffer = NULL;
  301|  1.00M|    size_t newsize = 0;
  302|       |
  303|  1.00M|    if ((p == NULL) || (p->buffer == NULL)) {
  ------------------
  |  Branch (303:9): [True: 0, False: 1.00M]
  |  Branch (303:24): [True: 0, False: 1.00M]
  ------------------
  304|      0|        return NULL;
  305|      0|    }
  306|       |
  307|  1.00M|    if ((p->length > 0) && (p->offset >= p->length)) {
  ------------------
  |  Branch (307:9): [True: 1.00M, False: 0]
  |  Branch (307:28): [True: 0, False: 1.00M]
  ------------------
  308|       |        /* make sure that offset is valid */
  309|      0|        return NULL;
  310|      0|    }
  311|       |
  312|  1.00M|    if (needed > INT_MAX) {
  ------------------
  |  Branch (312:9): [True: 0, False: 1.00M]
  ------------------
  313|       |        /* sizes bigger than INT_MAX are currently not supported */
  314|      0|        return NULL;
  315|      0|    }
  316|       |
  317|  1.00M|    needed += p->offset + 1;
  318|  1.00M|    if (needed <= p->length) {
  ------------------
  |  Branch (318:9): [True: 1.00M, False: 2.55k]
  ------------------
  319|  1.00M|        return p->buffer + p->offset;
  320|  1.00M|    }
  321|       |
  322|  2.55k|    if (p->noalloc) {
  ------------------
  |  Branch (322:9): [True: 545, False: 2.00k]
  ------------------
  323|    545|        return NULL;
  324|    545|    }
  325|       |
  326|       |    /* calculate new buffer size */
  327|  2.00k|    if (needed > (INT_MAX / 2)) {
  ------------------
  |  Branch (327:9): [True: 0, False: 2.00k]
  ------------------
  328|       |        /* overflow of int, use INT_MAX if possible */
  329|      0|        if (needed <= INT_MAX) {
  ------------------
  |  Branch (329:13): [True: 0, False: 0]
  ------------------
  330|      0|            newsize = INT_MAX;
  331|      0|        } else {
  332|      0|            return NULL;
  333|      0|        }
  334|  2.00k|    } else {
  335|  2.00k|        newsize = needed * 2;
  336|  2.00k|    }
  337|       |
  338|  2.00k|    newbuffer = (unsigned char *)loader_realloc(p->pAllocator, p->buffer, p->length, newsize, VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE);
  339|  2.00k|    if (newbuffer == NULL) {
  ------------------
  |  Branch (339:9): [True: 0, False: 2.00k]
  ------------------
  340|      0|        *out_of_memory = true;
  ------------------
  |  |   67|      0|#define true ((cJSON_bool)1)
  ------------------
  341|      0|        loader_free(p->pAllocator, p->buffer);
  342|      0|        p->length = 0;
  343|      0|        p->buffer = NULL;
  344|       |
  345|      0|        return NULL;
  346|      0|    }
  347|       |
  348|  2.00k|    p->length = newsize;
  349|  2.00k|    p->buffer = newbuffer;
  350|       |
  351|  2.00k|    return newbuffer + p->offset;
  352|  2.00k|}
cJSON.c:print_string:
  783|  1.00M|static cJSON_bool print_string(const cJSON *const item, printbuffer *const p, bool *out_of_memory) {
  784|  1.00M|    return print_string_ptr((unsigned char *)item->valuestring, p, out_of_memory);
  785|  1.00M|}
cJSON.c:print_string_ptr:
  674|  1.00M|static cJSON_bool print_string_ptr(const unsigned char *const input, printbuffer *const output_buffer, bool *out_of_memory) {
  675|  1.00M|    const unsigned char *input_pointer = NULL;
  676|  1.00M|    unsigned char *output = NULL;
  677|  1.00M|    unsigned char *output_pointer = NULL;
  678|  1.00M|    size_t output_length = 0;
  679|       |    /* numbers of additional characters needed for escaping */
  680|  1.00M|    size_t escape_characters = 0;
  681|       |
  682|  1.00M|    if (output_buffer == NULL) {
  ------------------
  |  Branch (682:9): [True: 0, False: 1.00M]
  ------------------
  683|      0|        return false;
  ------------------
  |  |   72|      0|#define false ((cJSON_bool)0)
  ------------------
  684|      0|    }
  685|       |
  686|       |    /* empty string */
  687|  1.00M|    if (input == NULL) {
  ------------------
  |  Branch (687:9): [True: 0, False: 1.00M]
  ------------------
  688|      0|        output = ensure(output_buffer, sizeof(""), out_of_memory);
  689|      0|        if (output == NULL) {
  ------------------
  |  Branch (689:13): [True: 0, False: 0]
  ------------------
  690|      0|            return false;
  ------------------
  |  |   72|      0|#define false ((cJSON_bool)0)
  ------------------
  691|      0|        }
  692|       |
  693|      0|        return true;
  ------------------
  |  |   67|      0|#define true ((cJSON_bool)1)
  ------------------
  694|      0|    }
  695|       |
  696|       |    /* set "flag" to 1 if something needs to be escaped */
  697|  32.6M|    for (input_pointer = input; *input_pointer; input_pointer++) {
  ------------------
  |  Branch (697:33): [True: 31.6M, False: 1.00M]
  ------------------
  698|  31.6M|        switch (*input_pointer) {
  699|    296|            case '\"':
  ------------------
  |  Branch (699:13): [True: 296, False: 31.6M]
  ------------------
  700|  1.04k|            case '\\':
  ------------------
  |  Branch (700:13): [True: 744, False: 31.6M]
  ------------------
  701|  17.0k|            case '\b':
  ------------------
  |  Branch (701:13): [True: 16.0k, False: 31.6M]
  ------------------
  702|  18.9k|            case '\f':
  ------------------
  |  Branch (702:13): [True: 1.84k, False: 31.6M]
  ------------------
  703|  23.7k|            case '\n':
  ------------------
  |  Branch (703:13): [True: 4.79k, False: 31.6M]
  ------------------
  704|  30.2k|            case '\r':
  ------------------
  |  Branch (704:13): [True: 6.58k, False: 31.6M]
  ------------------
  705|  38.6k|            case '\t':
  ------------------
  |  Branch (705:13): [True: 8.40k, False: 31.6M]
  ------------------
  706|       |                /* one character escape sequence */
  707|  38.6k|                escape_characters++;
  708|  38.6k|                break;
  709|  31.6M|            default:
  ------------------
  |  Branch (709:13): [True: 31.6M, False: 38.6k]
  ------------------
  710|  31.6M|                if (*input_pointer < 32) {
  ------------------
  |  Branch (710:21): [True: 26.8M, False: 4.75M]
  ------------------
  711|       |                    /* UTF-16 escape sequence uXXXX */
  712|  26.8M|                    escape_characters += 5;
  713|  26.8M|                }
  714|  31.6M|                break;
  715|  31.6M|        }
  716|  31.6M|    }
  717|  1.00M|    output_length = (size_t)(input_pointer - input) + escape_characters;
  718|       |
  719|  1.00M|    output = ensure(output_buffer, output_length + sizeof(""), out_of_memory);
  720|  1.00M|    if (output == NULL) {
  ------------------
  |  Branch (720:9): [True: 545, False: 1.00M]
  ------------------
  721|    545|        return false;
  ------------------
  |  |   72|    545|#define false ((cJSON_bool)0)
  ------------------
  722|    545|    }
  723|       |
  724|       |    /* no characters have to be escaped */
  725|  1.00M|    if (escape_characters == 0) {
  ------------------
  |  Branch (725:9): [True: 914k, False: 88.9k]
  ------------------
  726|   914k|        memcpy(output, input, output_length);
  727|   914k|        output[output_length] = '\0';
  728|       |
  729|   914k|        return true;
  ------------------
  |  |   67|   914k|#define true ((cJSON_bool)1)
  ------------------
  730|   914k|    }
  731|       |
  732|  88.9k|    output_pointer = output;
  733|       |    /* copy the string */
  734|  27.6M|    for (input_pointer = input; *input_pointer != '\0'; (void)input_pointer++, output_pointer++) {
  ------------------
  |  Branch (734:33): [True: 27.5M, False: 88.9k]
  ------------------
  735|  27.5M|        if ((*input_pointer > 31) && (*input_pointer != '\"') && (*input_pointer != '\\')) {
  ------------------
  |  Branch (735:13): [True: 982k, False: 26.5M]
  |  Branch (735:38): [True: 982k, False: 182]
  |  Branch (735:66): [True: 981k, False: 678]
  ------------------
  736|       |            /* normal character, copy */
  737|   981k|            *output_pointer = *input_pointer;
  738|  26.5M|        } else {
  739|       |            // Loader specific modification - don't add a backslash because that will 'double up' any existing back slashes.
  740|       |            // This change was added right after vulkan's public release, so while it may not be a problem, there are plenty
  741|       |            // of API calls made which might not work if the paths have "\\"" in them
  742|       |            /* character needs to be escaped */
  743|       |            //*output_pointer++ = '\\';
  744|  26.5M|            switch (*input_pointer) {
  745|    678|                case '\\':
  ------------------
  |  Branch (745:17): [True: 678, False: 26.5M]
  ------------------
  746|    678|                    *output_pointer = '\\';
  747|    678|                    break;
  748|    182|                case '\"':
  ------------------
  |  Branch (748:17): [True: 182, False: 26.5M]
  ------------------
  749|    182|                    *output_pointer = '\"';
  750|    182|                    break;
  751|  16.0k|                case '\b':
  ------------------
  |  Branch (751:17): [True: 16.0k, False: 26.5M]
  ------------------
  752|  16.0k|                    *output_pointer = '\b';
  753|  16.0k|                    break;
  754|  1.83k|                case '\f':
  ------------------
  |  Branch (754:17): [True: 1.83k, False: 26.5M]
  ------------------
  755|  1.83k|                    *output_pointer = '\f';
  756|  1.83k|                    break;
  757|  4.78k|                case '\n':
  ------------------
  |  Branch (757:17): [True: 4.78k, False: 26.5M]
  ------------------
  758|  4.78k|                    *output_pointer = '\n';
  759|  4.78k|                    break;
  760|  6.15k|                case '\r':
  ------------------
  |  Branch (760:17): [True: 6.15k, False: 26.5M]
  ------------------
  761|  6.15k|                    *output_pointer = '\r';
  762|  6.15k|                    break;
  763|  8.24k|                case '\t':
  ------------------
  |  Branch (763:17): [True: 8.24k, False: 26.5M]
  ------------------
  764|  8.24k|                    *output_pointer = '\t';
  765|  8.24k|                    break;
  766|  26.4M|                default:
  ------------------
  |  Branch (766:17): [True: 26.4M, False: 37.9k]
  ------------------
  767|       |                    /* escape and print as unicode codepoint */
  768|  26.4M|                    snprintf((char *)output_pointer, output_length - (size_t)(output_pointer - output), "u%04x", *input_pointer);
  769|  26.4M|                    output_pointer += 4;
  770|  26.4M|                    break;
  771|  26.5M|            }
  772|  26.5M|        }
  773|  27.5M|    }
  774|       |    // The loader-specific escaping above emits one byte where the standard form emits two, so the written
  775|       |    // length is shorter than output_length. Terminate at the actual end, otherwise the bytes between it and
  776|       |    // output_length (uninitialized when the caller buffer is not zeroed) get read back as part of the string.
  777|  88.9k|    *output_pointer = '\0';
  778|       |
  779|  88.9k|    return true;
  ------------------
  |  |   67|  88.9k|#define true ((cJSON_bool)1)
  ------------------
  780|  88.9k|}
cJSON.c:get_object_item:
 1533|  4.12M|static cJSON *get_object_item(const cJSON *const object, const char *const name, const cJSON_bool case_sensitive) {
 1534|  4.12M|    cJSON *current_element = NULL;
 1535|       |
 1536|  4.12M|    if ((object == NULL) || (name == NULL)) {
  ------------------
  |  Branch (1536:9): [True: 0, False: 4.12M]
  |  Branch (1536:29): [True: 0, False: 4.12M]
  ------------------
 1537|      0|        return NULL;
 1538|      0|    }
 1539|       |
 1540|  4.12M|    current_element = object->child;
 1541|  4.12M|    if (case_sensitive) {
  ------------------
  |  Branch (1541:9): [True: 0, False: 4.12M]
  ------------------
 1542|      0|        while ((current_element != NULL) && (current_element->string != NULL) && (strcmp(name, current_element->string) != 0)) {
  ------------------
  |  Branch (1542:16): [True: 0, False: 0]
  |  Branch (1542:45): [True: 0, False: 0]
  |  Branch (1542:82): [True: 0, False: 0]
  ------------------
 1543|      0|            current_element = current_element->next;
 1544|      0|        }
 1545|  4.12M|    } else {
 1546|  26.7M|        while ((current_element != NULL) &&
  ------------------
  |  Branch (1546:16): [True: 24.7M, False: 2.06M]
  ------------------
 1547|  24.7M|               (case_insensitive_strcmp((const unsigned char *)name, (const unsigned char *)(current_element->string)) != 0)) {
  ------------------
  |  Branch (1547:16): [True: 22.6M, False: 2.06M]
  ------------------
 1548|  22.6M|            current_element = current_element->next;
 1549|  22.6M|        }
 1550|  4.12M|    }
 1551|       |
 1552|  4.12M|    if ((current_element == NULL) || (current_element->string == NULL)) {
  ------------------
  |  Branch (1552:9): [True: 2.06M, False: 2.06M]
  |  Branch (1552:38): [True: 0, False: 2.06M]
  ------------------
 1553|  2.06M|        return NULL;
 1554|  2.06M|    }
 1555|       |
 1556|  2.06M|    return current_element;
 1557|  4.12M|}
cJSON.c:case_insensitive_strcmp:
  120|  24.7M|static int case_insensitive_strcmp(const unsigned char *string1, const unsigned char *string2) {
  121|  24.7M|    if ((string1 == NULL) || (string2 == NULL)) {
  ------------------
  |  Branch (121:9): [True: 0, False: 24.7M]
  |  Branch (121:30): [True: 3.44k, False: 24.7M]
  ------------------
  122|  3.44k|        return 1;
  123|  3.44k|    }
  124|       |
  125|  24.7M|    if (string1 == string2) {
  ------------------
  |  Branch (125:9): [True: 0, False: 24.7M]
  ------------------
  126|      0|        return 0;
  127|      0|    }
  128|       |
  129|  51.2M|    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: 51.2M]
  |  Branch (129:12): [True: 28.5M, False: 22.6M]
  |  Branch (129:33): [True: 0, False: 0]
  |  Branch (129:33): [True: 0, False: 0]
  |  Branch (129:33): [Folded, False: 51.2M]
  ------------------
  130|  28.5M|        if (*string1 == '\0') {
  ------------------
  |  Branch (130:13): [True: 2.06M, False: 26.4M]
  ------------------
  131|  2.06M|            return 0;
  132|  2.06M|        }
  133|  28.5M|    }
  134|       |
  135|  22.6M|    return tolower(*string1) - tolower(*string2);
  ------------------
  |  Branch (135:12): [True: 0, False: 0]
  |  Branch (135:12): [True: 0, False: 0]
  |  Branch (135:12): [Folded, False: 22.6M]
  |  Branch (135:32): [True: 0, False: 0]
  |  Branch (135:32): [True: 0, False: 0]
  |  Branch (135:32): [Folded, False: 22.6M]
  ------------------
  136|  24.7M|}

util_SubmitDebugUtilsMessageEXT:
   78|  1.11M|                                         const VkDebugUtilsMessengerCallbackDataEXT *pCallbackData) {
   79|  1.11M|    VkBool32 bail = false;
   80|       |
   81|  1.11M|    if (NULL != pCallbackData) {
  ------------------
  |  Branch (81:9): [True: 1.11M, False: 0]
  ------------------
   82|       |        // The messenger/report chain is guarded by loader_lock everywhere it is modified (see the create/destroy
   83|       |        // terminators). loader_lock is recursive, so taking it here is safe even when a caller already holds it.
   84|  1.11M|        loader_platform_thread_lock_mutex(&loader_lock);
   85|  1.11M|        VkLayerDbgFunctionNode *pTrav = inst->current_dbg_function_head;
   86|  1.11M|        VkDebugReportObjectTypeEXT object_type = VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT;
   87|  1.11M|        VkDebugReportFlagsEXT object_flags = 0;
   88|  1.11M|        uint64_t object_handle = 0;
   89|       |
   90|  1.11M|        debug_utils_AnnotFlagsToReportFlags(messageSeverity, messageTypes, &object_flags);
   91|  1.11M|        if (0 < pCallbackData->objectCount) {
  ------------------
  |  Branch (91:13): [True: 1.11M, False: 0]
  ------------------
   92|  1.11M|            debug_utils_AnnotObjectToDebugReportObject(pCallbackData->pObjects, &object_type, &object_handle);
   93|  1.11M|        }
   94|  1.11M|        while (pTrav) {
  ------------------
  |  Branch (94:16): [True: 0, False: 1.11M]
  ------------------
   95|      0|            if (pTrav->is_messenger && (pTrav->messenger.messageSeverity & messageSeverity) &&
  ------------------
  |  Branch (95:17): [True: 0, False: 0]
  |  Branch (95:40): [True: 0, False: 0]
  ------------------
   96|      0|                (pTrav->messenger.messageType & messageTypes)) {
  ------------------
  |  Branch (96:17): [True: 0, False: 0]
  ------------------
   97|      0|                if (pTrav->messenger.pfnUserCallback(messageSeverity, messageTypes, pCallbackData, pTrav->pUserData)) {
  ------------------
  |  Branch (97:21): [True: 0, False: 0]
  ------------------
   98|      0|                    bail = true;
   99|      0|                }
  100|      0|            }
  101|      0|            if (!pTrav->is_messenger && pTrav->report.msgFlags & object_flags) {
  ------------------
  |  Branch (101:17): [True: 0, False: 0]
  |  Branch (101:41): [True: 0, False: 0]
  ------------------
  102|      0|                if (pTrav->report.pfnMsgCallback(object_flags, object_type, object_handle, 0, pCallbackData->messageIdNumber,
  ------------------
  |  Branch (102:21): [True: 0, False: 0]
  ------------------
  103|      0|                                                 pCallbackData->pMessageIdName, pCallbackData->pMessage, pTrav->pUserData)) {
  104|      0|                    bail = true;
  105|      0|                }
  106|      0|            }
  107|      0|            pTrav = pTrav->pNext;
  108|      0|        }
  109|  1.11M|        loader_platform_thread_unlock_mutex(&loader_lock);
  110|  1.11M|    }
  111|       |
  112|  1.11M|    return bail;
  113|  1.11M|}
util_CreateDebugUtilsMessengers:
  134|  6.58k|                                         const VkAllocationCallbacks *pAllocator) {
  135|  6.58k|    const void *pNext = pChain;
  136|  6.58k|    while (pNext) {
  ------------------
  |  Branch (136:12): [True: 0, False: 6.58k]
  ------------------
  137|      0|        VkBaseInStructure in_structure = {0};
  138|      0|        memcpy(&in_structure, pNext, sizeof(VkBaseInStructure));
  139|      0|        if (in_structure.sType == VK_STRUCTURE_TYPE_DEBUG_UTILS_MESSENGER_CREATE_INFO_EXT) {
  ------------------
  |  Branch (139:13): [True: 0, False: 0]
  ------------------
  140|       |            // Assign a unique handle to each messenger (just use the address of the VkDebugUtilsMessengerCreateInfoEXT)
  141|       |            // This is only being used this way due to it being for an 'anonymous' callback during instance creation
  142|       |            // NOLINTNEXTLINE(performance-no-int-to-ptr) - non-dispatchable handle; round-trip via uintptr_t is required
  143|      0|            VkDebugUtilsMessengerEXT messenger_handle = (VkDebugUtilsMessengerEXT)(uintptr_t)pNext;
  144|      0|            VkResult ret = util_CreateDebugUtilsMessenger(inst, (const VkDebugUtilsMessengerCreateInfoEXT *)pNext, pAllocator,
  145|      0|                                                          messenger_handle);
  146|      0|            if (ret != VK_SUCCESS) {
  ------------------
  |  Branch (146:17): [True: 0, False: 0]
  ------------------
  147|      0|                return ret;
  148|      0|            }
  149|      0|        }
  150|      0|        pNext = in_structure.pNext;
  151|      0|    }
  152|  6.58k|    return VK_SUCCESS;
  153|  6.58k|}
util_CreateDebugReportCallbacks:
  417|  6.58k|                                         const VkAllocationCallbacks *pAllocator) {
  418|  6.58k|    const void *pNext = pChain;
  419|  6.58k|    while (pNext) {
  ------------------
  |  Branch (419:12): [True: 0, False: 6.58k]
  ------------------
  420|      0|        VkBaseInStructure in_structure = {0};
  421|      0|        memcpy(&in_structure, pNext, sizeof(VkBaseInStructure));
  422|      0|        if (in_structure.sType == VK_STRUCTURE_TYPE_DEBUG_REPORT_CREATE_INFO_EXT) {
  ------------------
  |  Branch (422:13): [True: 0, False: 0]
  ------------------
  423|       |            // Assign a unique handle to each callback (just use the address of the VkDebugReportCallbackCreateInfoEXT):
  424|       |            // This is only being used this way due to it being for an 'anonymous' callback during instance creation
  425|       |            // NOLINTNEXTLINE(performance-no-int-to-ptr) - non-dispatchable handle; round-trip via uintptr_t is required
  426|      0|            VkDebugReportCallbackEXT report_handle = (VkDebugReportCallbackEXT)(uintptr_t)pNext;
  427|      0|            VkResult ret =
  428|      0|                util_CreateDebugReportCallback(inst, (const VkDebugReportCallbackCreateInfoEXT *)pNext, pAllocator, report_handle);
  429|      0|            if (ret != VK_SUCCESS) {
  ------------------
  |  Branch (429:17): [True: 0, False: 0]
  ------------------
  430|      0|                return ret;
  431|      0|            }
  432|      0|        }
  433|      0|        pNext = in_structure.pNext;
  434|      0|    }
  435|  6.58k|    return VK_SUCCESS;
  436|  6.58k|}
destroy_debug_callbacks_chain:
  619|  6.58k|void destroy_debug_callbacks_chain(struct loader_instance *inst, const VkAllocationCallbacks *pAllocator) {
  620|  6.58k|    VkLayerDbgFunctionNode *pTrav = inst->current_dbg_function_head;
  621|  6.58k|    VkLayerDbgFunctionNode *pNext = NULL;
  622|  6.58k|    while (pTrav) {
  ------------------
  |  Branch (622:12): [True: 0, False: 6.58k]
  ------------------
  623|      0|        pNext = pTrav->pNext;
  624|      0|        loader_free_with_instance_fallback(pAllocator, inst, pTrav);
  625|      0|        pTrav = pNext;
  626|      0|    }
  627|       |    inst->current_dbg_function_head = NULL;
  628|  6.58k|}
debug_utils_AnnotFlagsToReportFlags:
  704|  1.11M|                                         VkDebugUtilsMessageTypeFlagsEXT da_type, VkDebugReportFlagsEXT *dr_flags) {
  705|  1.11M|    if (NULL == dr_flags) {
  ------------------
  |  Branch (705:9): [True: 0, False: 1.11M]
  ------------------
  706|      0|        return false;
  707|      0|    }
  708|       |
  709|  1.11M|    *dr_flags = 0;
  710|       |
  711|  1.11M|    if ((da_severity & VK_DEBUG_UTILS_MESSAGE_SEVERITY_ERROR_BIT_EXT) != 0) {
  ------------------
  |  Branch (711:9): [True: 16.9k, False: 1.09M]
  ------------------
  712|  16.9k|        *dr_flags |= VK_DEBUG_REPORT_ERROR_BIT_EXT;
  713|  1.09M|    } else if ((da_severity & VK_DEBUG_UTILS_MESSAGE_SEVERITY_WARNING_BIT_EXT) != 0) {
  ------------------
  |  Branch (713:16): [True: 777k, False: 320k]
  ------------------
  714|   777k|        if ((da_type & VK_DEBUG_UTILS_MESSAGE_TYPE_PERFORMANCE_BIT_EXT) != 0) {
  ------------------
  |  Branch (714:13): [True: 0, False: 777k]
  ------------------
  715|      0|            *dr_flags |= VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT;
  716|   777k|        } else {
  717|   777k|            *dr_flags |= VK_DEBUG_REPORT_WARNING_BIT_EXT;
  718|   777k|        }
  719|   777k|    } else if ((da_severity & VK_DEBUG_UTILS_MESSAGE_SEVERITY_INFO_BIT_EXT) != 0) {
  ------------------
  |  Branch (719:16): [True: 216k, False: 103k]
  ------------------
  720|   216k|        *dr_flags |= VK_DEBUG_REPORT_INFORMATION_BIT_EXT;
  721|   216k|    } else if ((da_severity & VK_DEBUG_UTILS_MESSAGE_SEVERITY_VERBOSE_BIT_EXT) != 0) {
  ------------------
  |  Branch (721:16): [True: 103k, False: 0]
  ------------------
  722|   103k|        *dr_flags |= VK_DEBUG_REPORT_DEBUG_BIT_EXT;
  723|   103k|    }
  724|       |
  725|       |    return true;
  726|  1.11M|}
debug_utils_AnnotObjectToDebugReportObject:
  743|  1.11M|                                                VkDebugReportObjectTypeEXT *dr_object_type, uint64_t *dr_object_handle) {
  744|  1.11M|    if (NULL == da_object_name_info || NULL == dr_object_type || NULL == dr_object_handle) {
  ------------------
  |  Branch (744:9): [True: 0, False: 1.11M]
  |  Branch (744:40): [True: 0, False: 1.11M]
  |  Branch (744:66): [True: 0, False: 1.11M]
  ------------------
  745|      0|        return false;
  746|      0|    }
  747|  1.11M|    *dr_object_type = convertCoreObjectToDebugReportObject(da_object_name_info->objectType);
  748|  1.11M|    *dr_object_handle = da_object_name_info->objectHandle;
  749|       |    return true;
  750|  1.11M|}

debug_utils.c:convertCoreObjectToDebugReportObject:
  391|  1.11M|static inline VkDebugReportObjectTypeEXT convertCoreObjectToDebugReportObject(VkObjectType core_report_obj){
  392|  1.11M|    if (core_report_obj == VK_OBJECT_TYPE_UNKNOWN) {
  ------------------
  |  Branch (392:9): [True: 0, False: 1.11M]
  ------------------
  393|      0|        return VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT;
  394|  1.11M|    } else if (core_report_obj == VK_OBJECT_TYPE_UNKNOWN) {
  ------------------
  |  Branch (394:16): [True: 0, False: 1.11M]
  ------------------
  395|      0|        return VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT;
  396|  1.11M|    } else if (core_report_obj == VK_OBJECT_TYPE_INSTANCE) {
  ------------------
  |  Branch (396:16): [True: 1.11M, False: 0]
  ------------------
  397|  1.11M|        return VK_DEBUG_REPORT_OBJECT_TYPE_INSTANCE_EXT;
  398|  1.11M|    } else if (core_report_obj == VK_OBJECT_TYPE_PHYSICAL_DEVICE) {
  ------------------
  |  Branch (398:16): [True: 0, False: 0]
  ------------------
  399|      0|        return VK_DEBUG_REPORT_OBJECT_TYPE_PHYSICAL_DEVICE_EXT;
  400|      0|    } else if (core_report_obj == VK_OBJECT_TYPE_DEVICE) {
  ------------------
  |  Branch (400:16): [True: 0, False: 0]
  ------------------
  401|      0|        return VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT;
  402|      0|    } else if (core_report_obj == VK_OBJECT_TYPE_QUEUE) {
  ------------------
  |  Branch (402:16): [True: 0, False: 0]
  ------------------
  403|      0|        return VK_DEBUG_REPORT_OBJECT_TYPE_QUEUE_EXT;
  404|      0|    } else if (core_report_obj == VK_OBJECT_TYPE_SEMAPHORE) {
  ------------------
  |  Branch (404:16): [True: 0, False: 0]
  ------------------
  405|      0|        return VK_DEBUG_REPORT_OBJECT_TYPE_SEMAPHORE_EXT;
  406|      0|    } else if (core_report_obj == VK_OBJECT_TYPE_COMMAND_BUFFER) {
  ------------------
  |  Branch (406:16): [True: 0, False: 0]
  ------------------
  407|      0|        return VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT;
  408|      0|    } else if (core_report_obj == VK_OBJECT_TYPE_FENCE) {
  ------------------
  |  Branch (408:16): [True: 0, False: 0]
  ------------------
  409|      0|        return VK_DEBUG_REPORT_OBJECT_TYPE_FENCE_EXT;
  410|      0|    } else if (core_report_obj == VK_OBJECT_TYPE_DEVICE_MEMORY) {
  ------------------
  |  Branch (410:16): [True: 0, False: 0]
  ------------------
  411|      0|        return VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_MEMORY_EXT;
  412|      0|    } else if (core_report_obj == VK_OBJECT_TYPE_BUFFER) {
  ------------------
  |  Branch (412:16): [True: 0, False: 0]
  ------------------
  413|      0|        return VK_DEBUG_REPORT_OBJECT_TYPE_BUFFER_EXT;
  414|      0|    } else if (core_report_obj == VK_OBJECT_TYPE_IMAGE) {
  ------------------
  |  Branch (414:16): [True: 0, False: 0]
  ------------------
  415|      0|        return VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT;
  416|      0|    } else if (core_report_obj == VK_OBJECT_TYPE_EVENT) {
  ------------------
  |  Branch (416:16): [True: 0, False: 0]
  ------------------
  417|      0|        return VK_DEBUG_REPORT_OBJECT_TYPE_EVENT_EXT;
  418|      0|    } else if (core_report_obj == VK_OBJECT_TYPE_QUERY_POOL) {
  ------------------
  |  Branch (418:16): [True: 0, False: 0]
  ------------------
  419|      0|        return VK_DEBUG_REPORT_OBJECT_TYPE_QUERY_POOL_EXT;
  420|      0|    } else if (core_report_obj == VK_OBJECT_TYPE_BUFFER_VIEW) {
  ------------------
  |  Branch (420:16): [True: 0, False: 0]
  ------------------
  421|      0|        return VK_DEBUG_REPORT_OBJECT_TYPE_BUFFER_VIEW_EXT;
  422|      0|    } else if (core_report_obj == VK_OBJECT_TYPE_IMAGE_VIEW) {
  ------------------
  |  Branch (422:16): [True: 0, False: 0]
  ------------------
  423|      0|        return VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_VIEW_EXT;
  424|      0|    } else if (core_report_obj == VK_OBJECT_TYPE_SHADER_MODULE) {
  ------------------
  |  Branch (424:16): [True: 0, False: 0]
  ------------------
  425|      0|        return VK_DEBUG_REPORT_OBJECT_TYPE_SHADER_MODULE_EXT;
  426|      0|    } else if (core_report_obj == VK_OBJECT_TYPE_PIPELINE_CACHE) {
  ------------------
  |  Branch (426:16): [True: 0, False: 0]
  ------------------
  427|      0|        return VK_DEBUG_REPORT_OBJECT_TYPE_PIPELINE_CACHE_EXT;
  428|      0|    } else if (core_report_obj == VK_OBJECT_TYPE_PIPELINE_LAYOUT) {
  ------------------
  |  Branch (428:16): [True: 0, False: 0]
  ------------------
  429|      0|        return VK_DEBUG_REPORT_OBJECT_TYPE_PIPELINE_LAYOUT_EXT;
  430|      0|    } else if (core_report_obj == VK_OBJECT_TYPE_RENDER_PASS) {
  ------------------
  |  Branch (430:16): [True: 0, False: 0]
  ------------------
  431|      0|        return VK_DEBUG_REPORT_OBJECT_TYPE_RENDER_PASS_EXT;
  432|      0|    } else if (core_report_obj == VK_OBJECT_TYPE_PIPELINE) {
  ------------------
  |  Branch (432:16): [True: 0, False: 0]
  ------------------
  433|      0|        return VK_DEBUG_REPORT_OBJECT_TYPE_PIPELINE_EXT;
  434|      0|    } else if (core_report_obj == VK_OBJECT_TYPE_DESCRIPTOR_SET_LAYOUT) {
  ------------------
  |  Branch (434:16): [True: 0, False: 0]
  ------------------
  435|      0|        return VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_SET_LAYOUT_EXT;
  436|      0|    } else if (core_report_obj == VK_OBJECT_TYPE_SAMPLER) {
  ------------------
  |  Branch (436:16): [True: 0, False: 0]
  ------------------
  437|      0|        return VK_DEBUG_REPORT_OBJECT_TYPE_SAMPLER_EXT;
  438|      0|    } else if (core_report_obj == VK_OBJECT_TYPE_DESCRIPTOR_POOL) {
  ------------------
  |  Branch (438:16): [True: 0, False: 0]
  ------------------
  439|      0|        return VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_POOL_EXT;
  440|      0|    } else if (core_report_obj == VK_OBJECT_TYPE_DESCRIPTOR_SET) {
  ------------------
  |  Branch (440:16): [True: 0, False: 0]
  ------------------
  441|      0|        return VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_SET_EXT;
  442|      0|    } else if (core_report_obj == VK_OBJECT_TYPE_FRAMEBUFFER) {
  ------------------
  |  Branch (442:16): [True: 0, False: 0]
  ------------------
  443|      0|        return VK_DEBUG_REPORT_OBJECT_TYPE_FRAMEBUFFER_EXT;
  444|      0|    } else if (core_report_obj == VK_OBJECT_TYPE_COMMAND_POOL) {
  ------------------
  |  Branch (444:16): [True: 0, False: 0]
  ------------------
  445|      0|        return VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_POOL_EXT;
  446|      0|    } else if (core_report_obj == VK_OBJECT_TYPE_DESCRIPTOR_UPDATE_TEMPLATE) {
  ------------------
  |  Branch (446:16): [True: 0, False: 0]
  ------------------
  447|      0|        return VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_UPDATE_TEMPLATE_EXT;
  448|      0|    } else if (core_report_obj == VK_OBJECT_TYPE_SAMPLER_YCBCR_CONVERSION) {
  ------------------
  |  Branch (448:16): [True: 0, False: 0]
  ------------------
  449|      0|        return VK_DEBUG_REPORT_OBJECT_TYPE_SAMPLER_YCBCR_CONVERSION_EXT;
  450|      0|    } else if (core_report_obj == VK_OBJECT_TYPE_SURFACE_KHR) {
  ------------------
  |  Branch (450:16): [True: 0, False: 0]
  ------------------
  451|      0|        return VK_DEBUG_REPORT_OBJECT_TYPE_SURFACE_KHR_EXT;
  452|      0|    } else if (core_report_obj == VK_OBJECT_TYPE_SWAPCHAIN_KHR) {
  ------------------
  |  Branch (452:16): [True: 0, False: 0]
  ------------------
  453|      0|        return VK_DEBUG_REPORT_OBJECT_TYPE_SWAPCHAIN_KHR_EXT;
  454|      0|    } else if (core_report_obj == VK_OBJECT_TYPE_DISPLAY_KHR) {
  ------------------
  |  Branch (454:16): [True: 0, False: 0]
  ------------------
  455|      0|        return VK_DEBUG_REPORT_OBJECT_TYPE_DISPLAY_KHR_EXT;
  456|      0|    } else if (core_report_obj == VK_OBJECT_TYPE_DISPLAY_MODE_KHR) {
  ------------------
  |  Branch (456:16): [True: 0, False: 0]
  ------------------
  457|      0|        return VK_DEBUG_REPORT_OBJECT_TYPE_DISPLAY_MODE_KHR_EXT;
  458|      0|    } else if (core_report_obj == VK_OBJECT_TYPE_DEBUG_REPORT_CALLBACK_EXT) {
  ------------------
  |  Branch (458:16): [True: 0, False: 0]
  ------------------
  459|      0|        return VK_DEBUG_REPORT_OBJECT_TYPE_DEBUG_REPORT_CALLBACK_EXT_EXT;
  460|      0|    } else if (core_report_obj == VK_OBJECT_TYPE_CU_MODULE_NVX) {
  ------------------
  |  Branch (460:16): [True: 0, False: 0]
  ------------------
  461|      0|        return VK_DEBUG_REPORT_OBJECT_TYPE_CU_MODULE_NVX_EXT;
  462|      0|    } else if (core_report_obj == VK_OBJECT_TYPE_CU_FUNCTION_NVX) {
  ------------------
  |  Branch (462:16): [True: 0, False: 0]
  ------------------
  463|      0|        return VK_DEBUG_REPORT_OBJECT_TYPE_CU_FUNCTION_NVX_EXT;
  464|      0|    } else if (core_report_obj == VK_OBJECT_TYPE_ACCELERATION_STRUCTURE_KHR) {
  ------------------
  |  Branch (464:16): [True: 0, False: 0]
  ------------------
  465|      0|        return VK_DEBUG_REPORT_OBJECT_TYPE_ACCELERATION_STRUCTURE_KHR_EXT;
  466|      0|    } else if (core_report_obj == VK_OBJECT_TYPE_VALIDATION_CACHE_EXT) {
  ------------------
  |  Branch (466:16): [True: 0, False: 0]
  ------------------
  467|      0|        return VK_DEBUG_REPORT_OBJECT_TYPE_VALIDATION_CACHE_EXT_EXT;
  468|      0|    } else if (core_report_obj == VK_OBJECT_TYPE_ACCELERATION_STRUCTURE_NV) {
  ------------------
  |  Branch (468:16): [True: 0, False: 0]
  ------------------
  469|      0|        return VK_DEBUG_REPORT_OBJECT_TYPE_ACCELERATION_STRUCTURE_NV_EXT;
  470|      0|    } else if (core_report_obj == VK_OBJECT_TYPE_CUDA_MODULE_NV) {
  ------------------
  |  Branch (470:16): [True: 0, False: 0]
  ------------------
  471|      0|        return VK_DEBUG_REPORT_OBJECT_TYPE_CUDA_MODULE_NV_EXT;
  472|      0|    } else if (core_report_obj == VK_OBJECT_TYPE_CUDA_FUNCTION_NV) {
  ------------------
  |  Branch (472:16): [True: 0, False: 0]
  ------------------
  473|      0|        return VK_DEBUG_REPORT_OBJECT_TYPE_CUDA_FUNCTION_NV_EXT;
  474|      0|    } else if (core_report_obj == VK_OBJECT_TYPE_BUFFER_COLLECTION_FUCHSIA) {
  ------------------
  |  Branch (474:16): [True: 0, False: 0]
  ------------------
  475|      0|        return VK_DEBUG_REPORT_OBJECT_TYPE_BUFFER_COLLECTION_FUCHSIA_EXT;
  476|      0|    }
  477|      0|    return VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT;
  478|  1.11M|}

loader_make_version:
  113|  19.3k|loader_api_version loader_make_version(uint32_t version) {
  114|  19.3k|    loader_api_version out_version;
  115|  19.3k|    out_version.major = VK_API_VERSION_MAJOR(version);
  116|       |    out_version.minor = VK_API_VERSION_MINOR(version);
  117|  19.3k|    out_version.patch = 0;
  118|  19.3k|    return out_version;
  119|  19.3k|}
loader_make_full_version:
  122|  9.81k|loader_api_version loader_make_full_version(uint32_t version) {
  123|  9.81k|    loader_api_version out_version;
  124|  9.81k|    out_version.major = VK_API_VERSION_MAJOR(version);
  125|  9.81k|    out_version.minor = VK_API_VERSION_MINOR(version);
  126|       |    out_version.patch = VK_API_VERSION_PATCH(version);
  127|  9.81k|    return out_version;
  128|  9.81k|}
loader_combine_version:
  131|  88.7k|loader_api_version loader_combine_version(uint32_t major, uint32_t minor, uint32_t patch) {
  132|  88.7k|    loader_api_version out_version;
  133|  88.7k|    out_version.major = (uint16_t)major;
  134|  88.7k|    out_version.minor = (uint16_t)minor;
  135|  88.7k|    out_version.patch = (uint16_t)patch;
  136|  88.7k|    return out_version;
  137|  88.7k|}
loader_check_version_meets_required:
  140|  92.5k|bool loader_check_version_meets_required(loader_api_version required, loader_api_version version) {
  141|       |    // major version is satisfied
  142|  92.5k|    return (version.major > required.major) ||
  ------------------
  |  Branch (142:12): [True: 46.1k, False: 46.3k]
  ------------------
  143|       |           // major version is equal, minor version is patch version is greater to minimum minor
  144|  46.3k|           (version.major == required.major && version.minor > required.minor) ||
  ------------------
  |  Branch (144:13): [True: 10.0k, False: 36.2k]
  |  Branch (144:48): [True: 1.98k, False: 8.08k]
  ------------------
  145|       |           // major and minor version are equal, patch version is greater or equal to minimum patch
  146|  44.3k|           (version.major == required.major && version.minor == required.minor && version.patch >= required.patch);
  ------------------
  |  Branch (146:13): [True: 8.08k, False: 36.2k]
  |  Branch (146:48): [True: 4.79k, False: 3.29k]
  |  Branch (146:83): [True: 3.69k, False: 1.09k]
  ------------------
  147|  92.5k|}
loader_opendir:
  172|  69.7k|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|  69.7k|    return opendir(name);
  178|       |#else
  179|       |#warning dirent.h - opendir not available on this platform
  180|       |#endif  // _WIN32
  181|  69.7k|}
loader_closedir:
  182|  5.53k|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|  5.53k|    return closedir(dir);
  188|       |#else
  189|       |#warning dirent.h - closedir not available on this platform
  190|       |#endif  // _WIN32
  191|  5.53k|}
is_json:
  193|   183k|bool is_json(const char *path, size_t len) {
  194|   183k|    if (len < 5) {
  ------------------
  |  Branch (194:9): [True: 13.4k, False: 169k]
  ------------------
  195|  13.4k|        return false;
  196|  13.4k|    }
  197|   169k|    return !strncmp(path + len - 5, ".json", 5);
  198|   183k|}
loader_free_layer_properties:
  248|   547k|void loader_free_layer_properties(const struct loader_instance *inst, struct loader_layer_properties *layer_properties) {
  249|   547k|    loader_instance_heap_free(inst, layer_properties->manifest_file_name);
  250|   547k|    loader_instance_heap_free(inst, layer_properties->lib_name);
  251|   547k|    loader_instance_heap_free(inst, layer_properties->functions.str_gipa);
  252|   547k|    loader_instance_heap_free(inst, layer_properties->functions.str_gdpa);
  253|   547k|    loader_instance_heap_free(inst, layer_properties->functions.str_negotiate_interface);
  254|   547k|    loader_destroy_generic_list(inst, (struct loader_generic_list *)&layer_properties->instance_extension_list);
  255|   547k|    if (layer_properties->device_extension_list.capacity > 0 && NULL != layer_properties->device_extension_list.list) {
  ------------------
  |  Branch (255:9): [True: 1.51k, False: 546k]
  |  Branch (255:65): [True: 1.51k, False: 0]
  ------------------
  256|  19.4k|        for (uint32_t i = 0; i < layer_properties->device_extension_list.count; i++) {
  ------------------
  |  Branch (256:30): [True: 17.9k, False: 1.51k]
  ------------------
  257|  17.9k|            free_string_list(inst, &layer_properties->device_extension_list.list[i].entrypoints);
  258|  17.9k|        }
  259|  1.51k|    }
  260|   547k|    loader_destroy_generic_list(inst, (struct loader_generic_list *)&layer_properties->device_extension_list);
  261|   547k|    loader_instance_heap_free(inst, layer_properties->disable_env_var.name);
  262|   547k|    loader_instance_heap_free(inst, layer_properties->disable_env_var.value);
  263|   547k|    loader_instance_heap_free(inst, layer_properties->enable_env_var.name);
  264|   547k|    loader_instance_heap_free(inst, layer_properties->enable_env_var.value);
  265|   547k|    free_string_list(inst, &layer_properties->component_layer_names);
  266|   547k|    loader_instance_heap_free(inst, layer_properties->pre_instance_functions.enumerate_instance_extension_properties);
  267|   547k|    loader_instance_heap_free(inst, layer_properties->pre_instance_functions.enumerate_instance_layer_properties);
  268|   547k|    loader_instance_heap_free(inst, layer_properties->pre_instance_functions.enumerate_instance_version);
  269|   547k|    free_string_list(inst, &layer_properties->override_paths);
  270|   547k|    free_string_list(inst, &layer_properties->blacklist_layer_names);
  271|   547k|    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|   547k|    memset(layer_properties, 0, sizeof(struct loader_layer_properties));
  275|   547k|}
is_string_in_string_list:
  288|  82.8k|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|  1.22M|    for (size_t i = 0; i < string_list->count; i++) {
  ------------------
  |  Branch (290:24): [True: 1.13M, False: 81.9k]
  ------------------
  291|  1.13M|        if (strcmp(string_list->list[i], str) == 0) {
  ------------------
  |  Branch (291:13): [True: 868, False: 1.13M]
  ------------------
  292|    868|            return true;
  293|    868|        }
  294|  1.13M|    }
  295|  81.9k|    return false;
  296|  82.8k|}
loader_copy_to_new_str:
  298|   536k|VkResult loader_copy_to_new_str(const struct loader_instance *inst, const char *source_str, char **dest_str) {
  299|   536k|    assert(source_str && dest_str);
  300|   536k|    size_t str_len = strlen(source_str) + 1;
  301|   536k|    *dest_str = loader_instance_heap_calloc(inst, str_len, VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE);
  302|   536k|    if (NULL == *dest_str) return VK_ERROR_OUT_OF_HOST_MEMORY;
  ------------------
  |  Branch (302:9): [True: 0, False: 536k]
  ------------------
  303|   536k|    loader_strncpy(*dest_str, str_len, source_str, str_len);
  304|   536k|    (*dest_str)[str_len - 1] = 0;
  305|   536k|    return VK_SUCCESS;
  306|   536k|}
create_string_list:
  308|  44.4k|VkResult create_string_list(const struct loader_instance *inst, uint32_t allocated_count, struct loader_string_list *string_list) {
  309|  44.4k|    assert(string_list);
  310|  44.4k|    string_list->list =
  311|  44.4k|        (char **)loader_instance_heap_calloc(inst, sizeof(char *) * allocated_count, VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE);
  312|  44.4k|    if (NULL == string_list->list) {
  ------------------
  |  Branch (312:9): [True: 0, False: 44.4k]
  ------------------
  313|      0|        return VK_ERROR_OUT_OF_HOST_MEMORY;
  314|      0|    }
  315|  44.4k|    string_list->allocated_count = allocated_count;
  316|  44.4k|    string_list->count = 0;
  317|  44.4k|    return VK_SUCCESS;
  318|  44.4k|}
increase_str_capacity_by_at_least_one:
  320|   151k|VkResult increase_str_capacity_by_at_least_one(const struct loader_instance *inst, struct loader_string_list *string_list) {
  321|   151k|    assert(string_list);
  322|   151k|    if (string_list->allocated_count == 0) {
  ------------------
  |  Branch (322:9): [True: 14.3k, False: 137k]
  ------------------
  323|  14.3k|        string_list->allocated_count = 32;
  324|  14.3k|        string_list->list = (char **)loader_instance_heap_calloc(inst, sizeof(char *) * string_list->allocated_count,
  325|  14.3k|                                                                 VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE);
  326|  14.3k|        if (NULL == string_list->list) {
  ------------------
  |  Branch (326:13): [True: 0, False: 14.3k]
  ------------------
  327|      0|            return VK_ERROR_OUT_OF_HOST_MEMORY;
  328|      0|        }
  329|   137k|    } else if (string_list->count + 1 > string_list->allocated_count) {
  ------------------
  |  Branch (329:16): [True: 100, False: 137k]
  ------------------
  330|    100|        uint32_t new_allocated_count = string_list->allocated_count * 2;
  331|    100|        void *new_ptr = loader_instance_heap_realloc(inst, (void *)string_list->list, sizeof(char *) * string_list->allocated_count,
  332|    100|                                                     sizeof(char *) * new_allocated_count, VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE);
  333|    100|        if (NULL == new_ptr) {
  ------------------
  |  Branch (333:13): [True: 0, False: 100]
  ------------------
  334|      0|            return VK_ERROR_OUT_OF_HOST_MEMORY;
  335|      0|        }
  336|    100|        string_list->list = (char **)new_ptr;
  337|    100|        string_list->allocated_count *= 2;
  338|    100|    }
  339|   151k|    return VK_SUCCESS;
  340|   151k|}
append_str_to_string_list:
  342|   151k|VkResult append_str_to_string_list(const struct loader_instance *inst, struct loader_string_list *string_list, char *str) {
  343|   151k|    assert(string_list && str);
  344|   151k|    VkResult res = increase_str_capacity_by_at_least_one(inst, string_list);
  345|   151k|    if (res == VK_ERROR_OUT_OF_HOST_MEMORY) {
  ------------------
  |  Branch (345:9): [True: 0, False: 151k]
  ------------------
  346|      0|        loader_instance_heap_free(inst, str);  // Must clean up in case of failure
  347|      0|        return res;
  348|      0|    }
  349|   151k|    string_list->list[string_list->count++] = str;
  350|   151k|    return VK_SUCCESS;
  351|   151k|}
append_str_to_string_list_if_unique:
  354|  75.0k|                                             char *str) {
  355|  75.0k|    if (is_string_in_string_list(string_list, str)) {
  ------------------
  |  Branch (355:9): [True: 868, False: 74.1k]
  ------------------
  356|       |        // Since this string is a duplicate and this function takes ownership, we need to free it.
  357|    868|        loader_instance_heap_free(inst, str);
  358|    868|        return VK_SUCCESS;
  359|    868|    }
  360|  74.1k|    return append_str_to_string_list(inst, string_list, str);
  361|  75.0k|}
copy_str_to_string_list:
  379|  7.80k|                                 size_t str_len) {
  380|  7.80k|    assert(string_list && str);
  381|  7.80k|    char *new_str = loader_instance_heap_calloc(inst, str_len + 1, VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE);
  382|  7.80k|    if (NULL == new_str) {
  ------------------
  |  Branch (382:9): [True: 0, False: 7.80k]
  ------------------
  383|      0|        return VK_ERROR_OUT_OF_HOST_MEMORY;
  384|      0|    }
  385|  7.80k|    loader_strncpy(new_str, str_len + 1, str, str_len);
  386|  7.80k|    new_str[str_len] = '\0';
  387|  7.80k|    return append_str_to_string_list(inst, string_list, new_str);
  388|  7.80k|}
copy_str_to_string_list_if_unique:
  391|  7.80k|                                           const char *str, size_t str_len) {
  392|  7.80k|    if (is_string_in_string_list(string_list, str)) {
  ------------------
  |  Branch (392:9): [True: 0, False: 7.80k]
  ------------------
  393|      0|        return VK_SUCCESS;
  394|      0|    }
  395|  7.80k|    return copy_str_to_string_list(inst, string_list, str, str_len);
  396|  7.80k|}
free_string_list:
  423|  2.25M|void free_string_list(const struct loader_instance *inst, struct loader_string_list *string_list) {
  424|  2.25M|    assert(string_list);
  425|  2.25M|    if (string_list->list) {
  ------------------
  |  Branch (425:9): [True: 58.7k, False: 2.19M]
  ------------------
  426|   210k|        for (uint32_t i = 0; i < string_list->count; i++) {
  ------------------
  |  Branch (426:30): [True: 151k, False: 58.7k]
  ------------------
  427|   151k|            loader_instance_heap_free(inst, string_list->list[i]);
  428|       |            string_list->list[i] = NULL;
  429|   151k|        }
  430|  58.7k|        loader_instance_heap_free(inst, (void *)string_list->list);
  431|  58.7k|    }
  432|  2.25M|    memset(string_list, 0, sizeof(struct loader_string_list));
  433|  2.25M|}
loader_parse_version_string:
  710|   336k|uint32_t loader_parse_version_string(char *vers_str) {
  711|   336k|    uint32_t variant = 0;
  712|   336k|    uint32_t major = 0;
  713|   336k|    uint32_t minor = 0;
  714|   336k|    uint32_t patch = 0;
  715|   336k|    char *vers_tok;
  716|   336k|    char *context = NULL;
  717|   336k|    if (!vers_str) {
  ------------------
  |  Branch (717:9): [True: 0, False: 336k]
  ------------------
  718|      0|        return 0;
  719|      0|    }
  720|       |
  721|   336k|    vers_tok = thread_safe_strtok(vers_str, ".\"\n\r", &context);
  722|   336k|    if (NULL != vers_tok) {
  ------------------
  |  Branch (722:9): [True: 105k, False: 231k]
  ------------------
  723|   105k|        major = (uint16_t)strtoul(vers_tok, NULL, 10);
  724|   105k|        vers_tok = thread_safe_strtok(NULL, ".\"\n\r", &context);
  725|   105k|        if (NULL != vers_tok) {
  ------------------
  |  Branch (725:13): [True: 46.3k, False: 58.8k]
  ------------------
  726|  46.3k|            minor = (uint16_t)strtoul(vers_tok, NULL, 10);
  727|  46.3k|            vers_tok = thread_safe_strtok(NULL, ".\"\n\r", &context);
  728|  46.3k|            if (NULL != vers_tok) {
  ------------------
  |  Branch (728:17): [True: 40.9k, False: 5.40k]
  ------------------
  729|  40.9k|                patch = (uint16_t)strtoul(vers_tok, NULL, 10);
  730|  40.9k|                vers_tok = thread_safe_strtok(NULL, ".\"\n\r", &context);
  731|       |                // check that we are using a 4 part version string
  732|  40.9k|                if (NULL != vers_tok) {
  ------------------
  |  Branch (732:21): [True: 1.30k, False: 39.6k]
  ------------------
  733|       |                    // if we are, move the values over into the correct place
  734|  1.30k|                    variant = major;
  735|  1.30k|                    major = minor;
  736|  1.30k|                    minor = patch;
  737|  1.30k|                    patch = (uint16_t)strtoul(vers_tok, NULL, 10);
  738|  1.30k|                }
  739|  40.9k|            }
  740|  46.3k|        }
  741|   105k|    }
  742|       |
  743|       |    return VK_MAKE_API_VERSION(variant, major, minor, patch);
  744|   336k|}
compare_vk_extension_properties:
  746|   659k|TEST_FUNCTION_EXPORT bool compare_vk_extension_properties(const VkExtensionProperties *op1, const VkExtensionProperties *op2) {
  747|   659k|    return strncmp(op1->extensionName, op2->extensionName, VK_MAX_EXTENSION_NAME_SIZE) == 0 ? true : false;
  ------------------
  |  Branch (747:12): [True: 5.42k, False: 653k]
  ------------------
  748|   659k|}
has_vk_extension_property:
  760|  16.6k|bool has_vk_extension_property(const VkExtensionProperties *vk_ext_prop, const struct loader_extension_list *ext_list) {
  761|   225k|    for (uint32_t i = 0; i < ext_list->count; i++) {
  ------------------
  |  Branch (761:26): [True: 210k, False: 15.2k]
  ------------------
  762|   210k|        if (compare_vk_extension_properties(&ext_list->list[i], vk_ext_prop)) return true;
  ------------------
  |  Branch (762:13): [True: 1.41k, False: 208k]
  ------------------
  763|   210k|    }
  764|  15.2k|    return false;
  765|  16.6k|}
has_vk_dev_ext_property:
  768|  26.0k|bool has_vk_dev_ext_property(const VkExtensionProperties *ext_prop, const struct loader_device_extension_list *ext_list) {
  769|   470k|    for (uint32_t i = 0; i < ext_list->count; i++) {
  ------------------
  |  Branch (769:26): [True: 448k, False: 22.0k]
  ------------------
  770|   448k|        if (compare_vk_extension_properties(&ext_list->list[i].props, ext_prop)) return true;
  ------------------
  |  Branch (770:13): [True: 4.00k, False: 444k]
  ------------------
  771|   448k|    }
  772|  22.0k|    return false;
  773|  26.0k|}
loader_append_layer_property:
  776|   223k|                                      struct loader_layer_properties *layer_property) {
  777|   223k|    VkResult res = VK_SUCCESS;
  778|   223k|    if (layer_list->capacity == 0) {
  ------------------
  |  Branch (778:9): [True: 3.36k, False: 219k]
  ------------------
  779|  3.36k|        res = loader_init_generic_list(inst, (struct loader_generic_list *)layer_list, sizeof(struct loader_layer_properties));
  780|  3.36k|        if (VK_SUCCESS != res) {
  ------------------
  |  Branch (780:13): [True: 0, False: 3.36k]
  ------------------
  781|      0|            goto out;
  782|      0|        }
  783|  3.36k|    }
  784|       |
  785|       |    // Ensure enough room to add an entry
  786|   223k|    if ((layer_list->count + 1) * sizeof(struct loader_layer_properties) > layer_list->capacity) {
  ------------------
  |  Branch (786:9): [True: 686, False: 222k]
  ------------------
  787|    686|        void *new_ptr = loader_instance_heap_realloc(inst, layer_list->list, layer_list->capacity, layer_list->capacity * 2,
  788|    686|                                                     VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE);
  789|    686|        if (NULL == new_ptr) {
  ------------------
  |  Branch (789:13): [True: 0, False: 686]
  ------------------
  790|      0|            loader_log(inst, VULKAN_LOADER_ERROR_BIT, 0, "loader_append_layer_property: realloc failed for layer list");
  791|      0|            res = VK_ERROR_OUT_OF_HOST_MEMORY;
  792|      0|            goto out;
  793|      0|        }
  794|    686|        layer_list->list = new_ptr;
  795|    686|        layer_list->capacity *= 2;
  796|    686|    }
  797|   223k|    memcpy(&layer_list->list[layer_list->count], layer_property, sizeof(struct loader_layer_properties));
  798|   223k|    layer_list->count++;
  799|   223k|    memset(layer_property, 0, sizeof(struct loader_layer_properties));
  800|   223k|out:
  801|   223k|    if (res != VK_SUCCESS) {
  ------------------
  |  Branch (801:9): [True: 0, False: 223k]
  ------------------
  802|      0|        loader_free_layer_properties(inst, layer_property);
  803|      0|    }
  804|   223k|    return res;
  805|   223k|}
loader_find_layer_property:
  808|  13.3k|struct loader_layer_properties *loader_find_layer_property(const char *name, const struct loader_layer_list *layer_list) {
  809|   534k|    for (uint32_t i = 0; i < layer_list->count; i++) {
  ------------------
  |  Branch (809:26): [True: 527k, False: 7.27k]
  ------------------
  810|   527k|        const VkLayerProperties *item = &layer_list->list[i].info;
  811|   527k|        if (strcmp(name, item->layerName) == 0) return &layer_list->list[i];
  ------------------
  |  Branch (811:13): [True: 6.10k, False: 521k]
  ------------------
  812|   527k|    }
  813|  7.27k|    return NULL;
  814|  13.3k|}
loader_find_layer_name_in_blacklist:
  837|  18.9k|bool loader_find_layer_name_in_blacklist(const char *layer_name, struct loader_layer_properties *meta_layer_props) {
  838|  18.9k|    for (uint32_t black_layer = 0; black_layer < meta_layer_props->blacklist_layer_names.count; ++black_layer) {
  ------------------
  |  Branch (838:36): [True: 0, False: 18.9k]
  ------------------
  839|      0|        if (!strcmp(meta_layer_props->blacklist_layer_names.list[black_layer], layer_name)) {
  ------------------
  |  Branch (839:13): [True: 0, False: 0]
  ------------------
  840|      0|            return true;
  841|      0|        }
  842|      0|    }
  843|  18.9k|    return false;
  844|  18.9k|}
loader_delete_layer_list_and_properties:
  848|  19.7k|                                                                  struct loader_layer_list *layer_list) {
  849|  19.7k|    uint32_t i;
  850|  19.7k|    if (!layer_list) return;
  ------------------
  |  Branch (850:9): [True: 0, False: 19.7k]
  ------------------
  851|       |
  852|   220k|    for (i = 0; i < layer_list->count; i++) {
  ------------------
  |  Branch (852:17): [True: 200k, False: 19.7k]
  ------------------
  853|   200k|        if (layer_list->list[i].lib_handle) {
  ------------------
  |  Branch (853:13): [True: 0, False: 200k]
  ------------------
  854|      0|            loader_platform_close_library(layer_list->list[i].lib_handle);
  855|      0|            loader_log(inst, VULKAN_LOADER_DEBUG_BIT | VULKAN_LOADER_LAYER_BIT, 0, "Unloading layer library %s",
  856|      0|                       layer_list->list[i].lib_name);
  857|      0|            layer_list->list[i].lib_handle = NULL;
  858|      0|        }
  859|   200k|        loader_free_layer_properties(inst, &(layer_list->list[i]));
  860|   200k|    }
  861|  19.7k|    layer_list->count = 0;
  862|       |
  863|  19.7k|    if (layer_list->capacity > 0) {
  ------------------
  |  Branch (863:9): [True: 3.71k, False: 16.0k]
  ------------------
  864|  3.71k|        layer_list->capacity = 0;
  865|  3.71k|        loader_instance_heap_free(inst, layer_list->list);
  866|  3.71k|    }
  867|  19.7k|    memset(layer_list, 0, sizeof(struct loader_layer_list));
  868|  19.7k|}
loader_remove_layer_in_list:
  871|  22.3k|                                 uint32_t layer_to_remove) {
  872|  22.3k|    if (layer_list == NULL || layer_to_remove >= layer_list->count) {
  ------------------
  |  Branch (872:9): [True: 0, False: 22.3k]
  |  Branch (872:31): [True: 0, False: 22.3k]
  ------------------
  873|      0|        return;
  874|      0|    }
  875|  22.3k|    loader_free_layer_properties(inst, &(layer_list->list[layer_to_remove]));
  876|       |
  877|       |    // Remove the current invalid meta-layer from the layer list.  Use memmove since we are
  878|       |    // overlapping the source and destination addresses.
  879|  22.3k|    if (layer_to_remove + 1 <= layer_list->count) {
  ------------------
  |  Branch (879:9): [True: 22.3k, False: 0]
  ------------------
  880|  22.3k|        memmove(&layer_list->list[layer_to_remove], &layer_list->list[layer_to_remove + 1],
  881|  22.3k|                sizeof(struct loader_layer_properties) * (layer_list->count - 1 - layer_to_remove));
  882|  22.3k|    }
  883|       |    // Decrement the count (because we now have one less) and decrement the loop index since we need to
  884|       |    // re-check this index.
  885|  22.3k|    layer_list->count--;
  886|  22.3k|}
loader_remove_layers_in_blacklist:
  890|    402|void loader_remove_layers_in_blacklist(const struct loader_instance *inst, struct loader_layer_list *layer_list) {
  891|    402|    struct loader_layer_properties *override_prop = loader_find_layer_property(VK_OVERRIDE_LAYER_NAME, layer_list);
  ------------------
  |  |  142|    402|#define VK_OVERRIDE_LAYER_NAME "VK_LAYER_LUNARG_override"
  ------------------
  892|    402|    if (NULL == override_prop) {
  ------------------
  |  Branch (892:9): [True: 0, False: 402]
  ------------------
  893|      0|        return;
  894|      0|    }
  895|       |
  896|  20.5k|    for (int32_t j = 0; j < (int32_t)(layer_list->count); j++) {
  ------------------
  |  Branch (896:25): [True: 20.1k, False: 402]
  ------------------
  897|  20.1k|        struct loader_layer_properties cur_layer_prop = layer_list->list[j];
  898|  20.1k|        const char *cur_layer_name = &cur_layer_prop.info.layerName[0];
  899|       |
  900|       |        // Skip the override layer itself.
  901|  20.1k|        if (!strcmp(VK_OVERRIDE_LAYER_NAME, cur_layer_name)) {
  ------------------
  |  |  142|  20.1k|#define VK_OVERRIDE_LAYER_NAME "VK_LAYER_LUNARG_override"
  ------------------
  |  Branch (901:13): [True: 1.14k, False: 18.9k]
  ------------------
  902|  1.14k|            continue;
  903|  1.14k|        }
  904|       |
  905|       |        // If found in the override layer's blacklist, remove it
  906|  18.9k|        if (loader_find_layer_name_in_blacklist(cur_layer_name, override_prop)) {
  ------------------
  |  Branch (906:13): [True: 0, False: 18.9k]
  ------------------
  907|      0|            loader_log(inst, VULKAN_LOADER_DEBUG_BIT, 0,
  908|      0|                       "loader_remove_layers_in_blacklist: Override layer is active and layer %s is in the blacklist inside of it. "
  909|      0|                       "Removing that layer from current layer list.",
  910|      0|                       cur_layer_name);
  911|      0|            loader_remove_layer_in_list(inst, layer_list, j);
  912|      0|            j--;
  913|       |
  914|       |            // Re-do the query for the override layer
  915|      0|            override_prop = loader_find_layer_property(VK_OVERRIDE_LAYER_NAME, layer_list);
  ------------------
  |  |  142|      0|#define VK_OVERRIDE_LAYER_NAME "VK_LAYER_LUNARG_override"
  ------------------
  916|      0|        }
  917|  18.9k|    }
  918|    402|}
loader_init_generic_list:
 1075|  6.65k|VkResult loader_init_generic_list(const struct loader_instance *inst, struct loader_generic_list *list_info, size_t element_size) {
 1076|  6.65k|    size_t capacity = 32 * element_size;
 1077|  6.65k|    list_info->count = 0;
 1078|  6.65k|    list_info->capacity = 0;
 1079|  6.65k|    list_info->list = loader_instance_heap_calloc(inst, capacity, VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE);
 1080|  6.65k|    if (list_info->list == NULL) {
  ------------------
  |  Branch (1080:9): [True: 0, False: 6.65k]
  ------------------
 1081|      0|        loader_log(inst, VULKAN_LOADER_ERROR_BIT, 0, "loader_init_generic_list: Failed to allocate space for generic list");
 1082|      0|        return VK_ERROR_OUT_OF_HOST_MEMORY;
 1083|      0|    }
 1084|  6.65k|    list_info->capacity = capacity;
 1085|  6.65k|    return VK_SUCCESS;
 1086|  6.65k|}
loader_destroy_generic_list:
 1104|  1.12M|void loader_destroy_generic_list(const struct loader_instance *inst, struct loader_generic_list *list) {
 1105|  1.12M|    loader_instance_heap_free(inst, list->list);
 1106|  1.12M|    memset(list, 0, sizeof(struct loader_generic_list));
 1107|  1.12M|}
loader_add_to_ext_list:
 1160|  13.7k|                                uint32_t prop_list_count, const VkExtensionProperties *props) {
 1161|  13.7k|    if (ext_list->list == NULL || ext_list->capacity == 0) {
  ------------------
  |  Branch (1161:9): [True: 1.43k, False: 12.2k]
  |  Branch (1161:35): [True: 0, False: 12.2k]
  ------------------
 1162|  1.43k|        VkResult res = loader_init_generic_list(inst, (struct loader_generic_list *)ext_list, sizeof(VkExtensionProperties));
 1163|  1.43k|        if (VK_SUCCESS != res) {
  ------------------
  |  Branch (1163:13): [True: 0, False: 1.43k]
  ------------------
 1164|      0|            return res;
 1165|      0|        }
 1166|  1.43k|    }
 1167|       |
 1168|  27.4k|    for (uint32_t i = 0; i < prop_list_count; i++) {
  ------------------
  |  Branch (1168:26): [True: 13.7k, False: 13.7k]
  ------------------
 1169|  13.7k|        const VkExtensionProperties *cur_ext = &props[i];
 1170|       |
 1171|       |        // look for duplicates
 1172|  13.7k|        if (has_vk_extension_property(cur_ext, ext_list)) {
  ------------------
  |  Branch (1172:13): [True: 1.27k, False: 12.4k]
  ------------------
 1173|  1.27k|            continue;
 1174|  1.27k|        }
 1175|       |
 1176|       |        // add to list at end
 1177|       |        // check for enough capacity
 1178|  12.4k|        if (ext_list->count * sizeof(VkExtensionProperties) >= ext_list->capacity) {
  ------------------
  |  Branch (1178:13): [True: 209, False: 12.2k]
  ------------------
 1179|    209|            void *new_ptr = loader_instance_heap_realloc(inst, ext_list->list, ext_list->capacity, ext_list->capacity * 2,
 1180|    209|                                                         VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE);
 1181|    209|            if (new_ptr == NULL) {
  ------------------
  |  Branch (1181:17): [True: 0, False: 209]
  ------------------
 1182|      0|                loader_log(inst, VULKAN_LOADER_ERROR_BIT, 0,
 1183|      0|                           "loader_add_to_ext_list: Failed to reallocate space for extension list");
 1184|      0|                return VK_ERROR_OUT_OF_HOST_MEMORY;
 1185|      0|            }
 1186|    209|            ext_list->list = new_ptr;
 1187|       |
 1188|       |            // double capacity
 1189|    209|            ext_list->capacity *= 2;
 1190|    209|        }
 1191|       |
 1192|       |        // every caller passes the address of an array element or on-stack struct, never NULL
 1193|       |        // NOLINTNEXTLINE(clang-analyzer-core.NonNullParamChecker)
 1194|  12.4k|        memcpy(&ext_list->list[ext_list->count], cur_ext, sizeof(VkExtensionProperties));
 1195|  12.4k|        ext_list->count++;
 1196|  12.4k|    }
 1197|  13.7k|    return VK_SUCCESS;
 1198|  13.7k|}
loader_add_to_dev_ext_list:
 1205|  21.5k|                                    const VkExtensionProperties *props, struct loader_string_list *entrys) {
 1206|  21.5k|    VkResult res = VK_SUCCESS;
 1207|  21.5k|    bool should_free_entrys = true;
 1208|  21.5k|    if (ext_list->list == NULL || ext_list->capacity == 0) {
  ------------------
  |  Branch (1208:9): [True: 1.51k, False: 20.0k]
  |  Branch (1208:35): [True: 0, False: 20.0k]
  ------------------
 1209|  1.51k|        res = loader_init_generic_list(inst, (struct loader_generic_list *)ext_list, sizeof(struct loader_dev_ext_props));
 1210|  1.51k|        if (VK_SUCCESS != res) {
  ------------------
  |  Branch (1210:13): [True: 0, False: 1.51k]
  ------------------
 1211|      0|            goto out;
 1212|      0|        }
 1213|  1.51k|    }
 1214|       |
 1215|       |    // look for duplicates
 1216|  21.5k|    if (has_vk_dev_ext_property(props, ext_list)) {
  ------------------
  |  Branch (1216:9): [True: 3.63k, False: 17.9k]
  ------------------
 1217|  3.63k|        goto out;
 1218|  3.63k|    }
 1219|       |
 1220|  17.9k|    uint32_t idx = ext_list->count;
 1221|       |    // add to list at end
 1222|       |    // check for enough capacity
 1223|  17.9k|    if (idx * sizeof(struct loader_dev_ext_props) >= ext_list->capacity) {
  ------------------
  |  Branch (1223:9): [True: 387, False: 17.5k]
  ------------------
 1224|    387|        void *new_ptr = loader_instance_heap_realloc(inst, ext_list->list, ext_list->capacity, ext_list->capacity * 2,
 1225|    387|                                                     VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE);
 1226|       |
 1227|    387|        if (NULL == new_ptr) {
  ------------------
  |  Branch (1227:13): [True: 0, False: 387]
  ------------------
 1228|      0|            loader_log(inst, VULKAN_LOADER_ERROR_BIT, 0,
 1229|      0|                       "loader_add_to_dev_ext_list: Failed to reallocate space for device extension list");
 1230|      0|            res = VK_ERROR_OUT_OF_HOST_MEMORY;
 1231|      0|            goto out;
 1232|      0|        }
 1233|    387|        ext_list->list = new_ptr;
 1234|       |
 1235|       |        // double capacity
 1236|    387|        ext_list->capacity *= 2;
 1237|    387|    }
 1238|       |
 1239|       |    // every caller passes the address of an array element or on-stack struct, never NULL
 1240|       |    // NOLINTNEXTLINE(clang-analyzer-core.NonNullParamChecker)
 1241|  17.9k|    memcpy(&ext_list->list[idx].props, props, sizeof(*props));
 1242|  17.9k|    if (entrys) {
  ------------------
  |  Branch (1242:9): [True: 1.11k, False: 16.8k]
  ------------------
 1243|  1.11k|        ext_list->list[idx].entrypoints = *entrys;
 1244|  1.11k|        should_free_entrys = false;
 1245|  16.8k|    } else {
 1246|  16.8k|        memset(&ext_list->list[idx].entrypoints, 0, sizeof(ext_list->list[idx].entrypoints));
 1247|  16.8k|    }
 1248|  17.9k|    ext_list->count++;
 1249|  21.5k|out:
 1250|  21.5k|    if (NULL != entrys && should_free_entrys) {
  ------------------
  |  Branch (1250:9): [True: 2.43k, False: 19.1k]
  |  Branch (1250:27): [True: 1.32k, False: 1.11k]
  ------------------
 1251|  1.32k|        free_string_list(inst, entrys);
 1252|  1.32k|    }
 1253|  21.5k|    return res;
 1254|  17.9k|}
loader_destroy_pointer_layer_list:
 1281|  6.58k|void loader_destroy_pointer_layer_list(const struct loader_instance *inst, struct loader_pointer_layer_list *layer_list) {
 1282|  6.58k|    loader_instance_heap_free(inst, (void *)layer_list->list);
 1283|  6.58k|    memset(layer_list, 0, sizeof(struct loader_pointer_layer_list));
 1284|  6.58k|}
loader_layer_is_available:
 1315|  22.3k|                               const struct loader_layer_properties *prop) {
 1316|  22.3k|    bool available = true;
 1317|  22.3k|    bool is_implicit = (0 == (prop->type_flags & VK_LAYER_TYPE_FLAG_EXPLICIT_LAYER));
 1318|  22.3k|    bool disabled_by_type =
 1319|  22.3k|        is_implicit ? filters->disable_filter.disable_all_implicit : filters->disable_filter.disable_all_explicit;
  ------------------
  |  Branch (1319:9): [True: 3.22k, False: 19.1k]
  ------------------
 1320|  22.3k|    if ((filters->disable_filter.disable_all || disabled_by_type ||
  ------------------
  |  Branch (1320:10): [True: 0, False: 22.3k]
  |  Branch (1320:49): [True: 0, False: 22.3k]
  ------------------
 1321|  22.3k|         check_name_matches_filter_environment_var(prop->info.layerName, &filters->disable_filter.additional_filters)) &&
  ------------------
  |  Branch (1321:10): [True: 0, False: 22.3k]
  ------------------
 1322|      0|        !check_name_matches_filter_environment_var(prop->info.layerName, &filters->allow_filter)) {
  ------------------
  |  Branch (1322:9): [True: 0, False: 0]
  ------------------
 1323|      0|        available = false;
 1324|      0|    }
 1325|  22.3k|    if (check_name_matches_filter_environment_var(prop->info.layerName, &filters->enable_filter)) {
  ------------------
  |  Branch (1325:9): [True: 30, False: 22.2k]
  ------------------
 1326|     30|        available = true;
 1327|  22.2k|    } else if (!available) {
  ------------------
  |  Branch (1327:16): [True: 0, False: 22.2k]
  ------------------
 1328|      0|        loader_log(inst, VULKAN_LOADER_WARN_BIT | VULKAN_LOADER_LAYER_BIT, 0,
 1329|      0|                   "Layer \"%s\" forced disabled because name matches filter of env var \'%s\'.", prop->info.layerName,
 1330|      0|                   VK_LAYERS_DISABLE_ENV_VAR);
  ------------------
  |  |  120|      0|#define VK_LAYERS_DISABLE_ENV_VAR "VK_LOADER_LAYERS_DISABLE"
  ------------------
 1331|      0|    }
 1332|       |
 1333|  22.3k|    return available;
 1334|  22.3k|}
loader_implicit_layer_is_enabled:
 1379|  1.53k|                                      const struct loader_layer_properties *prop) {
 1380|  1.53k|    bool enable = false;
 1381|  1.53k|    bool forced_disabled = false;
 1382|  1.53k|    bool forced_enabled = false;
 1383|       |
 1384|  1.53k|    if ((filters->disable_filter.disable_all || filters->disable_filter.disable_all_implicit ||
  ------------------
  |  Branch (1384:10): [True: 0, False: 1.53k]
  |  Branch (1384:49): [True: 0, False: 1.53k]
  ------------------
 1385|  1.53k|         check_name_matches_filter_environment_var(prop->info.layerName, &filters->disable_filter.additional_filters)) &&
  ------------------
  |  Branch (1385:10): [True: 0, False: 1.53k]
  ------------------
 1386|      0|        !check_name_matches_filter_environment_var(prop->info.layerName, &filters->allow_filter)) {
  ------------------
  |  Branch (1386:9): [True: 0, False: 0]
  ------------------
 1387|      0|        forced_disabled = true;
 1388|      0|    }
 1389|  1.53k|    if (check_name_matches_filter_environment_var(prop->info.layerName, &filters->enable_filter)) {
  ------------------
  |  Branch (1389:9): [True: 0, False: 1.53k]
  ------------------
 1390|      0|        forced_enabled = true;
 1391|      0|    }
 1392|       |
 1393|       |    // If no enable_environment variable is specified, this implicit layer is always be enabled by default.
 1394|  1.53k|    if (NULL == prop->enable_env_var.name) {
  ------------------
  |  Branch (1394:9): [True: 1.45k, False: 77]
  ------------------
 1395|  1.45k|        enable = true;
 1396|  1.45k|    } else {
 1397|     77|        char *env_value = loader_getenv(prop->enable_env_var.name, inst);
 1398|     77|        if (env_value && !strcmp(prop->enable_env_var.value, env_value)) {
  ------------------
  |  Branch (1398:13): [True: 75, False: 2]
  |  Branch (1398:26): [True: 0, False: 75]
  ------------------
 1399|      0|            enable = true;
 1400|      0|        }
 1401|       |
 1402|       |        // Otherwise, only enable this layer if the enable environment variable is defined
 1403|     77|        loader_free_getenv(env_value, inst);
 1404|     77|    }
 1405|       |
 1406|  1.53k|    if (forced_enabled) {
  ------------------
  |  Branch (1406:9): [True: 0, False: 1.53k]
  ------------------
 1407|       |        // Only report a message that we've forced on a layer if it wouldn't have been enabled
 1408|       |        // normally.
 1409|      0|        if (!enable) {
  ------------------
  |  Branch (1409:13): [True: 0, False: 0]
  ------------------
 1410|      0|            enable = true;
 1411|      0|            loader_log(inst, VULKAN_LOADER_WARN_BIT | VULKAN_LOADER_LAYER_BIT, 0,
 1412|      0|                       "Implicit layer \"%s\" forced enabled due to env var \'%s\'.", prop->info.layerName,
 1413|      0|                       VK_LAYERS_ENABLE_ENV_VAR);
  ------------------
  |  |  119|      0|#define VK_LAYERS_ENABLE_ENV_VAR "VK_LOADER_LAYERS_ENABLE"
  ------------------
 1414|      0|        }
 1415|  1.53k|    } else if (enable && forced_disabled) {
  ------------------
  |  Branch (1415:16): [True: 1.45k, False: 77]
  |  Branch (1415:26): [True: 0, False: 1.45k]
  ------------------
 1416|      0|        enable = false;
 1417|       |        // Report a message that we've forced off a layer if it would have been enabled normally.
 1418|      0|        loader_log(inst, VULKAN_LOADER_WARN_BIT | VULKAN_LOADER_LAYER_BIT, 0,
 1419|      0|                   "Implicit layer \"%s\" forced disabled because name matches filter of env var \'%s\'.", prop->info.layerName,
 1420|      0|                   VK_LAYERS_DISABLE_ENV_VAR);
  ------------------
  |  |  120|      0|#define VK_LAYERS_DISABLE_ENV_VAR "VK_LOADER_LAYERS_DISABLE"
  ------------------
 1421|      0|        return enable;
 1422|      0|    }
 1423|       |
 1424|       |    // The disable_environment has priority over everything else.  If it is defined, the layer is always
 1425|       |    // disabled.
 1426|  1.53k|    if (NULL != prop->disable_env_var.name) {
  ------------------
  |  Branch (1426:9): [True: 902, False: 632]
  ------------------
 1427|    902|        char *env_value = loader_getenv(prop->disable_env_var.name, inst);
 1428|    902|        if (NULL != env_value) {
  ------------------
  |  Branch (1428:13): [True: 2, False: 900]
  ------------------
 1429|      2|            enable = false;
 1430|      2|        }
 1431|    902|        loader_free_getenv(env_value, inst);
 1432|    902|    } else if ((prop->type_flags & VK_LAYER_TYPE_FLAG_EXPLICIT_LAYER) == 0) {
  ------------------
  |  Branch (1432:16): [True: 0, False: 632]
  ------------------
 1433|      0|        loader_log(inst, VULKAN_LOADER_WARN_BIT | VULKAN_LOADER_LAYER_BIT, 0,
 1434|      0|                   "Implicit layer \"%s\" missing disabled environment variable!", prop->info.layerName);
 1435|      0|    }
 1436|       |
 1437|       |    // Enable this layer if it is included in the override layer
 1438|  1.53k|    if (inst != NULL && inst->override_layer_present) {
  ------------------
  |  Branch (1438:9): [True: 1.53k, False: 0]
  |  Branch (1438:25): [True: 0, False: 1.53k]
  ------------------
 1439|      0|        struct loader_layer_properties *override = NULL;
 1440|      0|        for (uint32_t i = 0; i < inst->instance_layer_list.count; ++i) {
  ------------------
  |  Branch (1440:30): [True: 0, False: 0]
  ------------------
 1441|      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 (1441:17): [True: 0, False: 0]
  ------------------
 1442|      0|                override = &inst->instance_layer_list.list[i];
 1443|      0|                break;
 1444|      0|            }
 1445|      0|        }
 1446|      0|        if (override != NULL) {
  ------------------
  |  Branch (1446:13): [True: 0, False: 0]
  ------------------
 1447|      0|            for (uint32_t i = 0; i < override->component_layer_names.count; ++i) {
  ------------------
  |  Branch (1447:34): [True: 0, False: 0]
  ------------------
 1448|      0|                if (strcmp(override->component_layer_names.list[i], prop->info.layerName) == 0) {
  ------------------
  |  Branch (1448:21): [True: 0, False: 0]
  ------------------
 1449|      0|                    enable = true;
 1450|      0|                    break;
 1451|      0|                }
 1452|      0|            }
 1453|      0|        }
 1454|      0|    }
 1455|       |
 1456|  1.53k|    return enable;
 1457|  1.53k|}
loader_clear_scanned_icd_list:
 1881|  6.59k|void loader_clear_scanned_icd_list(const struct loader_instance *inst, struct loader_icd_tramp_list *icd_tramp_list) {
 1882|  6.59k|    if (0 != icd_tramp_list->capacity && icd_tramp_list->scanned_list) {
  ------------------
  |  Branch (1882:9): [True: 2, False: 6.58k]
  |  Branch (1882:42): [True: 2, False: 0]
  ------------------
 1883|      2|        for (uint32_t i = 0; i < icd_tramp_list->count; i++) {
  ------------------
  |  Branch (1883:30): [True: 0, False: 2]
  ------------------
 1884|      0|            if (icd_tramp_list->scanned_list[i].handle) {
  ------------------
  |  Branch (1884:17): [True: 0, False: 0]
  ------------------
 1885|      0|                loader_platform_close_library(icd_tramp_list->scanned_list[i].handle);
 1886|       |                icd_tramp_list->scanned_list[i].handle = NULL;
 1887|      0|            }
 1888|      0|            loader_instance_heap_free(inst, icd_tramp_list->scanned_list[i].lib_name);
 1889|      0|        }
 1890|      2|        loader_instance_heap_free(inst, icd_tramp_list->scanned_list);
 1891|      2|    }
 1892|  6.59k|    memset(icd_tramp_list, 0, sizeof(struct loader_icd_tramp_list));
 1893|  6.59k|}
loader_init_scanned_icd_list:
 1895|      2|VkResult loader_init_scanned_icd_list(const struct loader_instance *inst, struct loader_icd_tramp_list *icd_tramp_list) {
 1896|      2|    VkResult res = VK_SUCCESS;
 1897|      2|    loader_clear_scanned_icd_list(inst, icd_tramp_list);
 1898|      2|    icd_tramp_list->capacity = 8 * sizeof(struct loader_scanned_icd);
 1899|      2|    icd_tramp_list->scanned_list = loader_instance_heap_alloc(inst, icd_tramp_list->capacity, VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE);
 1900|      2|    if (NULL == icd_tramp_list->scanned_list) {
  ------------------
  |  Branch (1900:9): [True: 0, False: 2]
  ------------------
 1901|      0|        loader_log(inst, VULKAN_LOADER_ERROR_BIT, 0,
 1902|      0|                   "loader_init_scanned_icd_list: Realloc failed for layer list when attempting to add new layer");
 1903|      0|        res = VK_ERROR_OUT_OF_HOST_MEMORY;
 1904|      0|    }
 1905|      2|    return res;
 1906|      2|}
loader_scan_for_direct_drivers:
 2044|      2|                                        struct loader_icd_tramp_list *icd_tramp_list, bool *direct_driver_loading_exclusive_mode) {
 2045|      2|    if (NULL == pCreateInfo) {
  ------------------
  |  Branch (2045:9): [True: 0, False: 2]
  ------------------
 2046|       |        // Don't do this logic unless we are being called from vkCreateInstance, when pCreateInfo will be non-null
 2047|      0|        return VK_SUCCESS;
 2048|      0|    }
 2049|      2|    bool direct_driver_loading_enabled = false;
 2050|       |    // Try to if VK_LUNARG_direct_driver_loading is enabled and if we are using it exclusively
 2051|       |    // Skip this step if inst is NULL, aka when this function is being called before instance creation
 2052|      2|    if (inst != NULL && pCreateInfo->ppEnabledExtensionNames && pCreateInfo->enabledExtensionCount > 0) {
  ------------------
  |  Branch (2052:9): [True: 2, False: 0]
  |  Branch (2052:25): [True: 0, False: 2]
  |  Branch (2052:65): [True: 0, False: 0]
  ------------------
 2053|       |        // Look through the enabled extension list, make sure VK_LUNARG_direct_driver_loading is present
 2054|      0|        for (uint32_t i = 0; i < pCreateInfo->enabledExtensionCount; i++) {
  ------------------
  |  Branch (2054:30): [True: 0, False: 0]
  ------------------
 2055|      0|            if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], VK_LUNARG_DIRECT_DRIVER_LOADING_EXTENSION_NAME) == 0) {
  ------------------
  |  Branch (2055:17): [True: 0, False: 0]
  ------------------
 2056|      0|                direct_driver_loading_enabled = true;
 2057|      0|                break;
 2058|      0|            }
 2059|      0|        }
 2060|      0|    }
 2061|      2|    const VkDirectDriverLoadingListLUNARG *ddl_list = NULL;
 2062|       |    // Find the VkDirectDriverLoadingListLUNARG struct in the pNext chain of vkInstanceCreateInfo
 2063|      2|    const void *pNext = pCreateInfo->pNext;
 2064|      2|    while (pNext) {
  ------------------
  |  Branch (2064:12): [True: 0, False: 2]
  ------------------
 2065|      0|        VkBaseInStructure out_structure = {0};
 2066|      0|        memcpy(&out_structure, pNext, sizeof(VkBaseInStructure));
 2067|      0|        if (out_structure.sType == VK_STRUCTURE_TYPE_DIRECT_DRIVER_LOADING_LIST_LUNARG) {
  ------------------
  |  Branch (2067:13): [True: 0, False: 0]
  ------------------
 2068|      0|            ddl_list = (VkDirectDriverLoadingListLUNARG *)pNext;
 2069|      0|            break;
 2070|      0|        }
 2071|      0|        pNext = out_structure.pNext;
 2072|      0|    }
 2073|      2|    if (NULL == ddl_list) {
  ------------------
  |  Branch (2073:9): [True: 2, False: 0]
  ------------------
 2074|      2|        if (direct_driver_loading_enabled) {
  ------------------
  |  Branch (2074:13): [True: 0, False: 2]
  ------------------
 2075|      0|            loader_log(inst, VULKAN_LOADER_WARN_BIT | VULKAN_LOADER_DRIVER_BIT, 0,
 2076|      0|                       "loader_scan_for_direct_drivers: The VK_LUNARG_direct_driver_loading extension was enabled but the "
 2077|      0|                       "pNext chain of "
 2078|      0|                       "VkInstanceCreateInfo did not contain the "
 2079|      0|                       "VkDirectDriverLoadingListLUNARG structure.");
 2080|      0|        }
 2081|       |        // Always want to exit early if there was no VkDirectDriverLoadingListLUNARG in the pNext chain
 2082|      2|        return VK_SUCCESS;
 2083|      2|    }
 2084|       |
 2085|      0|    if (!direct_driver_loading_enabled) {
  ------------------
  |  Branch (2085:9): [True: 0, False: 0]
  ------------------
 2086|      0|        loader_log(inst, VULKAN_LOADER_WARN_BIT | VULKAN_LOADER_DRIVER_BIT, 0,
 2087|      0|                   "loader_scan_for_direct_drivers: The pNext chain of VkInstanceCreateInfo contained the "
 2088|      0|                   "VkDirectDriverLoadingListLUNARG structure, but the VK_LUNARG_direct_driver_loading extension was "
 2089|      0|                   "not enabled.");
 2090|      0|        return VK_SUCCESS;
 2091|      0|    }
 2092|       |    // If we are using exclusive mode, skip looking for any more drivers from system or environment variables
 2093|      0|    if (ddl_list->mode == VK_DIRECT_DRIVER_LOADING_MODE_EXCLUSIVE_LUNARG) {
  ------------------
  |  Branch (2093:9): [True: 0, False: 0]
  ------------------
 2094|      0|        *direct_driver_loading_exclusive_mode = true;
 2095|      0|        loader_log(inst, VULKAN_LOADER_INFO_BIT | VULKAN_LOADER_DRIVER_BIT, 0,
 2096|      0|                   "loader_scan_for_direct_drivers: The VK_LUNARG_direct_driver_loading extension is active and specified "
 2097|      0|                   "VK_DIRECT_DRIVER_LOADING_MODE_EXCLUSIVE_LUNARG, skipping system and environment "
 2098|      0|                   "variable driver search mechanisms.");
 2099|      0|    }
 2100|      0|    if (NULL == ddl_list->pDrivers) {
  ------------------
  |  Branch (2100:9): [True: 0, False: 0]
  ------------------
 2101|      0|        loader_log(inst, VULKAN_LOADER_WARN_BIT | VULKAN_LOADER_DRIVER_BIT, 0,
 2102|      0|                   "loader_scan_for_direct_drivers: The VkDirectDriverLoadingListLUNARG structure in the pNext chain of "
 2103|      0|                   "VkInstanceCreateInfo has a NULL pDrivers member.");
 2104|      0|        return VK_SUCCESS;
 2105|      0|    }
 2106|      0|    if (ddl_list->driverCount == 0) {
  ------------------
  |  Branch (2106:9): [True: 0, False: 0]
  ------------------
 2107|      0|        loader_log(inst, VULKAN_LOADER_WARN_BIT | VULKAN_LOADER_DRIVER_BIT, 0,
 2108|      0|                   "loader_scan_for_direct_drivers: The VkDirectDriverLoadingListLUNARG structure in the pNext chain of "
 2109|      0|                   "VkInstanceCreateInfo has a non-null pDrivers member but a driverCount member with a value "
 2110|      0|                   "of zero.");
 2111|      0|        return VK_SUCCESS;
 2112|      0|    }
 2113|       |    // Go through all VkDirectDriverLoadingInfoLUNARG entries and add each driver
 2114|       |    // Because icd_tramp's are prepended, this will result in the drivers appearing at the end
 2115|      0|    for (uint32_t i = 0; i < ddl_list->driverCount; i++) {
  ------------------
  |  Branch (2115:26): [True: 0, False: 0]
  ------------------
 2116|      0|        VkResult res = loader_add_direct_driver(inst, i, &ddl_list->pDrivers[i], icd_tramp_list);
 2117|      0|        if (res == VK_ERROR_OUT_OF_HOST_MEMORY) {
  ------------------
  |  Branch (2117:13): [True: 0, False: 0]
  ------------------
 2118|      0|            return res;
 2119|      0|        }
 2120|      0|    }
 2121|       |
 2122|      0|    return VK_SUCCESS;
 2123|      0|}
loader_initialize:
 2366|      2|void loader_initialize(void) {
 2367|      2|    loader_platform_thread_create_mutex(&loader_lock);
 2368|      2|    loader_platform_thread_create_mutex(&loader_preload_icd_lock);
 2369|      2|    init_global_loader_settings();
 2370|      2|#endif
 2371|       |
 2372|       |    // initialize logging
 2373|      2|    loader_init_global_debug_level();
 2374|       |#if defined(_WIN32)
 2375|       |    windows_initialization();
 2376|       |#endif
 2377|       |
 2378|      2|    loader_api_version version = loader_make_full_version(VK_HEADER_VERSION_COMPLETE);
 2379|      2|    loader_log(NULL, VULKAN_LOADER_INFO_BIT, 0, "Vulkan Loader Version %d.%d.%d", version.major, version.minor, version.patch);
 2380|       |
 2381|       |#if defined(GIT_BRANCH_NAME) && defined(GIT_TAG_INFO)
 2382|       |    loader_log(NULL, VULKAN_LOADER_INFO_BIT, 0, "[Vulkan Loader Git - Tag: " GIT_BRANCH_NAME ", Branch/Commit: " GIT_TAG_INFO "]");
 2383|       |#endif
 2384|       |
 2385|      2|    char *loader_disable_dynamic_library_unloading_env_var = loader_getenv("VK_LOADER_DISABLE_DYNAMIC_LIBRARY_UNLOADING", NULL);
 2386|      2|    if (loader_disable_dynamic_library_unloading_env_var &&
  ------------------
  |  Branch (2386:9): [True: 0, False: 2]
  ------------------
 2387|       |        // NOLINTNEXTLINE(bugprone-not-null-terminated-result) - n=2 intentionally excludes "1x" values like "10"
 2388|      0|        0 == strncmp(loader_disable_dynamic_library_unloading_env_var, "1", 2)) {
  ------------------
  |  Branch (2388:9): [True: 0, False: 0]
  ------------------
 2389|      0|        loader_disable_dynamic_library_unloading = true;
 2390|      0|        loader_log(NULL, VULKAN_LOADER_WARN_BIT, 0, "Vulkan Loader: library unloading is disabled");
 2391|      2|    } else {
 2392|      2|        loader_disable_dynamic_library_unloading = false;
 2393|      2|    }
 2394|      2|    loader_free_getenv(loader_disable_dynamic_library_unloading_env_var, NULL);
 2395|       |#if defined(LOADER_USE_UNSAFE_FILE_SEARCH)
 2396|       |    loader_log(NULL, VULKAN_LOADER_WARN_BIT, 0, "Vulkan Loader: unsafe searching is enabled");
 2397|       |#endif
 2398|       |#if defined(_WIN32)
 2399|       |    return TRUE;
 2400|       |#endif
 2401|      2|}
loader_init_library:
 2438|      2|__attribute__((constructor)) void loader_init_library(void) { loader_initialize(); }
loader_get_next_path:
 2449|  92.4k|char *loader_get_next_path(char *path) {
 2450|  92.4k|    uint32_t len;
 2451|  92.4k|    char *next;
 2452|       |
 2453|  92.4k|    if (path == NULL) return NULL;
  ------------------
  |  Branch (2453:9): [True: 0, False: 92.4k]
  ------------------
 2454|  92.4k|    next = strchr(path, PATH_SEPARATOR);
  ------------------
  |  |  154|  92.4k|#define PATH_SEPARATOR ':'
  ------------------
 2455|  92.4k|    if (next == NULL) {
  ------------------
  |  Branch (2455:9): [True: 92.4k, False: 0]
  ------------------
 2456|  92.4k|        len = (uint32_t)strlen(path);
 2457|  92.4k|        next = path + len;
 2458|  92.4k|    } else {
 2459|      0|        *next = '\0';
 2460|      0|        next++;
 2461|      0|    }
 2462|       |
 2463|  92.4k|    return next;
 2464|  92.4k|}
combine_manifest_directory_and_library_path:
 2474|   164k|                                                     const char *manifest_file_path, char **out_fullpath) {
 2475|   164k|    assert(library_path && manifest_file_path && out_fullpath);
 2476|   164k|    if (loader_platform_is_path_absolute(library_path)) {
  ------------------
  |  Branch (2476:9): [True: 60.1k, False: 103k]
  ------------------
 2477|  60.1k|        *out_fullpath = library_path;
 2478|  60.1k|        return VK_SUCCESS;
 2479|  60.1k|    }
 2480|   103k|    VkResult res = VK_SUCCESS;
 2481|       |
 2482|   103k|    size_t library_path_len = strlen(library_path);
 2483|   103k|    size_t manifest_file_path_str_len = strlen(manifest_file_path);
 2484|   103k|    bool library_path_contains_directory_symbol = false;
 2485|  37.4M|    for (size_t i = 0; i < library_path_len; i++) {
  ------------------
  |  Branch (2485:24): [True: 37.4M, False: 4.58k]
  ------------------
 2486|  37.4M|        if (library_path[i] == DIRECTORY_SYMBOL) {
  ------------------
  |  |  155|  37.4M|#define DIRECTORY_SYMBOL '/'
  ------------------
  |  Branch (2486:13): [True: 99.3k, False: 37.3M]
  ------------------
 2487|  99.3k|            library_path_contains_directory_symbol = true;
 2488|  99.3k|            break;
 2489|  99.3k|        }
 2490|  37.4M|    }
 2491|       |    // Means that the library_path is neither absolute nor relative - thus we should not modify it at all
 2492|   103k|    if (!library_path_contains_directory_symbol) {
  ------------------
  |  Branch (2492:9): [True: 4.58k, False: 99.3k]
  ------------------
 2493|  4.58k|        *out_fullpath = library_path;
 2494|  4.58k|        return VK_SUCCESS;
 2495|  4.58k|    }
 2496|       |    // must include both a directory symbol and the null terminator
 2497|  99.3k|    size_t new_str_len = library_path_len + manifest_file_path_str_len + 1 + 1;
 2498|       |
 2499|  99.3k|    *out_fullpath = loader_instance_heap_calloc(inst, new_str_len, VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE);
 2500|  99.3k|    if (NULL == *out_fullpath) {
  ------------------
  |  Branch (2500:9): [True: 0, False: 99.3k]
  ------------------
 2501|      0|        res = VK_ERROR_OUT_OF_HOST_MEMORY;
 2502|      0|        goto out;
 2503|      0|    }
 2504|  99.3k|    size_t cur_loc_in_out_fullpath = 0;
 2505|       |    // look for the last occurrence of DIRECTORY_SYMBOL in manifest_file_path
 2506|  99.3k|    size_t last_directory_symbol = 0;
 2507|  99.3k|    bool found_directory_symbol = false;
 2508|  1.85M|    for (size_t i = 0; i < manifest_file_path_str_len; i++) {
  ------------------
  |  Branch (2508:24): [True: 1.75M, False: 99.3k]
  ------------------
 2509|  1.75M|        if (manifest_file_path[i] == DIRECTORY_SYMBOL) {
  ------------------
  |  |  155|  1.75M|#define DIRECTORY_SYMBOL '/'
  ------------------
  |  Branch (2509:13): [True: 28.4k, False: 1.72M]
  ------------------
 2510|  28.4k|            last_directory_symbol = i + 1;  // we want to include the symbol
 2511|  28.4k|            found_directory_symbol = true;
 2512|       |            // dont break because we want to find the last occurrence
 2513|  28.4k|        }
 2514|  1.75M|    }
 2515|       |    // Add manifest_file_path up to the last directory symbol
 2516|  99.3k|    if (found_directory_symbol) {
  ------------------
  |  Branch (2516:9): [True: 2.56k, False: 96.8k]
  ------------------
 2517|  2.56k|        loader_strncpy(*out_fullpath, new_str_len, manifest_file_path, last_directory_symbol);
 2518|  2.56k|        cur_loc_in_out_fullpath += last_directory_symbol;
 2519|  2.56k|    }
 2520|  99.3k|    loader_strncpy(&(*out_fullpath)[cur_loc_in_out_fullpath], new_str_len - cur_loc_in_out_fullpath, library_path,
 2521|  99.3k|                   library_path_len);
 2522|  99.3k|    cur_loc_in_out_fullpath += library_path_len + 1;
 2523|  99.3k|    (*out_fullpath)[cur_loc_in_out_fullpath] = '\0';
 2524|       |
 2525|  99.3k|out:
 2526|  99.3k|    loader_instance_heap_free(inst, library_path);
 2527|       |
 2528|  99.3k|    return res;
 2529|  99.3k|}
loader_get_fullpath:
 2535|  21.2k|void loader_get_fullpath(const char *file, const char *in_dirs, size_t out_size, char *out_fullpath) {
 2536|  21.2k|    if (!loader_platform_is_path(file) && *in_dirs) {
  ------------------
  |  Branch (2536:9): [True: 21.1k, False: 94]
  |  Branch (2536:43): [True: 21.1k, False: 0]
  ------------------
 2537|  21.1k|        size_t dirs_copy_len = strlen(in_dirs) + 1;
 2538|  21.1k|        char *dirs_copy = loader_stack_alloc(dirs_copy_len);
  ------------------
  |  |   42|  21.1k|#define loader_stack_alloc(size) alloca(size)
  ------------------
 2539|  21.1k|        loader_strncpy(dirs_copy, dirs_copy_len, in_dirs, dirs_copy_len);
 2540|       |
 2541|       |        // find if file exists after prepending paths in given list
 2542|       |        // for (dir = dirs_copy; *dir && (next_dir = loader_get_next_path(dir)); dir = next_dir) {
 2543|  21.1k|        char *dir = dirs_copy;
 2544|  21.1k|        char *next_dir = loader_get_next_path(dir);
 2545|  21.9k|        while (*dir && next_dir && out_fullpath) {
  ------------------
  |  Branch (2545:16): [True: 21.1k, False: 730]
  |  Branch (2545:24): [True: 21.1k, False: 0]
  |  Branch (2545:36): [True: 21.1k, False: 0]
  ------------------
 2546|  21.1k|            int path_concat_ret = snprintf(out_fullpath, out_size, "%s%c%s", dir, DIRECTORY_SYMBOL, file);
  ------------------
  |  |  155|  21.1k|#define DIRECTORY_SYMBOL '/'
  ------------------
 2547|  21.1k|            if (path_concat_ret >= 0 && loader_platform_file_exists(out_fullpath)) {
  ------------------
  |  Branch (2547:17): [True: 21.1k, False: 0]
  |  Branch (2547:41): [True: 20.4k, False: 730]
  ------------------
 2548|  20.4k|                return;
 2549|  20.4k|            }
 2550|    730|            dir = next_dir;
 2551|    730|            next_dir = loader_get_next_path(dir);
 2552|    730|        }
 2553|  21.1k|    }
 2554|       |
 2555|    824|    (void)snprintf(out_fullpath, out_size, "%s", file);
 2556|    824|}
verify_meta_layer_component_layers:
 2563|  8.90k|                                        struct loader_layer_list *instance_layers, bool *already_checked_meta_layers) {
 2564|  8.90k|    struct loader_layer_properties *prop = &instance_layers->list[prop_index];
 2565|  8.90k|    loader_api_version meta_layer_version = loader_make_version(prop->info.specVersion);
 2566|       |
 2567|  8.90k|    if (NULL == already_checked_meta_layers) {
  ------------------
  |  Branch (2567:9): [True: 6.08k, False: 2.81k]
  ------------------
 2568|  6.08k|        already_checked_meta_layers = loader_stack_alloc(sizeof(bool) * instance_layers->count);
  ------------------
  |  |   42|  6.08k|#define loader_stack_alloc(size) alloca(size)
  ------------------
 2569|  6.08k|        if (already_checked_meta_layers == NULL) {
  ------------------
  |  Branch (2569:13): [True: 0, False: 6.08k]
  ------------------
 2570|      0|            return false;
 2571|      0|        }
 2572|  6.08k|        memset(already_checked_meta_layers, 0, sizeof(bool) * instance_layers->count);
 2573|  6.08k|    }
 2574|       |
 2575|       |    // Mark this meta layer as 'already checked', indicating which layers have already been recursed.
 2576|  8.90k|    already_checked_meta_layers[prop_index] = true;
 2577|       |
 2578|  11.1k|    for (uint32_t comp_layer = 0; comp_layer < prop->component_layer_names.count; comp_layer++) {
  ------------------
  |  Branch (2578:35): [True: 4.52k, False: 6.63k]
  ------------------
 2579|  4.52k|        struct loader_layer_properties *comp_prop =
 2580|  4.52k|            loader_find_layer_property(prop->component_layer_names.list[comp_layer], instance_layers);
 2581|  4.52k|        if (comp_prop == NULL) {
  ------------------
  |  Branch (2581:13): [True: 686, False: 3.83k]
  ------------------
 2582|    686|            loader_log(inst, VULKAN_LOADER_WARN_BIT, 0,
 2583|    686|                       "verify_meta_layer_component_layers: Meta-layer %s can't find component layer %s at index %d."
 2584|    686|                       "  Skipping this layer.",
 2585|    686|                       prop->info.layerName, prop->component_layer_names.list[comp_layer], comp_layer);
 2586|       |
 2587|    686|            return false;
 2588|    686|        }
 2589|       |
 2590|       |        // Check the version of each layer, they need to be at least MAJOR and MINOR
 2591|  3.83k|        loader_api_version comp_prop_version = loader_make_version(comp_prop->info.specVersion);
 2592|  3.83k|        if (!loader_check_version_meets_required(meta_layer_version, comp_prop_version)) {
  ------------------
  |  Branch (2592:13): [True: 242, False: 3.59k]
  ------------------
 2593|    242|            loader_log(inst, VULKAN_LOADER_WARN_BIT, 0,
 2594|    242|                       "verify_meta_layer_component_layers: Meta-layer uses API version %d.%d, but component "
 2595|    242|                       "layer %d has API version %d.%d that is lower.  Skipping this layer.",
 2596|    242|                       meta_layer_version.major, meta_layer_version.minor, comp_layer, comp_prop_version.major,
 2597|    242|                       comp_prop_version.minor);
 2598|       |
 2599|    242|            return false;
 2600|    242|        }
 2601|       |
 2602|       |        // Make sure the layer isn't using it's own name
 2603|  3.59k|        if (!strcmp(prop->info.layerName, prop->component_layer_names.list[comp_layer])) {
  ------------------
  |  Branch (2603:13): [True: 167, False: 3.42k]
  ------------------
 2604|    167|            loader_log(inst, VULKAN_LOADER_WARN_BIT, 0,
 2605|    167|                       "verify_meta_layer_component_layers: Meta-layer %s lists itself in its component layer "
 2606|    167|                       "list at index %d.  Skipping this layer.",
 2607|    167|                       prop->info.layerName, comp_layer);
 2608|       |
 2609|    167|            return false;
 2610|    167|        }
 2611|  3.42k|        if (comp_prop->type_flags & VK_LAYER_TYPE_FLAG_META_LAYER) {
  ------------------
  |  Branch (2611:13): [True: 3.01k, False: 418]
  ------------------
 2612|  3.01k|            size_t comp_prop_index = INT32_MAX;
 2613|       |            // Make sure we haven't verified this meta layer before
 2614|   169k|            for (uint32_t i = 0; i < instance_layers->count; i++) {
  ------------------
  |  Branch (2614:34): [True: 166k, False: 3.01k]
  ------------------
 2615|   166k|                if (strcmp(comp_prop->info.layerName, instance_layers->list[i].info.layerName) == 0) {
  ------------------
  |  Branch (2615:21): [True: 20.4k, False: 146k]
  ------------------
 2616|  20.4k|                    comp_prop_index = i;
 2617|  20.4k|                }
 2618|   166k|            }
 2619|  3.01k|            if (comp_prop_index != INT32_MAX && already_checked_meta_layers[comp_prop_index]) {
  ------------------
  |  Branch (2619:17): [True: 3.01k, False: 0]
  |  Branch (2619:49): [True: 198, False: 2.81k]
  ------------------
 2620|    198|                loader_log(inst, VULKAN_LOADER_WARN_BIT, 0,
 2621|    198|                           "verify_meta_layer_component_layers: Recursive dependency between Meta-layer %s and  Meta-layer %s.  "
 2622|    198|                           "Skipping this layer.",
 2623|    198|                           instance_layers->list[prop_index].info.layerName, comp_prop->info.layerName);
 2624|    198|                return false;
 2625|    198|            }
 2626|       |
 2627|  2.81k|            loader_log(inst, VULKAN_LOADER_INFO_BIT, 0,
 2628|  2.81k|                       "verify_meta_layer_component_layers: Adding meta-layer %s which also contains meta-layer %s",
 2629|  2.81k|                       prop->info.layerName, comp_prop->info.layerName);
 2630|       |
 2631|       |            // Make sure if the layer is using a meta-layer in its component list that we also verify that.
 2632|  2.81k|            if (!verify_meta_layer_component_layers(inst, comp_prop_index, instance_layers, already_checked_meta_layers)) {
  ------------------
  |  Branch (2632:17): [True: 971, False: 1.84k]
  ------------------
 2633|    971|                loader_log(inst, VULKAN_LOADER_WARN_BIT, 0,
 2634|    971|                           "Meta-layer %s component layer %s can not find all component layers."
 2635|    971|                           "  Skipping this layer.",
 2636|    971|                           prop->info.layerName, prop->component_layer_names.list[comp_layer]);
 2637|    971|                return false;
 2638|    971|            }
 2639|  2.81k|        }
 2640|  3.42k|    }
 2641|       |    // Didn't exit early so that means it passed all checks
 2642|  6.63k|    loader_log(inst, VULKAN_LOADER_INFO_BIT | VULKAN_LOADER_LAYER_BIT, 0,
 2643|  6.63k|               "Meta-layer \"%s\" all %d component layers appear to be valid.", prop->info.layerName,
 2644|  6.63k|               prop->component_layer_names.count);
 2645|       |
 2646|       |    // If layer logging is on, list the internals included in the meta-layer
 2647|  8.82k|    for (uint32_t comp_layer = 0; comp_layer < prop->component_layer_names.count; comp_layer++) {
  ------------------
  |  Branch (2647:35): [True: 2.18k, False: 6.63k]
  ------------------
 2648|  2.18k|        loader_log(inst, VULKAN_LOADER_LAYER_BIT, 0, "  [%d] %s", comp_layer, prop->component_layer_names.list[comp_layer]);
 2649|  2.18k|    }
 2650|       |    return true;
 2651|  8.90k|}
update_meta_layer_extensions_from_component_layers:
 2657|  4.79k|                                                            struct loader_layer_list *instance_layers) {
 2658|  4.79k|    VkResult res = VK_SUCCESS;
 2659|  6.65k|    for (uint32_t comp_layer = 0; comp_layer < prop->component_layer_names.count; comp_layer++) {
  ------------------
  |  Branch (2659:35): [True: 1.86k, False: 4.79k]
  ------------------
 2660|  1.86k|        struct loader_layer_properties *comp_prop =
 2661|  1.86k|            loader_find_layer_property(prop->component_layer_names.list[comp_layer], instance_layers);
 2662|       |
 2663|  1.86k|        if (NULL != comp_prop->instance_extension_list.list) {
  ------------------
  |  Branch (2663:13): [True: 282, False: 1.57k]
  ------------------
 2664|  3.26k|            for (uint32_t ext = 0; ext < comp_prop->instance_extension_list.count; ext++) {
  ------------------
  |  Branch (2664:36): [True: 2.98k, False: 282]
  ------------------
 2665|  2.98k|                loader_log(inst, VULKAN_LOADER_DEBUG_BIT, 0, "Meta-layer %s component layer %s adding instance extension %s",
 2666|  2.98k|                           prop->info.layerName, prop->component_layer_names.list[comp_layer],
 2667|  2.98k|                           comp_prop->instance_extension_list.list[ext].extensionName);
 2668|       |
 2669|  2.98k|                if (!has_vk_extension_property(&comp_prop->instance_extension_list.list[ext], &prop->instance_extension_list)) {
  ------------------
  |  Branch (2669:21): [True: 2.83k, False: 145]
  ------------------
 2670|  2.83k|                    res = loader_add_to_ext_list(inst, &prop->instance_extension_list, 1,
 2671|  2.83k|                                                 &comp_prop->instance_extension_list.list[ext]);
 2672|  2.83k|                    if (VK_ERROR_OUT_OF_HOST_MEMORY == res) {
  ------------------
  |  Branch (2672:25): [True: 0, False: 2.83k]
  ------------------
 2673|      0|                        return res;
 2674|      0|                    }
 2675|  2.83k|                }
 2676|  2.98k|            }
 2677|    282|        }
 2678|  1.86k|        if (NULL != comp_prop->device_extension_list.list) {
  ------------------
  |  Branch (2678:13): [True: 313, False: 1.54k]
  ------------------
 2679|  4.76k|            for (uint32_t ext = 0; ext < comp_prop->device_extension_list.count; ext++) {
  ------------------
  |  Branch (2679:36): [True: 4.45k, False: 313]
  ------------------
 2680|  4.45k|                loader_log(inst, VULKAN_LOADER_DEBUG_BIT, 0, "Meta-layer %s component layer %s adding device extension %s",
 2681|  4.45k|                           prop->info.layerName, prop->component_layer_names.list[comp_layer],
 2682|  4.45k|                           comp_prop->device_extension_list.list[ext].props.extensionName);
 2683|       |
 2684|  4.45k|                if (!has_vk_dev_ext_property(&comp_prop->device_extension_list.list[ext].props, &prop->device_extension_list)) {
  ------------------
  |  Branch (2684:21): [True: 4.08k, False: 368]
  ------------------
 2685|  4.08k|                    res = loader_add_to_dev_ext_list(inst, &prop->device_extension_list,
 2686|  4.08k|                                                     &comp_prop->device_extension_list.list[ext].props, NULL);
 2687|  4.08k|                    if (VK_ERROR_OUT_OF_HOST_MEMORY == res) {
  ------------------
  |  Branch (2687:25): [True: 0, False: 4.08k]
  ------------------
 2688|      0|                        return res;
 2689|      0|                    }
 2690|  4.08k|                }
 2691|  4.45k|            }
 2692|    313|        }
 2693|  1.86k|    }
 2694|  4.79k|    return res;
 2695|  4.79k|}
verify_all_meta_layers:
 2699|  4.90k|                                struct loader_layer_list *instance_layers, bool *override_layer_present) {
 2700|  4.90k|    VkResult res = VK_SUCCESS;
 2701|  4.90k|    *override_layer_present = false;
 2702|  28.5k|    for (int32_t i = 0; i < (int32_t)instance_layers->count; i++) {
  ------------------
  |  Branch (2702:25): [True: 23.6k, False: 4.90k]
  ------------------
 2703|  23.6k|        struct loader_layer_properties *prop = &instance_layers->list[i];
 2704|       |
 2705|       |        // If this is a meta-layer, make sure it is valid
 2706|  23.6k|        if (prop->type_flags & VK_LAYER_TYPE_FLAG_META_LAYER) {
  ------------------
  |  Branch (2706:13): [True: 6.08k, False: 17.5k]
  ------------------
 2707|  6.08k|            if (verify_meta_layer_component_layers(inst, i, instance_layers, NULL)) {
  ------------------
  |  Branch (2707:17): [True: 4.79k, False: 1.29k]
  ------------------
 2708|       |                // If any meta layer is valid, update its extension list to include the extensions from its component layers.
 2709|  4.79k|                res = update_meta_layer_extensions_from_component_layers(inst, prop, instance_layers);
 2710|  4.79k|                if (VK_ERROR_OUT_OF_HOST_MEMORY == res) {
  ------------------
  |  Branch (2710:21): [True: 0, False: 4.79k]
  ------------------
 2711|      0|                    return res;
 2712|      0|                }
 2713|  4.79k|                if (prop->is_override && loader_implicit_layer_is_enabled(inst, filters, prop)) {
  ------------------
  |  Branch (2713:21): [True: 1.04k, False: 3.75k]
  |  Branch (2713:42): [True: 1.03k, False: 6]
  ------------------
 2714|  1.03k|                    *override_layer_present = true;
 2715|  1.03k|                }
 2716|  4.79k|            } else {
 2717|  1.29k|                loader_log(inst, VULKAN_LOADER_DEBUG_BIT, 0,
 2718|  1.29k|                           "Removing meta-layer %s from instance layer list since it appears invalid.", prop->info.layerName);
 2719|       |
 2720|  1.29k|                loader_remove_layer_in_list(inst, instance_layers, i);
 2721|  1.29k|                i--;
 2722|  1.29k|            }
 2723|  6.08k|        }
 2724|  23.6k|    }
 2725|  4.90k|    return res;
 2726|  4.90k|}
remove_all_non_valid_override_layers:
 2730|  4.90k|void remove_all_non_valid_override_layers(struct loader_instance *inst, struct loader_layer_list *instance_layers) {
 2731|  4.90k|    if (instance_layers == NULL) {
  ------------------
  |  Branch (2731:9): [True: 0, False: 4.90k]
  ------------------
 2732|      0|        return;
 2733|      0|    }
 2734|       |
 2735|  4.90k|    char cur_path[1024];
 2736|  4.90k|    char *ret = loader_platform_executable_path(cur_path, 1024);
 2737|  4.90k|    if (NULL == ret) {
  ------------------
  |  Branch (2737:9): [True: 0, False: 4.90k]
  ------------------
 2738|      0|        return;
 2739|      0|    }
 2740|       |    // Find out if there is an override layer with same the app_key_path as the path to the current executable.
 2741|       |    // If more than one is found, remove it and use the first layer
 2742|       |    // Remove any layers which aren't global and do not have the same app_key_path as the path to the current executable.
 2743|  4.90k|    bool found_active_override_layer = false;
 2744|  4.90k|    int global_layer_index = -1;
 2745|  9.41k|    for (uint32_t i = 0; i < instance_layers->count; i++) {
  ------------------
  |  Branch (2745:26): [True: 4.50k, False: 4.90k]
  ------------------
 2746|  4.50k|        struct loader_layer_properties *props = &instance_layers->list[i];
 2747|  4.50k|        if (strcmp(props->info.layerName, VK_OVERRIDE_LAYER_NAME) == 0) {
  ------------------
  |  |  142|  4.50k|#define VK_OVERRIDE_LAYER_NAME "VK_LAYER_LUNARG_override"
  ------------------
  |  Branch (2747:13): [True: 709, False: 3.79k]
  ------------------
 2748|    709|            if (props->app_key_paths.count > 0) {  // not the global layer
  ------------------
  |  Branch (2748:17): [True: 143, False: 566]
  ------------------
 2749|    790|                for (uint32_t j = 0; j < props->app_key_paths.count; j++) {
  ------------------
  |  Branch (2749:38): [True: 647, False: 143]
  ------------------
 2750|    647|                    if (strcmp(props->app_key_paths.list[j], cur_path) == 0) {
  ------------------
  |  Branch (2750:25): [True: 0, False: 647]
  ------------------
 2751|      0|                        if (!found_active_override_layer) {
  ------------------
  |  Branch (2751:29): [True: 0, False: 0]
  ------------------
 2752|      0|                            found_active_override_layer = true;
 2753|      0|                        } else {
 2754|      0|                            loader_log(inst, VULKAN_LOADER_WARN_BIT | VULKAN_LOADER_LAYER_BIT, 0,
 2755|      0|                                       "remove_all_non_valid_override_layers: Multiple override layers where the same path in "
 2756|      0|                                       "app_keys "
 2757|      0|                                       "was found. Using the first layer found");
 2758|       |
 2759|       |                            // Remove duplicate active override layers that have the same app_key_path
 2760|      0|                            loader_remove_layer_in_list(inst, instance_layers, i);
 2761|      0|                            i--;
 2762|      0|                        }
 2763|      0|                    }
 2764|    647|                }
 2765|    143|                if (!found_active_override_layer) {
  ------------------
  |  Branch (2765:21): [True: 143, False: 0]
  ------------------
 2766|    143|                    loader_log(inst, VULKAN_LOADER_INFO_BIT | VULKAN_LOADER_LAYER_BIT, 0,
 2767|    143|                               "--Override layer found but not used because app \'%s\' is not in \'app_keys\' list!", cur_path);
 2768|       |
 2769|       |                    // Remove non-global override layers that don't have an app_key that matches cur_path
 2770|    143|                    loader_remove_layer_in_list(inst, instance_layers, i);
 2771|    143|                    i--;
 2772|    143|                }
 2773|    566|            } else {
 2774|    566|                if (global_layer_index == -1) {
  ------------------
  |  Branch (2774:21): [True: 494, False: 72]
  ------------------
 2775|    494|                    global_layer_index = (int)i;
 2776|    494|                } else {
 2777|     72|                    loader_log(
 2778|     72|                        inst, VULKAN_LOADER_WARN_BIT | VULKAN_LOADER_LAYER_BIT, 0,
 2779|     72|                        "remove_all_non_valid_override_layers: Multiple global override layers found. Using the first global "
 2780|     72|                        "layer found");
 2781|     72|                    loader_remove_layer_in_list(inst, instance_layers, i);
 2782|     72|                    i--;
 2783|     72|                }
 2784|    566|            }
 2785|    709|        }
 2786|  4.50k|    }
 2787|       |    // Remove global layer if layer with same the app_key_path as the path to the current executable is found
 2788|  4.90k|    if (found_active_override_layer && global_layer_index >= 0) {
  ------------------
  |  Branch (2788:9): [True: 0, False: 4.90k]
  |  Branch (2788:40): [True: 0, False: 0]
  ------------------
 2789|      0|        loader_remove_layer_in_list(inst, instance_layers, global_layer_index);
 2790|      0|    }
 2791|       |    // Should be at most 1 override layer in the list now.
 2792|  4.90k|    if (found_active_override_layer) {
  ------------------
  |  Branch (2792:9): [True: 0, False: 4.90k]
  ------------------
 2793|      0|        loader_log(inst, VULKAN_LOADER_INFO_BIT | VULKAN_LOADER_LAYER_BIT, 0, "Using the override layer for app key %s", cur_path);
 2794|  4.90k|    } else if (global_layer_index >= 0) {
  ------------------
  |  Branch (2794:16): [True: 494, False: 4.41k]
  ------------------
 2795|    494|        loader_log(inst, VULKAN_LOADER_INFO_BIT | VULKAN_LOADER_LAYER_BIT, 0, "Using the global override layer");
 2796|    494|    }
 2797|  4.90k|}
loader_read_layer_json:
 2811|   525k|                                cJSON *layer_node, loader_api_version version, bool is_implicit, char *filename) {
 2812|   525k|    assert(layer_instance_list);
 2813|   525k|    char *library_path = NULL;
 2814|   525k|    VkResult result = VK_SUCCESS;
 2815|   525k|    struct loader_layer_properties props = {0};
 2816|       |
 2817|   525k|    result = loader_copy_to_new_str(inst, filename, &props.manifest_file_name);
 2818|   525k|    if (result == VK_ERROR_OUT_OF_HOST_MEMORY) {
  ------------------
  |  Branch (2818:9): [True: 0, False: 525k]
  ------------------
 2819|      0|        goto out;
 2820|      0|    }
 2821|       |
 2822|       |    // Parse name
 2823|       |
 2824|   525k|    result = loader_parse_json_string_to_existing_str(layer_node, "name", VK_MAX_EXTENSION_NAME_SIZE, props.info.layerName);
 2825|   525k|    if (VK_ERROR_INITIALIZATION_FAILED == result) {
  ------------------
  |  Branch (2825:9): [True: 90.9k, False: 434k]
  ------------------
 2826|  90.9k|        loader_log(inst, VULKAN_LOADER_WARN_BIT, 0,
 2827|  90.9k|                   "Layer located at %s didn't find required layer value \"name\" in manifest JSON file, skipping this layer",
 2828|  90.9k|                   filename);
 2829|  90.9k|        goto out;
 2830|  90.9k|    }
 2831|       |
 2832|       |    // Check if this layer's name matches the override layer name, set is_override to true if so.
 2833|   434k|    if (!strcmp(props.info.layerName, VK_OVERRIDE_LAYER_NAME)) {
  ------------------
  |  |  142|   434k|#define VK_OVERRIDE_LAYER_NAME "VK_LAYER_LUNARG_override"
  ------------------
  |  Branch (2833:9): [True: 4.52k, False: 430k]
  ------------------
 2834|  4.52k|        props.is_override = true;
 2835|  4.52k|    }
 2836|       |
 2837|   434k|    if (0 != strncmp(props.info.layerName, "VK_LAYER_", 9)) {
  ------------------
  |  Branch (2837:9): [True: 426k, False: 7.67k]
  ------------------
 2838|   426k|        loader_log(inst, VULKAN_LOADER_WARN_BIT, 0, "Layer name %s does not conform to naming standard (Policy #LLP_LAYER_3)",
 2839|   426k|                   props.info.layerName);
 2840|   426k|    }
 2841|       |
 2842|       |    // Parse type
 2843|   434k|    char *type = loader_cJSON_GetStringValue(loader_cJSON_GetObjectItem(layer_node, "type"));
 2844|   434k|    if (NULL == type) {
  ------------------
  |  Branch (2844:9): [True: 31.4k, False: 403k]
  ------------------
 2845|  31.4k|        loader_log(inst, VULKAN_LOADER_WARN_BIT, 0,
 2846|  31.4k|                   "Layer located at %s didn't find required layer value \"type\" in manifest JSON file, skipping this layer",
 2847|  31.4k|                   filename);
 2848|  31.4k|        result = VK_ERROR_INITIALIZATION_FAILED;
 2849|  31.4k|        goto out;
 2850|  31.4k|    }
 2851|       |
 2852|       |    // Add list entry
 2853|   403k|    if (!strcmp(type, "DEVICE")) {
  ------------------
  |  Branch (2853:9): [True: 89, False: 402k]
  ------------------
 2854|     89|        loader_log(inst, VULKAN_LOADER_WARN_BIT | VULKAN_LOADER_LAYER_BIT, 0, "Device layers are deprecated. Skipping layer %s",
 2855|     89|                   props.info.layerName);
 2856|     89|        result = VK_ERROR_INITIALIZATION_FAILED;
 2857|     89|        goto out;
 2858|     89|    }
 2859|       |
 2860|       |    // Allow either GLOBAL or INSTANCE type interchangeably to handle layers that must work with older loaders
 2861|   402k|    if (!strcmp(type, "INSTANCE") || !strcmp(type, "GLOBAL")) {
  ------------------
  |  Branch (2861:9): [True: 325k, False: 77.3k]
  |  Branch (2861:38): [True: 51.9k, False: 25.4k]
  ------------------
 2862|   377k|        props.type_flags = VK_LAYER_TYPE_FLAG_INSTANCE_LAYER;
 2863|   377k|        if (!is_implicit) {
  ------------------
  |  Branch (2863:13): [True: 370k, False: 7.46k]
  ------------------
 2864|   370k|            props.type_flags |= VK_LAYER_TYPE_FLAG_EXPLICIT_LAYER;
 2865|   370k|        }
 2866|   377k|    } else {
 2867|  25.4k|        result = VK_ERROR_INITIALIZATION_FAILED;
 2868|  25.4k|        goto out;
 2869|  25.4k|    }
 2870|       |
 2871|       |    // Parse api_version
 2872|   377k|    char *api_version = loader_cJSON_GetStringValue(loader_cJSON_GetObjectItem(layer_node, "api_version"));
 2873|   377k|    if (NULL == api_version) {
  ------------------
  |  Branch (2873:9): [True: 50.5k, False: 327k]
  ------------------
 2874|  50.5k|        loader_log(
 2875|  50.5k|            inst, VULKAN_LOADER_WARN_BIT, 0,
 2876|  50.5k|            "Layer located at %s didn't find required layer value \"api_version\" in manifest JSON file, skipping this layer",
 2877|  50.5k|            filename);
 2878|  50.5k|        result = VK_ERROR_INITIALIZATION_FAILED;
 2879|  50.5k|        goto out;
 2880|  50.5k|    }
 2881|       |
 2882|   327k|    props.info.specVersion = loader_parse_version_string(api_version);
 2883|       |
 2884|       |    // Make sure the layer's manifest doesn't contain a non zero variant value
 2885|   327k|    if (VK_API_VERSION_VARIANT(props.info.specVersion) != 0) {
  ------------------
  |  Branch (2885:9): [True: 1.55k, False: 325k]
  ------------------
 2886|  1.55k|        loader_log(inst, VULKAN_LOADER_INFO_BIT | VULKAN_LOADER_LAYER_BIT, 0,
 2887|  1.55k|                   "Layer \"%s\" has an \'api_version\' field which contains a non-zero variant value of %d. "
 2888|  1.55k|                   " Skipping Layer.",
 2889|  1.55k|                   props.info.layerName, VK_API_VERSION_VARIANT(props.info.specVersion));
 2890|  1.55k|        result = VK_ERROR_INITIALIZATION_FAILED;
 2891|  1.55k|        goto out;
 2892|  1.55k|    }
 2893|       |
 2894|       |    // Parse implementation_version
 2895|   325k|    char *implementation_version = loader_cJSON_GetStringValue(loader_cJSON_GetObjectItem(layer_node, "implementation_version"));
 2896|   325k|    if (NULL == implementation_version) {
  ------------------
  |  Branch (2896:9): [True: 30.9k, False: 294k]
  ------------------
 2897|  30.9k|        loader_log(inst, VULKAN_LOADER_WARN_BIT, 0,
 2898|  30.9k|                   "Layer located at %s didn't find required layer value \"implementation_version\" in manifest JSON file, "
 2899|  30.9k|                   "skipping this layer",
 2900|  30.9k|                   filename);
 2901|  30.9k|        result = VK_ERROR_INITIALIZATION_FAILED;
 2902|  30.9k|        goto out;
 2903|  30.9k|    }
 2904|   294k|    props.info.implementationVersion = (uint32_t)strtoul(implementation_version, NULL, 10);
 2905|       |
 2906|       |    // Parse description
 2907|       |
 2908|   294k|    result = loader_parse_json_string_to_existing_str(layer_node, "description", VK_MAX_DESCRIPTION_SIZE, props.info.description);
 2909|   294k|    if (VK_ERROR_INITIALIZATION_FAILED == result) {
  ------------------
  |  Branch (2909:9): [True: 50.7k, False: 243k]
  ------------------
 2910|  50.7k|        loader_log(
 2911|  50.7k|            inst, VULKAN_LOADER_WARN_BIT, 0,
 2912|  50.7k|            "Layer located at %s didn't find required layer value \"description\" in manifest JSON file, skipping this layer",
 2913|  50.7k|            filename);
 2914|  50.7k|        goto out;
 2915|  50.7k|    }
 2916|       |
 2917|       |    // Parse library_path
 2918|       |
 2919|       |    // Library path no longer required unless component_layers is also not defined
 2920|   243k|    result = loader_parse_json_string(layer_node, "library_path", &library_path);
 2921|   243k|    if (result == VK_ERROR_OUT_OF_HOST_MEMORY) {
  ------------------
  |  Branch (2921:9): [True: 0, False: 243k]
  ------------------
 2922|      0|        loader_log(inst, VULKAN_LOADER_WARN_BIT, 0,
 2923|      0|                   "Skipping layer \"%s\" due to problem accessing the library_path value in the manifest JSON file",
 2924|      0|                   props.info.layerName);
 2925|      0|        result = VK_ERROR_OUT_OF_HOST_MEMORY;
 2926|      0|        goto out;
 2927|      0|    }
 2928|   243k|    if (NULL != library_path) {
  ------------------
  |  Branch (2928:9): [True: 164k, False: 78.7k]
  ------------------
 2929|   164k|        if (NULL != loader_cJSON_GetObjectItem(layer_node, "component_layers")) {
  ------------------
  |  Branch (2929:13): [True: 830, False: 164k]
  ------------------
 2930|    830|            loader_log(
 2931|    830|                inst, VULKAN_LOADER_WARN_BIT, 0,
 2932|    830|                "Layer \"%s\" contains meta-layer-specific component_layers, but also defining layer library path.  Both are not "
 2933|    830|                "compatible, so skipping this layer",
 2934|    830|                props.info.layerName);
 2935|    830|            result = VK_ERROR_INITIALIZATION_FAILED;
 2936|    830|            loader_instance_heap_free(inst, library_path);
 2937|    830|            goto out;
 2938|    830|        }
 2939|       |
 2940|       |        // This function takes ownership of library_path_str - so we don't need to clean it up
 2941|   164k|        result = combine_manifest_directory_and_library_path(inst, library_path, filename, &props.lib_name);
 2942|   164k|        if (result == VK_ERROR_OUT_OF_HOST_MEMORY) goto out;
  ------------------
  |  Branch (2942:13): [True: 0, False: 164k]
  ------------------
 2943|   164k|    }
 2944|       |
 2945|       |    // Parse component_layers
 2946|       |
 2947|   242k|    if (NULL == library_path) {
  ------------------
  |  Branch (2947:9): [True: 78.7k, False: 164k]
  ------------------
 2948|  78.7k|        if (!loader_check_version_meets_required(LOADER_VERSION_1_1_0, version)) {
  ------------------
  |  |  270|  78.7k|#define LOADER_VERSION_1_1_0 loader_combine_version(1, 1, 0)
  ------------------
  |  Branch (2948:13): [True: 34.8k, False: 43.8k]
  ------------------
 2949|  34.8k|            loader_log(inst, VULKAN_LOADER_WARN_BIT, 0,
 2950|  34.8k|                       "Layer \"%s\" contains meta-layer-specific component_layers, but using older JSON file version.",
 2951|  34.8k|                       props.info.layerName);
 2952|  34.8k|        }
 2953|       |
 2954|  78.7k|        result = loader_parse_json_array_of_strings(inst, layer_node, "component_layers", &(props.component_layer_names));
 2955|  78.7k|        if (VK_ERROR_OUT_OF_HOST_MEMORY == result) {
  ------------------
  |  Branch (2955:13): [True: 0, False: 78.7k]
  ------------------
 2956|      0|            goto out;
 2957|      0|        }
 2958|  78.7k|        if (VK_ERROR_INITIALIZATION_FAILED == result) {
  ------------------
  |  Branch (2958:13): [True: 34.9k, False: 43.8k]
  ------------------
 2959|  34.9k|            loader_log(inst, VULKAN_LOADER_WARN_BIT, 0,
 2960|  34.9k|                       "Layer \"%s\" is missing both library_path and component_layers fields.  One or the other MUST be defined.  "
 2961|  34.9k|                       "Skipping this layer",
 2962|  34.9k|                       props.info.layerName);
 2963|  34.9k|            goto out;
 2964|  34.9k|        }
 2965|       |        // This is now, officially, a meta-layer
 2966|  43.8k|        props.type_flags |= VK_LAYER_TYPE_FLAG_META_LAYER;
 2967|  43.8k|        loader_log(inst, VULKAN_LOADER_INFO_BIT | VULKAN_LOADER_LAYER_BIT, 0, "Encountered meta-layer \"%s\"",
 2968|  43.8k|                   props.info.layerName);
 2969|  43.8k|    }
 2970|       |
 2971|       |    // Parse blacklisted_layers
 2972|       |
 2973|   207k|    if (props.is_override) {
  ------------------
  |  Branch (2973:9): [True: 2.19k, False: 205k]
  ------------------
 2974|  2.19k|        result = loader_parse_json_array_of_strings(inst, layer_node, "blacklisted_layers", &(props.blacklist_layer_names));
 2975|  2.19k|        if (VK_ERROR_OUT_OF_HOST_MEMORY == result) {
  ------------------
  |  Branch (2975:13): [True: 0, False: 2.19k]
  ------------------
 2976|      0|            goto out;
 2977|      0|        }
 2978|  2.19k|    }
 2979|       |
 2980|       |    // Parse override_paths
 2981|       |
 2982|   207k|    result = loader_parse_json_array_of_strings(inst, layer_node, "override_paths", &(props.override_paths));
 2983|   207k|    if (VK_ERROR_OUT_OF_HOST_MEMORY == result) {
  ------------------
  |  Branch (2983:9): [True: 0, False: 207k]
  ------------------
 2984|      0|        goto out;
 2985|      0|    }
 2986|   207k|    if (NULL != props.override_paths.list && !loader_check_version_meets_required(loader_combine_version(1, 1, 0), version)) {
  ------------------
  |  Branch (2986:9): [True: 870, False: 207k]
  |  Branch (2986:46): [True: 495, False: 375]
  ------------------
 2987|    495|        loader_log(inst, VULKAN_LOADER_WARN_BIT, 0,
 2988|    495|                   "Layer \"%s\" contains meta-layer-specific override paths, but using older JSON file version.",
 2989|    495|                   props.info.layerName);
 2990|    495|    }
 2991|       |
 2992|       |    // Parse disable_environment
 2993|       |
 2994|   207k|    if (is_implicit) {
  ------------------
  |  Branch (2994:9): [True: 5.55k, False: 202k]
  ------------------
 2995|  5.55k|        cJSON *disable_environment = loader_cJSON_GetObjectItem(layer_node, "disable_environment");
 2996|  5.55k|        if (disable_environment == NULL) {
  ------------------
  |  Branch (2996:13): [True: 951, False: 4.60k]
  ------------------
 2997|    951|            loader_log(inst, VULKAN_LOADER_WARN_BIT, 0,
 2998|    951|                       "Layer \"%s\" doesn't contain required layer object disable_environment in the manifest JSON file, skipping "
 2999|    951|                       "this layer",
 3000|    951|                       props.info.layerName);
 3001|    951|            result = VK_ERROR_INITIALIZATION_FAILED;
 3002|    951|            goto out;
 3003|    951|        }
 3004|       |
 3005|  4.60k|        if (!disable_environment->child || disable_environment->child->type != cJSON_String ||
  ------------------
  |  |  101|  9.19k|#define cJSON_String (1 << 4)
  ------------------
  |  Branch (3005:13): [True: 9, False: 4.59k]
  |  Branch (3005:44): [True: 37, False: 4.55k]
  ------------------
 3006|  4.55k|            !disable_environment->child->string || !disable_environment->child->valuestring) {
  ------------------
  |  Branch (3006:13): [True: 47, False: 4.50k]
  |  Branch (3006:52): [True: 0, False: 4.50k]
  ------------------
 3007|     93|            loader_log(inst, VULKAN_LOADER_WARN_BIT, 0,
 3008|     93|                       "Layer \"%s\" doesn't contain required child value in object disable_environment in the manifest JSON file, "
 3009|     93|                       "skipping this layer (Policy #LLP_LAYER_9)",
 3010|     93|                       props.info.layerName);
 3011|     93|            result = VK_ERROR_INITIALIZATION_FAILED;
 3012|     93|            goto out;
 3013|     93|        }
 3014|  4.50k|        result = loader_copy_to_new_str(inst, disable_environment->child->string, &(props.disable_env_var.name));
 3015|  4.50k|        if (VK_SUCCESS != result) goto out;
  ------------------
  |  Branch (3015:13): [True: 0, False: 4.50k]
  ------------------
 3016|  4.50k|        result = loader_copy_to_new_str(inst, disable_environment->child->valuestring, &(props.disable_env_var.value));
 3017|  4.50k|        if (VK_SUCCESS != result) goto out;
  ------------------
  |  Branch (3017:13): [True: 0, False: 4.50k]
  ------------------
 3018|  4.50k|    }
 3019|       |
 3020|       |    // Now get all optional items and objects and put in list:
 3021|       |    // functions
 3022|       |    // instance_extensions
 3023|       |    // device_extensions
 3024|       |    // enable_environment (implicit layers only)
 3025|       |    // library_arch
 3026|       |
 3027|       |    // Layer interface functions
 3028|       |    //    vkGetInstanceProcAddr
 3029|       |    //    vkGetDeviceProcAddr
 3030|       |    //    vkNegotiateLoaderLayerInterfaceVersion (starting with JSON file 1.1.0)
 3031|   206k|    cJSON *functions = loader_cJSON_GetObjectItem(layer_node, "functions");
 3032|   206k|    if (functions != NULL) {
  ------------------
  |  Branch (3032:9): [True: 174, False: 206k]
  ------------------
 3033|    174|        if (loader_check_version_meets_required(loader_combine_version(1, 1, 0), version)) {
  ------------------
  |  Branch (3033:13): [True: 77, False: 97]
  ------------------
 3034|     77|            result = loader_parse_json_string(functions, "vkNegotiateLoaderLayerInterfaceVersion",
 3035|     77|                                              &props.functions.str_negotiate_interface);
 3036|     77|            if (result == VK_ERROR_OUT_OF_HOST_MEMORY) goto out;
  ------------------
  |  Branch (3036:17): [True: 0, False: 77]
  ------------------
 3037|     77|        }
 3038|    174|        result = loader_parse_json_string(functions, "vkGetInstanceProcAddr", &props.functions.str_gipa);
 3039|    174|        if (result == VK_ERROR_OUT_OF_HOST_MEMORY) goto out;
  ------------------
  |  Branch (3039:13): [True: 0, False: 174]
  ------------------
 3040|       |
 3041|    174|        if (NULL == props.functions.str_negotiate_interface && props.functions.str_gipa &&
  ------------------
  |  Branch (3041:13): [True: 174, False: 0]
  |  Branch (3041:64): [True: 0, False: 174]
  ------------------
 3042|      0|            loader_check_version_meets_required(loader_combine_version(1, 1, 0), version)) {
  ------------------
  |  Branch (3042:13): [True: 0, False: 0]
  ------------------
 3043|      0|            loader_log(inst, VULKAN_LOADER_INFO_BIT, 0,
 3044|      0|                       "Layer \"%s\" using deprecated \'vkGetInstanceProcAddr\' tag which was deprecated starting with JSON "
 3045|      0|                       "file version 1.1.0. The new vkNegotiateLoaderLayerInterfaceVersion function is preferred, though for "
 3046|      0|                       "compatibility reasons it may be desirable to continue using the deprecated tag.",
 3047|      0|                       props.info.layerName);
 3048|      0|        }
 3049|       |
 3050|    174|        result = loader_parse_json_string(functions, "vkGetDeviceProcAddr", &props.functions.str_gdpa);
 3051|    174|        if (result == VK_ERROR_OUT_OF_HOST_MEMORY) goto out;
  ------------------
  |  Branch (3051:13): [True: 0, False: 174]
  ------------------
 3052|       |
 3053|    174|        if (NULL == props.functions.str_negotiate_interface && props.functions.str_gdpa &&
  ------------------
  |  Branch (3053:13): [True: 174, False: 0]
  |  Branch (3053:64): [True: 0, False: 174]
  ------------------
 3054|      0|            loader_check_version_meets_required(loader_combine_version(1, 1, 0), version)) {
  ------------------
  |  Branch (3054:13): [True: 0, False: 0]
  ------------------
 3055|      0|            loader_log(inst, VULKAN_LOADER_INFO_BIT, 0,
 3056|      0|                       "Layer \"%s\" using deprecated \'vkGetDeviceProcAddr\' tag which was deprecated starting with JSON "
 3057|      0|                       "file version 1.1.0. The new vkNegotiateLoaderLayerInterfaceVersion function is preferred, though for "
 3058|      0|                       "compatibility reasons it may be desirable to continue using the deprecated tag.",
 3059|      0|                       props.info.layerName);
 3060|      0|        }
 3061|    174|    }
 3062|       |
 3063|       |    // instance_extensions
 3064|       |    //   array of {
 3065|       |    //     name
 3066|       |    //     spec_version
 3067|       |    //   }
 3068|       |
 3069|   206k|    cJSON *instance_extensions = loader_cJSON_GetObjectItem(layer_node, "instance_extensions");
 3070|   206k|    if (instance_extensions != NULL && instance_extensions->type == cJSON_Array) {
  ------------------
  |  |  102|  2.12k|#define cJSON_Array (1 << 5)
  ------------------
  |  Branch (3070:9): [True: 2.12k, False: 204k]
  |  Branch (3070:40): [True: 1.56k, False: 560]
  ------------------
 3071|  1.56k|        cJSON *ext_item = NULL;
 3072|  18.3k|        cJSON_ArrayForEach(ext_item, instance_extensions) {
  ------------------
  |  |  213|  19.9k|    for (element = (array != NULL) ? (array)->child : NULL; element != NULL; element = element->next)
  |  |  ------------------
  |  |  |  Branch (213:20): [True: 1.56k, False: 0]
  |  |  |  Branch (213:61): [True: 18.3k, False: 1.56k]
  |  |  ------------------
  ------------------
 3073|  18.3k|            if (ext_item->type != cJSON_Object) {
  ------------------
  |  |  103|  18.3k|#define cJSON_Object (1 << 6)
  ------------------
  |  Branch (3073:17): [True: 1.60k, False: 16.7k]
  ------------------
 3074|  1.60k|                continue;
 3075|  1.60k|            }
 3076|       |
 3077|  16.7k|            VkExtensionProperties ext_prop = {0};
 3078|  16.7k|            result = loader_parse_json_string_to_existing_str(ext_item, "name", VK_MAX_EXTENSION_NAME_SIZE, ext_prop.extensionName);
 3079|  16.7k|            if (result == VK_ERROR_INITIALIZATION_FAILED) {
  ------------------
  |  Branch (3079:17): [True: 4.08k, False: 12.6k]
  ------------------
 3080|  4.08k|                continue;
 3081|  4.08k|            }
 3082|  12.6k|            char *spec_version = NULL;
 3083|  12.6k|            result = loader_parse_json_string(ext_item, "spec_version", &spec_version);
 3084|  12.6k|            if (result == VK_ERROR_OUT_OF_HOST_MEMORY) goto out;
  ------------------
  |  Branch (3084:17): [True: 0, False: 12.6k]
  ------------------
 3085|  12.6k|            if (NULL != spec_version) {
  ------------------
  |  Branch (3085:17): [True: 1.32k, False: 11.3k]
  ------------------
 3086|  1.32k|                ext_prop.specVersion = (uint32_t)strtoul(spec_version, NULL, 10);
 3087|  1.32k|            }
 3088|  12.6k|            loader_instance_heap_free(inst, spec_version);
 3089|  12.6k|            bool ext_unsupported = wsi_unsupported_instance_extension(&ext_prop);
 3090|  12.6k|            if (!ext_unsupported) {
  ------------------
  |  Branch (3090:17): [True: 10.8k, False: 1.80k]
  ------------------
 3091|  10.8k|                result = loader_add_to_ext_list(inst, &props.instance_extension_list, 1, &ext_prop);
 3092|  10.8k|                if (result == VK_ERROR_OUT_OF_HOST_MEMORY) goto out;
  ------------------
  |  Branch (3092:21): [True: 0, False: 10.8k]
  ------------------
 3093|  10.8k|            }
 3094|  12.6k|        }
 3095|  1.56k|    }
 3096|       |
 3097|       |    // device_extensions
 3098|       |    //   array of {
 3099|       |    //     name
 3100|       |    //     spec_version
 3101|       |    //     entrypoints
 3102|       |    //   }
 3103|   206k|    cJSON *device_extensions = loader_cJSON_GetObjectItem(layer_node, "device_extensions");
 3104|   206k|    if (device_extensions != NULL && device_extensions->type == cJSON_Array) {
  ------------------
  |  |  102|  1.75k|#define cJSON_Array (1 << 5)
  ------------------
  |  Branch (3104:9): [True: 1.75k, False: 205k]
  |  Branch (3104:38): [True: 1.42k, False: 333]
  ------------------
 3105|  1.42k|        cJSON *ext_item = NULL;
 3106|  23.0k|        cJSON_ArrayForEach(ext_item, device_extensions) {
  ------------------
  |  |  213|  24.5k|    for (element = (array != NULL) ? (array)->child : NULL; element != NULL; element = element->next)
  |  |  ------------------
  |  |  |  Branch (213:20): [True: 1.42k, False: 0]
  |  |  |  Branch (213:61): [True: 23.0k, False: 1.42k]
  |  |  ------------------
  ------------------
 3107|  23.0k|            if (ext_item->type != cJSON_Object) {
  ------------------
  |  |  103|  23.0k|#define cJSON_Object (1 << 6)
  ------------------
  |  Branch (3107:17): [True: 1.40k, False: 21.6k]
  ------------------
 3108|  1.40k|                continue;
 3109|  1.40k|            }
 3110|       |
 3111|  21.6k|            VkExtensionProperties ext_prop = {0};
 3112|  21.6k|            result = loader_parse_json_string_to_existing_str(ext_item, "name", VK_MAX_EXTENSION_NAME_SIZE, ext_prop.extensionName);
 3113|  21.6k|            if (result == VK_ERROR_INITIALIZATION_FAILED) {
  ------------------
  |  Branch (3113:17): [True: 4.15k, False: 17.5k]
  ------------------
 3114|  4.15k|                continue;
 3115|  4.15k|            }
 3116|       |
 3117|  17.5k|            char *spec_version = NULL;
 3118|  17.5k|            result = loader_parse_json_string(ext_item, "spec_version", &spec_version);
 3119|  17.5k|            if (result == VK_ERROR_OUT_OF_HOST_MEMORY) goto out;
  ------------------
  |  Branch (3119:17): [True: 0, False: 17.5k]
  ------------------
 3120|  17.5k|            if (NULL != spec_version) {
  ------------------
  |  Branch (3120:17): [True: 474, False: 17.0k]
  ------------------
 3121|    474|                ext_prop.specVersion = (uint32_t)strtoul(spec_version, NULL, 10);
 3122|    474|            }
 3123|  17.5k|            loader_instance_heap_free(inst, spec_version);
 3124|       |
 3125|  17.5k|            cJSON *entrypoints = loader_cJSON_GetObjectItem(ext_item, "entrypoints");
 3126|  17.5k|            if (entrypoints == NULL) {
  ------------------
  |  Branch (3126:17): [True: 15.0k, False: 2.43k]
  ------------------
 3127|  15.0k|                result = loader_add_to_dev_ext_list(inst, &props.device_extension_list, &ext_prop, NULL);
 3128|  15.0k|                if (result == VK_ERROR_OUT_OF_HOST_MEMORY) goto out;
  ------------------
  |  Branch (3128:21): [True: 0, False: 15.0k]
  ------------------
 3129|  15.0k|                continue;
 3130|  15.0k|            }
 3131|       |
 3132|  2.43k|            struct loader_string_list entrys = {0};
 3133|  2.43k|            result = loader_parse_json_array_of_strings(inst, ext_item, "entrypoints", &entrys);
 3134|  2.43k|            if (result == VK_ERROR_OUT_OF_HOST_MEMORY) goto out;
  ------------------
  |  Branch (3134:17): [True: 0, False: 2.43k]
  ------------------
 3135|  2.43k|            result = loader_add_to_dev_ext_list(inst, &props.device_extension_list, &ext_prop, &entrys);
 3136|  2.43k|            if (result == VK_ERROR_OUT_OF_HOST_MEMORY) goto out;
  ------------------
  |  Branch (3136:17): [True: 0, False: 2.43k]
  ------------------
 3137|  2.43k|        }
 3138|  1.42k|    }
 3139|   206k|    if (is_implicit) {
  ------------------
  |  Branch (3139:9): [True: 4.50k, False: 202k]
  ------------------
 3140|  4.50k|        cJSON *enable_environment = loader_cJSON_GetObjectItem(layer_node, "enable_environment");
 3141|       |
 3142|       |        // enable_environment is optional
 3143|  4.50k|        if (enable_environment && enable_environment->child && enable_environment->child->type == cJSON_String &&
  ------------------
  |  |  101|  5.00k|#define cJSON_String (1 << 4)
  ------------------
  |  Branch (3143:13): [True: 1.27k, False: 3.23k]
  |  Branch (3143:35): [True: 501, False: 775]
  |  Branch (3143:64): [True: 461, False: 40]
  ------------------
 3144|    461|            enable_environment->child->string && enable_environment->child->valuestring) {
  ------------------
  |  Branch (3144:13): [True: 321, False: 140]
  |  Branch (3144:50): [True: 321, False: 0]
  ------------------
 3145|    321|            result = loader_copy_to_new_str(inst, enable_environment->child->string, &(props.enable_env_var.name));
 3146|    321|            if (VK_SUCCESS != result) goto out;
  ------------------
  |  Branch (3146:17): [True: 0, False: 321]
  ------------------
 3147|    321|            result = loader_copy_to_new_str(inst, enable_environment->child->valuestring, &(props.enable_env_var.value));
 3148|    321|            if (VK_SUCCESS != result) goto out;
  ------------------
  |  Branch (3148:17): [True: 0, False: 321]
  ------------------
 3149|    321|        }
 3150|  4.50k|    }
 3151|       |
 3152|       |    // Read in the pre-instance stuff
 3153|   206k|    cJSON *pre_instance = loader_cJSON_GetObjectItem(layer_node, "pre_instance_functions");
 3154|   206k|    if (NULL != pre_instance) {
  ------------------
  |  Branch (3154:9): [True: 269, False: 206k]
  ------------------
 3155|       |        // Supported versions started in 1.1.2, so anything newer
 3156|    269|        if (!loader_check_version_meets_required(loader_combine_version(1, 1, 2), version)) {
  ------------------
  |  Branch (3156:13): [True: 165, False: 104]
  ------------------
 3157|    165|            loader_log(inst, VULKAN_LOADER_ERROR_BIT, 0,
 3158|    165|                       "Found pre_instance_functions section in layer from \"%s\". This section is only valid in manifest version "
 3159|    165|                       "1.1.2 or later. The section will be ignored",
 3160|    165|                       filename);
 3161|    165|        } else if (!is_implicit) {
  ------------------
  |  Branch (3161:20): [True: 80, False: 24]
  ------------------
 3162|     80|            loader_log(inst, VULKAN_LOADER_WARN_BIT, 0,
 3163|     80|                       "Found pre_instance_functions section in explicit layer from \"%s\". This section is only valid in implicit "
 3164|     80|                       "layers. The section will be ignored",
 3165|     80|                       filename);
 3166|     80|        } else {
 3167|     24|            result = loader_parse_json_string(pre_instance, "vkEnumerateInstanceExtensionProperties",
 3168|     24|                                              &props.pre_instance_functions.enumerate_instance_extension_properties);
 3169|     24|            if (result == VK_ERROR_OUT_OF_HOST_MEMORY) goto out;
  ------------------
  |  Branch (3169:17): [True: 0, False: 24]
  ------------------
 3170|       |
 3171|     24|            result = loader_parse_json_string(pre_instance, "vkEnumerateInstanceLayerProperties",
 3172|     24|                                              &props.pre_instance_functions.enumerate_instance_layer_properties);
 3173|     24|            if (result == VK_ERROR_OUT_OF_HOST_MEMORY) goto out;
  ------------------
  |  Branch (3173:17): [True: 0, False: 24]
  ------------------
 3174|       |
 3175|     24|            result = loader_parse_json_string(pre_instance, "vkEnumerateInstanceVersion",
 3176|     24|                                              &props.pre_instance_functions.enumerate_instance_version);
 3177|     24|            if (result == VK_ERROR_OUT_OF_HOST_MEMORY) goto out;
  ------------------
  |  Branch (3177:17): [True: 0, False: 24]
  ------------------
 3178|     24|        }
 3179|    269|    }
 3180|       |
 3181|   206k|    if (loader_cJSON_GetObjectItem(layer_node, "app_keys")) {
  ------------------
  |  Branch (3181:9): [True: 1.92k, False: 204k]
  ------------------
 3182|  1.92k|        if (!props.is_override) {
  ------------------
  |  Branch (3182:13): [True: 1.25k, False: 664]
  ------------------
 3183|  1.25k|            loader_log(inst, VULKAN_LOADER_WARN_BIT | VULKAN_LOADER_LAYER_BIT, 0,
 3184|  1.25k|                       "Layer %s contains app_keys, but any app_keys can only be provided by the override meta layer. "
 3185|  1.25k|                       "These will be ignored.",
 3186|  1.25k|                       props.info.layerName);
 3187|  1.25k|        }
 3188|       |
 3189|  1.92k|        result = loader_parse_json_array_of_strings(inst, layer_node, "app_keys", &props.app_key_paths);
 3190|  1.92k|        if (result == VK_ERROR_OUT_OF_HOST_MEMORY) goto out;
  ------------------
  |  Branch (3190:13): [True: 0, False: 1.92k]
  ------------------
 3191|  1.92k|    }
 3192|       |
 3193|   206k|    char *library_arch = loader_cJSON_GetStringValue(loader_cJSON_GetObjectItem(layer_node, "library_arch"));
 3194|   206k|    if (NULL != library_arch) {
  ------------------
  |  Branch (3194:9): [True: 13, False: 206k]
  ------------------
 3195|     13|        if ((strncmp(library_arch, "32", 2) == 0 && sizeof(void *) != 4) ||
  ------------------
  |  Branch (3195:14): [True: 10, False: 3]
  |  Branch (3195:53): [True: 0, Folded]
  ------------------
 3196|     10|            (strncmp(library_arch, "64", 2) == 0 && sizeof(void *) != 8)) {
  ------------------
  |  Branch (3196:14): [True: 0, False: 3]
  |  Branch (3196:53): [Folded, False: 0]
  ------------------
 3197|     10|            loader_log(inst, VULKAN_LOADER_INFO_BIT, 0,
 3198|     10|                       "The library architecture in layer %s doesn't match the current running architecture, skipping this layer",
 3199|     10|                       filename);
 3200|     10|            result = VK_ERROR_INITIALIZATION_FAILED;
 3201|     10|            goto out;
 3202|     10|        }
 3203|     13|    }
 3204|       |
 3205|   206k|    result = VK_SUCCESS;
 3206|       |
 3207|   525k|out:
 3208|       |    // Try to append the layer property
 3209|   525k|    if (VK_SUCCESS == result) {
  ------------------
  |  Branch (3209:9): [True: 206k, False: 318k]
  ------------------
 3210|   206k|        result = loader_append_layer_property(inst, layer_instance_list, &props);
 3211|   206k|    }
 3212|       |    // If appending fails - free all the memory allocated in it
 3213|   525k|    if (VK_SUCCESS != result) {
  ------------------
  |  Branch (3213:9): [True: 318k, False: 206k]
  ------------------
 3214|   318k|        loader_free_layer_properties(inst, &props);
 3215|   318k|    }
 3216|   525k|    return result;
 3217|   206k|}
is_valid_layer_json_version:
 3219|  9.81k|bool is_valid_layer_json_version(const loader_api_version *layer_json) {
 3220|       |    // Supported versions are: 1.0.0, 1.0.1, 1.1.0 - 1.1.2, and 1.2.0 - 1.2.1.
 3221|  9.81k|    if ((layer_json->major == 1 && layer_json->minor == 2 && layer_json->patch < 2) ||
  ------------------
  |  Branch (3221:10): [True: 2.46k, False: 7.34k]
  |  Branch (3221:36): [True: 377, False: 2.09k]
  |  Branch (3221:62): [True: 199, False: 178]
  ------------------
 3222|  9.61k|        (layer_json->major == 1 && layer_json->minor == 1 && layer_json->patch < 3) ||
  ------------------
  |  Branch (3222:10): [True: 2.27k, False: 7.34k]
  |  Branch (3222:36): [True: 448, False: 1.82k]
  |  Branch (3222:62): [True: 295, False: 153]
  ------------------
 3223|  9.32k|        (layer_json->major == 1 && layer_json->minor == 0 && layer_json->patch < 2)) {
  ------------------
  |  Branch (3223:10): [True: 1.97k, False: 7.34k]
  |  Branch (3223:36): [True: 1.48k, False: 493]
  |  Branch (3223:62): [True: 1.14k, False: 336]
  ------------------
 3224|  1.64k|        return true;
 3225|  1.64k|    }
 3226|  8.17k|    return false;
 3227|  9.81k|}
loader_add_layer_properties:
 3239|  11.1k|                                     bool is_implicit, char *filename) {
 3240|       |    // The following Fields in layer manifest file that are required:
 3241|       |    //   - "file_format_version"
 3242|       |    //   - If more than one "layer" object are used, then the "layers" array is
 3243|       |    //     required
 3244|  11.1k|    VkResult result = VK_ERROR_INITIALIZATION_FAILED;
 3245|       |    // Make sure sure the top level json value is an object
 3246|  11.1k|    if (!json || json->type != cJSON_Object) {
  ------------------
  |  |  103|  11.1k|#define cJSON_Object (1 << 6)
  ------------------
  |  Branch (3246:9): [True: 0, False: 11.1k]
  |  Branch (3246:18): [True: 1.33k, False: 9.86k]
  ------------------
 3247|  1.33k|        goto out;
 3248|  1.33k|    }
 3249|  9.86k|    char *file_vers = loader_cJSON_GetStringValue(loader_cJSON_GetObjectItem(json, "file_format_version"));
 3250|  9.86k|    if (NULL == file_vers) {
  ------------------
  |  Branch (3250:9): [True: 49, False: 9.81k]
  ------------------
 3251|     49|        loader_log(inst, VULKAN_LOADER_WARN_BIT | VULKAN_LOADER_LAYER_BIT, 0,
 3252|     49|                   "loader_add_layer_properties: Manifest %s missing required field file_format_version", filename);
 3253|     49|        goto out;
 3254|     49|    }
 3255|       |
 3256|  9.81k|    loader_log(inst, VULKAN_LOADER_INFO_BIT, 0, "Found manifest file %s (file version %s)", filename, file_vers);
 3257|       |    // Get the major/minor/and patch as integers for easier comparison
 3258|  9.81k|    loader_api_version json_version = loader_make_full_version(loader_parse_version_string(file_vers));
 3259|       |
 3260|  9.81k|    if (!is_valid_layer_json_version(&json_version)) {
  ------------------
  |  Branch (3260:9): [True: 8.17k, False: 1.64k]
  ------------------
 3261|  8.17k|        loader_log(inst, VULKAN_LOADER_INFO_BIT | VULKAN_LOADER_LAYER_BIT, 0,
 3262|  8.17k|                   "loader_add_layer_properties: %s has unknown layer manifest file version %d.%d.%d.  May cause errors.", filename,
 3263|  8.17k|                   json_version.major, json_version.minor, json_version.patch);
 3264|  8.17k|    }
 3265|       |
 3266|       |    // If "layers" is present, read in the array of layer objects
 3267|  9.81k|    cJSON *layers_node = loader_cJSON_GetObjectItem(json, "layers");
 3268|  9.81k|    if (layers_node != NULL) {
  ------------------
  |  Branch (3268:9): [True: 8.10k, False: 1.70k]
  ------------------
 3269|       |        // Supported versions started in 1.0.1, so anything newer
 3270|  8.10k|        if (!loader_check_version_meets_required(loader_combine_version(1, 0, 1), json_version)) {
  ------------------
  |  Branch (3270:13): [True: 4.47k, False: 3.63k]
  ------------------
 3271|  4.47k|            loader_log(inst, VULKAN_LOADER_WARN_BIT | VULKAN_LOADER_LAYER_BIT, 0,
 3272|  4.47k|                       "loader_add_layer_properties: \'layers\' tag not supported until file version 1.0.1, but %s is reporting "
 3273|  4.47k|                       "version %s",
 3274|  4.47k|                       filename, file_vers);
 3275|  4.47k|        }
 3276|  8.10k|        cJSON *layer_node = NULL;
 3277|   523k|        cJSON_ArrayForEach(layer_node, layers_node) {
  ------------------
  |  |  213|   530k|    for (element = (array != NULL) ? (array)->child : NULL; element != NULL; element = element->next)
  |  |  ------------------
  |  |  |  Branch (213:20): [True: 8.10k, False: 0]
  |  |  |  Branch (213:61): [True: 523k, False: 6.93k]
  |  |  ------------------
  ------------------
 3278|   523k|            if (layer_node->type != cJSON_Object) {
  ------------------
  |  |  103|   523k|#define cJSON_Object (1 << 6)
  ------------------
  |  Branch (3278:17): [True: 1.17k, False: 522k]
  ------------------
 3279|  1.17k|                loader_log(
 3280|  1.17k|                    inst, VULKAN_LOADER_WARN_BIT | VULKAN_LOADER_LAYER_BIT, 0,
 3281|  1.17k|                    "loader_add_layer_properties: Array element in \"layers\" field in manifest JSON file %s is not an object.  "
 3282|  1.17k|                    "Skipping this file",
 3283|  1.17k|                    filename);
 3284|  1.17k|                goto out;
 3285|  1.17k|            }
 3286|   522k|            result = loader_read_layer_json(inst, layer_instance_list, layer_node, json_version, is_implicit, filename);
 3287|   522k|        }
 3288|  8.10k|    } else {
 3289|       |        // Otherwise, try to read in individual layers
 3290|  1.70k|        cJSON *layer_node = loader_cJSON_GetObjectItem(json, "layer");
 3291|  1.70k|        if (layer_node == NULL) {
  ------------------
  |  Branch (3291:13): [True: 1.01k, False: 695]
  ------------------
 3292|       |            // Don't warn if this happens to be an ICD manifest
 3293|  1.01k|            if (loader_cJSON_GetObjectItem(json, "ICD") == NULL) {
  ------------------
  |  Branch (3293:17): [True: 964, False: 47]
  ------------------
 3294|    964|                loader_log(
 3295|    964|                    inst, VULKAN_LOADER_WARN_BIT | VULKAN_LOADER_LAYER_BIT, 0,
 3296|    964|                    "loader_add_layer_properties: Can not find 'layer' object in manifest JSON file %s.  Skipping this file.",
 3297|    964|                    filename);
 3298|    964|            }
 3299|  1.01k|            goto out;
 3300|  1.01k|        }
 3301|       |        // Loop through all "layer" objects in the file to get a count of them
 3302|       |        // first.
 3303|    695|        uint16_t layer_count = 0;
 3304|    695|        cJSON *tempNode = layer_node;
 3305|  4.13k|        do {
 3306|  4.13k|            tempNode = tempNode->next;
 3307|  4.13k|            layer_count++;
 3308|  4.13k|        } while (tempNode != NULL);
  ------------------
  |  Branch (3308:18): [True: 3.43k, False: 695]
  ------------------
 3309|       |
 3310|       |        // Throw a warning if we encounter multiple "layer" objects in file
 3311|       |        // versions newer than 1.0.0.  Having multiple objects with the same
 3312|       |        // name at the same level is actually a JSON standard violation.
 3313|    695|        if (layer_count > 1 && loader_check_version_meets_required(loader_combine_version(1, 0, 1), json_version)) {
  ------------------
  |  Branch (3313:13): [True: 550, False: 145]
  |  Branch (3313:32): [True: 237, False: 313]
  ------------------
 3314|    237|            loader_log(inst, VULKAN_LOADER_ERROR_BIT | VULKAN_LOADER_LAYER_BIT, 0,
 3315|    237|                       "loader_add_layer_properties: Multiple 'layer' nodes are deprecated starting in file version \"1.0.1\".  "
 3316|    237|                       "Please use 'layers' : [] array instead in %s.",
 3317|    237|                       filename);
 3318|    458|        } else {
 3319|  3.52k|            do {
 3320|  3.52k|                result = loader_read_layer_json(inst, layer_instance_list, layer_node, json_version, is_implicit, filename);
 3321|  3.52k|                if (result == VK_ERROR_OUT_OF_HOST_MEMORY) {
  ------------------
  |  Branch (3321:21): [True: 0, False: 3.52k]
  ------------------
 3322|      0|                    goto out;
 3323|      0|                }
 3324|  3.52k|                layer_node = layer_node->next;
 3325|  3.52k|            } while (layer_node != NULL);
  ------------------
  |  Branch (3325:22): [True: 3.07k, False: 458]
  ------------------
 3326|    458|        }
 3327|    695|    }
 3328|       |
 3329|  11.1k|out:
 3330|       |
 3331|  11.1k|    return result;
 3332|  9.81k|}
copy_data_file_info:
 3336|  64.4k|                             size_t relative_path_size, struct loader_string_list *search_paths) {
 3337|  64.4k|    if (NULL != cur_path) {
  ------------------
  |  Branch (3337:9): [True: 64.4k, False: 0]
  ------------------
 3338|  64.4k|        uint32_t start = 0;
 3339|  64.4k|        uint32_t stop = 0;
 3340|       |
 3341|   139k|        while (cur_path[start] != '\0') {
  ------------------
  |  Branch (3341:16): [True: 75.1k, False: 64.4k]
  ------------------
 3342|  87.9k|            while (cur_path[start] == PATH_SEPARATOR && cur_path[start] != '\0') {
  ------------------
  |  |  154|   175k|#define PATH_SEPARATOR ':'
  ------------------
  |  Branch (3342:20): [True: 12.7k, False: 75.1k]
  |  Branch (3342:57): [True: 12.7k, False: 0]
  ------------------
 3343|  12.7k|                start++;
 3344|  12.7k|            }
 3345|  75.1k|            stop = start;
 3346|  1.19M|            while (cur_path[stop] != PATH_SEPARATOR && cur_path[stop] != '\0') {
  ------------------
  |  |  154|  2.38M|#define PATH_SEPARATOR ':'
  ------------------
  |  Branch (3346:20): [True: 1.18M, False: 10.8k]
  |  Branch (3346:56): [True: 1.11M, False: 64.2k]
  ------------------
 3347|  1.11M|                stop++;
 3348|  1.11M|            }
 3349|  75.1k|            const size_t s = stop - start;
 3350|  75.1k|            if (s) {
  ------------------
  |  Branch (3350:17): [True: 75.0k, False: 114]
  ------------------
 3351|       |                // space enough for base path, relative path, path separator, and null terminator
 3352|  75.0k|                size_t new_str_len = s + relative_path_size + 2;
 3353|       |
 3354|  75.0k|                char *new_str = loader_instance_heap_calloc(inst, new_str_len, VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE);
 3355|  75.0k|                if (NULL == new_str) {
  ------------------
  |  Branch (3355:21): [True: 0, False: 75.0k]
  ------------------
 3356|      0|                    return VK_ERROR_OUT_OF_HOST_MEMORY;
 3357|      0|                }
 3358|  75.0k|                memcpy(new_str, &cur_path[start], s);
 3359|  75.0k|                new_str[s] = '\0';
 3360|       |
 3361|       |                // If this is a specific JSON file, just add it and don't add any
 3362|       |                // relative path or directory symbol to it.
 3363|  75.0k|                if (!is_json(new_str, s)) {
  ------------------
  |  Branch (3363:21): [True: 73.3k, False: 1.68k]
  ------------------
 3364|       |                    // Add the relative directory if present.
 3365|  73.3k|                    if (relative_path_size > 0) {
  ------------------
  |  Branch (3365:25): [True: 66.8k, False: 6.43k]
  ------------------
 3366|  66.8k|                        char *rel_start = new_str + s;
 3367|       |
 3368|       |                        // If last symbol written was not a directory symbol, add it.
 3369|  66.8k|                        if (*(rel_start - 1) != DIRECTORY_SYMBOL) {
  ------------------
  |  |  155|  66.8k|#define DIRECTORY_SYMBOL '/'
  ------------------
  |  Branch (3369:29): [True: 66.8k, False: 0]
  ------------------
 3370|  66.8k|                            *rel_start++ = DIRECTORY_SYMBOL;
  ------------------
  |  |  155|  66.8k|#define DIRECTORY_SYMBOL '/'
  ------------------
 3371|  66.8k|                        }
 3372|  66.8k|                        memcpy(rel_start, relative_path, relative_path_size);
 3373|  66.8k|                        rel_start[relative_path_size] = '\0';
 3374|  66.8k|                    }
 3375|  73.3k|                }
 3376|       |
 3377|  75.0k|                VkResult res = append_str_to_string_list_if_unique(inst, search_paths, new_str);
 3378|  75.0k|                if (VK_SUCCESS != res) {
  ------------------
  |  Branch (3378:21): [True: 0, False: 75.0k]
  ------------------
 3379|      0|                    return res;
 3380|      0|                }
 3381|  75.0k|                start = stop;
 3382|  75.0k|            }
 3383|  75.1k|        }
 3384|  64.4k|    }
 3385|  64.4k|    return VK_SUCCESS;
 3386|  64.4k|}
add_if_manifest_file:
 3389|  21.2k|VkResult add_if_manifest_file(const struct loader_instance *inst, const char *file_name, struct loader_string_list *out_files) {
 3390|  21.2k|    assert(NULL != file_name && "add_if_manifest_file: Received NULL pointer for file_name");
 3391|  21.2k|    assert(NULL != out_files && "add_if_manifest_file: Received NULL pointer for out_files");
 3392|       |
 3393|       |    // Look for files ending with ".json" suffix
 3394|  21.2k|    size_t name_len = strlen(file_name);
 3395|  21.2k|    if (!is_json(file_name, name_len)) {
  ------------------
  |  Branch (3395:9): [True: 13.4k, False: 7.80k]
  ------------------
 3396|       |        // Use incomplete to indicate invalid name, but to keep going.
 3397|  13.4k|        return VK_INCOMPLETE;
 3398|  13.4k|    }
 3399|       |
 3400|       |    // A directory search path and a file inside it can reach the same manifest.
 3401|  7.80k|    return copy_str_to_string_list_if_unique(inst, out_files, file_name, name_len);
 3402|  21.2k|}
add_data_files:
 3425|  9.81k|                        struct loader_string_list *out_files) {
 3426|  9.81k|    VkResult vk_result = VK_SUCCESS;
 3427|  9.81k|    char full_path[2048];
 3428|  9.81k|#if !defined(_WIN32)
 3429|  9.81k|    char temp_path[2048];
 3430|  9.81k|#endif
 3431|       |
 3432|  80.3k|    for (size_t i = 0; i < search_paths->count; i++) {
  ------------------
  |  Branch (3432:24): [True: 70.5k, False: 9.81k]
  ------------------
 3433|       |        // Now, parse the paths
 3434|  70.5k|        char *next_file = search_paths->list[i];
 3435|   141k|        while (NULL != next_file && *next_file != '\0') {
  ------------------
  |  Branch (3435:16): [True: 141k, False: 0]
  |  Branch (3435:37): [True: 70.5k, False: 70.5k]
  ------------------
 3436|  70.5k|            char *name = NULL;
 3437|  70.5k|            char *cur_file = next_file;
 3438|  70.5k|            next_file = loader_get_next_path(cur_file);
 3439|       |
 3440|       |            // Is this a JSON file, then try to open it.
 3441|  70.5k|            size_t len = strlen(cur_file);
 3442|  70.5k|            if (is_json(cur_file, len)) {
  ------------------
  |  Branch (3442:17): [True: 784, False: 69.7k]
  ------------------
 3443|       |#if defined(_WIN32)
 3444|       |                name = cur_file;
 3445|       |#elif COMMON_UNIX_PLATFORMS
 3446|       |                // Only Linux has relative paths, make a copy of location so it isn't modified
 3447|    784|                size_t str_len;
 3448|    784|                if (NULL != next_file) {
  ------------------
  |  Branch (3448:21): [True: 784, False: 0]
  ------------------
 3449|    784|                    str_len = next_file - cur_file + 1;
 3450|    784|                } else {
 3451|      0|                    str_len = strlen(cur_file) + 1;
 3452|      0|                }
 3453|    784|                if (str_len > sizeof(temp_path)) {
  ------------------
  |  Branch (3453:21): [True: 5, False: 779]
  ------------------
 3454|      5|                    loader_log(inst, VULKAN_LOADER_DEBUG_BIT, 0, "add_data_files: Path to %s too long", cur_file);
 3455|      5|                    continue;
 3456|      5|                }
 3457|    779|                strncpy(temp_path, cur_file, str_len);
 3458|    779|                name = temp_path;
 3459|       |#else
 3460|       |#warning add_data_files must define relative path copy for this platform
 3461|       |#endif
 3462|    779|                loader_get_fullpath(cur_file, name, sizeof(full_path), full_path);
 3463|    779|                name = full_path;
 3464|       |
 3465|    779|                VkResult local_res;
 3466|    779|                local_res = add_if_manifest_file(inst, name, out_files);
 3467|       |
 3468|       |                // Incomplete means this was not a valid data file.
 3469|    779|                if (local_res == VK_INCOMPLETE) {
  ------------------
  |  Branch (3469:21): [True: 0, False: 779]
  ------------------
 3470|      0|                    continue;
 3471|      0|                }
 3472|    779|                if (local_res != VK_SUCCESS) {
  ------------------
  |  Branch (3472:21): [True: 0, False: 779]
  ------------------
 3473|      0|                    vk_result = local_res;
 3474|      0|                    break;
 3475|      0|                }
 3476|  69.7k|            } else {  // Otherwise, treat it as a directory
 3477|  69.7k|                DIR *dir_stream = loader_opendir(inst, cur_file);
 3478|  69.7k|                if (NULL == dir_stream) {
  ------------------
  |  Branch (3478:21): [True: 64.1k, False: 5.53k]
  ------------------
 3479|  64.1k|                    continue;
 3480|  64.1k|                }
 3481|  26.0k|                while (1) {
  ------------------
  |  Branch (3481:24): [True: 26.0k, Folded]
  ------------------
 3482|  26.0k|                    errno = 0;
 3483|       |                    // NOLINTNEXTLINE(concurrency-mt-unsafe) - readdir is safe here since each thread uses its own dir_stream
 3484|  26.0k|                    struct dirent *dir_entry = readdir(dir_stream);
 3485|  26.0k|#if !defined(WIN32)  // Windows doesn't use readdir, don't check errors on functions which aren't called
 3486|  26.0k|                    if (errno != 0) {
  ------------------
  |  Branch (3486:25): [True: 0, False: 26.0k]
  ------------------
 3487|       |                        // NOLINTNEXTLINE(concurrency-mt-unsafe) - strerror's static buffer is used immediately and not retained
 3488|      0|                        loader_log(inst, VULKAN_LOADER_ERROR_BIT, 0, "readdir failed with %d: %s", errno, strerror(errno));
 3489|      0|                        break;
 3490|      0|                    }
 3491|  26.0k|#endif
 3492|  26.0k|                    if (NULL == dir_entry) {
  ------------------
  |  Branch (3492:25): [True: 5.53k, False: 20.4k]
  ------------------
 3493|  5.53k|                        break;
 3494|  5.53k|                    }
 3495|       |
 3496|  20.4k|                    name = &(dir_entry->d_name[0]);
 3497|       |                    // 'name' is the bare filename, 'cur_file' is the directory being scanned; the substring "file" in
 3498|       |                    // cur_file just confuses the naming heuristic below.
 3499|       |                    // NOLINTNEXTLINE(readability-suspicious-call-argument) - arguments are correctly ordered, not swapped
 3500|  20.4k|                    loader_get_fullpath(name, cur_file, sizeof(full_path), full_path);
 3501|  20.4k|                    name = full_path;
 3502|       |
 3503|  20.4k|                    VkResult local_res;
 3504|  20.4k|                    local_res = add_if_manifest_file(inst, name, out_files);
 3505|       |
 3506|       |                    // Incomplete means this was not a valid data file.
 3507|  20.4k|                    if (local_res == VK_INCOMPLETE) {
  ------------------
  |  Branch (3507:25): [True: 13.4k, False: 7.02k]
  ------------------
 3508|  13.4k|                        continue;
 3509|  13.4k|                    }
 3510|  7.02k|                    if (local_res != VK_SUCCESS) {
  ------------------
  |  Branch (3510:25): [True: 0, False: 7.02k]
  ------------------
 3511|      0|                        vk_result = local_res;
 3512|      0|                        break;
 3513|      0|                    }
 3514|  7.02k|                }
 3515|  5.53k|                loader_closedir(inst, dir_stream);
 3516|  5.53k|                if (vk_result != VK_SUCCESS) {
  ------------------
  |  Branch (3516:21): [True: 0, False: 5.53k]
  ------------------
 3517|      0|                    goto out;
 3518|      0|                }
 3519|  5.53k|            }
 3520|  70.5k|        }
 3521|  70.5k|    }
 3522|       |
 3523|  9.81k|out:
 3524|       |
 3525|  9.81k|    return vk_result;
 3526|  9.81k|}
read_data_files_in_search_paths:
 3532|  9.81k|                                         struct loader_string_list *out_files) {
 3533|  9.81k|    VkResult vk_result = VK_SUCCESS;
 3534|  9.81k|    char *override_env = NULL;
 3535|  9.81k|    char *additional_env = NULL;
 3536|  9.81k|    struct loader_string_list search_paths = {0};
 3537|       |
 3538|  9.81k|#if COMMON_UNIX_PLATFORMS
 3539|  9.81k|    const char *relative_location = NULL;  // Only used on unix platforms
 3540|  9.81k|    size_t rel_size = 0;                   // unused in windows, dont declare so no compiler warnings are generated
 3541|  9.81k|#endif
 3542|       |
 3543|       |#if defined(__APPLE__)
 3544|       |    char *bundle_path = NULL;
 3545|       |    char *search_only_in_bundle_env_var = loader_secure_getenv(VK_LOADER_SEARCH_ONLY_IN_BUNDLE_ENV_VAR, inst);
 3546|       |#endif
 3547|       |
 3548|       |#if defined(_WIN32)
 3549|       |    char *package_path = NULL;
 3550|       |#elif COMMON_UNIX_PLATFORMS
 3551|       |    // Determine how much space is needed to generate the full search path
 3552|       |    // for the current manifest files.
 3553|  9.81k|    char *xdg_config_home = loader_secure_getenv("XDG_CONFIG_HOME", inst);
 3554|  9.81k|    char *xdg_config_dirs = loader_secure_getenv("XDG_CONFIG_DIRS", inst);
 3555|       |
 3556|  9.81k|#if !defined(__Fuchsia__) && !defined(__QNX__)
 3557|  9.81k|    if (NULL == xdg_config_dirs || '\0' == xdg_config_dirs[0]) {
  ------------------
  |  Branch (3557:9): [True: 9.81k, False: 0]
  |  Branch (3557:36): [True: 0, False: 0]
  ------------------
 3558|  9.81k|        xdg_config_dirs = FALLBACK_CONFIG_DIRS;
 3559|  9.81k|    }
 3560|  9.81k|#endif
 3561|       |
 3562|  9.81k|    char *xdg_data_home = loader_secure_getenv("XDG_DATA_HOME", inst);
 3563|  9.81k|    char *xdg_data_dirs = loader_secure_getenv("XDG_DATA_DIRS", inst);
 3564|       |
 3565|  9.81k|#if !defined(__Fuchsia__) && !defined(__QNX__)
 3566|  9.81k|    if (NULL == xdg_data_dirs || '\0' == xdg_data_dirs[0]) {
  ------------------
  |  Branch (3566:9): [True: 9.81k, False: 0]
  |  Branch (3566:34): [True: 0, False: 0]
  ------------------
 3567|  9.81k|        xdg_data_dirs = FALLBACK_DATA_DIRS;
 3568|  9.81k|    }
 3569|  9.81k|#endif
 3570|       |
 3571|  9.81k|    char *home = NULL;
 3572|  9.81k|    char *default_data_home = NULL;
 3573|  9.81k|    char *default_config_home = NULL;
 3574|  9.81k|    char *home_data_dir = NULL;
 3575|  9.81k|    char *home_config_dir = NULL;
 3576|       |
 3577|       |    // Only use HOME if XDG_DATA_HOME is not present on the system
 3578|  9.81k|    home = loader_secure_getenv("HOME", inst);
 3579|  9.81k|    if (home != NULL) {
  ------------------
  |  Branch (3579:9): [True: 9.81k, False: 0]
  ------------------
 3580|  9.81k|        if (NULL == xdg_config_home || '\0' == xdg_config_home[0]) {
  ------------------
  |  Branch (3580:13): [True: 9.81k, False: 0]
  |  Branch (3580:40): [True: 0, False: 0]
  ------------------
 3581|  9.81k|            const char config_suffix[] = "/.config";
 3582|  9.81k|            size_t default_config_home_len = strlen(home) + sizeof(config_suffix) + 1;
 3583|  9.81k|            default_config_home = loader_instance_heap_calloc(inst, default_config_home_len, VK_SYSTEM_ALLOCATION_SCOPE_COMMAND);
 3584|  9.81k|            if (default_config_home == NULL) {
  ------------------
  |  Branch (3584:17): [True: 0, False: 9.81k]
  ------------------
 3585|      0|                vk_result = VK_ERROR_OUT_OF_HOST_MEMORY;
 3586|      0|                goto out;
 3587|      0|            }
 3588|  9.81k|            strncpy(default_config_home, home, default_config_home_len);
 3589|  9.81k|            strncat(default_config_home, config_suffix, default_config_home_len);
 3590|  9.81k|        }
 3591|  9.81k|        if (NULL == xdg_data_home || '\0' == xdg_data_home[0]) {
  ------------------
  |  Branch (3591:13): [True: 9.81k, False: 0]
  |  Branch (3591:38): [True: 0, False: 0]
  ------------------
 3592|  9.81k|            const char data_suffix[] = "/.local/share";
 3593|  9.81k|            size_t default_data_home_len = strlen(home) + sizeof(data_suffix) + 1;
 3594|  9.81k|            default_data_home = loader_instance_heap_calloc(inst, default_data_home_len, VK_SYSTEM_ALLOCATION_SCOPE_COMMAND);
 3595|  9.81k|            if (default_data_home == NULL) {
  ------------------
  |  Branch (3595:17): [True: 0, False: 9.81k]
  ------------------
 3596|      0|                vk_result = VK_ERROR_OUT_OF_HOST_MEMORY;
 3597|      0|                goto out;
 3598|      0|            }
 3599|  9.81k|            strncpy(default_data_home, home, default_data_home_len);
 3600|  9.81k|            strncat(default_data_home, data_suffix, default_data_home_len);
 3601|  9.81k|        }
 3602|  9.81k|    }
 3603|       |
 3604|  9.81k|    if (NULL != default_config_home) {
  ------------------
  |  Branch (3604:9): [True: 9.81k, False: 0]
  ------------------
 3605|  9.81k|        home_config_dir = default_config_home;
 3606|  9.81k|    } else {
 3607|      0|        home_config_dir = xdg_config_home;
 3608|      0|    }
 3609|  9.81k|    if (NULL != default_data_home) {
  ------------------
  |  Branch (3609:9): [True: 9.81k, False: 0]
  ------------------
 3610|  9.81k|        home_data_dir = default_data_home;
 3611|  9.81k|    } else {
 3612|      0|        home_data_dir = xdg_data_home;
 3613|      0|    }
 3614|       |#else
 3615|       |#warning read_data_files_in_search_paths unsupported platform
 3616|       |#endif
 3617|       |
 3618|  9.81k|    switch (manifest_type) {
 3619|      2|        case LOADER_DATA_FILE_MANIFEST_DRIVER:
  ------------------
  |  Branch (3619:9): [True: 2, False: 9.81k]
  ------------------
 3620|      2|            if (loader_settings_should_use_driver_environment_variables(inst)) {
  ------------------
  |  Branch (3620:17): [True: 2, False: 0]
  ------------------
 3621|      2|                override_env = loader_secure_getenv(VK_DRIVER_FILES_ENV_VAR, inst);
  ------------------
  |  |  113|      2|#define VK_DRIVER_FILES_ENV_VAR "VK_DRIVER_FILES"
  ------------------
 3622|      2|                if (NULL == override_env) {
  ------------------
  |  Branch (3622:21): [True: 2, False: 0]
  ------------------
 3623|       |                    // Not there, so fall back to the old name
 3624|      2|                    override_env = loader_secure_getenv(VK_ICD_FILENAMES_ENV_VAR, inst);
  ------------------
  |  |  112|      2|#define VK_ICD_FILENAMES_ENV_VAR "VK_ICD_FILENAMES"  // Deprecated in v1.3.207 loader
  ------------------
 3625|      2|                }
 3626|      2|                additional_env = loader_secure_getenv(VK_ADDITIONAL_DRIVER_FILES_ENV_VAR, inst);
  ------------------
  |  |  116|      2|#define VK_ADDITIONAL_DRIVER_FILES_ENV_VAR "VK_ADD_DRIVER_FILES"
  ------------------
 3627|      2|            }
 3628|      2|#if COMMON_UNIX_PLATFORMS
 3629|      2|            relative_location = VK_DRIVERS_INFO_RELATIVE_DIR;
  ------------------
  |  |  165|      2|#define VK_DRIVERS_INFO_RELATIVE_DIR VULKAN_DIR VULKAN_ICDCONF_DIR
  |  |  ------------------
  |  |  |  |  157|      2|#define VULKAN_DIR "vulkan/"
  |  |  ------------------
  |  |               #define VK_DRIVERS_INFO_RELATIVE_DIR VULKAN_DIR VULKAN_ICDCONF_DIR
  |  |  ------------------
  |  |  |  |  158|      2|#define VULKAN_ICDCONF_DIR "icd.d"
  |  |  ------------------
  ------------------
 3630|      2|#endif
 3631|       |#if defined(_WIN32)
 3632|       |            package_path = windows_get_app_package_manifest_path(inst);
 3633|       |#endif
 3634|      2|            break;
 3635|  4.90k|        case LOADER_DATA_FILE_MANIFEST_IMPLICIT_LAYER:
  ------------------
  |  Branch (3635:9): [True: 4.90k, False: 4.90k]
  ------------------
 3636|  4.90k|            override_env = loader_secure_getenv(VK_IMPLICIT_LAYER_PATH_ENV_VAR, inst);
  ------------------
  |  |  130|  4.90k|#define VK_IMPLICIT_LAYER_PATH_ENV_VAR "VK_IMPLICIT_LAYER_PATH"
  ------------------
 3637|  4.90k|            additional_env = loader_secure_getenv(VK_ADDITIONAL_IMPLICIT_LAYER_PATH_ENV_VAR, inst);
  ------------------
  |  |  131|  4.90k|#define VK_ADDITIONAL_IMPLICIT_LAYER_PATH_ENV_VAR "VK_ADD_IMPLICIT_LAYER_PATH"
  ------------------
 3638|  4.90k|#if COMMON_UNIX_PLATFORMS
 3639|  4.90k|            relative_location = VK_ILAYERS_INFO_RELATIVE_DIR;
  ------------------
  |  |  168|  4.90k|#define VK_ILAYERS_INFO_RELATIVE_DIR VULKAN_DIR VULKAN_ILAYERCONF_DIR
  |  |  ------------------
  |  |  |  |  157|  4.90k|#define VULKAN_DIR "vulkan/"
  |  |  ------------------
  |  |               #define VK_ILAYERS_INFO_RELATIVE_DIR VULKAN_DIR VULKAN_ILAYERCONF_DIR
  |  |  ------------------
  |  |  |  |  162|  4.90k|#define VULKAN_ILAYERCONF_DIR "implicit_layer.d"
  |  |  ------------------
  ------------------
 3640|  4.90k|#endif
 3641|       |#if defined(_WIN32)
 3642|       |            package_path = windows_get_app_package_manifest_path(inst);
 3643|       |#endif
 3644|  4.90k|            break;
 3645|  4.90k|        case LOADER_DATA_FILE_MANIFEST_EXPLICIT_LAYER:
  ------------------
  |  Branch (3645:9): [True: 4.90k, False: 4.90k]
  ------------------
 3646|  4.90k|            override_env = loader_secure_getenv(VK_EXPLICIT_LAYER_PATH_ENV_VAR, inst);
  ------------------
  |  |  114|  4.90k|#define VK_EXPLICIT_LAYER_PATH_ENV_VAR "VK_LAYER_PATH"
  ------------------
 3647|  4.90k|            additional_env = loader_secure_getenv(VK_ADDITIONAL_EXPLICIT_LAYER_PATH_ENV_VAR, inst);
  ------------------
  |  |  117|  4.90k|#define VK_ADDITIONAL_EXPLICIT_LAYER_PATH_ENV_VAR "VK_ADD_LAYER_PATH"
  ------------------
 3648|  4.90k|#if COMMON_UNIX_PLATFORMS
 3649|  4.90k|            relative_location = VK_ELAYERS_INFO_RELATIVE_DIR;
  ------------------
  |  |  167|  4.90k|#define VK_ELAYERS_INFO_RELATIVE_DIR VULKAN_DIR VULKAN_ELAYERCONF_DIR
  |  |  ------------------
  |  |  |  |  157|  4.90k|#define VULKAN_DIR "vulkan/"
  |  |  ------------------
  |  |               #define VK_ELAYERS_INFO_RELATIVE_DIR VULKAN_DIR VULKAN_ELAYERCONF_DIR
  |  |  ------------------
  |  |  |  |  161|  4.90k|#define VULKAN_ELAYERCONF_DIR "explicit_layer.d"
  |  |  ------------------
  ------------------
 3650|  4.90k|#endif
 3651|  4.90k|            break;
 3652|      0|        default:
  ------------------
  |  Branch (3652:9): [True: 0, False: 9.81k]
  ------------------
 3653|      0|            assert(false && "Shouldn't get here!");
 3654|      0|            break;
 3655|  9.81k|    }
 3656|       |
 3657|       |    // Log a message when VK_LAYER_PATH is set but the override layer paths take priority
 3658|  9.81k|    if (manifest_type == LOADER_DATA_FILE_MANIFEST_EXPLICIT_LAYER &&
  ------------------
  |  Branch (3658:9): [True: 4.90k, False: 4.90k]
  ------------------
 3659|  4.90k|        (NULL != override_env && NULL != path_overrides && path_overrides->count > 0)) {
  ------------------
  |  Branch (3659:10): [True: 0, False: 4.90k]
  |  Branch (3659:34): [True: 0, False: 0]
  |  Branch (3659:60): [True: 0, False: 0]
  ------------------
 3660|      0|        loader_log(inst, VULKAN_LOADER_INFO_BIT | VULKAN_LOADER_LAYER_BIT, 0,
 3661|      0|                   "Ignoring VK_LAYER_PATH. The Override layer is active and has override paths set, which takes priority. "
 3662|      0|                   "VK_LAYER_PATH is set to %s",
 3663|      0|                   override_env);
 3664|      0|    }
 3665|       |
 3666|       |    // Add the remaining paths to the list
 3667|  9.81k|    if (NULL != path_overrides && path_overrides->count > 0) {
  ------------------
  |  Branch (3667:9): [True: 4.90k, False: 4.90k]
  |  Branch (3667:35): [True: 256, False: 4.64k]
  ------------------
 3668|  3.88k|        for (size_t i = 0; i < path_overrides->count; i++) {
  ------------------
  |  Branch (3668:28): [True: 3.62k, False: 256]
  ------------------
 3669|  3.62k|            if (NULL != path_overrides->list[i]) {
  ------------------
  |  Branch (3669:17): [True: 3.62k, False: 0]
  ------------------
 3670|  3.62k|                if (manifest_type == LOADER_DATA_FILE_MANIFEST_EXPLICIT_LAYER) {
  ------------------
  |  Branch (3670:21): [True: 3.62k, False: 0]
  ------------------
 3671|  3.62k|                    loader_log(inst, VULKAN_LOADER_INFO_BIT | VULKAN_LOADER_LAYER_BIT, 0, "%s", path_overrides->list[i]);
 3672|  3.62k|                }
 3673|  3.62k|                vk_result = copy_data_file_info(inst, path_overrides->list[i], NULL, 0, &search_paths);
 3674|  3.62k|                if (vk_result == VK_ERROR_OUT_OF_HOST_MEMORY) {
  ------------------
  |  Branch (3674:21): [True: 0, False: 3.62k]
  ------------------
 3675|      0|                    goto out;
 3676|      0|                }
 3677|  3.62k|            }
 3678|  3.62k|        }
 3679|  9.55k|    } else if (override_env != NULL) {
  ------------------
  |  Branch (3679:16): [True: 0, False: 9.55k]
  ------------------
 3680|      0|        vk_result = copy_data_file_info(inst, override_env, NULL, 0, &search_paths);
 3681|      0|        if (vk_result == VK_ERROR_OUT_OF_HOST_MEMORY) {
  ------------------
  |  Branch (3681:13): [True: 0, False: 0]
  ------------------
 3682|      0|            goto out;
 3683|      0|        }
 3684|  9.55k|    } else {
 3685|       |        // Add any additional search paths defined in the additive environment variable
 3686|  9.55k|        if (NULL != additional_env) {
  ------------------
  |  Branch (3686:13): [True: 0, False: 9.55k]
  ------------------
 3687|      0|            vk_result = copy_data_file_info(inst, additional_env, NULL, 0, &search_paths);
 3688|      0|            if (vk_result == VK_ERROR_OUT_OF_HOST_MEMORY) {
  ------------------
  |  Branch (3688:17): [True: 0, False: 0]
  ------------------
 3689|      0|                goto out;
 3690|      0|            }
 3691|      0|        }
 3692|       |
 3693|       |#if defined(_WIN32)
 3694|       |        if (NULL != package_path) {
 3695|       |            vk_result = copy_data_file_info(inst, package_path, NULL, 0, &search_paths);
 3696|       |            if (vk_result == VK_ERROR_OUT_OF_HOST_MEMORY) {
 3697|       |                goto out;
 3698|       |            }
 3699|       |        }
 3700|       |#elif COMMON_UNIX_PLATFORMS
 3701|  9.55k|        bool search_outside_of_bundle = true;
 3702|       |
 3703|  9.55k|        rel_size = strlen(relative_location);
 3704|  9.55k|        if (rel_size > 0) {
  ------------------
  |  Branch (3704:13): [True: 9.55k, False: 0]
  ------------------
 3705|       |#if defined(__APPLE__)
 3706|       |            // Add the bundle's Resources dir to the beginning of the search path.
 3707|       |            // Looks for manifests in the bundle first, before any system directories.
 3708|       |            // This also appears to work unmodified for iOS, it finds the app bundle on the devices
 3709|       |            // file system. (RSW)
 3710|       |            CFBundleRef main_bundle = CFBundleGetMainBundle();
 3711|       |            if (NULL != main_bundle) {
 3712|       |                CFURLRef ref = CFBundleCopyResourcesDirectoryURL(main_bundle);
 3713|       |                if (NULL != ref) {
 3714|       |                    // Allocate large scratch buffer to hold the bundles path, the relative location inside the bundle, plus a path
 3715|       |                    // separator and null terminator. Since we are using a while loop, initialize length with half the intended size
 3716|       |                    size_t bundle_path_len = (MAXPATHLEN + rel_size + 2) / 2;
 3717|       |                    bool bundle_query_success = false;
 3718|       |                    uint32_t retry_count = 0;
 3719|       |                    while (!bundle_query_success && retry_count < 4) {
 3720|       |                        void *new_bundle_path = loader_instance_heap_realloc(
 3721|       |                            inst, bundle_path, bundle_path_len, bundle_path_len * 2, VK_SYSTEM_ALLOCATION_SCOPE_COMMAND);
 3722|       |                        if (NULL == new_bundle_path) {
 3723|       |                            loader_log(inst, VULKAN_LOADER_ERROR_BIT, 0,
 3724|       |                                       "read_data_files_in_search_paths: Failed to allocate space for bundle path of length %d",
 3725|       |                                       (uint32_t)bundle_path_len * 2);
 3726|       |                            vk_result = VK_ERROR_OUT_OF_HOST_MEMORY;
 3727|       |                            goto out;
 3728|       |                        }
 3729|       |                        bundle_path = new_bundle_path;
 3730|       |                        bundle_path_len = bundle_path_len * 2;
 3731|       |                        memset(bundle_path, 0, bundle_path_len);
 3732|       |                        bundle_query_success = CFURLGetFileSystemRepresentation(ref, TRUE, (UInt8 *)bundle_path, bundle_path_len);
 3733|       |                        retry_count++;
 3734|       |                    }
 3735|       |
 3736|       |                    if (bundle_query_success) {
 3737|       |                        size_t cur_bundle_len = strlen(bundle_path);
 3738|       |
 3739|       |                        if (cur_bundle_len + rel_size + 2 > bundle_path_len) {
 3740|       |                            loader_log(inst, VULKAN_LOADER_ERROR_BIT, 0,
 3741|       |                                       "read_data_files_in_search_paths: bundle_path %s of size %d does not have enough space to "
 3742|       |                                       "append relative_path",
 3743|       |                                       bundle_path, (uint32_t)bundle_path_len);
 3744|       |                            vk_result = VK_ERROR_INITIALIZATION_FAILED;
 3745|       |                            goto out;
 3746|       |                        }
 3747|       |                        bundle_path[cur_bundle_len] = DIRECTORY_SYMBOL;
 3748|       |                        cur_bundle_len++;
 3749|       |                        memcpy(bundle_path + cur_bundle_len, relative_location, rel_size);
 3750|       |                        cur_bundle_len += rel_size;
 3751|       |                        bundle_path[cur_bundle_len] = '\0';
 3752|       |
 3753|       |                        vk_result = copy_data_file_info(inst, bundle_path, NULL, 0, &search_paths);
 3754|       |                        if (vk_result == VK_ERROR_OUT_OF_HOST_MEMORY) {
 3755|       |                            goto out;
 3756|       |                        }
 3757|       |                    }
 3758|       |                    CFRelease(ref);
 3759|       |                }
 3760|       |            }
 3761|       |
 3762|       |            if (NULL != search_only_in_bundle_env_var) {
 3763|       |                search_outside_of_bundle = false;
 3764|       |            }
 3765|       |#endif  // __APPLE__
 3766|  9.55k|            if (search_outside_of_bundle) {
  ------------------
  |  Branch (3766:17): [True: 9.55k, False: 0]
  ------------------
 3767|       |                // Only add the home folders if not NULL
 3768|  9.55k|                if (NULL != home_config_dir) {
  ------------------
  |  Branch (3768:21): [True: 9.55k, False: 0]
  ------------------
 3769|  9.55k|                    vk_result = copy_data_file_info(inst, home_config_dir, relative_location, rel_size, &search_paths);
 3770|  9.55k|                    if (VK_SUCCESS != vk_result) {
  ------------------
  |  Branch (3770:25): [True: 0, False: 9.55k]
  ------------------
 3771|      0|                        goto out;
 3772|      0|                    }
 3773|  9.55k|                }
 3774|  9.55k|                vk_result = copy_data_file_info(inst, xdg_config_dirs, relative_location, rel_size, &search_paths);
 3775|  9.55k|                if (VK_SUCCESS != vk_result) {
  ------------------
  |  Branch (3775:21): [True: 0, False: 9.55k]
  ------------------
 3776|      0|                    goto out;
 3777|      0|                }
 3778|  9.55k|                vk_result = copy_data_file_info(inst, SYSCONFDIR, relative_location, rel_size, &search_paths);
 3779|  9.55k|                if (VK_SUCCESS != vk_result) {
  ------------------
  |  Branch (3779:21): [True: 0, False: 9.55k]
  ------------------
 3780|      0|                    goto out;
 3781|      0|                }
 3782|  9.55k|#if defined(EXTRASYSCONFDIR)
 3783|  9.55k|                vk_result = copy_data_file_info(inst, EXTRASYSCONFDIR, relative_location, rel_size, &search_paths);
 3784|  9.55k|                if (VK_SUCCESS != vk_result) {
  ------------------
  |  Branch (3784:21): [True: 0, False: 9.55k]
  ------------------
 3785|      0|                    goto out;
 3786|      0|                }
 3787|  9.55k|#endif
 3788|       |
 3789|       |                // Only add the home folders if not NULL
 3790|  9.55k|                if (NULL != home_data_dir) {
  ------------------
  |  Branch (3790:21): [True: 9.55k, False: 0]
  ------------------
 3791|  9.55k|                    vk_result = copy_data_file_info(inst, home_data_dir, relative_location, rel_size, &search_paths);
 3792|  9.55k|                    if (VK_SUCCESS != vk_result) {
  ------------------
  |  Branch (3792:25): [True: 0, False: 9.55k]
  ------------------
 3793|      0|                        goto out;
 3794|      0|                    }
 3795|  9.55k|                }
 3796|  9.55k|                vk_result = copy_data_file_info(inst, xdg_data_dirs, relative_location, rel_size, &search_paths);
 3797|  9.55k|                if (VK_SUCCESS != vk_result) {
  ------------------
  |  Branch (3797:21): [True: 0, False: 9.55k]
  ------------------
 3798|      0|                    goto out;
 3799|      0|                }
 3800|  9.55k|            }
 3801|  9.55k|        }
 3802|       |#else
 3803|       |#warning read_data_files_in_search_paths unsupported platform
 3804|       |#endif
 3805|  9.55k|    }
 3806|       |
 3807|       |    // Print out the paths being searched if debugging is enabled
 3808|  9.81k|    uint32_t log_flags = 0;
 3809|       |
 3810|  9.81k|    if (manifest_type == LOADER_DATA_FILE_MANIFEST_DRIVER) {
  ------------------
  |  Branch (3810:9): [True: 2, False: 9.81k]
  ------------------
 3811|      2|        log_flags = VULKAN_LOADER_DRIVER_BIT;
 3812|      2|        loader_log(inst, VULKAN_LOADER_DRIVER_BIT, 0, "Searching for driver manifest files");
 3813|  9.81k|    } else {
 3814|  9.81k|        log_flags = VULKAN_LOADER_LAYER_BIT;
 3815|  9.81k|        loader_log(inst, VULKAN_LOADER_LAYER_BIT, 0, "Searching for %s layer manifest files",
 3816|  9.81k|                   manifest_type == LOADER_DATA_FILE_MANIFEST_EXPLICIT_LAYER ? "explicit" : "implicit");
  ------------------
  |  Branch (3816:20): [True: 4.90k, False: 4.90k]
  ------------------
 3817|  9.81k|    }
 3818|  9.81k|    loader_log(inst, log_flags, 0, "   In following locations:");
 3819|       |
 3820|  80.3k|    for (size_t i = 0; i < search_paths.count; i++) {
  ------------------
  |  Branch (3820:24): [True: 70.5k, False: 9.81k]
  ------------------
 3821|  70.5k|        loader_log(inst, log_flags, 0, "      %s", search_paths.list[i]);
 3822|  70.5k|    }
 3823|       |
 3824|       |    // Now, parse the paths and add any manifest files found in them.
 3825|  9.81k|    vk_result = add_data_files(inst, &search_paths, out_files);
 3826|       |
 3827|  9.81k|    if (log_flags != 0 && out_files->count > 0) {
  ------------------
  |  Branch (3827:9): [True: 9.81k, False: 0]
  |  Branch (3827:27): [True: 4.24k, False: 5.57k]
  ------------------
 3828|  4.24k|        loader_log(inst, log_flags, 0, "   Found the following files:");
 3829|  12.0k|        for (uint32_t cur_file = 0; cur_file < out_files->count; ++cur_file) {
  ------------------
  |  Branch (3829:37): [True: 7.80k, False: 4.24k]
  ------------------
 3830|  7.80k|            loader_log(inst, log_flags, 0, "      %s", out_files->list[cur_file]);
 3831|  7.80k|        }
 3832|  5.57k|    } else {
 3833|  5.57k|        loader_log(inst, log_flags, 0, "   Found no files");
 3834|  5.57k|    }
 3835|       |
 3836|  9.81k|    if ((NULL != path_overrides && path_overrides->count > 0) || NULL != override_env) {
  ------------------
  |  Branch (3836:10): [True: 4.90k, False: 4.90k]
  |  Branch (3836:36): [True: 256, False: 4.64k]
  |  Branch (3836:66): [True: 0, False: 9.55k]
  ------------------
 3837|    256|        *override_active = true;
 3838|  9.55k|    } else {
 3839|  9.55k|        *override_active = false;
 3840|  9.55k|    }
 3841|       |
 3842|  9.81k|out:
 3843|       |
 3844|  9.81k|    loader_free_getenv(additional_env, inst);
 3845|  9.81k|    loader_free_getenv(override_env, inst);
 3846|       |#if defined(_WIN32)
 3847|       |    loader_instance_heap_free(inst, package_path);
 3848|       |#elif COMMON_UNIX_PLATFORMS
 3849|       |#if defined(__APPLE__)
 3850|       |    loader_instance_heap_free(inst, bundle_path);
 3851|       |    loader_free_getenv(search_only_in_bundle_env_var, inst);
 3852|       |#endif
 3853|  9.81k|    loader_free_getenv(xdg_config_home, inst);
 3854|  9.81k|    loader_free_getenv(xdg_config_dirs, inst);
 3855|  9.81k|    loader_free_getenv(xdg_data_home, inst);
 3856|  9.81k|    loader_free_getenv(xdg_data_dirs, inst);
 3857|  9.81k|    loader_free_getenv(xdg_data_home, inst);
 3858|  9.81k|    loader_free_getenv(home, inst);
 3859|  9.81k|    loader_instance_heap_free(inst, default_data_home);
 3860|  9.81k|    loader_instance_heap_free(inst, default_config_home);
 3861|       |#else
 3862|       |#warning read_data_files_in_search_paths unsupported platform
 3863|       |#endif
 3864|       |
 3865|  9.81k|    free_string_list(inst, &search_paths);
 3866|       |
 3867|  9.81k|    return vk_result;
 3868|  9.81k|}
loader_get_data_files:
 3894|  9.81k|                               const struct loader_string_list *path_overrides, struct loader_string_list *out_files) {
 3895|  9.81k|    VkResult res = VK_SUCCESS;
 3896|  9.81k|    bool override_active = false;
 3897|       |
 3898|       |    // Free and init the out_files information so there's no false data left from uninitialized variables.
 3899|  9.81k|    free_string_list(inst, out_files);
 3900|       |
 3901|  9.81k|    res = read_data_files_in_search_paths(inst, manifest_type, path_overrides, &override_active, out_files);
 3902|  9.81k|    if (VK_SUCCESS != res) {
  ------------------
  |  Branch (3902:9): [True: 0, False: 9.81k]
  ------------------
 3903|      0|        goto out;
 3904|      0|    }
 3905|       |
 3906|       |#if defined(_WIN32)
 3907|       |    // Read the registry if the override wasn't active.
 3908|       |    if (!override_active) {
 3909|       |        bool warn_if_not_present = false;
 3910|       |        char *registry_location = NULL;
 3911|       |
 3912|       |        switch (manifest_type) {
 3913|       |            default:
 3914|       |                goto out;
 3915|       |            case LOADER_DATA_FILE_MANIFEST_DRIVER:
 3916|       |                warn_if_not_present = true;
 3917|       |                registry_location = VK_DRIVERS_INFO_REGISTRY_LOC;
 3918|       |                break;
 3919|       |            case LOADER_DATA_FILE_MANIFEST_IMPLICIT_LAYER:
 3920|       |                registry_location = VK_ILAYERS_INFO_REGISTRY_LOC;
 3921|       |                break;
 3922|       |            case LOADER_DATA_FILE_MANIFEST_EXPLICIT_LAYER:
 3923|       |                warn_if_not_present = true;
 3924|       |                registry_location = VK_ELAYERS_INFO_REGISTRY_LOC;
 3925|       |                break;
 3926|       |        }
 3927|       |        VkResult tmp_res =
 3928|       |            windows_read_data_files_in_registry(inst, manifest_type, warn_if_not_present, registry_location, out_files);
 3929|       |        // Only return an error if there was an error this time, and no manifest files from before.
 3930|       |        if (VK_SUCCESS != tmp_res && out_files->count == 0) {
 3931|       |            res = tmp_res;
 3932|       |            goto out;
 3933|       |        }
 3934|       |    }
 3935|       |#endif
 3936|       |
 3937|  9.81k|out:
 3938|       |
 3939|  9.81k|    if (VK_SUCCESS != res) {
  ------------------
  |  Branch (3939:9): [True: 0, False: 9.81k]
  ------------------
 3940|      0|        free_string_list(inst, out_files);
 3941|      0|    }
 3942|       |
 3943|  9.81k|    return res;
 3944|  9.81k|}
loader_icd_scan:
 4111|      2|                         const VkInstanceCreateInfo *pCreateInfo, bool *skipped_portability_drivers) {
 4112|      2|    VkResult res = VK_SUCCESS;
 4113|      2|    struct loader_string_list manifest_files = {0};
 4114|      2|    struct loader_envvar_filter select_filter = {0};
 4115|      2|    struct loader_envvar_filter disable_filter = {0};
 4116|      2|    struct ICDManifestInfo *icd_details = NULL;
 4117|       |
 4118|       |    // Set up the ICD Trampoline list so elements can be written into it.
 4119|      2|    res = loader_init_scanned_icd_list(inst, icd_tramp_list);
 4120|      2|    if (res == VK_ERROR_OUT_OF_HOST_MEMORY) {
  ------------------
  |  Branch (4120:9): [True: 0, False: 2]
  ------------------
 4121|      0|        return res;
 4122|      0|    }
 4123|       |
 4124|      2|    bool direct_driver_loading_exclusive_mode = false;
 4125|      2|    res = loader_scan_for_direct_drivers(inst, pCreateInfo, icd_tramp_list, &direct_driver_loading_exclusive_mode);
 4126|      2|    if (res == VK_ERROR_OUT_OF_HOST_MEMORY) {
  ------------------
  |  Branch (4126:9): [True: 0, False: 2]
  ------------------
 4127|      0|        goto out;
 4128|      0|    }
 4129|      2|    if (direct_driver_loading_exclusive_mode) {
  ------------------
  |  Branch (4129:9): [True: 0, False: 2]
  ------------------
 4130|       |        // Make sure to jump over the system & env-var driver discovery mechanisms if exclusive mode is set, even if no drivers
 4131|       |        // were successfully found through the direct driver loading mechanism
 4132|      0|        goto out;
 4133|      0|    }
 4134|       |
 4135|      2|    if (loader_settings_should_use_driver_environment_variables(inst)) {
  ------------------
  |  Branch (4135:9): [True: 2, False: 0]
  ------------------
 4136|       |        // Parse the filter environment variables to determine if we have any special behavior
 4137|      2|        res = parse_generic_filter_environment_var(inst, VK_DRIVERS_SELECT_ENV_VAR, &select_filter);
  ------------------
  |  |  122|      2|#define VK_DRIVERS_SELECT_ENV_VAR "VK_LOADER_DRIVERS_SELECT"
  ------------------
 4138|      2|        if (VK_SUCCESS != res) {
  ------------------
  |  Branch (4138:13): [True: 0, False: 2]
  ------------------
 4139|      0|            goto out;
 4140|      0|        }
 4141|      2|        res = parse_generic_filter_environment_var(inst, VK_DRIVERS_DISABLE_ENV_VAR, &disable_filter);
  ------------------
  |  |  123|      2|#define VK_DRIVERS_DISABLE_ENV_VAR "VK_LOADER_DRIVERS_DISABLE"
  ------------------
 4142|      2|        if (VK_SUCCESS != res) {
  ------------------
  |  Branch (4142:13): [True: 0, False: 2]
  ------------------
 4143|      0|            goto out;
 4144|      0|        }
 4145|      2|    }
 4146|       |
 4147|       |    // Get a list of manifest files for ICDs
 4148|      2|    res = loader_get_data_files(inst, LOADER_DATA_FILE_MANIFEST_DRIVER, NULL, &manifest_files);
 4149|      2|    if (VK_SUCCESS != res) {
  ------------------
  |  Branch (4149:9): [True: 0, False: 2]
  ------------------
 4150|      0|        goto out;
 4151|      0|    }
 4152|       |
 4153|       |    // Add any drivers provided by the loader settings file
 4154|      2|    res = loader_settings_get_additional_driver_files(inst, &manifest_files);
 4155|      2|    if (VK_SUCCESS != res) {
  ------------------
  |  Branch (4155:9): [True: 0, False: 2]
  ------------------
 4156|      0|        goto out;
 4157|      0|    }
 4158|       |
 4159|      2|    icd_details = loader_stack_alloc(sizeof(struct ICDManifestInfo) * manifest_files.count);
  ------------------
  |  |   42|      2|#define loader_stack_alloc(size) alloca(size)
  ------------------
 4160|      2|    if (NULL == icd_details) {
  ------------------
  |  Branch (4160:9): [True: 0, False: 2]
  ------------------
 4161|      0|        res = VK_ERROR_OUT_OF_HOST_MEMORY;
 4162|      0|        goto out;
 4163|      0|    }
 4164|      2|    memset(icd_details, 0, sizeof(struct ICDManifestInfo) * manifest_files.count);
 4165|       |
 4166|      2|    for (uint32_t i = 0; i < manifest_files.count; i++) {
  ------------------
  |  Branch (4166:26): [True: 0, False: 2]
  ------------------
 4167|      0|        VkResult icd_res = VK_SUCCESS;
 4168|       |
 4169|      0|        icd_res = loader_parse_icd_manifest(inst, manifest_files.list[i], &icd_details[i], skipped_portability_drivers);
 4170|      0|        if (VK_ERROR_OUT_OF_HOST_MEMORY == icd_res) {
  ------------------
  |  Branch (4170:13): [True: 0, False: 0]
  ------------------
 4171|      0|            res = icd_res;
 4172|      0|            goto out;
 4173|      0|        } else if (VK_ERROR_INCOMPATIBLE_DRIVER == icd_res) {
  ------------------
  |  Branch (4173:20): [True: 0, False: 0]
  ------------------
 4174|      0|            continue;
 4175|      0|        }
 4176|       |
 4177|      0|        if (select_filter.count > 0 || disable_filter.count > 0) {
  ------------------
  |  Branch (4177:13): [True: 0, False: 0]
  |  Branch (4177:40): [True: 0, False: 0]
  ------------------
 4178|       |            // Get only the filename for comparing to the filters
 4179|      0|            char *just_filename_str = strrchr(manifest_files.list[i], DIRECTORY_SYMBOL);
  ------------------
  |  |  155|      0|#define DIRECTORY_SYMBOL '/'
  ------------------
 4180|       |
 4181|       |            // No directory symbol, just the filename
 4182|      0|            if (NULL == just_filename_str) {
  ------------------
  |  Branch (4182:17): [True: 0, False: 0]
  ------------------
 4183|      0|                just_filename_str = manifest_files.list[i];
 4184|      0|            } else {
 4185|      0|                just_filename_str++;
 4186|      0|            }
 4187|       |
 4188|      0|            bool name_matches_select =
 4189|      0|                (select_filter.count > 0 && check_name_matches_filter_environment_var(just_filename_str, &select_filter));
  ------------------
  |  Branch (4189:18): [True: 0, False: 0]
  |  Branch (4189:45): [True: 0, False: 0]
  ------------------
 4190|      0|            bool name_matches_disable =
 4191|      0|                (disable_filter.count > 0 && check_name_matches_filter_environment_var(just_filename_str, &disable_filter));
  ------------------
  |  Branch (4191:18): [True: 0, False: 0]
  |  Branch (4191:46): [True: 0, False: 0]
  ------------------
 4192|       |
 4193|      0|            if (name_matches_disable && !name_matches_select) {
  ------------------
  |  Branch (4193:17): [True: 0, False: 0]
  |  Branch (4193:41): [True: 0, False: 0]
  ------------------
 4194|      0|                loader_log(inst, VULKAN_LOADER_WARN_BIT | VULKAN_LOADER_DRIVER_BIT, 0,
 4195|      0|                           "Driver \"%s\" ignored because it was disabled by env var \'%s\'", just_filename_str,
 4196|      0|                           VK_DRIVERS_DISABLE_ENV_VAR);
  ------------------
  |  |  123|      0|#define VK_DRIVERS_DISABLE_ENV_VAR "VK_LOADER_DRIVERS_DISABLE"
  ------------------
 4197|      0|                continue;
 4198|      0|            }
 4199|      0|            if (select_filter.count != 0 && !name_matches_select) {
  ------------------
  |  Branch (4199:17): [True: 0, False: 0]
  |  Branch (4199:45): [True: 0, False: 0]
  ------------------
 4200|      0|                loader_log(inst, VULKAN_LOADER_WARN_BIT | VULKAN_LOADER_DRIVER_BIT, 0,
 4201|      0|                           "Driver \"%s\" ignored because not selected by env var \'%s\'", just_filename_str,
 4202|      0|                           VK_DRIVERS_SELECT_ENV_VAR);
  ------------------
  |  |  122|      0|#define VK_DRIVERS_SELECT_ENV_VAR "VK_LOADER_DRIVERS_SELECT"
  ------------------
 4203|      0|                continue;
 4204|      0|            }
 4205|      0|        }
 4206|       |
 4207|      0|        enum loader_layer_library_status lib_status;
 4208|      0|        icd_res =
 4209|      0|            loader_scanned_icd_add(inst, icd_tramp_list, icd_details[i].full_library_path, icd_details[i].version, &lib_status);
 4210|      0|        if (VK_ERROR_OUT_OF_HOST_MEMORY == icd_res) {
  ------------------
  |  Branch (4210:13): [True: 0, False: 0]
  ------------------
 4211|      0|            res = icd_res;
 4212|      0|            goto out;
 4213|      0|        } else if (VK_ERROR_INCOMPATIBLE_DRIVER == icd_res) {
  ------------------
  |  Branch (4213:20): [True: 0, False: 0]
  ------------------
 4214|      0|            switch (lib_status) {
  ------------------
  |  Branch (4214:21): [True: 0, False: 0]
  ------------------
 4215|      0|                case LOADER_LAYER_LIB_NOT_LOADED:
  ------------------
  |  Branch (4215:17): [True: 0, False: 0]
  ------------------
 4216|      0|                case LOADER_LAYER_LIB_ERROR_FAILED_TO_LOAD:
  ------------------
  |  Branch (4216:17): [True: 0, False: 0]
  ------------------
 4217|      0|                case LOADER_LAYER_LIB_ERROR_NEGOTIATE_INTERFACE_VERSION_FAILED:
  ------------------
  |  Branch (4217:17): [True: 0, False: 0]
  ------------------
 4218|      0|                case LOADER_LAYER_LIB_ERROR_UNABLE_TO_FIND_VK_GET_INSTANCE_PROC_ADDR:
  ------------------
  |  Branch (4218:17): [True: 0, False: 0]
  ------------------
 4219|      0|                    loader_log(inst, VULKAN_LOADER_ERROR_BIT | VULKAN_LOADER_DRIVER_BIT, 0,
 4220|      0|                               "loader_icd_scan: Failed loading library associated with ICD JSON %s. Ignoring this JSON",
 4221|      0|                               icd_details[i].full_library_path);
 4222|      0|                    break;
 4223|      0|                case LOADER_LAYER_LIB_ERROR_WRONG_BIT_TYPE:
  ------------------
  |  Branch (4223:17): [True: 0, False: 0]
  ------------------
 4224|      0|                    loader_log(inst, VULKAN_LOADER_DRIVER_BIT, 0, "Requested ICD %s was wrong bit-type. Ignoring this JSON",
 4225|      0|                               icd_details[i].full_library_path);
 4226|      0|                    break;
 4227|      0|                case LOADER_LAYER_LIB_SUCCESS_LOADED:
  ------------------
  |  Branch (4227:17): [True: 0, False: 0]
  ------------------
 4228|      0|                case LOADER_LAYER_LIB_ERROR_OUT_OF_MEMORY:
  ------------------
  |  Branch (4228:17): [True: 0, False: 0]
  ------------------
 4229|       |                    // Shouldn't be able to reach this but if it is, best to report a debug
 4230|      0|                    loader_log(inst, VULKAN_LOADER_WARN_BIT | VULKAN_LOADER_DRIVER_BIT, 0,
 4231|      0|                               "Shouldn't reach this. A valid version of requested ICD %s was loaded but something bad "
 4232|      0|                               "happened afterwards.",
 4233|      0|                               icd_details[i].full_library_path);
 4234|      0|                    break;
 4235|      0|            }
 4236|      0|        }
 4237|      0|    }
 4238|       |
 4239|      2|out:
 4240|      2|    if (NULL != icd_details) {
  ------------------
  |  Branch (4240:9): [True: 2, False: 0]
  ------------------
 4241|       |        // Successfully got the icd_details structure, which means we need to free the paths contained within
 4242|      2|        for (uint32_t i = 0; i < manifest_files.count; i++) {
  ------------------
  |  Branch (4242:30): [True: 0, False: 2]
  ------------------
 4243|      0|            loader_instance_heap_free(inst, icd_details[i].full_library_path);
 4244|      0|        }
 4245|      2|    }
 4246|      2|    free_string_list(inst, &manifest_files);
 4247|      2|    return res;
 4248|      2|}
loader_parse_instance_layers:
 4254|  9.81k|                                      const struct loader_string_list *path_overrides, struct loader_layer_list *instance_layers) {
 4255|  9.81k|    assert(manifest_type == LOADER_DATA_FILE_MANIFEST_IMPLICIT_LAYER || manifest_type == LOADER_DATA_FILE_MANIFEST_EXPLICIT_LAYER);
 4256|  9.81k|    VkResult res = VK_SUCCESS;
 4257|  9.81k|    struct loader_string_list manifest_files = {0};
 4258|       |
 4259|  9.81k|    res = loader_get_data_files(inst, manifest_type, path_overrides, &manifest_files);
 4260|  9.81k|    if (VK_SUCCESS != res) {
  ------------------
  |  Branch (4260:9): [True: 0, False: 9.81k]
  ------------------
 4261|      0|        goto out;
 4262|      0|    }
 4263|       |
 4264|  17.6k|    for (uint32_t i = 0; i < manifest_files.count; i++) {
  ------------------
  |  Branch (4264:26): [True: 7.80k, False: 9.81k]
  ------------------
 4265|  7.80k|        char *file_str = manifest_files.list[i];
 4266|  7.80k|        if (file_str == NULL) {
  ------------------
  |  Branch (4266:13): [True: 0, False: 7.80k]
  ------------------
 4267|      0|            continue;
 4268|      0|        }
 4269|       |
 4270|       |        // Parse file into JSON struct
 4271|  7.80k|        cJSON *json = NULL;
 4272|  7.80k|        VkResult local_res = loader_get_json(inst, file_str, &json);
 4273|  7.80k|        if (VK_ERROR_OUT_OF_HOST_MEMORY == local_res) {
  ------------------
  |  Branch (4273:13): [True: 0, False: 7.80k]
  ------------------
 4274|      0|            res = VK_ERROR_OUT_OF_HOST_MEMORY;
 4275|      0|            goto out;
 4276|  7.80k|        } else if (VK_SUCCESS != local_res || NULL == json) {
  ------------------
  |  Branch (4276:20): [True: 112, False: 7.69k]
  |  Branch (4276:47): [True: 2.71k, False: 4.98k]
  ------------------
 4277|  2.82k|            continue;
 4278|  2.82k|        }
 4279|       |
 4280|  4.98k|        local_res = loader_add_layer_properties(inst, instance_layers, json,
 4281|  4.98k|                                                manifest_type == LOADER_DATA_FILE_MANIFEST_IMPLICIT_LAYER, file_str);
 4282|  4.98k|        loader_cJSON_Delete(json);
 4283|       |
 4284|       |        // If the error is anything other than out of memory we still want to try to load the other layers
 4285|  4.98k|        if (VK_ERROR_OUT_OF_HOST_MEMORY == local_res) {
  ------------------
  |  Branch (4285:13): [True: 0, False: 4.98k]
  ------------------
 4286|      0|            res = VK_ERROR_OUT_OF_HOST_MEMORY;
 4287|      0|            goto out;
 4288|      0|        }
 4289|  4.98k|    }
 4290|  9.81k|out:
 4291|  9.81k|    free_string_list(inst, &manifest_files);
 4292|       |
 4293|  9.81k|    return res;
 4294|  9.81k|}
get_override_layer_override_paths:
 4299|    257|                                           struct loader_string_list *override_paths) {
 4300|    257|    if (prop->override_paths.count > 0) {
  ------------------
  |  Branch (4300:9): [True: 257, False: 0]
  ------------------
 4301|  3.73k|        for (uint32_t j = 0; j < prop->override_paths.count; j++) {
  ------------------
  |  Branch (4301:30): [True: 3.48k, False: 257]
  ------------------
 4302|  3.48k|            VkResult result = copy_data_file_info(inst, prop->override_paths.list[j], NULL, 0, override_paths);
 4303|  3.48k|            if (VK_SUCCESS != result) {
  ------------------
  |  Branch (4303:17): [True: 0, False: 3.48k]
  ------------------
 4304|      0|                return result;
 4305|      0|            }
 4306|  3.48k|            loader_log(inst, VULKAN_LOADER_WARN_BIT | VULKAN_LOADER_LAYER_BIT, 0, "Override layer has override path %s",
 4307|  3.48k|                       prop->override_paths.list[j]);
 4308|  3.48k|        }
 4309|    257|    }
 4310|    257|    return VK_SUCCESS;
 4311|    257|}
loader_remove_duplicate_layers:
 4313|  4.90k|void loader_remove_duplicate_layers(struct loader_instance *inst, struct loader_layer_list *layers) {
 4314|       |    // Remove duplicate layers (that share the same layerName)
 4315|  17.2k|    for (uint32_t i = 0; i < layers->count; ++i) {
  ------------------
  |  Branch (4315:26): [True: 12.3k, False: 4.90k]
  ------------------
 4316|  12.3k|        bool has_duplicate = false;
 4317|  12.3k|        uint32_t duplicate_index = 0;
 4318|  83.5k|        for (uint32_t j = i + 1; j < layers->count; ++j) {
  ------------------
  |  Branch (4318:34): [True: 81.1k, False: 2.32k]
  ------------------
 4319|  81.1k|            if (strcmp(layers->list[i].info.layerName, layers->list[j].info.layerName) == 0) {
  ------------------
  |  Branch (4319:17): [True: 10.0k, False: 71.1k]
  ------------------
 4320|  10.0k|                has_duplicate = true;
 4321|  10.0k|                duplicate_index = j;
 4322|  10.0k|                break;
 4323|  10.0k|            }
 4324|  81.1k|        }
 4325|  12.3k|        if (has_duplicate) {
  ------------------
  |  Branch (4325:13): [True: 10.0k, False: 2.32k]
  ------------------
 4326|  10.0k|            loader_log(inst, VULKAN_LOADER_WARN_BIT, 0, "Removing layer %s (%s) because it is a duplicate of %s (%s)",
 4327|  10.0k|                       layers->list[duplicate_index].info.layerName, layers->list[duplicate_index].manifest_file_name,
 4328|  10.0k|                       layers->list[i].info.layerName, layers->list[i].manifest_file_name);
 4329|  10.0k|            loader_remove_layer_in_list(inst, layers, duplicate_index);
 4330|  10.0k|        }
 4331|  12.3k|    }
 4332|  4.90k|}
loader_scan_for_layers:
 4335|  6.58k|                                const struct loader_envvar_all_filters *filters) {
 4336|  6.58k|    VkResult res = VK_SUCCESS;
 4337|  6.58k|    struct loader_layer_list settings_layers = {0};
 4338|  6.58k|    struct loader_layer_list regular_instance_layers = {0};
 4339|  6.58k|    bool override_layer_valid = false;
 4340|  6.58k|    struct loader_string_list override_paths = {0};
 4341|       |
 4342|  6.58k|    bool should_search_for_other_layers = true;
 4343|  6.58k|    res = get_settings_layers(inst, &settings_layers, &should_search_for_other_layers);
 4344|  6.58k|    if (VK_SUCCESS != res) {
  ------------------
  |  Branch (4344:9): [True: 0, False: 6.58k]
  ------------------
 4345|      0|        goto out;
 4346|      0|    }
 4347|       |
 4348|       |    // If we should not look for layers using other mechanisms, assign settings_layers to instance_layers and jump to the
 4349|       |    // output
 4350|  6.58k|    if (!should_search_for_other_layers) {
  ------------------
  |  Branch (4350:9): [True: 1.68k, False: 4.90k]
  ------------------
 4351|  1.68k|        *instance_layers = settings_layers;
 4352|  1.68k|        memset(&settings_layers, 0, sizeof(struct loader_layer_list));
 4353|  1.68k|        goto out;
 4354|  1.68k|    }
 4355|       |
 4356|  4.90k|    res = loader_parse_instance_layers(inst, LOADER_DATA_FILE_MANIFEST_IMPLICIT_LAYER, NULL, &regular_instance_layers);
 4357|  4.90k|    if (VK_SUCCESS != res) {
  ------------------
  |  Branch (4357:9): [True: 0, False: 4.90k]
  ------------------
 4358|      0|        goto out;
 4359|      0|    }
 4360|       |
 4361|       |    // Remove any extraneous override layers.
 4362|  4.90k|    remove_all_non_valid_override_layers(inst, &regular_instance_layers);
 4363|       |
 4364|       |    // Check to see if the override layer is present, and use it's override paths.
 4365|  8.80k|    for (uint32_t i = 0; i < regular_instance_layers.count; i++) {
  ------------------
  |  Branch (4365:26): [True: 4.15k, False: 4.64k]
  ------------------
 4366|  4.15k|        struct loader_layer_properties *prop = &regular_instance_layers.list[i];
 4367|  4.15k|        if (prop->is_override && loader_implicit_layer_is_enabled(inst, filters, prop) && prop->override_paths.count > 0) {
  ------------------
  |  Branch (4367:13): [True: 494, False: 3.66k]
  |  Branch (4367:34): [True: 421, False: 73]
  |  Branch (4367:91): [True: 257, False: 164]
  ------------------
 4368|    257|            res = get_override_layer_override_paths(inst, prop, &override_paths);
 4369|    257|            if (VK_SUCCESS != res) {
  ------------------
  |  Branch (4369:17): [True: 0, False: 257]
  ------------------
 4370|      0|                goto out;
 4371|      0|            }
 4372|    257|            break;
 4373|    257|        }
 4374|  4.15k|    }
 4375|       |
 4376|       |    // Get a list of manifest files for explicit layers
 4377|  4.90k|    res = loader_parse_instance_layers(inst, LOADER_DATA_FILE_MANIFEST_EXPLICIT_LAYER, &override_paths, &regular_instance_layers);
 4378|  4.90k|    if (VK_SUCCESS != res) {
  ------------------
  |  Branch (4378:9): [True: 0, False: 4.90k]
  ------------------
 4379|      0|        goto out;
 4380|      0|    }
 4381|       |
 4382|       |    // Verify any meta-layers in the list are valid and all the component layers are
 4383|       |    // actually present in the available layer list
 4384|  4.90k|    res = verify_all_meta_layers(inst, filters, &regular_instance_layers, &override_layer_valid);
 4385|  4.90k|    if (VK_ERROR_OUT_OF_HOST_MEMORY == res) {
  ------------------
  |  Branch (4385:9): [True: 0, False: 4.90k]
  ------------------
 4386|      0|        goto out;
 4387|      0|    }
 4388|       |
 4389|  4.90k|    if (override_layer_valid) {
  ------------------
  |  Branch (4389:9): [True: 402, False: 4.50k]
  ------------------
 4390|    402|        loader_remove_layers_in_blacklist(inst, &regular_instance_layers);
 4391|    402|        if (NULL != inst) {
  ------------------
  |  Branch (4391:13): [True: 402, False: 0]
  ------------------
 4392|    402|            inst->override_layer_present = true;
 4393|    402|        }
 4394|    402|    }
 4395|       |
 4396|       |    // Remove disabled layers
 4397|  27.2k|    for (uint32_t i = 0; i < regular_instance_layers.count; ++i) {
  ------------------
  |  Branch (4397:26): [True: 22.3k, False: 4.90k]
  ------------------
 4398|  22.3k|        if (!loader_layer_is_available(inst, filters, &regular_instance_layers.list[i])) {
  ------------------
  |  Branch (4398:13): [True: 0, False: 22.3k]
  ------------------
 4399|      0|            loader_remove_layer_in_list(inst, &regular_instance_layers, i);
 4400|      0|            i--;
 4401|      0|        }
 4402|  22.3k|    }
 4403|       |
 4404|       |    // Make sure no layers have the same layerName
 4405|  4.90k|    loader_remove_duplicate_layers(inst, &regular_instance_layers);
 4406|       |
 4407|  4.90k|    res = combine_settings_layers_with_regular_layers(inst, &settings_layers, &regular_instance_layers, instance_layers);
 4408|       |
 4409|  6.58k|out:
 4410|  6.58k|    loader_delete_layer_list_and_properties(inst, &settings_layers);
 4411|  6.58k|    loader_delete_layer_list_and_properties(inst, &regular_instance_layers);
 4412|       |
 4413|  6.58k|    free_string_list(inst, &override_paths);
 4414|  6.58k|    return res;
 4415|  4.90k|}
loader_validate_layers:
 5636|  6.58k|                                const char *const *ppEnabledLayerNames, const struct loader_layer_list *list) {
 5637|  6.58k|    struct loader_layer_properties *prop;
 5638|       |
 5639|  6.58k|    if (layer_count > 0 && ppEnabledLayerNames == NULL) {
  ------------------
  |  Branch (5639:9): [True: 6.58k, False: 0]
  |  Branch (5639:28): [True: 0, False: 6.58k]
  ------------------
 5640|      0|        loader_log(inst, VULKAN_LOADER_ERROR_BIT, 0,
 5641|      0|                   "loader_validate_layers: ppEnabledLayerNames is NULL but enabledLayerCount is greater than zero");
 5642|      0|        return VK_ERROR_LAYER_NOT_PRESENT;
 5643|      0|    }
 5644|       |
 5645|  6.59k|    for (uint32_t i = 0; i < layer_count; i++) {
  ------------------
  |  Branch (5645:26): [True: 6.58k, False: 2]
  ------------------
 5646|  6.58k|        VkStringErrorFlags result = vk_string_validate(MaxLoaderStringLength, ppEnabledLayerNames[i]);
 5647|  6.58k|        if (result != VK_STRING_ERROR_NONE) {
  ------------------
  |  Branch (5647:13): [True: 0, False: 6.58k]
  ------------------
 5648|      0|            loader_log(inst, VULKAN_LOADER_ERROR_BIT, 0,
 5649|      0|                       "loader_validate_layers: ppEnabledLayerNames contains string that is too long or is badly formed");
 5650|      0|            return VK_ERROR_LAYER_NOT_PRESENT;
 5651|      0|        }
 5652|       |
 5653|  6.58k|        prop = loader_find_layer_property(ppEnabledLayerNames[i], list);
 5654|  6.58k|        if (NULL == prop) {
  ------------------
  |  Branch (5654:13): [True: 6.58k, False: 2]
  ------------------
 5655|  6.58k|            loader_log(inst, VULKAN_LOADER_ERROR_BIT, 0,
 5656|  6.58k|                       "loader_validate_layers: Layer %d does not exist in the list of available layers", i);
 5657|  6.58k|            return VK_ERROR_LAYER_NOT_PRESENT;
 5658|  6.58k|        }
 5659|      2|        if (inst->settings.settings_active && inst->settings.layer_configurations_active &&
  ------------------
  |  Branch (5659:13): [True: 1, False: 1]
  |  Branch (5659:47): [True: 1, False: 0]
  ------------------
 5660|      1|            prop->settings_control_value != LOADER_SETTINGS_LAYER_CONTROL_ON &&
  ------------------
  |  Branch (5660:13): [True: 1, False: 0]
  ------------------
 5661|      1|            prop->settings_control_value != LOADER_SETTINGS_LAYER_CONTROL_DEFAULT) {
  ------------------
  |  Branch (5661:13): [True: 0, False: 1]
  ------------------
 5662|      0|            loader_log(inst, VULKAN_LOADER_ERROR_BIT, 0,
 5663|      0|                       "loader_validate_layers: Layer %d was explicitly prevented from being enabled by the loader settings file",
 5664|      0|                       i);
 5665|      0|            return VK_ERROR_LAYER_NOT_PRESENT;
 5666|      0|        }
 5667|      2|    }
 5668|      2|    return VK_SUCCESS;
 5669|  6.58k|}
vk_string_validate:
 7522|  6.58k|TEST_FUNCTION_EXPORT VkStringErrorFlags vk_string_validate(const int max_length, const char *utf8) {
 7523|  6.58k|    VkStringErrorFlags result = VK_STRING_ERROR_NONE;
 7524|  6.58k|    int num_char_bytes = 0;
 7525|  6.58k|    int i;
 7526|  6.58k|    int j;
 7527|       |
 7528|  6.58k|    if (utf8 == NULL) {
  ------------------
  |  Branch (7528:9): [True: 0, False: 6.58k]
  ------------------
 7529|      0|        return VK_STRING_ERROR_NULL_PTR;
 7530|      0|    }
 7531|       |
 7532|   184k|    for (i = 0; i <= max_length; i++) {
  ------------------
  |  Branch (7532:17): [True: 184k, False: 0]
  ------------------
 7533|   184k|        if (utf8[i] == 0) {
  ------------------
  |  Branch (7533:13): [True: 6.58k, False: 177k]
  ------------------
 7534|  6.58k|            break;
 7535|  6.58k|        }
 7536|   177k|        if (i == max_length) {
  ------------------
  |  Branch (7536:13): [True: 0, False: 177k]
  ------------------
 7537|      0|            result |= VK_STRING_ERROR_LENGTH;
 7538|      0|            break;
 7539|      0|        }
 7540|   177k|        if ((utf8[i] >= 0x20) && (utf8[i] < 0x7f)) {
  ------------------
  |  Branch (7540:13): [True: 177k, False: 0]
  |  Branch (7540:34): [True: 177k, False: 0]
  ------------------
 7541|   177k|            num_char_bytes = 0;
 7542|   177k|        } else if ((utf8[i] & UTF8_ONE_BYTE_MASK) == UTF8_ONE_BYTE_CODE) {
  ------------------
  |  Branch (7542:20): [True: 0, False: 0]
  ------------------
 7543|      0|            num_char_bytes = 1;
 7544|      0|        } else if ((utf8[i] & UTF8_TWO_BYTE_MASK) == UTF8_TWO_BYTE_CODE) {
  ------------------
  |  Branch (7544:20): [True: 0, False: 0]
  ------------------
 7545|      0|            num_char_bytes = 2;
 7546|      0|        } else if ((utf8[i] & UTF8_THREE_BYTE_MASK) == UTF8_THREE_BYTE_CODE) {
  ------------------
  |  Branch (7546:20): [True: 0, False: 0]
  ------------------
 7547|      0|            num_char_bytes = 3;
 7548|      0|        } else {
 7549|      0|            result = VK_STRING_ERROR_BAD_DATA;
 7550|      0|        }
 7551|       |
 7552|       |        // Validate the following num_char_bytes of data
 7553|   177k|        for (j = 0; (j < num_char_bytes) && (i < max_length); j++) {
  ------------------
  |  Branch (7553:21): [True: 0, False: 177k]
  |  Branch (7553:45): [True: 0, False: 0]
  ------------------
 7554|      0|            if (++i == max_length) {
  ------------------
  |  Branch (7554:17): [True: 0, False: 0]
  ------------------
 7555|      0|                result |= VK_STRING_ERROR_LENGTH;
 7556|      0|                break;
 7557|      0|            }
 7558|      0|            if (utf8[i] == 0) {
  ------------------
  |  Branch (7558:17): [True: 0, False: 0]
  ------------------
 7559|       |                // The string terminated in the middle of a multi-byte character. Stop here so the
 7560|       |                // continuation-byte scan doesn't read past the terminator.
 7561|      0|                result |= VK_STRING_ERROR_BAD_DATA;
 7562|      0|                return result;
 7563|      0|            }
 7564|      0|            if ((utf8[i] & UTF8_DATA_BYTE_MASK) != UTF8_DATA_BYTE_CODE) {
  ------------------
  |  Branch (7564:17): [True: 0, False: 0]
  ------------------
 7565|      0|                result |= VK_STRING_ERROR_BAD_DATA;
 7566|      0|            }
 7567|      0|        }
 7568|   177k|    }
 7569|  6.58k|    return result;
 7570|  6.58k|}

loader_getenv:
   43|    983|char *loader_getenv(const char *name, const struct loader_instance *inst) {
   44|    983|    if (NULL == name) return NULL;
  ------------------
  |  Branch (44:9): [True: 0, False: 983]
  ------------------
   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|    983|    (void)inst;
   48|       |    // NOLINTNEXTLINE(concurrency-mt-unsafe) - there is no portable reentrant getenv; the loader never calls setenv concurrently
   49|    983|    return getenv(name);
   50|    983|}
loader_secure_getenv:
   52|   121k|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|   121k|    char *out;
   67|   121k|#if defined(HAVE_SECURE_GETENV) && !defined(LOADER_USE_UNSAFE_FILE_SEARCH)
   68|   121k|    (void)inst;
   69|   121k|    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|   121k|    return out;
   80|   121k|#endif
   81|   121k|}
loader_free_getenv:
   83|  92.6k|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|  92.6k|    (void)val;
   87|  92.6k|    (void)inst;
   88|  92.6k|}
determine_filter_type:
  193|  6.58k|                           size_t *new_length) {
  194|  6.58k|    size_t filter_length = strlen(filter_string);
  195|  6.58k|    bool star_begin = false;
  196|  6.58k|    bool star_end = false;
  197|  6.58k|    if ('~' == filter_string[0]) {
  ------------------
  |  Branch (197:9): [True: 0, False: 6.58k]
  ------------------
  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|  6.58k|    } else {
  203|  6.58k|        if ('*' == filter_string[0]) {
  ------------------
  |  Branch (203:13): [True: 0, False: 6.58k]
  ------------------
  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|  6.58k|        if ('*' == filter_string[filter_length - 1]) {
  ------------------
  |  Branch (213:13): [True: 0, False: 6.58k]
  ------------------
  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|  6.58k|        if (star_begin && star_end) {
  ------------------
  |  Branch (223:13): [True: 0, False: 6.58k]
  |  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|  6.58k|        } else if (star_begin) {
  ------------------
  |  Branch (227:20): [True: 0, False: 6.58k]
  ------------------
  228|      0|            *new_start = &filter_string[1];
  229|      0|            *new_length = filter_length - 1;
  230|      0|            *filter_type = FILTER_STRING_SUFFIX;
  231|  6.58k|        } else if (star_end) {
  ------------------
  |  Branch (231:20): [True: 0, False: 6.58k]
  ------------------
  232|      0|            *filter_type = FILTER_STRING_PREFIX;
  233|      0|            *new_start = filter_string;
  234|      0|            *new_length = filter_length - 1;
  235|  6.58k|        } else {
  236|  6.58k|            *filter_type = FILTER_STRING_FULLNAME;
  237|  6.58k|            *new_start = filter_string;
  238|  6.58k|            *new_length = filter_length;
  239|  6.58k|        }
  240|  6.58k|    }
  241|  6.58k|}
parse_generic_filter_environment_var:
  246|  13.1k|                                              struct loader_envvar_filter *filter_struct) {
  247|  13.1k|    VkResult result = VK_SUCCESS;
  248|  13.1k|    memset(filter_struct, 0, sizeof(struct loader_envvar_filter));
  249|  13.1k|    char *parsing_string = NULL;
  250|  13.1k|    char *env_var_value = loader_secure_getenv(env_var_name, inst);
  251|  13.1k|    if (NULL == env_var_value) {
  ------------------
  |  Branch (251:9): [True: 6.59k, False: 6.58k]
  ------------------
  252|  6.59k|        return result;
  253|  6.59k|    }
  254|  6.58k|    const size_t env_var_len = strlen(env_var_value);
  255|  6.58k|    if (env_var_len == 0) {
  ------------------
  |  Branch (255:9): [True: 0, False: 6.58k]
  ------------------
  256|      0|        goto out;
  257|      0|    }
  258|       |    // Allocate a separate string since scan_for_next_comma modifies the original string
  259|  6.58k|    parsing_string = loader_instance_heap_calloc(inst, env_var_len + 1, VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE);
  260|  6.58k|    if (NULL == parsing_string) {
  ------------------
  |  Branch (260:9): [True: 0, False: 6.58k]
  ------------------
  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|  26.3k|    for (uint32_t iii = 0; iii < env_var_len; ++iii) {
  ------------------
  |  Branch (267:28): [True: 19.7k, False: 6.58k]
  ------------------
  268|  19.7k|        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: 19.7k]
  ------------------
  269|  19.7k|    }
  270|  6.58k|    parsing_string[env_var_len] = '\0';
  271|       |
  272|  6.58k|    char *context = NULL;
  273|  6.58k|    char *token = thread_safe_strtok(parsing_string, ",", &context);
  274|  13.1k|    while (NULL != token) {
  ------------------
  |  Branch (274:12): [True: 6.58k, False: 6.58k]
  ------------------
  275|  6.58k|        enum loader_filter_string_type cur_filter_type;
  276|  6.58k|        const char *actual_start;
  277|  6.58k|        size_t actual_len;
  278|  6.58k|        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|  6.58k|        size_t stored_len = actual_len < VK_MAX_EXTENSION_NAME_SIZE - 1 ? actual_len : VK_MAX_EXTENSION_NAME_SIZE - 1;
  ------------------
  |  Branch (281:29): [True: 6.58k, False: 0]
  ------------------
  282|  6.58k|        loader_strncpy(filter_struct->filters[filter_struct->count].value, VK_MAX_EXTENSION_NAME_SIZE, actual_start, stored_len);
  283|  6.58k|        filter_struct->filters[filter_struct->count].value[stored_len] = '\0';
  284|  6.58k|        filter_struct->filters[filter_struct->count].length = stored_len;
  285|  6.58k|        filter_struct->filters[filter_struct->count++].type = cur_filter_type;
  286|  6.58k|        if (filter_struct->count >= MAX_ADDITIONAL_FILTERS) {
  ------------------
  |  |  530|  6.58k|#define MAX_ADDITIONAL_FILTERS 16
  ------------------
  |  Branch (286:13): [True: 0, False: 6.58k]
  ------------------
  287|      0|            break;
  288|      0|        }
  289|  6.58k|        token = thread_safe_strtok(NULL, ",", &context);
  290|  6.58k|    }
  291|       |
  292|  6.58k|out:
  293|       |
  294|  6.58k|    loader_instance_heap_free(inst, parsing_string);
  295|  6.58k|    loader_free_getenv(env_var_value, inst);
  296|  6.58k|    return result;
  297|  6.58k|}
parse_layers_disable_filter_environment_var:
  303|  6.58k|                                                     struct loader_envvar_disable_layers_filter *disable_struct) {
  304|  6.58k|    VkResult result = VK_SUCCESS;
  305|  6.58k|    memset(disable_struct, 0, sizeof(struct loader_envvar_disable_layers_filter));
  306|  6.58k|    char *parsing_string = NULL;
  307|  6.58k|    char *env_var_value = loader_secure_getenv(VK_LAYERS_DISABLE_ENV_VAR, inst);
  ------------------
  |  |  120|  6.58k|#define VK_LAYERS_DISABLE_ENV_VAR "VK_LOADER_LAYERS_DISABLE"
  ------------------
  308|  6.58k|    if (NULL == env_var_value) {
  ------------------
  |  Branch (308:9): [True: 6.58k, False: 0]
  ------------------
  309|  6.58k|        goto out;
  310|  6.58k|    }
  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) {
  ------------------
  |  |  530|      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|  6.58k|out:
  364|  6.58k|    loader_instance_heap_free(inst, parsing_string);
  365|  6.58k|    loader_free_getenv(env_var_value, inst);
  366|  6.58k|    return result;
  367|      0|}
parse_layer_environment_var_filters:
  370|  6.58k|VkResult parse_layer_environment_var_filters(const struct loader_instance *inst, struct loader_envvar_all_filters *layer_filters) {
  371|  6.58k|    VkResult res = parse_generic_filter_environment_var(inst, VK_LAYERS_ENABLE_ENV_VAR, &layer_filters->enable_filter);
  ------------------
  |  |  119|  6.58k|#define VK_LAYERS_ENABLE_ENV_VAR "VK_LOADER_LAYERS_ENABLE"
  ------------------
  372|  6.58k|    if (VK_SUCCESS != res) {
  ------------------
  |  Branch (372:9): [True: 0, False: 6.58k]
  ------------------
  373|      0|        return res;
  374|      0|    }
  375|  6.58k|    res = parse_layers_disable_filter_environment_var(inst, &layer_filters->disable_filter);
  376|  6.58k|    if (VK_SUCCESS != res) {
  ------------------
  |  Branch (376:9): [True: 0, False: 6.58k]
  ------------------
  377|      0|        return res;
  378|      0|    }
  379|  6.58k|    res = parse_generic_filter_environment_var(inst, VK_LAYERS_ALLOW_ENV_VAR, &layer_filters->allow_filter);
  ------------------
  |  |  121|  6.58k|#define VK_LAYERS_ALLOW_ENV_VAR "VK_LOADER_LAYERS_ALLOW"
  ------------------
  380|  6.58k|    if (VK_SUCCESS != res) {
  ------------------
  |  Branch (380:9): [True: 0, False: 6.58k]
  ------------------
  381|      0|        return res;
  382|      0|    }
  383|  6.58k|    return res;
  384|  6.58k|}
check_name_matches_filter_environment_var:
  405|  47.7k|bool check_name_matches_filter_environment_var(const char *name, const struct loader_envvar_filter *filter_struct) {
  406|  47.7k|    bool ret_value = false;
  407|  47.7k|    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|  71.5k|    for (uint32_t filt = 0; filt < filter_struct->count; ++filt) {
  ------------------
  |  Branch (411:29): [True: 23.8k, False: 47.6k]
  ------------------
  412|  23.8k|        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|  23.8k|        if (filter->length > name_len) {
  ------------------
  |  Branch (414:13): [True: 16.7k, False: 7.07k]
  ------------------
  415|  16.7k|            continue;
  416|  16.7k|        }
  417|  7.07k|        switch (filter->type) {
  ------------------
  |  Branch (417:17): [True: 7.07k, False: 0]
  ------------------
  418|      0|            case FILTER_STRING_SPECIAL:
  ------------------
  |  Branch (418:13): [True: 0, False: 7.07k]
  ------------------
  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: 7.07k]
  ------------------
  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: 7.07k]
  ------------------
  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: 7.07k]
  ------------------
  441|      0|                ret_value = name_segment_matches_filter_value(name, filter->value, filter->length);
  442|      0|                break;
  443|       |
  444|  7.07k|            case FILTER_STRING_FULLNAME:
  ------------------
  |  Branch (444:13): [True: 7.07k, False: 0]
  ------------------
  445|  7.07k|                ret_value = (name_len == filter->length) && name_segment_matches_filter_value(name, filter->value, filter->length);
  ------------------
  |  Branch (445:29): [True: 348, False: 6.73k]
  |  Branch (445:61): [True: 30, False: 318]
  ------------------
  446|  7.07k|                break;
  447|  7.07k|        }
  448|  7.07k|        if (ret_value) {
  ------------------
  |  Branch (448:13): [True: 30, False: 7.04k]
  ------------------
  449|     30|            break;
  450|     30|        }
  451|  7.07k|    }
  452|  47.7k|    return ret_value;
  453|  47.7k|}
loader_environment.c:name_segment_matches_filter_value:
  390|    348|static bool name_segment_matches_filter_value(const char *name_segment, const char *lowercase_filter_value, size_t count) {
  391|    449|    for (size_t iii = 0; iii < count; ++iii) {
  ------------------
  |  Branch (391:26): [True: 419, False: 30]
  ------------------
  392|    419|        if ((char)tolower((unsigned char)name_segment[iii]) != lowercase_filter_value[iii]) {
  ------------------
  |  Branch (392:13): [True: 318, False: 101]
  |  Branch (392:19): [True: 0, False: 0]
  |  Branch (392:19): [True: 0, False: 0]
  |  Branch (392:19): [Folded, False: 419]
  ------------------
  393|    318|            return false;
  394|    318|        }
  395|    419|    }
  396|     30|    return true;
  397|    348|}

loader_get_json:
  164|  24.4k|TEST_FUNCTION_EXPORT VkResult loader_get_json(const struct loader_instance *inst, const char *filename, cJSON **json) {
  165|  24.4k|    char *json_buf = NULL;
  166|  24.4k|    VkResult res = VK_SUCCESS;
  167|       |
  168|  24.4k|    assert(json != NULL);
  169|       |
  170|  24.4k|    size_t json_len = 0;
  171|  24.4k|    *json = NULL;
  172|  24.4k|    res = loader_read_entire_file(inst, filename, &json_len, &json_buf);
  173|  24.4k|    if (VK_SUCCESS != res) {
  ------------------
  |  Branch (173:9): [True: 696, False: 23.7k]
  ------------------
  174|    696|        goto out;
  175|    696|    }
  176|  24.4k|    bool out_of_memory = false;
  177|       |    // Parse text from file
  178|  23.7k|    *json = loader_cJSON_ParseWithLength(inst ? &inst->alloc_callbacks : NULL, json_buf, json_len, &out_of_memory);
  ------------------
  |  Branch (178:42): [True: 23.7k, False: 0]
  ------------------
  179|  23.7k|    if (out_of_memory) {
  ------------------
  |  Branch (179:9): [True: 0, False: 23.7k]
  ------------------
  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|  23.7k|    } else if (*json == NULL) {
  ------------------
  |  Branch (184:16): [True: 9.22k, False: 14.5k]
  ------------------
  185|  9.22k|        loader_log(inst, VULKAN_LOADER_ERROR_BIT, 0, "loader_get_json: Invalid JSON file %s.", filename);
  186|  9.22k|        goto out;
  187|  9.22k|    }
  188|       |
  189|  24.4k|out:
  190|  24.4k|    loader_instance_heap_free(inst, json_buf);
  191|  24.4k|    if (res != VK_SUCCESS && *json != NULL) {
  ------------------
  |  Branch (191:9): [True: 696, False: 23.7k]
  |  Branch (191:30): [True: 0, False: 696]
  ------------------
  192|      0|        loader_cJSON_Delete(*json);
  193|      0|        *json = NULL;
  194|      0|    }
  195|       |
  196|  24.4k|    return res;
  197|  23.7k|}
loader_parse_json_string_to_existing_str:
  199|   858k|VkResult loader_parse_json_string_to_existing_str(cJSON *object, const char *key, size_t out_str_len, char *out_string) {
  200|   858k|    if (NULL == key) {
  ------------------
  |  Branch (200:9): [True: 0, False: 858k]
  ------------------
  201|      0|        return VK_ERROR_INITIALIZATION_FAILED;
  202|      0|    }
  203|   858k|    cJSON *item = loader_cJSON_GetObjectItem(object, key);
  204|   858k|    if (NULL == item) {
  ------------------
  |  Branch (204:9): [True: 134k, False: 723k]
  ------------------
  205|   134k|        return VK_ERROR_INITIALIZATION_FAILED;
  206|   134k|    }
  207|       |
  208|   723k|    if (item->type != cJSON_String || item->valuestring == NULL) {
  ------------------
  |  |  101|  1.44M|#define cJSON_String (1 << 4)
  ------------------
  |  Branch (208:9): [True: 14.5k, False: 709k]
  |  Branch (208:39): [True: 0, False: 709k]
  ------------------
  209|  14.5k|        return VK_ERROR_INITIALIZATION_FAILED;
  210|  14.5k|    }
  211|   723k|    bool out_of_memory = false;
  212|   709k|    bool success = loader_cJSON_PrintPreallocated(item, out_string, (int)out_str_len, cJSON_False);
  ------------------
  |  |   97|   709k|#define cJSON_False (1 << 0)
  ------------------
  213|   709k|    if (out_of_memory) {
  ------------------
  |  Branch (213:9): [True: 0, False: 709k]
  ------------------
  214|      0|        return VK_ERROR_OUT_OF_HOST_MEMORY;
  215|      0|    }
  216|   709k|    if (!success) {
  ------------------
  |  Branch (216:9): [True: 545, False: 708k]
  ------------------
  217|    545|        return VK_ERROR_INITIALIZATION_FAILED;
  218|    545|    }
  219|   708k|    return VK_SUCCESS;
  220|   709k|}
loader_parse_json_string:
  222|   333k|VkResult loader_parse_json_string(cJSON *object, const char *key, char **out_string) {
  223|   333k|    if (NULL == key) {
  ------------------
  |  Branch (223:9): [True: 0, False: 333k]
  ------------------
  224|      0|        return VK_ERROR_INITIALIZATION_FAILED;
  225|      0|    }
  226|       |
  227|   333k|    cJSON *item = loader_cJSON_GetObjectItem(object, key);
  228|   333k|    if (NULL == item || NULL == item->valuestring) {
  ------------------
  |  Branch (228:9): [True: 107k, False: 225k]
  |  Branch (228:25): [True: 337, False: 225k]
  ------------------
  229|   107k|        return VK_ERROR_INITIALIZATION_FAILED;
  230|   107k|    }
  231|       |
  232|   333k|    bool out_of_memory = false;
  233|   225k|    char *str = loader_cJSON_Print(item, &out_of_memory);
  234|   225k|    if (out_of_memory || NULL == str) {
  ------------------
  |  Branch (234:9): [True: 0, False: 225k]
  |  Branch (234:26): [True: 0, False: 225k]
  ------------------
  235|      0|        return VK_ERROR_OUT_OF_HOST_MEMORY;
  236|      0|    }
  237|   225k|    if (NULL != out_string) {
  ------------------
  |  Branch (237:9): [True: 225k, False: 0]
  ------------------
  238|   225k|        *out_string = str;
  239|   225k|    }
  240|   225k|    return VK_SUCCESS;
  241|   225k|}
loader_parse_json_array_of_strings:
  243|   294k|                                            struct loader_string_list *string_list) {
  244|   294k|    if (NULL == key) {
  ------------------
  |  Branch (244:9): [True: 0, False: 294k]
  ------------------
  245|      0|        return VK_ERROR_INITIALIZATION_FAILED;
  246|      0|    }
  247|   294k|    cJSON *item = loader_cJSON_GetObjectItem(object, key);
  248|   294k|    if (NULL == item) {
  ------------------
  |  Branch (248:9): [True: 244k, False: 49.6k]
  ------------------
  249|   244k|        return VK_ERROR_INITIALIZATION_FAILED;
  250|   244k|    }
  251|       |
  252|  49.6k|    uint32_t count = loader_cJSON_GetArraySize(item);
  253|  49.6k|    if (count == 0) {
  ------------------
  |  Branch (253:9): [True: 5.22k, False: 44.4k]
  ------------------
  254|  5.22k|        return VK_SUCCESS;
  255|  5.22k|    }
  256|       |
  257|  44.4k|    VkResult res = create_string_list(inst, count, string_list);
  258|  44.4k|    if (VK_ERROR_OUT_OF_HOST_MEMORY == res) {
  ------------------
  |  Branch (258:9): [True: 0, False: 44.4k]
  ------------------
  259|      0|        goto out;
  260|      0|    }
  261|  44.4k|    cJSON *element = NULL;
  262|  71.4k|    cJSON_ArrayForEach(element, item) {
  ------------------
  |  |  213|   113k|    for (element = (array != NULL) ? (array)->child : NULL; element != NULL; element = element->next)
  |  |  ------------------
  |  |  |  Branch (213:20): [True: 44.4k, False: 0]
  |  |  |  Branch (213:61): [True: 71.4k, False: 42.5k]
  |  |  ------------------
  ------------------
  263|  71.4k|        if (element->type != cJSON_String) {
  ------------------
  |  |  101|  71.4k|#define cJSON_String (1 << 4)
  ------------------
  |  Branch (263:13): [True: 1.89k, False: 69.5k]
  ------------------
  264|  1.89k|            return VK_ERROR_INITIALIZATION_FAILED;
  265|  1.89k|        }
  266|  71.4k|        bool out_of_memory = false;
  267|  69.5k|        char *out_data = loader_cJSON_Print(element, &out_of_memory);
  268|  69.5k|        if (out_of_memory) {
  ------------------
  |  Branch (268:13): [True: 0, False: 69.5k]
  ------------------
  269|      0|            res = VK_ERROR_OUT_OF_HOST_MEMORY;
  270|      0|            goto out;
  271|      0|        }
  272|  69.5k|        res = append_str_to_string_list(inst, string_list, out_data);
  273|  69.5k|        if (VK_ERROR_OUT_OF_HOST_MEMORY == res) {
  ------------------
  |  Branch (273:13): [True: 0, False: 69.5k]
  ------------------
  274|      0|            goto out;
  275|      0|        }
  276|  69.5k|    }
  277|  42.5k|out:
  278|  42.5k|    if (res == VK_ERROR_OUT_OF_HOST_MEMORY && NULL != string_list->list) {
  ------------------
  |  Branch (278:9): [True: 0, False: 42.5k]
  |  Branch (278:47): [True: 0, False: 0]
  ------------------
  279|      0|        free_string_list(inst, string_list);
  280|      0|    }
  281|       |
  282|  42.5k|    return res;
  283|  44.4k|}
loader_json.c:loader_read_entire_file:
  110|  24.4k|                                        char **out_buff) {
  111|  24.4k|    FILE *file = NULL;
  112|  24.4k|    struct stat stats = {0};
  113|  24.4k|    VkResult res = VK_SUCCESS;
  114|       |
  115|       |    // fprintf(stderr, "loader_get_json: Reading JSON file %s\n", filename);
  116|  24.4k|    file = fopen(filename, "rb");
  117|  24.4k|#ifdef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
  118|  24.4k|    if (file == NULL) {
  ------------------
  |  Branch (118:9): [True: 5.80k, False: 18.6k]
  ------------------
  119|  5.80k|        create_callback_file(filename);
  120|  5.80k|        file = fopen(filename, "rb");
  121|  5.80k|    }
  122|  24.4k|#endif
  123|  24.4k|    if (NULL == file) {
  ------------------
  |  Branch (123:9): [True: 601, False: 23.8k]
  ------------------
  124|    601|        loader_log(inst, VULKAN_LOADER_ERROR_BIT, 0, "loader_get_json: Failed to open JSON file %s", filename);
  125|    601|        res = VK_ERROR_INITIALIZATION_FAILED;
  126|    601|        goto out;
  127|    601|    }
  128|  23.8k|    if (-1 == fstat(fileno(file), &stats)) {
  ------------------
  |  Branch (128:9): [True: 0, False: 23.8k]
  ------------------
  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|  23.8k|    *out_buff = (char *)loader_instance_heap_calloc(inst, stats.st_size + 1, VK_SYSTEM_ALLOCATION_SCOPE_COMMAND);
  134|  23.8k|    if (NULL == *out_buff) {
  ------------------
  |  Branch (134:9): [True: 0, False: 23.8k]
  ------------------
  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|  23.8k|    if (stats.st_size != (long int)fread(*out_buff, sizeof(char), stats.st_size, file)) {
  ------------------
  |  Branch (139:9): [True: 95, False: 23.7k]
  ------------------
  140|     95|        loader_log(inst, VULKAN_LOADER_ERROR_BIT, 0, "loader_get_json: Failed to read entire JSON file %s", filename);
  141|     95|        res = VK_ERROR_INITIALIZATION_FAILED;
  142|     95|        goto out;
  143|     95|    }
  144|  23.7k|    *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|  23.7k|    (*out_buff)[stats.st_size] = '\0';
  149|       |
  150|  24.4k|out:
  151|  24.4k|    if (NULL != file) {
  ------------------
  |  Branch (151:9): [True: 23.8k, False: 601]
  ------------------
  152|       |        // NOLINTNEXTLINE(cert-err33-c) - file was only opened for reading, nothing to flush; res already reflects any read failure
  153|  23.8k|        fclose(file);
  154|  23.8k|    }
  155|  24.4k|    return res;
  156|  23.7k|}

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|}
generate_debug_flag_str:
   93|  2.35k|void generate_debug_flag_str(VkFlags msg_type, size_t cmd_line_size, char *cmd_line_msg) {
   94|  2.35k|    cmd_line_msg[0] = '\0';
   95|       |
   96|  2.35k|    if ((msg_type & VULKAN_LOADER_ERROR_BIT) != 0) {
  ------------------
  |  Branch (96:9): [True: 84, False: 2.27k]
  ------------------
   97|     84|        loader_strncat(cmd_line_msg, cmd_line_size, "ERROR", sizeof("ERROR"));
   98|     84|    }
   99|  2.35k|    if ((msg_type & VULKAN_LOADER_WARN_BIT) != 0) {
  ------------------
  |  Branch (99:9): [True: 86, False: 2.27k]
  ------------------
  100|     86|        if (strlen(cmd_line_msg) > 0) {
  ------------------
  |  Branch (100:13): [True: 74, False: 12]
  ------------------
  101|     74|            loader_strncat(cmd_line_msg, cmd_line_size, " | ", sizeof(" | "));
  102|     74|        }
  103|     86|        loader_strncat(cmd_line_msg, cmd_line_size, "WARNING", sizeof("WARNING"));
  104|     86|    }
  105|  2.35k|    if ((msg_type & VULKAN_LOADER_INFO_BIT) != 0) {
  ------------------
  |  Branch (105:9): [True: 98, False: 2.25k]
  ------------------
  106|     98|        if (strlen(cmd_line_msg) > 0) {
  ------------------
  |  Branch (106:13): [True: 74, False: 24]
  ------------------
  107|     74|            loader_strncat(cmd_line_msg, cmd_line_size, " | ", sizeof(" | "));
  108|     74|        }
  109|     98|        loader_strncat(cmd_line_msg, cmd_line_size, "INFO", sizeof("INFO"));
  110|     98|    }
  111|  2.35k|    if ((msg_type & VULKAN_LOADER_DEBUG_BIT) != 0) {
  ------------------
  |  Branch (111:9): [True: 85, False: 2.27k]
  ------------------
  112|     85|        if (strlen(cmd_line_msg) > 0) {
  ------------------
  |  Branch (112:13): [True: 81, False: 4]
  ------------------
  113|     81|            loader_strncat(cmd_line_msg, cmd_line_size, " | ", sizeof(" | "));
  114|     81|        }
  115|     85|        loader_strncat(cmd_line_msg, cmd_line_size, "DEBUG", sizeof("DEBUG"));
  116|     85|    }
  117|  2.35k|    if ((msg_type & VULKAN_LOADER_PERF_BIT) != 0) {
  ------------------
  |  Branch (117:9): [True: 85, False: 2.27k]
  ------------------
  118|     85|        if (strlen(cmd_line_msg) > 0) {
  ------------------
  |  Branch (118:13): [True: 78, False: 7]
  ------------------
  119|     78|            loader_strncat(cmd_line_msg, cmd_line_size, " | ", sizeof(" | "));
  120|     78|        }
  121|     85|        loader_strncat(cmd_line_msg, cmd_line_size, "PERF", sizeof("PERF"));
  122|     85|    }
  123|  2.35k|    if ((msg_type & VULKAN_LOADER_DRIVER_BIT) != 0) {
  ------------------
  |  Branch (123:9): [True: 90, False: 2.26k]
  ------------------
  124|     90|        if (strlen(cmd_line_msg) > 0) {
  ------------------
  |  Branch (124:13): [True: 86, False: 4]
  ------------------
  125|     86|            loader_strncat(cmd_line_msg, cmd_line_size, " | ", sizeof(" | "));
  126|     86|        }
  127|     90|        loader_strncat(cmd_line_msg, cmd_line_size, "DRIVER", sizeof("DRIVER"));
  128|     90|    }
  129|  2.35k|    if ((msg_type & VULKAN_LOADER_LAYER_BIT) != 0) {
  ------------------
  |  Branch (129:9): [True: 88, False: 2.26k]
  ------------------
  130|     88|        if (strlen(cmd_line_msg) > 0) {
  ------------------
  |  Branch (130:13): [True: 79, False: 9]
  ------------------
  131|     79|            loader_strncat(cmd_line_msg, cmd_line_size, " | ", sizeof(" | "));
  132|     79|        }
  133|     88|        loader_strncat(cmd_line_msg, cmd_line_size, "LAYER", sizeof("LAYER"));
  134|     88|    }
  135|       |
  136|  2.35k|#undef STRNCAT_TO_BUFFER
  137|  2.35k|}
loader_log:
  141|  1.11M|    loader_log(const struct loader_instance *inst, VkFlags msg_type, int32_t msg_code, const char *format, ...) {
  142|  1.11M|    (void)msg_code;
  143|  1.11M|    char msg[512] = {0};
  144|       |
  145|  1.11M|    va_list ap;
  146|  1.11M|    va_start(ap, format);
  147|  1.11M|    int ret = vsnprintf(msg, sizeof(msg), format, ap);
  148|  1.11M|    if ((ret >= (int)sizeof(msg)) || ret < 0) {
  ------------------
  |  Branch (148:9): [True: 1.07k, False: 1.11M]
  |  Branch (148:38): [True: 0, False: 1.11M]
  ------------------
  149|  1.07k|        msg[sizeof(msg) - 1] = '\0';
  150|  1.07k|    }
  151|  1.11M|    va_end(ap);
  152|       |
  153|  1.11M|    if (inst) {
  ------------------
  |  Branch (153:9): [True: 1.11M, False: 2]
  ------------------
  154|       |        // NOLINTNEXTLINE(clang-analyzer-optin.core.EnumCastOutOfRange) - external Vulkan enum, has no zero value we can add
  155|  1.11M|        VkDebugUtilsMessageSeverityFlagBitsEXT severity = 0;
  156|  1.11M|        VkDebugUtilsMessageTypeFlagsEXT type = 0;
  157|  1.11M|        VkDebugUtilsMessengerCallbackDataEXT callback_data = {0};
  158|  1.11M|        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|  1.11M|        if ((msg_type & VULKAN_LOADER_INFO_BIT) != 0) {
  ------------------
  |  Branch (161:13): [True: 106k, False: 1.00M]
  ------------------
  162|   106k|            severity = VK_DEBUG_UTILS_MESSAGE_SEVERITY_INFO_BIT_EXT;
  163|  1.00M|        } else if ((msg_type & VULKAN_LOADER_WARN_BIT) != 0) {
  ------------------
  |  Branch (163:20): [True: 777k, False: 230k]
  ------------------
  164|   777k|            severity = VK_DEBUG_UTILS_MESSAGE_SEVERITY_WARNING_BIT_EXT;
  165|   777k|        } else if ((msg_type & VULKAN_LOADER_ERROR_BIT) != 0) {
  ------------------
  |  Branch (165:20): [True: 16.9k, False: 213k]
  ------------------
  166|  16.9k|            severity = VK_DEBUG_UTILS_MESSAGE_SEVERITY_ERROR_BIT_EXT;
  167|   213k|        } else if ((msg_type & VULKAN_LOADER_DEBUG_BIT) != 0) {
  ------------------
  |  Branch (167:20): [True: 103k, False: 109k]
  ------------------
  168|   103k|            severity = VK_DEBUG_UTILS_MESSAGE_SEVERITY_VERBOSE_BIT_EXT;
  169|   109k|        } else if ((msg_type & VULKAN_LOADER_LAYER_BIT) != 0 || (msg_type & VULKAN_LOADER_DRIVER_BIT) != 0) {
  ------------------
  |  Branch (169:20): [True: 109k, False: 20]
  |  Branch (169:65): [True: 20, False: 0]
  ------------------
  170|       |            // Just driver or just layer bit should be treated as an info message in debug utils.
  171|   109k|            severity = VK_DEBUG_UTILS_MESSAGE_SEVERITY_INFO_BIT_EXT;
  172|   109k|        }
  173|       |
  174|  1.11M|        if ((msg_type & VULKAN_LOADER_PERF_BIT) != 0) {
  ------------------
  |  Branch (174:13): [True: 0, False: 1.11M]
  ------------------
  175|      0|            type = VK_DEBUG_UTILS_MESSAGE_TYPE_PERFORMANCE_BIT_EXT;
  176|  1.11M|        } else if ((msg_type & VULKAN_LOADER_VALIDATION_BIT) != 0) {
  ------------------
  |  Branch (176:20): [True: 0, False: 1.11M]
  ------------------
  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|  1.11M|        } else {
  181|  1.11M|            type = VK_DEBUG_UTILS_MESSAGE_TYPE_GENERAL_BIT_EXT;
  182|  1.11M|        }
  183|       |
  184|  1.11M|        callback_data.sType = VK_STRUCTURE_TYPE_DEBUG_UTILS_MESSENGER_CALLBACK_DATA_EXT;
  185|  1.11M|        callback_data.pMessageIdName = "Loader Message";
  186|  1.11M|        callback_data.pMessage = msg;
  187|  1.11M|        callback_data.objectCount = 1;
  188|  1.11M|        callback_data.pObjects = &object_name;
  189|  1.11M|        object_name.sType = VK_STRUCTURE_TYPE_DEBUG_UTILS_OBJECT_NAME_INFO_EXT;
  190|  1.11M|        object_name.objectType = VK_OBJECT_TYPE_INSTANCE;
  191|  1.11M|        object_name.objectHandle = (uint64_t)(uintptr_t)inst;
  192|       |
  193|  1.11M|        util_SubmitDebugUtilsMessageEXT(inst, severity, type, &callback_data);
  194|  1.11M|    }
  195|       |
  196|       |    // Always log to stderr if this is a fatal error
  197|  1.11M|    if (0 == (msg_type & VULKAN_LOADER_FATAL_ERROR_BIT)) {
  ------------------
  |  Branch (197:9): [True: 1.11M, False: 0]
  ------------------
  198|  1.11M|        if (inst && inst->settings.settings_active && inst->settings.debug_level > 0) {
  ------------------
  |  Branch (198:13): [True: 1.11M, False: 2]
  |  Branch (198:21): [True: 920k, False: 194k]
  |  Branch (198:55): [True: 43.4k, False: 877k]
  ------------------
  199|       |            // Exit early if the current instance settings have some debugging options but do match the current msg_type
  200|  43.4k|            if (0 == (msg_type & inst->settings.debug_level)) {
  ------------------
  |  Branch (200:17): [True: 26.9k, False: 16.4k]
  ------------------
  201|  26.9k|                return;
  202|  26.9k|            }
  203|       |            // Check the global settings and if that doesn't say to skip, check the environment variable
  204|  1.07M|        } else if (0 == (msg_type & g_loader_debug)) {
  ------------------
  |  Branch (204:20): [True: 1.07M, False: 0]
  ------------------
  205|  1.07M|            return;
  206|  1.07M|        }
  207|  1.11M|    }
  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|  16.4k|    char cmd_line_msg[64] = {0};
  220|  16.4k|    size_t cmd_line_size = sizeof(cmd_line_msg);
  221|       |
  222|  16.4k|    loader_strncat(cmd_line_msg, cmd_line_size, "[Vulkan Loader] ", sizeof("[Vulkan Loader] "));
  223|       |
  224|  16.4k|    bool need_separator = false;
  225|  16.4k|    if ((msg_type & VULKAN_LOADER_ERROR_BIT) != 0) {
  ------------------
  |  Branch (225:9): [True: 1.21k, False: 15.2k]
  ------------------
  226|  1.21k|        loader_strncat(cmd_line_msg, cmd_line_size, "ERROR", sizeof("ERROR"));
  227|  1.21k|        need_separator = true;
  228|  15.2k|    } else if ((msg_type & VULKAN_LOADER_WARN_BIT) != 0) {
  ------------------
  |  Branch (228:16): [True: 1.47k, False: 13.8k]
  ------------------
  229|  1.47k|        loader_strncat(cmd_line_msg, cmd_line_size, "WARNING", sizeof("WARNING"));
  230|  1.47k|        need_separator = true;
  231|  13.8k|    } else if ((msg_type & VULKAN_LOADER_INFO_BIT) != 0) {
  ------------------
  |  Branch (231:16): [True: 2.73k, False: 11.0k]
  ------------------
  232|  2.73k|        loader_strncat(cmd_line_msg, cmd_line_size, "INFO", sizeof("INFO"));
  233|  2.73k|        need_separator = true;
  234|  11.0k|    } else if ((msg_type & VULKAN_LOADER_DEBUG_BIT) != 0) {
  ------------------
  |  Branch (234:16): [True: 9.05k, False: 2.02k]
  ------------------
  235|  9.05k|        loader_strncat(cmd_line_msg, cmd_line_size, "DEBUG", sizeof("DEBUG"));
  236|  9.05k|        need_separator = true;
  237|  9.05k|    }
  238|       |
  239|  16.4k|    if ((msg_type & VULKAN_LOADER_PERF_BIT) != 0) {
  ------------------
  |  Branch (239:9): [True: 0, False: 16.4k]
  ------------------
  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|  16.4k|    } else if ((msg_type & VULKAN_LOADER_DRIVER_BIT) != 0) {
  ------------------
  |  Branch (244:16): [True: 0, False: 16.4k]
  ------------------
  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|  16.4k|    } else if ((msg_type & VULKAN_LOADER_LAYER_BIT) != 0) {
  ------------------
  |  Branch (249:16): [True: 4.76k, False: 11.7k]
  ------------------
  250|  4.76k|        if (need_separator) {
  ------------------
  |  Branch (250:13): [True: 2.74k, False: 2.02k]
  ------------------
  251|  2.74k|            loader_strncat(cmd_line_msg, cmd_line_size, " | ", sizeof(" | "));
  252|  2.74k|        }
  253|  4.76k|        loader_strncat(cmd_line_msg, cmd_line_size, "LAYER", sizeof("LAYER"));
  254|  4.76k|    }
  255|       |
  256|  16.4k|    loader_strncat(cmd_line_msg, cmd_line_size, ": ", sizeof(": "));
  257|  16.4k|    size_t num_used = strlen(cmd_line_msg);
  258|       |
  259|       |    // Justifies the output to at least 29 spaces
  260|  16.4k|    if (num_used < 32) {
  ------------------
  |  Branch (260:9): [True: 15.3k, False: 1.09k]
  ------------------
  261|  15.3k|        const char space_buffer[] = "                                ";
  262|       |        // Only write (32 - num_used) spaces
  263|  15.3k|        loader_strncat(cmd_line_msg, cmd_line_size, space_buffer, sizeof(space_buffer) - 1 - num_used);
  264|  15.3k|    }
  265|       |    // Assert that we didn't write more than what is available in cmd_line_msg
  266|  16.4k|    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|  16.4k|}

free_layer_configuration:
   41|  22.2k|void free_layer_configuration(const struct loader_instance* inst, loader_settings_layer_configuration* layer_configuration) {
   42|  22.2k|    loader_instance_heap_free(inst, layer_configuration->name);
   43|  22.2k|    loader_instance_heap_free(inst, layer_configuration->path);
   44|  22.2k|    memset(layer_configuration, 0, sizeof(loader_settings_layer_configuration));
   45|  22.2k|}
free_loader_settings:
   57|  6.59k|void free_loader_settings(const struct loader_instance* inst, loader_settings* settings) {
   58|  6.59k|    if (NULL != settings->layer_configurations) {
  ------------------
  |  Branch (58:9): [True: 2.27k, False: 4.31k]
  ------------------
   59|  20.7k|        for (uint32_t i = 0; i < settings->layer_configuration_count; i++) {
  ------------------
  |  Branch (59:30): [True: 18.4k, False: 2.27k]
  ------------------
   60|  18.4k|            free_layer_configuration(inst, &settings->layer_configurations[i]);
   61|  18.4k|        }
   62|  2.27k|        loader_instance_heap_free(inst, settings->layer_configurations);
   63|  2.27k|    }
   64|  6.59k|    if (NULL != settings->additional_drivers) {
  ------------------
  |  Branch (64:9): [True: 0, False: 6.59k]
  ------------------
   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|  6.59k|    if (NULL != settings->device_configurations) {
  ------------------
  |  Branch (70:9): [True: 0, False: 6.59k]
  ------------------
   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|  6.59k|    loader_instance_heap_free(inst, settings->settings_file_path);
   77|  6.59k|    memset(settings, 0, sizeof(loader_settings));
   78|  6.59k|}
parse_control_string:
   80|  19.2k|loader_settings_layer_control parse_control_string(char* control_string) {
   81|  19.2k|    loader_settings_layer_control layer_control = LOADER_SETTINGS_LAYER_CONTROL_DEFAULT;
   82|  19.2k|    if (strcmp(control_string, "auto") == 0)
  ------------------
  |  Branch (82:9): [True: 3.92k, False: 15.2k]
  ------------------
   83|  3.92k|        layer_control = LOADER_SETTINGS_LAYER_CONTROL_DEFAULT;
   84|  15.2k|    else if (strcmp(control_string, "on") == 0)
  ------------------
  |  Branch (84:14): [True: 2.93k, False: 12.3k]
  ------------------
   85|  2.93k|        layer_control = LOADER_SETTINGS_LAYER_CONTROL_ON;
   86|  12.3k|    else if (strcmp(control_string, "off") == 0)
  ------------------
  |  Branch (86:14): [True: 962, False: 11.3k]
  ------------------
   87|    962|        layer_control = LOADER_SETTINGS_LAYER_CONTROL_OFF;
   88|  11.3k|    else if (strcmp(control_string, "unordered_layer_location") == 0)
  ------------------
  |  Branch (88:14): [True: 1.00k, False: 10.3k]
  ------------------
   89|  1.00k|        layer_control = LOADER_SETTINGS_LAYER_UNORDERED_LAYER_LOCATION;
   90|  19.2k|    return layer_control;
   91|  19.2k|}
loader_settings_layer_control_to_string:
   93|  18.4k|const char* loader_settings_layer_control_to_string(loader_settings_layer_control control) {
   94|  18.4k|    switch (control) {
   95|  13.9k|        case LOADER_SETTINGS_LAYER_CONTROL_DEFAULT:
  ------------------
  |  Branch (95:9): [True: 13.9k, False: 4.55k]
  ------------------
   96|  13.9k|            return "auto";
   97|  2.59k|        case LOADER_SETTINGS_LAYER_CONTROL_ON:
  ------------------
  |  Branch (97:9): [True: 2.59k, False: 15.8k]
  ------------------
   98|  2.59k|            return "on";
   99|    960|        case LOADER_SETTINGS_LAYER_CONTROL_OFF:
  ------------------
  |  Branch (99:9): [True: 960, False: 17.5k]
  ------------------
  100|    960|            return "off";
  101|  1.00k|        case LOADER_SETTINGS_LAYER_UNORDERED_LAYER_LOCATION:
  ------------------
  |  Branch (101:9): [True: 1.00k, False: 17.4k]
  ------------------
  102|  1.00k|            return "unordered_layer_location";
  103|      0|        default:
  ------------------
  |  Branch (103:9): [True: 0, False: 18.4k]
  ------------------
  104|      0|            return "UNKNOWN_LAYER_CONTROl";
  105|  18.4k|    }
  106|  18.4k|}
parse_log_filters_from_strings:
  108|    341|uint32_t parse_log_filters_from_strings(struct loader_string_list* log_filters) {
  109|    341|    uint32_t filters = 0;
  110|  12.4k|    for (uint32_t i = 0; i < log_filters->count; i++) {
  ------------------
  |  Branch (110:26): [True: 12.1k, False: 341]
  ------------------
  111|  12.1k|        if (strcmp(log_filters->list[i], "all") == 0)
  ------------------
  |  Branch (111:13): [True: 226, False: 11.9k]
  ------------------
  112|    226|            filters |= VULKAN_LOADER_INFO_BIT | VULKAN_LOADER_WARN_BIT | VULKAN_LOADER_PERF_BIT | VULKAN_LOADER_ERROR_BIT |
  113|    226|                       VULKAN_LOADER_DEBUG_BIT | VULKAN_LOADER_LAYER_BIT | VULKAN_LOADER_DRIVER_BIT | VULKAN_LOADER_VALIDATION_BIT;
  114|  11.9k|        else if (strcmp(log_filters->list[i], "info") == 0)
  ------------------
  |  Branch (114:18): [True: 370, False: 11.5k]
  ------------------
  115|    370|            filters |= VULKAN_LOADER_INFO_BIT;
  116|  11.5k|        else if (strcmp(log_filters->list[i], "warn") == 0)
  ------------------
  |  Branch (116:18): [True: 644, False: 10.9k]
  ------------------
  117|    644|            filters |= VULKAN_LOADER_WARN_BIT;
  118|  10.9k|        else if (strcmp(log_filters->list[i], "perf") == 0)
  ------------------
  |  Branch (118:18): [True: 354, False: 10.5k]
  ------------------
  119|    354|            filters |= VULKAN_LOADER_PERF_BIT;
  120|  10.5k|        else if (strcmp(log_filters->list[i], "error") == 0)
  ------------------
  |  Branch (120:18): [True: 232, False: 10.3k]
  ------------------
  121|    232|            filters |= VULKAN_LOADER_ERROR_BIT;
  122|  10.3k|        else if (strcmp(log_filters->list[i], "debug") == 0)
  ------------------
  |  Branch (122:18): [True: 1.20k, False: 9.12k]
  ------------------
  123|  1.20k|            filters |= VULKAN_LOADER_DEBUG_BIT;
  124|  9.12k|        else if (strcmp(log_filters->list[i], "layer") == 0)
  ------------------
  |  Branch (124:18): [True: 265, False: 8.85k]
  ------------------
  125|    265|            filters |= VULKAN_LOADER_LAYER_BIT;
  126|  8.85k|        else if (strcmp(log_filters->list[i], "driver") == 0)
  ------------------
  |  Branch (126:18): [True: 106, False: 8.75k]
  ------------------
  127|    106|            filters |= VULKAN_LOADER_DRIVER_BIT;
  128|  8.75k|        else if (strcmp(log_filters->list[i], "validation") == 0)
  ------------------
  |  Branch (128:18): [True: 83, False: 8.66k]
  ------------------
  129|     83|            filters |= VULKAN_LOADER_VALIDATION_BIT;
  130|  12.1k|    }
  131|    341|    return filters;
  132|    341|}
parse_layer_configuration:
  147|  19.2k|                                   loader_settings_layer_configuration* layer_configuration) {
  148|  19.2k|    char* control_string = NULL;
  149|  19.2k|    VkResult res = loader_parse_json_string(layer_configuration_json, "control", &control_string);
  150|  19.2k|    if (res != VK_SUCCESS) {
  ------------------
  |  Branch (150:9): [True: 21, False: 19.2k]
  ------------------
  151|     21|        goto out;
  152|     21|    }
  153|  19.2k|    layer_configuration->control = parse_control_string(control_string);
  154|  19.2k|    loader_instance_heap_free(inst, control_string);
  155|       |
  156|       |    // If that is the only value - do no further parsing
  157|  19.2k|    if (layer_configuration->control == LOADER_SETTINGS_LAYER_UNORDERED_LAYER_LOCATION) {
  ------------------
  |  Branch (157:9): [True: 1.00k, False: 18.1k]
  ------------------
  158|  1.00k|        goto out;
  159|  1.00k|    }
  160|       |
  161|  18.1k|    res = loader_parse_json_string(layer_configuration_json, "name", &(layer_configuration->name));
  162|  18.1k|    if (res != VK_SUCCESS) {
  ------------------
  |  Branch (162:9): [True: 131, False: 18.0k]
  ------------------
  163|    131|        goto out;
  164|    131|    }
  165|       |
  166|  18.0k|    res = loader_parse_json_string(layer_configuration_json, "path", &(layer_configuration->path));
  167|  18.0k|    if (res != VK_SUCCESS) {
  ------------------
  |  Branch (167:9): [True: 10, False: 18.0k]
  ------------------
  168|     10|        goto out;
  169|     10|    }
  170|       |
  171|  18.0k|    cJSON* treat_as_implicit_manifest = loader_cJSON_GetObjectItem(layer_configuration_json, "treat_as_implicit_manifest");
  172|  18.0k|    if (treat_as_implicit_manifest && treat_as_implicit_manifest->type == cJSON_True) {
  ------------------
  |  |   98|    233|#define cJSON_True (1 << 1)
  ------------------
  |  Branch (172:9): [True: 233, False: 17.8k]
  |  Branch (172:39): [True: 156, False: 77]
  ------------------
  173|    156|        layer_configuration->treat_as_implicit_manifest = true;
  174|    156|    }
  175|  19.2k|out:
  176|  19.2k|    if (VK_SUCCESS != res) {
  ------------------
  |  Branch (176:9): [True: 162, False: 19.0k]
  ------------------
  177|    162|        free_layer_configuration(inst, layer_configuration);
  178|    162|    }
  179|  19.2k|    return res;
  180|  18.0k|}
parse_layer_configurations:
  182|  2.74k|VkResult parse_layer_configurations(const struct loader_instance* inst, cJSON* settings_object, loader_settings* loader_settings) {
  183|  2.74k|    VkResult res = VK_SUCCESS;
  184|       |
  185|  2.74k|    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|  2.74k|    if (NULL == layer_configurations) {
  ------------------
  |  Branch (187:9): [True: 289, False: 2.45k]
  ------------------
  188|    289|        return VK_SUCCESS;
  189|    289|    }
  190|       |
  191|  2.45k|    uint32_t layer_configurations_count = loader_cJSON_GetArraySize(layer_configurations);
  192|  2.45k|    if (layer_configurations_count == 0) {
  ------------------
  |  Branch (192:9): [True: 10, False: 2.44k]
  ------------------
  193|     10|        loader_settings->layer_configurations_active = true;
  194|     10|        return VK_SUCCESS;
  195|     10|    }
  196|       |
  197|  2.44k|    loader_settings->layer_configuration_count = layer_configurations_count;
  198|       |
  199|  2.44k|    loader_settings->layer_configurations = loader_instance_heap_calloc(
  200|  2.44k|        inst, sizeof(loader_settings_layer_configuration) * layer_configurations_count, VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE);
  201|  2.44k|    if (NULL == loader_settings->layer_configurations) {
  ------------------
  |  Branch (201:9): [True: 0, False: 2.44k]
  ------------------
  202|      0|        res = VK_ERROR_OUT_OF_HOST_MEMORY;
  203|      0|        goto out;
  204|      0|    }
  205|       |
  206|  2.44k|    cJSON* layer = NULL;
  207|  2.44k|    size_t i = 0;
  208|  19.2k|    cJSON_ArrayForEach(layer, layer_configurations) {
  ------------------
  |  |  213|  21.5k|    for (element = (array != NULL) ? (array)->child : NULL; element != NULL; element = element->next)
  |  |  ------------------
  |  |  |  Branch (213:20): [True: 2.44k, False: 0]
  |  |  |  Branch (213:61): [True: 19.2k, False: 2.27k]
  |  |  ------------------
  ------------------
  209|  19.2k|        if (layer->type != cJSON_Object) {
  ------------------
  |  |  103|  19.2k|#define cJSON_Object (1 << 6)
  ------------------
  |  Branch (209:13): [True: 12, False: 19.2k]
  ------------------
  210|     12|            res = VK_ERROR_INITIALIZATION_FAILED;
  211|     12|            goto out;
  212|     12|        }
  213|  19.2k|        res = parse_layer_configuration(inst, layer, &(loader_settings->layer_configurations[i++]));
  214|  19.2k|        if (VK_SUCCESS != res) {
  ------------------
  |  Branch (214:13): [True: 162, False: 19.0k]
  ------------------
  215|    162|            goto out;
  216|    162|        }
  217|  19.2k|    }
  218|  2.27k|    loader_settings->layer_configurations_active = true;
  219|  2.44k|out:
  220|  2.44k|    if (res != VK_SUCCESS) {
  ------------------
  |  Branch (220:9): [True: 174, False: 2.27k]
  ------------------
  221|    174|        if (loader_settings->layer_configurations) {
  ------------------
  |  Branch (221:13): [True: 174, False: 0]
  ------------------
  222|  3.80k|            for (size_t index = 0; index < loader_settings->layer_configuration_count; index++) {
  ------------------
  |  Branch (222:36): [True: 3.62k, False: 174]
  ------------------
  223|  3.62k|                free_layer_configuration(inst, &(loader_settings->layer_configurations[index]));
  224|  3.62k|            }
  225|    174|            loader_settings->layer_configuration_count = 0;
  226|    174|            loader_instance_heap_free(inst, loader_settings->layer_configurations);
  227|    174|            loader_settings->layer_configurations = NULL;
  228|    174|        }
  229|    174|    }
  230|       |
  231|  2.44k|    return res;
  232|  2.27k|}
parse_additional_drivers:
  248|  2.74k|VkResult parse_additional_drivers(const struct loader_instance* inst, cJSON* settings_object, loader_settings* loader_settings) {
  249|  2.74k|    VkResult res = VK_SUCCESS;
  250|       |
  251|  2.74k|    cJSON* additional_drivers_use_exclusively_json =
  252|  2.74k|        loader_cJSON_GetObjectItem(settings_object, "additional_drivers_use_exclusively");
  253|  2.74k|    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: 2.74k]
  |  Branch (253:52): [True: 0, False: 0]
  ------------------
  254|      0|        loader_settings->additional_drivers_use_exclusively = true;
  255|      0|    }
  256|       |
  257|  2.74k|    cJSON* additional_drivers_json = loader_cJSON_GetObjectItem(settings_object, "additional_drivers");
  258|  2.74k|    if (NULL == additional_drivers_json) {
  ------------------
  |  Branch (258:9): [True: 2.74k, False: 0]
  ------------------
  259|  2.74k|        return VK_SUCCESS;
  260|  2.74k|    }
  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:
  377|  2.74k|VkResult parse_device_configurations(const struct loader_instance* inst, cJSON* settings_object, loader_settings* loader_settings) {
  378|  2.74k|    VkResult res = VK_SUCCESS;
  379|       |
  380|  2.74k|    cJSON* device_configurations = loader_cJSON_GetObjectItem(settings_object, "device_configurations");
  381|  2.74k|    if (NULL == device_configurations) {
  ------------------
  |  Branch (381:9): [True: 2.74k, False: 0]
  ------------------
  382|  2.74k|        return VK_SUCCESS;
  383|  2.74k|    }
  384|       |
  385|      0|    uint32_t device_configuration_count = loader_cJSON_GetArraySize(device_configurations);
  386|      0|    if (device_configuration_count == 0) {
  ------------------
  |  Branch (386:9): [True: 0, False: 0]
  ------------------
  387|      0|        loader_settings->device_configurations_active = true;
  388|      0|        return VK_SUCCESS;
  389|      0|    }
  390|       |
  391|      0|    loader_settings->device_configuration_count = device_configuration_count;
  392|       |
  393|      0|    loader_settings->device_configurations = loader_instance_heap_calloc(
  394|      0|        inst, sizeof(loader_settings_device_configuration) * device_configuration_count, VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE);
  395|      0|    if (NULL == loader_settings->device_configurations) {
  ------------------
  |  Branch (395:9): [True: 0, False: 0]
  ------------------
  396|      0|        res = VK_ERROR_OUT_OF_HOST_MEMORY;
  397|      0|        goto out;
  398|      0|    }
  399|       |
  400|      0|    cJSON* device = NULL;
  401|      0|    size_t i = 0;
  402|      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]
  |  |  ------------------
  ------------------
  403|      0|        if (device->type != cJSON_Object) {
  ------------------
  |  |  103|      0|#define cJSON_Object (1 << 6)
  ------------------
  |  Branch (403:13): [True: 0, False: 0]
  ------------------
  404|      0|            res = VK_ERROR_INITIALIZATION_FAILED;
  405|      0|            goto out;
  406|      0|        }
  407|      0|        res = parse_device_configuration(inst, device, &(loader_settings->device_configurations[i]));
  408|      0|        if (res == VK_ERROR_OUT_OF_HOST_MEMORY) {
  ------------------
  |  Branch (408:13): [True: 0, False: 0]
  ------------------
  409|      0|            goto out;
  410|      0|        } else if (res != VK_SUCCESS) {
  ------------------
  |  Branch (410:20): [True: 0, False: 0]
  ------------------
  411|       |            // Skip a malformed entry rather than discarding every device configuration in the file
  412|      0|            res = VK_SUCCESS;
  413|      0|            continue;
  414|      0|        }
  415|      0|        i++;
  416|      0|    }
  417|       |    // Only the first i entries were successfully parsed; the trailing entries are unpopulated
  418|      0|    loader_settings->device_configuration_count = (uint32_t)i;
  419|      0|    loader_settings->device_configurations_active = true;
  420|      0|out:
  421|      0|    if (res != VK_SUCCESS) {
  ------------------
  |  Branch (421:9): [True: 0, False: 0]
  ------------------
  422|      0|        if (loader_settings->device_configurations) {
  ------------------
  |  Branch (422:13): [True: 0, False: 0]
  ------------------
  423|      0|            for (size_t index = 0; index < loader_settings->device_configuration_count; index++) {
  ------------------
  |  Branch (423:36): [True: 0, False: 0]
  ------------------
  424|      0|                free_device_configuration(inst, &(loader_settings->device_configurations[index]));
  425|      0|            }
  426|      0|            loader_settings->device_configuration_count = 0;
  427|      0|            loader_instance_heap_free(inst, loader_settings->device_configurations);
  428|       |            loader_settings->device_configurations = NULL;
  429|      0|        }
  430|      0|    }
  431|      0|    return res;
  432|      0|}
check_if_settings_path_exists:
  439|  29.1k|                                                            const char* suffix, char** settings_file_path) {
  440|  29.1k|    if (NULL == base || NULL == suffix) {
  ------------------
  |  Branch (440:9): [True: 13.1k, False: 15.9k]
  |  Branch (440:25): [True: 0, False: 15.9k]
  ------------------
  441|  13.1k|        return VK_ERROR_INITIALIZATION_FAILED;
  442|  13.1k|    }
  443|       |
  444|  15.9k|    size_t base_len = strlen(base);
  445|  15.9k|    size_t suffix_len = strlen(suffix);
  446|       |
  447|  15.9k|    uint32_t start = 0;
  448|  15.9k|    uint32_t stop = 0;
  449|  26.7k|    while (base[start] != '\0' && start < base_len) {
  ------------------
  |  Branch (449:12): [True: 16.6k, False: 10.0k]
  |  Branch (449:35): [True: 16.6k, False: 0]
  ------------------
  450|       |        // Skip any path separators preceding this segment so they don't end up in the constructed path
  451|  17.3k|        while (base[start] != '\0' && start < base_len && base[start] == PATH_SEPARATOR) {
  ------------------
  |  |  154|  17.3k|#define PATH_SEPARATOR ':'
  ------------------
  |  Branch (451:16): [True: 17.3k, False: 0]
  |  Branch (451:39): [True: 17.3k, False: 0]
  |  Branch (451:59): [True: 701, False: 16.6k]
  ------------------
  452|    701|            start++;
  453|    701|        }
  454|  16.6k|        stop = start;
  455|   105k|        while (base[stop] != '\0' && stop < base_len && base[stop] != PATH_SEPARATOR) {
  ------------------
  |  |  154|  89.8k|#define PATH_SEPARATOR ':'
  ------------------
  |  Branch (455:16): [True: 89.8k, False: 15.9k]
  |  Branch (455:38): [True: 89.8k, False: 0]
  |  Branch (455:57): [True: 89.1k, False: 701]
  ------------------
  456|  89.1k|            stop++;
  457|  89.1k|        }
  458|       |
  459|  16.6k|        size_t segment_len = (stop - start);
  460|  16.6k|        if (segment_len == 0) {
  ------------------
  |  Branch (460:13): [True: 0, False: 16.6k]
  ------------------
  461|       |            // only path separators remained - no more segments
  462|      0|            break;
  463|      0|        }
  464|  16.6k|        size_t path_len = segment_len + suffix_len + 1;
  465|  16.6k|        *settings_file_path = loader_instance_heap_calloc(inst, path_len, VK_SYSTEM_ALLOCATION_SCOPE_COMMAND);
  466|  16.6k|        if (NULL == *settings_file_path) {
  ------------------
  |  Branch (466:13): [True: 0, False: 16.6k]
  ------------------
  467|      0|            return VK_ERROR_OUT_OF_HOST_MEMORY;
  468|      0|        }
  469|  16.6k|        loader_strncpy(*settings_file_path, path_len, base + start, segment_len);
  470|  16.6k|        loader_strncat(*settings_file_path, path_len, suffix, suffix_len);
  471|       |
  472|  16.6k|        if (loader_platform_file_exists(*settings_file_path)) {
  ------------------
  |  Branch (472:13): [True: 5.88k, False: 10.7k]
  ------------------
  473|  5.88k|            return VK_SUCCESS;
  474|  5.88k|        }
  475|  10.7k|        loader_instance_heap_free(inst, *settings_file_path);
  476|  10.7k|        *settings_file_path = NULL;
  477|  10.7k|        start = stop;
  478|  10.7k|    }
  479|       |
  480|  10.0k|    return VK_ERROR_INITIALIZATION_FAILED;
  481|  15.9k|}
get_unix_settings_path:
  484|  6.58k|VkResult get_unix_settings_path(const struct loader_instance* inst, char** settings_file_path) {
  485|       |    // First, get XDG env-vars we use. Don't need to worry about free'ing because on linux getenv is non-allocating
  486|  6.58k|    char* xdg_config_home = loader_secure_getenv("XDG_CONFIG_HOME", inst);
  487|  6.58k|    char* xdg_config_dirs = loader_secure_getenv("XDG_CONFIG_DIRS", inst);
  488|  6.58k|    char* xdg_data_home = loader_secure_getenv("XDG_DATA_HOME", inst);
  489|  6.58k|    char* xdg_data_dirs = loader_secure_getenv("XDG_DATA_DIRS", inst);
  490|       |
  491|       |    // Use fallback directories for xdg_config_dirs and xdg_data_dirs if they are NULL.
  492|  6.58k|#if !defined(__Fuchsia__) && !defined(__QNX__)
  493|  6.58k|    if (NULL == xdg_config_dirs || '\0' == xdg_config_dirs[0]) {
  ------------------
  |  Branch (493:9): [True: 6.58k, False: 0]
  |  Branch (493:36): [True: 0, False: 0]
  ------------------
  494|  6.58k|        xdg_config_dirs = FALLBACK_CONFIG_DIRS;
  495|  6.58k|    }
  496|  6.58k|#endif
  497|       |
  498|  6.58k|#if !defined(__Fuchsia__) && !defined(__QNX__)
  499|  6.58k|    if (NULL == xdg_data_dirs || '\0' == xdg_data_dirs[0]) {
  ------------------
  |  Branch (499:9): [True: 6.58k, False: 0]
  |  Branch (499:34): [True: 0, False: 0]
  ------------------
  500|  6.58k|        xdg_data_dirs = FALLBACK_DATA_DIRS;
  501|  6.58k|    }
  502|  6.58k|#endif
  503|       |
  504|  6.58k|    VkResult res = check_if_settings_path_exists(
  505|  6.58k|        inst, xdg_config_home, "/" VULKAN_DIR "/loader_settings.d/" VK_LOADER_SETTINGS_FILENAME, settings_file_path);
  ------------------
  |  |  145|  6.58k|#define VK_LOADER_SETTINGS_FILENAME "vk_loader_settings.json"
  ------------------
  506|  6.58k|    if (res == VK_SUCCESS || res == VK_ERROR_OUT_OF_HOST_MEMORY) {
  ------------------
  |  Branch (506:9): [True: 0, False: 6.58k]
  |  Branch (506:30): [True: 0, False: 6.58k]
  ------------------
  507|      0|        return res;
  508|      0|    }
  509|       |
  510|  6.58k|    res = check_if_settings_path_exists(inst, xdg_data_home, "/" VULKAN_DIR "/loader_settings.d/" VK_LOADER_SETTINGS_FILENAME,
  ------------------
  |  |  145|  6.58k|#define VK_LOADER_SETTINGS_FILENAME "vk_loader_settings.json"
  ------------------
  511|  6.58k|                                        settings_file_path);
  512|  6.58k|    if (res == VK_SUCCESS || res == VK_ERROR_OUT_OF_HOST_MEMORY) {
  ------------------
  |  Branch (512:9): [True: 0, False: 6.58k]
  |  Branch (512:30): [True: 0, False: 6.58k]
  ------------------
  513|      0|        return res;
  514|      0|    }
  515|       |
  516|       |    // Check home if either xdg_config_home or xdg_data_home wasn't set
  517|  6.58k|    char* home = loader_secure_getenv("HOME", inst);
  518|  6.58k|    if (home != NULL) {
  ------------------
  |  Branch (518:9): [True: 6.58k, False: 0]
  ------------------
  519|  6.58k|        if (NULL == xdg_config_home || '\0' == xdg_config_home[0]) {
  ------------------
  |  Branch (519:13): [True: 6.58k, False: 0]
  |  Branch (519:40): [True: 0, False: 0]
  ------------------
  520|  6.58k|            res = check_if_settings_path_exists(
  521|  6.58k|                inst, home, "/.config/" VULKAN_DIR "/loader_settings.d/" VK_LOADER_SETTINGS_FILENAME, settings_file_path);
  ------------------
  |  |  145|  6.58k|#define VK_LOADER_SETTINGS_FILENAME "vk_loader_settings.json"
  ------------------
  522|  6.58k|            if (res == VK_SUCCESS || res == VK_ERROR_OUT_OF_HOST_MEMORY) {
  ------------------
  |  Branch (522:17): [True: 0, False: 6.58k]
  |  Branch (522:38): [True: 0, False: 6.58k]
  ------------------
  523|      0|                return res;
  524|      0|            }
  525|  6.58k|        }
  526|  6.58k|        if (NULL == xdg_data_home || '\0' == xdg_data_home[0]) {
  ------------------
  |  Branch (526:13): [True: 6.58k, False: 0]
  |  Branch (526:38): [True: 0, False: 0]
  ------------------
  527|  6.58k|            res = check_if_settings_path_exists(
  528|  6.58k|                inst, home, "/.local/share/" VULKAN_DIR "/loader_settings.d/" VK_LOADER_SETTINGS_FILENAME, settings_file_path);
  ------------------
  |  |  145|  6.58k|#define VK_LOADER_SETTINGS_FILENAME "vk_loader_settings.json"
  ------------------
  529|  6.58k|            if (res == VK_SUCCESS || res == VK_ERROR_OUT_OF_HOST_MEMORY) {
  ------------------
  |  Branch (529:17): [True: 5.88k, False: 701]
  |  Branch (529:38): [True: 0, False: 701]
  ------------------
  530|  5.88k|                return res;
  531|  5.88k|            }
  532|  6.58k|        }
  533|  6.58k|    }
  534|       |
  535|    701|    res = check_if_settings_path_exists(inst, xdg_config_dirs, "/" VULKAN_DIR "/loader_settings.d/" VK_LOADER_SETTINGS_FILENAME,
  ------------------
  |  |  145|    701|#define VK_LOADER_SETTINGS_FILENAME "vk_loader_settings.json"
  ------------------
  536|    701|                                        settings_file_path);
  537|    701|    if (res == VK_SUCCESS || res == VK_ERROR_OUT_OF_HOST_MEMORY) {
  ------------------
  |  Branch (537:9): [True: 0, False: 701]
  |  Branch (537:30): [True: 0, False: 701]
  ------------------
  538|      0|        return res;
  539|      0|    }
  540|       |
  541|    701|    res = check_if_settings_path_exists(inst, SYSCONFDIR, "/" VULKAN_DIR "/loader_settings.d/" VK_LOADER_SETTINGS_FILENAME,
  ------------------
  |  |  145|    701|#define VK_LOADER_SETTINGS_FILENAME "vk_loader_settings.json"
  ------------------
  542|    701|                                        settings_file_path);
  543|    701|    if (res == VK_SUCCESS || res == VK_ERROR_OUT_OF_HOST_MEMORY) {
  ------------------
  |  Branch (543:9): [True: 0, False: 701]
  |  Branch (543:30): [True: 0, False: 701]
  ------------------
  544|      0|        return res;
  545|      0|    }
  546|    701|#if defined(EXTRASYSCONFDIR)
  547|       |
  548|    701|    res = check_if_settings_path_exists(inst, EXTRASYSCONFDIR, "/" VULKAN_DIR "/loader_settings.d/" VK_LOADER_SETTINGS_FILENAME,
  ------------------
  |  |  145|    701|#define VK_LOADER_SETTINGS_FILENAME "vk_loader_settings.json"
  ------------------
  549|    701|                                        settings_file_path);
  550|    701|    if (res == VK_SUCCESS || res == VK_ERROR_OUT_OF_HOST_MEMORY) {
  ------------------
  |  Branch (550:9): [True: 0, False: 701]
  |  Branch (550:30): [True: 0, False: 701]
  ------------------
  551|      0|        return res;
  552|      0|    }
  553|    701|#endif
  554|    701|    res = check_if_settings_path_exists(inst, xdg_data_dirs, "/" VULKAN_DIR "/loader_settings.d/" VK_LOADER_SETTINGS_FILENAME,
  ------------------
  |  |  145|    701|#define VK_LOADER_SETTINGS_FILENAME "vk_loader_settings.json"
  ------------------
  555|    701|                                        settings_file_path);
  556|    701|    if (res == VK_SUCCESS || res == VK_ERROR_OUT_OF_HOST_MEMORY) {
  ------------------
  |  Branch (556:9): [True: 0, False: 701]
  |  Branch (556:30): [True: 0, False: 701]
  ------------------
  557|      0|        return res;
  558|      0|    }
  559|       |
  560|    701|    return VK_ERROR_INITIALIZATION_FAILED;
  561|    701|}
log_settings:
  620|  2.35k|void log_settings(const struct loader_instance* inst, loader_settings* settings) {
  621|  2.35k|    if (settings == NULL) {
  ------------------
  |  Branch (621:9): [True: 0, False: 2.35k]
  ------------------
  622|      0|        return;
  623|      0|    }
  624|  2.35k|    loader_log(inst, VULKAN_LOADER_INFO_BIT, 0, "Using layer configurations found in loader settings from %s",
  625|  2.35k|               settings->settings_file_path);
  626|       |
  627|  2.35k|    char cmd_line_msg[64] = {0};
  628|  2.35k|    size_t cmd_line_size = sizeof(cmd_line_msg);
  629|       |
  630|  2.35k|    cmd_line_msg[0] = '\0';
  631|       |
  632|  2.35k|    generate_debug_flag_str(settings->debug_level, cmd_line_size, cmd_line_msg);
  633|  2.35k|    if (strlen(cmd_line_msg)) {
  ------------------
  |  Branch (633:9): [True: 144, False: 2.21k]
  ------------------
  634|    144|        loader_log(inst, VULKAN_LOADER_DEBUG_BIT, 0, "Loader Settings Filters for Logging to Standard Error: %s", cmd_line_msg);
  635|    144|    }
  636|  2.35k|    if (settings->layer_configurations_active) {
  ------------------
  |  Branch (636:9): [True: 2.28k, False: 75]
  ------------------
  637|  2.28k|        loader_log(inst, VULKAN_LOADER_DEBUG_BIT, 0, "Layer Configurations count = %d", settings->layer_configuration_count);
  638|  20.7k|        for (uint32_t i = 0; i < settings->layer_configuration_count; i++) {
  ------------------
  |  Branch (638:30): [True: 18.4k, False: 2.28k]
  ------------------
  639|  18.4k|            loader_log(inst, VULKAN_LOADER_DEBUG_BIT, 0, "---- Layer Configuration [%d] ----", i);
  640|  18.4k|            if (settings->layer_configurations[i].control != LOADER_SETTINGS_LAYER_UNORDERED_LAYER_LOCATION) {
  ------------------
  |  Branch (640:17): [True: 17.4k, False: 1.00k]
  ------------------
  641|  17.4k|                loader_log(inst, VULKAN_LOADER_DEBUG_BIT, 0, "Name: %s", settings->layer_configurations[i].name);
  642|  17.4k|                loader_log(inst, VULKAN_LOADER_DEBUG_BIT, 0, "Path: %s", settings->layer_configurations[i].path);
  643|  17.4k|                loader_log(inst, VULKAN_LOADER_DEBUG_BIT, 0, "Layer Type: %s",
  644|  17.4k|                           settings->layer_configurations[i].treat_as_implicit_manifest ? "Implicit" : "Explicit");
  ------------------
  |  Branch (644:28): [True: 149, False: 17.3k]
  ------------------
  645|  17.4k|            }
  646|  18.4k|            loader_log(inst, VULKAN_LOADER_DEBUG_BIT, 0, "Control: %s",
  647|  18.4k|                       loader_settings_layer_control_to_string(settings->layer_configurations[i].control));
  648|  18.4k|        }
  649|  2.28k|    }
  650|  2.35k|    if (settings->additional_driver_count > 0) {
  ------------------
  |  Branch (650:9): [True: 0, False: 2.35k]
  ------------------
  651|      0|        loader_log(inst, VULKAN_LOADER_DEBUG_BIT, 0, "----");
  652|      0|        loader_log(inst, VULKAN_LOADER_DEBUG_BIT, 0, "Use Additional Drivers Exclusively = %s",
  653|      0|                   settings->additional_drivers_use_exclusively ? "true" : "false");
  ------------------
  |  Branch (653:20): [True: 0, False: 0]
  ------------------
  654|      0|        loader_log(inst, VULKAN_LOADER_DEBUG_BIT, 0, "Additional Driver Configurations count = %d",
  655|      0|                   settings->additional_driver_count);
  656|      0|        for (uint32_t i = 0; i < settings->additional_driver_count; i++) {
  ------------------
  |  Branch (656:30): [True: 0, False: 0]
  ------------------
  657|      0|            loader_log(inst, VULKAN_LOADER_DEBUG_BIT, 0, "---- Driver Configuration [%d] ----", i);
  658|      0|            loader_log(inst, VULKAN_LOADER_DEBUG_BIT, 0, "Path: %s", settings->additional_drivers[i].path);
  659|      0|        }
  660|      0|    }
  661|  2.35k|    if (settings->device_configurations_active) {
  ------------------
  |  Branch (661:9): [True: 0, False: 2.35k]
  ------------------
  662|      0|        loader_log(inst, VULKAN_LOADER_DEBUG_BIT, 0, "----");
  663|      0|        loader_log(inst, VULKAN_LOADER_DEBUG_BIT, 0, "Device Configurations count = %d", settings->device_configuration_count);
  664|      0|        for (uint32_t i = 0; i < settings->device_configuration_count; i++) {
  ------------------
  |  Branch (664:30): [True: 0, False: 0]
  ------------------
  665|      0|            loader_log(inst, VULKAN_LOADER_DEBUG_BIT, 0, "---- Device Configuration [%d] ----", i);
  666|      0|            char device_uuid_str[UUID_STR_LEN] = {0};
  667|      0|            loader_log_generate_uuid_string(settings->device_configurations[i].deviceUUID, device_uuid_str);
  668|      0|            char driver_uuid_str[UUID_STR_LEN] = {0};
  669|      0|            loader_log_generate_uuid_string(settings->device_configurations[i].driverUUID, driver_uuid_str);
  670|      0|            loader_log(inst, VULKAN_LOADER_DEBUG_BIT, 0, "deviceUUID: %s", device_uuid_str);
  671|      0|            loader_log(inst, VULKAN_LOADER_DEBUG_BIT, 0, "driverUUID: %s", driver_uuid_str);
  672|      0|            loader_log(inst, VULKAN_LOADER_DEBUG_BIT, 0, "driverVersion: %u", settings->device_configurations[i].driverVersion);
  673|      0|            if ('\0' != settings->device_configurations[i].deviceName[0]) {
  ------------------
  |  Branch (673:17): [True: 0, False: 0]
  ------------------
  674|      0|                loader_log(inst, VULKAN_LOADER_DEBUG_BIT, 0, "deviceName: %s", settings->device_configurations[i].deviceName);
  675|      0|            }
  676|      0|            if ('\0' != settings->device_configurations[i].driverName[0]) {
  ------------------
  |  Branch (676:17): [True: 0, False: 0]
  ------------------
  677|      0|                loader_log(inst, VULKAN_LOADER_DEBUG_BIT, 0, "driverName: %s", settings->device_configurations[i].driverName);
  678|      0|            }
  679|      0|        }
  680|      0|    }
  681|  2.35k|    loader_log(inst, VULKAN_LOADER_DEBUG_BIT, 0, "---------------------------------");
  682|  2.35k|}
get_loader_settings:
  687|  6.58k|VkResult get_loader_settings(const struct loader_instance* inst, loader_settings* loader_settings) {
  688|  6.58k|    VkResult res = VK_SUCCESS;
  689|  6.58k|    cJSON* json = NULL;
  690|  6.58k|    char* file_format_version_string = NULL;
  691|  6.58k|    char* settings_file_path = NULL;
  692|       |#if defined(WIN32)
  693|       |    res = windows_get_loader_settings_file_path(inst, &settings_file_path);
  694|       |    if (res != VK_SUCCESS) {
  695|       |        loader_log(inst, VULKAN_LOADER_INFO_BIT, 0,
  696|       |                   "No valid vk_loader_settings.json file found, no loader settings will be active");
  697|       |        goto out;
  698|       |    }
  699|       |
  700|       |#elif COMMON_UNIX_PLATFORMS
  701|       |    res = get_unix_settings_path(inst, &settings_file_path);
  702|  6.58k|    if (res != VK_SUCCESS) {
  ------------------
  |  Branch (702:9): [True: 701, False: 5.88k]
  ------------------
  703|    701|        loader_log(inst, VULKAN_LOADER_INFO_BIT, 0,
  704|    701|                   "No valid vk_loader_settings.json file found, no loader settings will be active");
  705|    701|        goto out;
  706|    701|    }
  707|       |#else
  708|       |#warning "Unsupported platform - must specify platform specific location for vk_loader_settings.json"
  709|       |#endif
  710|       |
  711|  5.88k|    res = loader_get_json(inst, settings_file_path, &json);
  712|       |    // Make sure sure the top level json value is an object
  713|  5.88k|    if (res != VK_SUCCESS || NULL == json || json->type != cJSON_Object) {
  ------------------
  |  |  103|  3.34k|#define cJSON_Object (1 << 6)
  ------------------
  |  Branch (713:9): [True: 77, False: 5.81k]
  |  Branch (713:30): [True: 2.47k, False: 3.34k]
  |  Branch (713:46): [True: 153, False: 3.18k]
  ------------------
  714|  2.70k|        goto out;
  715|  2.70k|    }
  716|       |
  717|  3.18k|    res = loader_parse_json_string(json, "file_format_version", &file_format_version_string);
  718|  3.18k|    if (res != VK_SUCCESS) {
  ------------------
  |  Branch (718:9): [True: 19, False: 3.16k]
  ------------------
  719|     19|        if (res != VK_ERROR_OUT_OF_HOST_MEMORY) {
  ------------------
  |  Branch (719:13): [True: 19, False: 0]
  ------------------
  720|     19|            loader_log(
  721|     19|                inst, VULKAN_LOADER_DEBUG_BIT, 0,
  722|     19|                "Loader settings file from %s missing required field file_format_version - no loader settings will be active",
  723|     19|                settings_file_path);
  724|     19|        }
  725|     19|        goto out;
  726|     19|    }
  727|       |
  728|       |    // Because the file may contain either a "settings_array" or a single "settings" object, we need to create a cJSON so that we
  729|       |    // can iterate on both cases with common code
  730|  3.16k|    cJSON settings_iter_parent = {0};
  731|       |
  732|  3.16k|    cJSON* settings_array = loader_cJSON_GetObjectItem(json, "settings_array");
  733|  3.16k|    cJSON* single_settings_object = loader_cJSON_GetObjectItem(json, "settings");
  734|  3.16k|    if (NULL != settings_array) {
  ------------------
  |  Branch (734:9): [True: 2.79k, False: 377]
  ------------------
  735|  2.79k|        memcpy(&settings_iter_parent, settings_array, sizeof(cJSON));
  736|  2.79k|    } else if (NULL != single_settings_object) {
  ------------------
  |  Branch (736:16): [True: 45, False: 332]
  ------------------
  737|     45|        settings_iter_parent.child = single_settings_object;
  738|    332|    } else {
  739|    332|        loader_log(inst, VULKAN_LOADER_DEBUG_BIT, 0,
  740|    332|                   "Loader settings file from %s missing required settings objects: Either one of the \"settings\" or "
  741|    332|                   "\"settings_array\" objects must be present - no loader settings will be active",
  742|    332|                   settings_file_path);
  743|    332|        res = VK_ERROR_INITIALIZATION_FAILED;
  744|    332|        goto out;
  745|    332|    }
  746|       |
  747|       |    // Corresponds to the settings object that has no app keys
  748|  2.83k|    cJSON* global_settings = NULL;
  749|       |    // Corresponds to the settings object which has a matching app key
  750|  2.83k|    cJSON* settings_to_use = NULL;
  751|       |
  752|  2.83k|    char current_process_path[1024];
  753|  2.83k|    bool valid_exe_path = NULL != loader_platform_executable_path(current_process_path, 1024);
  754|       |
  755|  2.83k|    cJSON* settings_object_iter = NULL;
  756|  3.35k|    cJSON_ArrayForEach(settings_object_iter, &settings_iter_parent) {
  ------------------
  |  |  213|  6.13k|    for (element = (array != NULL) ? (array)->child : NULL; element != NULL; element = element->next)
  |  |  ------------------
  |  |  |  Branch (213:20): [True: 2.83k, Folded]
  |  |  |  Branch (213:61): [True: 3.35k, False: 2.78k]
  |  |  ------------------
  ------------------
  757|  3.35k|        if (settings_object_iter->type != cJSON_Object) {
  ------------------
  |  |  103|  3.35k|#define cJSON_Object (1 << 6)
  ------------------
  |  Branch (757:13): [True: 57, False: 3.29k]
  ------------------
  758|     57|            loader_log(inst, VULKAN_LOADER_DEBUG_BIT, 0,
  759|     57|                       "Loader settings file from %s has a settings element that is not an object", settings_file_path);
  760|     57|            break;
  761|     57|        }
  762|       |
  763|  3.29k|        cJSON* app_keys = loader_cJSON_GetObjectItem(settings_object_iter, "app_keys");
  764|  3.29k|        if (NULL == app_keys) {
  ------------------
  |  Branch (764:13): [True: 3.11k, False: 180]
  ------------------
  765|       |            // use the first 'global' settings that has no app keys as the global one
  766|  3.11k|            if (global_settings == NULL) {
  ------------------
  |  Branch (766:17): [True: 2.74k, False: 370]
  ------------------
  767|  2.74k|                global_settings = settings_object_iter;
  768|  2.74k|            }
  769|  3.11k|            continue;
  770|  3.11k|        }
  771|       |        // No sense iterating if we couldn't get the executable path
  772|    180|        if (!valid_exe_path) {
  ------------------
  |  Branch (772:13): [True: 0, False: 180]
  ------------------
  773|      0|            break;
  774|      0|        }
  775|    180|        cJSON* app_key = NULL;
  776|    582|        cJSON_ArrayForEach(app_key, app_keys) {
  ------------------
  |  |  213|    762|    for (element = (array != NULL) ? (array)->child : NULL; element != NULL; element = element->next)
  |  |  ------------------
  |  |  |  Branch (213:20): [True: 180, False: 0]
  |  |  |  Branch (213:61): [True: 582, False: 180]
  |  |  ------------------
  ------------------
  777|    582|            char* app_key_str = loader_cJSON_GetStringValue(app_key);
  778|    582|            if (app_key_str && strcmp(current_process_path, app_key_str) == 0) {
  ------------------
  |  Branch (778:17): [True: 233, False: 349]
  |  Branch (778:32): [True: 0, False: 233]
  ------------------
  779|      0|                settings_to_use = settings_object_iter;
  780|      0|                break;
  781|      0|            }
  782|    582|        }
  783|       |
  784|       |        // Break if we have found a matching current_process_path
  785|    180|        if (NULL != settings_to_use) {
  ------------------
  |  Branch (785:13): [True: 0, False: 180]
  ------------------
  786|      0|            break;
  787|      0|        }
  788|    180|    }
  789|       |
  790|       |    // No app specific settings match - either use global settings or exit
  791|  2.83k|    if (settings_to_use == NULL) {
  ------------------
  |  Branch (791:9): [True: 2.83k, False: 0]
  ------------------
  792|  2.83k|        if (global_settings == NULL) {
  ------------------
  |  Branch (792:13): [True: 92, False: 2.74k]
  ------------------
  793|     92|            loader_log(inst, VULKAN_LOADER_DEBUG_BIT, 0,
  794|     92|                       "Loader settings file from %s missing global settings and none of the app specific settings matched the "
  795|     92|                       "current application - no loader settings will be active",
  796|     92|                       settings_file_path);
  797|     92|            goto out;  // No global settings were found - exit
  798|  2.74k|        } else {
  799|  2.74k|            settings_to_use = global_settings;  // Global settings are present - use it
  800|  2.74k|        }
  801|  2.83k|    }
  802|       |
  803|       |    // optional
  804|  2.74k|    cJSON* stderr_filter = loader_cJSON_GetObjectItem(settings_to_use, "stderr_log");
  805|  2.74k|    if (NULL != stderr_filter) {
  ------------------
  |  Branch (805:9): [True: 341, False: 2.40k]
  ------------------
  806|    341|        struct loader_string_list stderr_log = {0};
  807|    341|        VkResult stderr_log_result = VK_SUCCESS;
  808|    341|        stderr_log_result = loader_parse_json_array_of_strings(inst, settings_to_use, "stderr_log", &stderr_log);
  809|    341|        if (VK_ERROR_OUT_OF_HOST_MEMORY == stderr_log_result) {
  ------------------
  |  Branch (809:13): [True: 0, False: 341]
  ------------------
  810|      0|            res = VK_ERROR_OUT_OF_HOST_MEMORY;
  811|      0|            goto out;
  812|      0|        }
  813|       |        // NOLINTNEXTLINE(clang-analyzer-optin.core.EnumCastOutOfRange) - 0xFF is a valid bitwise-OR of all flags (the "all" filter)
  814|    341|        loader_settings->debug_level = parse_log_filters_from_strings(&stderr_log);
  815|    341|        free_string_list(inst, &stderr_log);
  816|    341|    }
  817|       |
  818|       |    // optional
  819|  2.74k|    cJSON* logs_to_use = loader_cJSON_GetObjectItem(settings_to_use, "log_locations");
  820|  2.74k|    if (NULL != logs_to_use) {
  ------------------
  |  Branch (820:9): [True: 79, False: 2.66k]
  ------------------
  821|     79|        cJSON* log_element = NULL;
  822|    324|        cJSON_ArrayForEach(log_element, logs_to_use) {
  ------------------
  |  |  213|    403|    for (element = (array != NULL) ? (array)->child : NULL; element != NULL; element = element->next)
  |  |  ------------------
  |  |  |  Branch (213:20): [True: 79, False: 0]
  |  |  |  Branch (213:61): [True: 324, False: 79]
  |  |  ------------------
  ------------------
  823|       |            // bool is_valid = true;
  824|    324|            struct loader_string_list log_destinations = {0};
  825|    324|            VkResult parse_dest_res = loader_parse_json_array_of_strings(inst, log_element, "destinations", &log_destinations);
  826|    324|            if (parse_dest_res != VK_SUCCESS) {
  ------------------
  |  Branch (826:17): [True: 321, False: 3]
  ------------------
  827|       |                // is_valid = false;
  828|    321|            }
  829|    324|            free_string_list(inst, &log_destinations);
  830|    324|            struct loader_string_list log_filters = {0};
  831|    324|            VkResult parse_filters_res = loader_parse_json_array_of_strings(inst, log_element, "filters", &log_filters);
  832|    324|            if (parse_filters_res != VK_SUCCESS) {
  ------------------
  |  Branch (832:17): [True: 313, False: 11]
  ------------------
  833|       |                // is_valid = false;
  834|    313|            }
  835|    324|            free_string_list(inst, &log_filters);
  836|    324|        }
  837|     79|    }
  838|       |
  839|  2.74k|    VkResult layer_configurations_res = parse_layer_configurations(inst, settings_to_use, loader_settings);
  840|  2.74k|    if (VK_ERROR_OUT_OF_HOST_MEMORY == layer_configurations_res) {
  ------------------
  |  Branch (840:9): [True: 0, False: 2.74k]
  ------------------
  841|      0|        res = layer_configurations_res;
  842|      0|        goto out;
  843|      0|    }
  844|       |
  845|       |    // Determine if there exists a layer configuration indicating where to put layers not contained in the settings file
  846|       |    // LOADER_SETTINGS_LAYER_UNORDERED_LAYER_LOCATION
  847|  17.2k|    for (uint32_t i = 0; i < loader_settings->layer_configuration_count; i++) {
  ------------------
  |  Branch (847:26): [True: 15.0k, False: 2.14k]
  ------------------
  848|  15.0k|        if (loader_settings->layer_configurations[i].control == LOADER_SETTINGS_LAYER_UNORDERED_LAYER_LOCATION) {
  ------------------
  |  Branch (848:13): [True: 598, False: 14.4k]
  ------------------
  849|    598|            loader_settings->has_unordered_layer_location = true;
  850|    598|            break;
  851|    598|        }
  852|  15.0k|    }
  853|       |
  854|  2.74k|    VkResult additional_drivers_res = parse_additional_drivers(inst, settings_to_use, loader_settings);
  855|  2.74k|    if (VK_ERROR_OUT_OF_HOST_MEMORY == additional_drivers_res) {
  ------------------
  |  Branch (855:9): [True: 0, False: 2.74k]
  ------------------
  856|      0|        res = additional_drivers_res;
  857|      0|        goto out;
  858|      0|    }
  859|       |
  860|  2.74k|    VkResult device_configurations_res = parse_device_configurations(inst, settings_to_use, loader_settings);
  861|  2.74k|    if (VK_ERROR_OUT_OF_HOST_MEMORY == device_configurations_res) {
  ------------------
  |  Branch (861:9): [True: 0, False: 2.74k]
  ------------------
  862|      0|        res = device_configurations_res;
  863|      0|        goto out;
  864|      0|    }
  865|       |
  866|       |    // Only consider the settings active if there is at least one "setting" active.
  867|       |    // Those are either logging, layers, additional_drivers, or device_configurations.
  868|  2.74k|    if (loader_settings->debug_level != 0 || loader_settings->layer_configurations_active ||
  ------------------
  |  Branch (868:9): [True: 146, False: 2.59k]
  |  Branch (868:46): [True: 2.21k, False: 388]
  ------------------
  869|  2.35k|        loader_settings->additional_driver_count != 0 || loader_settings->device_configurations_active) {
  ------------------
  |  Branch (869:9): [True: 0, False: 388]
  |  Branch (869:58): [True: 0, False: 388]
  ------------------
  870|  2.35k|        loader_settings->settings_file_path = settings_file_path;
  871|  2.35k|        settings_file_path = NULL;
  872|  2.35k|        loader_settings->settings_active = true;
  873|  2.35k|    } else {
  874|    388|        loader_log(inst, VULKAN_LOADER_INFO_BIT, 0,
  875|    388|                   "vk_loader_settings.json file found at \"%s\" but did not contain any valid settings.", settings_file_path);
  876|    388|    }
  877|  6.58k|out:
  878|  6.58k|    if (NULL != json) {
  ------------------
  |  Branch (878:9): [True: 3.34k, False: 3.24k]
  ------------------
  879|  3.34k|        loader_cJSON_Delete(json);
  880|  3.34k|    }
  881|       |
  882|  6.58k|    loader_instance_heap_free(inst, settings_file_path);
  883|       |
  884|  6.58k|    loader_instance_heap_free(inst, file_format_version_string);
  885|  6.58k|    return res;
  886|  2.74k|}
init_global_loader_settings:
  907|      2|void init_global_loader_settings(void) {
  908|      2|    loader_platform_thread_create_mutex(&global_loader_settings_lock);
  909|       |    // Free out the global settings in case the process was loaded & unloaded
  910|       |    free_loader_settings(NULL, &global_loader_settings);
  911|      2|}
get_current_settings_and_lock:
  927|  6.59k|const loader_settings* get_current_settings_and_lock(const struct loader_instance* inst) {
  928|  6.59k|    if (inst) {
  ------------------
  |  Branch (928:9): [True: 6.59k, False: 0]
  ------------------
  929|  6.59k|        return &inst->settings;
  930|  6.59k|    }
  931|      0|    loader_platform_thread_lock_mutex(&global_loader_settings_lock);
  932|      0|    return &global_loader_settings;
  933|  6.59k|}
release_current_settings_lock:
  935|  6.59k|void release_current_settings_lock(const struct loader_instance* inst) {
  936|  6.59k|    if (inst == NULL) {
  ------------------
  |  Branch (936:9): [True: 0, False: 6.59k]
  ------------------
  937|      0|        loader_platform_thread_unlock_mutex(&global_loader_settings_lock);
  938|      0|    }
  939|  6.59k|}
get_settings_layers:
  942|  6.58k|                                                  bool* should_search_for_other_layers) {
  943|  6.58k|    VkResult res = VK_SUCCESS;
  944|  6.58k|    *should_search_for_other_layers = true;  // default to true
  945|       |
  946|  6.58k|    const loader_settings* settings = get_current_settings_and_lock(inst);
  947|       |
  948|  6.58k|    if (NULL == settings || !settings->settings_active || !settings->layer_configurations_active) {
  ------------------
  |  Branch (948:9): [True: 0, False: 6.58k]
  |  Branch (948:29): [True: 4.23k, False: 2.35k]
  |  Branch (948:59): [True: 75, False: 2.28k]
  ------------------
  949|  4.30k|        goto out;
  950|  4.30k|    }
  951|       |
  952|       |    // Assume the list doesn't contain LOADER_SETTINGS_LAYER_UNORDERED_LAYER_LOCATION at first
  953|  2.28k|    *should_search_for_other_layers = false;
  954|       |
  955|  20.7k|    for (uint32_t i = 0; i < settings->layer_configuration_count; i++) {
  ------------------
  |  Branch (955:26): [True: 18.4k, False: 2.28k]
  ------------------
  956|  18.4k|        loader_settings_layer_configuration* layer_config = &settings->layer_configurations[i];
  957|       |
  958|       |        // If we encountered a layer that should be forced off, we add it to the settings_layers list but only
  959|       |        // with the data required to compare it with layers not in the settings file (aka name and manifest path)
  960|  18.4k|        if (layer_config->control == LOADER_SETTINGS_LAYER_CONTROL_OFF) {
  ------------------
  |  Branch (960:13): [True: 960, False: 17.5k]
  ------------------
  961|    960|            struct loader_layer_properties props = {0};
  962|    960|            props.settings_control_value = LOADER_SETTINGS_LAYER_CONTROL_OFF;
  963|    960|            loader_strncpy(props.info.layerName, VK_MAX_EXTENSION_NAME_SIZE, layer_config->name, VK_MAX_EXTENSION_NAME_SIZE);
  964|    960|            props.info.layerName[VK_MAX_EXTENSION_NAME_SIZE - 1] = '\0';
  965|    960|            res = loader_copy_to_new_str(inst, layer_config->path, &props.manifest_file_name);
  966|    960|            if (VK_ERROR_OUT_OF_HOST_MEMORY == res) {
  ------------------
  |  Branch (966:17): [True: 0, False: 960]
  ------------------
  967|      0|                goto out;
  968|      0|            }
  969|    960|            res = loader_append_layer_property(inst, settings_layers, &props);
  970|    960|            if (VK_ERROR_OUT_OF_HOST_MEMORY == res) {
  ------------------
  |  Branch (970:17): [True: 0, False: 960]
  ------------------
  971|      0|                loader_free_layer_properties(inst, &props);
  972|      0|                goto out;
  973|      0|            }
  974|    960|            continue;
  975|    960|        }
  976|       |
  977|       |        // The special layer location that indicates where unordered layers should go only should have the
  978|       |        // settings_control_value set - everything else should be NULL
  979|  17.5k|        if (layer_config->control == LOADER_SETTINGS_LAYER_UNORDERED_LAYER_LOCATION) {
  ------------------
  |  Branch (979:13): [True: 1.00k, False: 16.5k]
  ------------------
  980|  1.00k|            struct loader_layer_properties props = {0};
  981|  1.00k|            props.settings_control_value = LOADER_SETTINGS_LAYER_UNORDERED_LAYER_LOCATION;
  982|  1.00k|            res = loader_append_layer_property(inst, settings_layers, &props);
  983|  1.00k|            if (VK_ERROR_OUT_OF_HOST_MEMORY == res) {
  ------------------
  |  Branch (983:17): [True: 0, False: 1.00k]
  ------------------
  984|      0|                loader_free_layer_properties(inst, &props);
  985|      0|                goto out;
  986|      0|            }
  987|  1.00k|            *should_search_for_other_layers = true;
  988|  1.00k|            continue;
  989|  1.00k|        }
  990|       |
  991|  16.5k|        if (layer_config->path == NULL) {
  ------------------
  |  Branch (991:13): [True: 0, False: 16.5k]
  ------------------
  992|      0|            continue;
  993|      0|        }
  994|       |
  995|  16.5k|        if (!is_json(layer_config->path, strlen(layer_config->path))) {
  ------------------
  |  Branch (995:13): [True: 5.74k, False: 10.7k]
  ------------------
  996|  5.74k|            continue;
  997|  5.74k|        }
  998|       |
  999|  10.7k|        cJSON* json = NULL;
 1000|  10.7k|        VkResult local_res = loader_get_json(inst, layer_config->path, &json);
 1001|  10.7k|        if (VK_ERROR_OUT_OF_HOST_MEMORY == local_res) {
  ------------------
  |  Branch (1001:13): [True: 0, False: 10.7k]
  ------------------
 1002|      0|            res = VK_ERROR_OUT_OF_HOST_MEMORY;
 1003|      0|            goto out;
 1004|  10.7k|        } else if (VK_SUCCESS != local_res || NULL == json) {
  ------------------
  |  Branch (1004:20): [True: 507, False: 10.2k]
  |  Branch (1004:47): [True: 4.04k, False: 6.21k]
  ------------------
 1005|  4.55k|            continue;
 1006|  4.55k|        }
 1007|       |
 1008|       |        // Makes it possible to know if a new layer was added or not, since the only return value is VkResult
 1009|  6.21k|        uint32_t count_before_adding = settings_layers->count;
 1010|       |
 1011|  6.21k|        local_res =
 1012|  6.21k|            loader_add_layer_properties(inst, settings_layers, json, layer_config->treat_as_implicit_manifest, layer_config->path);
 1013|  6.21k|        loader_cJSON_Delete(json);
 1014|       |
 1015|       |        // If the error is anything other than out of memory we still want to try to load the other layers
 1016|  6.21k|        if (VK_ERROR_OUT_OF_HOST_MEMORY == local_res) {
  ------------------
  |  Branch (1016:13): [True: 0, False: 6.21k]
  ------------------
 1017|      0|            res = VK_ERROR_OUT_OF_HOST_MEMORY;
 1018|      0|            goto out;
 1019|  6.21k|        } else if (local_res != VK_SUCCESS || count_before_adding == settings_layers->count) {
  ------------------
  |  Branch (1019:20): [True: 4.06k, False: 2.14k]
  |  Branch (1019:47): [True: 0, False: 2.14k]
  ------------------
 1020|       |            // Indicates something was wrong with the layer, can't add it to the list
 1021|  4.06k|            continue;
 1022|  4.06k|        }
 1023|       |
 1024|  33.1k|        for (uint32_t j = count_before_adding; j < settings_layers->count; j++) {
  ------------------
  |  Branch (1024:48): [True: 31.0k, False: 2.14k]
  ------------------
 1025|  31.0k|            struct loader_layer_properties* newly_added_layer = &settings_layers->list[j];
 1026|  31.0k|            newly_added_layer->settings_control_value = layer_config->control;
 1027|       |            // If the manifest file found has a name that differs from the one in the settings, remove this layer from
 1028|       |            // consideration
 1029|  31.0k|            if (strncmp(newly_added_layer->info.layerName, layer_config->name, VK_MAX_EXTENSION_NAME_SIZE) != 0) {
  ------------------
  |  Branch (1029:17): [True: 9.69k, False: 21.3k]
  ------------------
 1030|  9.69k|                loader_remove_layer_in_list(inst, settings_layers, j);
 1031|  9.69k|                j--;
 1032|  9.69k|                continue;
 1033|  9.69k|            }
 1034|  31.0k|            bool should_remove = false;
 1035|       |            // Make sure the layer isn't already in the list
 1036|  21.1M|            for (uint32_t k = 0; k < j; k++) {
  ------------------
  |  Branch (1036:34): [True: 21.1M, False: 20.1k]
  ------------------
 1037|  21.1M|                if (0 == strncmp(settings_layers->list[k].info.layerName, newly_added_layer->info.layerName,
  ------------------
  |  Branch (1037:21): [True: 20.4M, False: 671k]
  ------------------
 1038|  21.1M|                                 VK_MAX_EXTENSION_NAME_SIZE)) {
 1039|  20.4M|                    if (0 == (newly_added_layer->type_flags & VK_LAYER_TYPE_FLAG_META_LAYER) &&
  ------------------
  |  Branch (1039:25): [True: 126k, False: 20.3M]
  ------------------
 1040|   126k|                        settings_layers->list[k].lib_name != NULL && newly_added_layer->lib_name != NULL &&
  ------------------
  |  Branch (1040:25): [True: 46.4k, False: 80.1k]
  |  Branch (1040:70): [True: 46.4k, False: 0]
  ------------------
 1041|  46.4k|                        strcmp(settings_layers->list[k].lib_name, newly_added_layer->lib_name) == 0) {
  ------------------
  |  Branch (1041:25): [True: 1.17k, False: 45.2k]
  ------------------
 1042|  1.17k|                        should_remove = true;
 1043|  1.17k|                        break;
 1044|  1.17k|                    }
 1045|  20.4M|                }
 1046|  21.1M|            }
 1047|  21.3k|            if (should_remove) {
  ------------------
  |  Branch (1047:17): [True: 1.17k, False: 20.1k]
  ------------------
 1048|  1.17k|                loader_remove_layer_in_list(inst, settings_layers, j);
 1049|  1.17k|                j--;
 1050|  1.17k|            }
 1051|  21.3k|        }
 1052|  2.14k|    }
 1053|       |
 1054|  6.58k|out:
 1055|  6.58k|    release_current_settings_lock(inst);
 1056|  6.58k|    return res;
 1057|  2.28k|}
check_if_layer_is_in_list:
 1068|  30.5k|                               bool consider_lib_path) {
 1069|       |    // If the layer is a meta layer, just check against the name
 1070|   198k|    for (uint32_t i = 0; i < layer_list->count; i++) {
  ------------------
  |  Branch (1070:26): [True: 193k, False: 5.36k]
  ------------------
 1071|   193k|        if (0 == strncmp(layer_list->list[i].info.layerName, layer_property->info.layerName, VK_MAX_EXTENSION_NAME_SIZE)) {
  ------------------
  |  Branch (1071:13): [True: 34.5k, False: 158k]
  ------------------
 1072|  34.5k|            if (layer_list->list[i].settings_control_value == LOADER_SETTINGS_LAYER_CONTROL_OFF) {
  ------------------
  |  Branch (1072:17): [True: 448, False: 34.1k]
  ------------------
 1073|    448|                return true;
 1074|    448|            }
 1075|  34.1k|            if (VK_LAYER_TYPE_FLAG_META_LAYER == (layer_property->type_flags & VK_LAYER_TYPE_FLAG_META_LAYER)) {
  ------------------
  |  Branch (1075:17): [True: 2.72k, False: 31.4k]
  ------------------
 1076|  2.72k|                return true;
 1077|  2.72k|            }
 1078|  31.4k|            if (!consider_lib_path) {
  ------------------
  |  Branch (1078:17): [True: 5.59k, False: 25.8k]
  ------------------
 1079|  5.59k|                return true;
 1080|  5.59k|            }
 1081|  25.8k|            if (layer_list->list[i].lib_name && layer_property->lib_name) {
  ------------------
  |  Branch (1081:17): [True: 22.3k, False: 3.41k]
  |  Branch (1081:49): [True: 16.3k, False: 6.00k]
  ------------------
 1082|  16.3k|                return strcmp(layer_list->list[i].lib_name, layer_property->lib_name) == 0;
 1083|  16.3k|            }
 1084|  25.8k|        }
 1085|   193k|    }
 1086|  5.36k|    return false;
 1087|  30.5k|}
combine_settings_layers_with_regular_layers:
 1091|  4.90k|                                                     struct loader_layer_list* output_layers) {
 1092|  4.90k|    VkResult res = VK_SUCCESS;
 1093|  4.90k|    bool has_unordered_layer_location = false;
 1094|  4.90k|    uint32_t unordered_layer_location_index = 0;
 1095|       |    // Location to put layers that aren't known to the settings file
 1096|       |    // Find it here so we dont have to pass in a loader_settings struct
 1097|  65.1k|    for (uint32_t i = 0; i < settings_layers->count; i++) {
  ------------------
  |  Branch (1097:26): [True: 60.8k, False: 4.30k]
  ------------------
 1098|  60.8k|        if (settings_layers->list[i].settings_control_value == LOADER_SETTINGS_LAYER_UNORDERED_LAYER_LOCATION) {
  ------------------
  |  Branch (1098:13): [True: 598, False: 60.2k]
  ------------------
 1099|    598|            has_unordered_layer_location = true;
 1100|    598|            unordered_layer_location_index = i;
 1101|    598|            break;
 1102|    598|        }
 1103|  60.8k|    }
 1104|       |
 1105|  4.90k|    if (settings_layers->count == 0 && regular_layers->count == 0) {
  ------------------
  |  Branch (1105:9): [True: 4.30k, False: 598]
  |  Branch (1105:40): [True: 3.33k, False: 975]
  ------------------
 1106|       |        // No layers to combine
 1107|  3.33k|        goto out;
 1108|  3.33k|    } else if (settings_layers->count == 0) {
  ------------------
  |  Branch (1108:16): [True: 975, False: 598]
  ------------------
 1109|       |        // No settings layers - just copy regular to output_layers - memset regular layers to prevent double frees
 1110|    975|        *output_layers = *regular_layers;
 1111|    975|        memset(regular_layers, 0, sizeof(struct loader_layer_list));
 1112|    975|        goto out;
 1113|    975|    } else if (regular_layers->count == 0 || !has_unordered_layer_location) {
  ------------------
  |  Branch (1113:16): [True: 257, False: 341]
  |  Branch (1113:46): [True: 0, False: 341]
  ------------------
 1114|       |        // No regular layers or has_unordered_layer_location is false - just copy settings to output_layers -
 1115|       |        // memset settings layers to prevent double frees
 1116|    257|        *output_layers = *settings_layers;
 1117|    257|        memset(settings_layers, 0, sizeof(struct loader_layer_list));
 1118|    257|        goto out;
 1119|    257|    }
 1120|       |
 1121|    341|    res = loader_init_generic_list(inst, (struct loader_generic_list*)output_layers,
 1122|    341|                                   (settings_layers->count + regular_layers->count) * sizeof(struct loader_layer_properties));
 1123|    341|    if (VK_SUCCESS != res) {
  ------------------
  |  Branch (1123:9): [True: 0, False: 341]
  ------------------
 1124|      0|        goto out;
 1125|      0|    }
 1126|       |
 1127|       |    // Insert the settings layers into output_layers up to unordered_layer_index
 1128|  11.6k|    for (uint32_t i = 0; i < unordered_layer_location_index; i++) {
  ------------------
  |  Branch (1128:26): [True: 11.3k, False: 341]
  ------------------
 1129|  11.3k|        if (!check_if_layer_is_in_list(output_layers, &settings_layers->list[i], true)) {
  ------------------
  |  Branch (1129:13): [True: 7.54k, False: 3.78k]
  ------------------
 1130|  7.54k|            res = loader_append_layer_property(inst, output_layers, &settings_layers->list[i]);
 1131|  7.54k|            if (VK_SUCCESS != res) {
  ------------------
  |  Branch (1131:17): [True: 0, False: 7.54k]
  ------------------
 1132|      0|                goto out;
 1133|      0|            }
 1134|  7.54k|        }
 1135|  11.3k|    }
 1136|       |
 1137|  6.95k|    for (uint32_t i = 0; i < regular_layers->count; i++) {
  ------------------
  |  Branch (1137:26): [True: 6.61k, False: 341]
  ------------------
 1138|       |        // Check if its already been put in the output_layers list as well as the remaining settings_layers
 1139|  6.61k|        bool regular_layer_is_ordered = check_if_layer_is_in_list(output_layers, &regular_layers->list[i], false) ||
  ------------------
  |  Branch (1139:41): [True: 2.82k, False: 3.78k]
  ------------------
 1140|  3.78k|                                        check_if_layer_is_in_list(settings_layers, &regular_layers->list[i], false);
  ------------------
  |  Branch (1140:41): [True: 3.12k, False: 657]
  ------------------
 1141|       |        // If it isn't found, add it
 1142|  6.61k|        if (!regular_layer_is_ordered) {
  ------------------
  |  Branch (1142:13): [True: 657, False: 5.95k]
  ------------------
 1143|    657|            res = loader_append_layer_property(inst, output_layers, &regular_layers->list[i]);
 1144|    657|            if (VK_SUCCESS != res) {
  ------------------
  |  Branch (1144:17): [True: 0, False: 657]
  ------------------
 1145|      0|                goto out;
 1146|      0|            }
 1147|  5.95k|        } else {
 1148|       |            // layer is already ordered and can be safely freed
 1149|  5.95k|            loader_free_layer_properties(inst, &regular_layers->list[i]);
 1150|  5.95k|        }
 1151|  6.61k|    }
 1152|       |
 1153|       |    // Insert the rest of the settings layers into combined_layers from  unordered_layer_index to the end
 1154|       |    // start at one after the unordered_layer_index
 1155|  9.13k|    for (uint32_t i = unordered_layer_location_index + 1; i < settings_layers->count; i++) {
  ------------------
  |  Branch (1155:59): [True: 8.79k, False: 341]
  ------------------
 1156|  8.79k|        if (!check_if_layer_is_in_list(output_layers, &settings_layers->list[i], true)) {
  ------------------
  |  Branch (1156:13): [True: 6.11k, False: 2.67k]
  ------------------
 1157|  6.11k|            res = loader_append_layer_property(inst, output_layers, &settings_layers->list[i]);
 1158|  6.11k|            if (VK_SUCCESS != res) {
  ------------------
  |  Branch (1158:17): [True: 0, False: 6.11k]
  ------------------
 1159|      0|                goto out;
 1160|      0|            }
 1161|  6.11k|        }
 1162|  8.79k|    }
 1163|       |
 1164|  4.90k|out:
 1165|  4.90k|    if (res != VK_SUCCESS) {
  ------------------
  |  Branch (1165:9): [True: 0, False: 4.90k]
  ------------------
 1166|      0|        loader_delete_layer_list_and_properties(inst, output_layers);
 1167|      0|    }
 1168|       |
 1169|  4.90k|    return res;
 1170|    341|}
loader_settings_get_additional_driver_files:
 1283|      2|VkResult loader_settings_get_additional_driver_files(const struct loader_instance* inst, struct loader_string_list* out_files) {
 1284|      2|    VkResult res = VK_SUCCESS;
 1285|       |
 1286|      2|    const loader_settings* settings = get_current_settings_and_lock(inst);
 1287|       |
 1288|      2|    if (NULL == settings || !settings->settings_active) {
  ------------------
  |  Branch (1288:9): [True: 0, False: 2]
  |  Branch (1288:29): [True: 1, False: 1]
  ------------------
 1289|      1|        goto out;
 1290|      1|    }
 1291|       |
 1292|      1|    if (settings->additional_drivers_use_exclusively) {
  ------------------
  |  Branch (1292:9): [True: 0, False: 1]
  ------------------
 1293|      0|        free_string_list(inst, out_files);
 1294|      0|    }
 1295|       |
 1296|      1|    for (uint32_t i = 0; i < settings->additional_driver_count; i++) {
  ------------------
  |  Branch (1296:26): [True: 0, False: 1]
  ------------------
 1297|      0|        res = prepend_if_manifest_file(inst, settings->additional_drivers[i].path, out_files);
 1298|      0|    }
 1299|       |
 1300|      2|out:
 1301|      2|    release_current_settings_lock(inst);
 1302|      2|    return res;
 1303|      1|}
loader_settings_should_use_driver_environment_variables:
 1305|      4|bool loader_settings_should_use_driver_environment_variables(const struct loader_instance* inst) {
 1306|      4|    bool should_use = true;
 1307|      4|    const loader_settings* settings = get_current_settings_and_lock(inst);
 1308|      4|    if (NULL == settings || !settings->settings_active) {
  ------------------
  |  Branch (1308:9): [True: 0, False: 4]
  |  Branch (1308:29): [True: 2, False: 2]
  ------------------
 1309|      2|        goto out;
 1310|      2|    }
 1311|      2|    if (settings->device_configurations_active) {
  ------------------
  |  Branch (1311:9): [True: 0, False: 2]
  ------------------
 1312|      0|        should_use = false;
 1313|      0|    }
 1314|      4|out:
 1315|      4|    release_current_settings_lock(inst);
 1316|      4|    return should_use;
 1317|      2|}

vkCreateInstance:
  522|  6.58k|                                                              const VkAllocationCallbacks *pAllocator, VkInstance *pInstance) {
  523|  6.58k|    struct loader_instance *ptr_instance = NULL;
  524|  6.58k|    VkInstance created_instance = VK_NULL_HANDLE;
  525|  6.58k|    VkResult res = VK_ERROR_INITIALIZATION_FAILED;
  526|  6.58k|    VkInstanceCreateInfo ici = {0};
  527|  6.58k|    bool portability_enumeration_flag_bit_set = false;
  528|  6.58k|    bool portability_enumeration_extension_enabled = false;
  529|  6.58k|    struct loader_envvar_all_filters layer_filters = {0};
  530|       |
  531|  6.58k|    LOADER_PLATFORM_THREAD_ONCE(&once_init, loader_initialize);
  532|       |
  533|  6.58k|    if (pCreateInfo == NULL) {
  ------------------
  |  Branch (533:9): [True: 0, False: 6.58k]
  ------------------
  534|      0|        loader_log(NULL, VULKAN_LOADER_FATAL_ERROR_BIT | VULKAN_LOADER_ERROR_BIT | VULKAN_LOADER_VALIDATION_BIT, 0,
  535|      0|                   "vkCreateInstance: \'pCreateInfo\' is NULL (VUID-vkCreateInstance-pCreateInfo-parameter)");
  536|      0|        goto out;
  537|      0|    }
  538|  6.58k|    ici = *pCreateInfo;
  539|       |
  540|  6.58k|    if (pInstance == NULL) {
  ------------------
  |  Branch (540:9): [True: 0, False: 6.58k]
  ------------------
  541|      0|        loader_log(NULL, VULKAN_LOADER_FATAL_ERROR_BIT | VULKAN_LOADER_ERROR_BIT | VULKAN_LOADER_VALIDATION_BIT, 0,
  542|      0|                   "vkCreateInstance \'pInstance\' not valid (VUID-vkCreateInstance-pInstance-parameter)");
  543|      0|        goto out;
  544|      0|    }
  545|       |
  546|  6.58k|    ptr_instance =
  547|  6.58k|        (struct loader_instance *)loader_calloc(pAllocator, sizeof(struct loader_instance), VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE);
  548|       |
  549|  6.58k|    if (ptr_instance == NULL) {
  ------------------
  |  Branch (549:9): [True: 0, False: 6.58k]
  ------------------
  550|      0|        res = VK_ERROR_OUT_OF_HOST_MEMORY;
  551|      0|        goto out;
  552|      0|    }
  553|       |
  554|  6.58k|    loader_platform_thread_lock_mutex(&loader_lock);
  555|  6.58k|    if (pAllocator) {
  ------------------
  |  Branch (555:9): [True: 0, False: 6.58k]
  ------------------
  556|      0|        ptr_instance->alloc_callbacks = *pAllocator;
  557|      0|    }
  558|  6.58k|    ptr_instance->magic = LOADER_MAGIC_NUMBER;
  ------------------
  |  |  329|  6.58k|#define LOADER_MAGIC_NUMBER 0x10ADED010110ADEDUL
  ------------------
  559|       |
  560|       |    // Save the application version
  561|  6.58k|    if (NULL == pCreateInfo->pApplicationInfo || 0 == pCreateInfo->pApplicationInfo->apiVersion) {
  ------------------
  |  Branch (561:9): [True: 0, False: 6.58k]
  |  Branch (561:50): [True: 0, False: 6.58k]
  ------------------
  562|      0|        ptr_instance->app_api_version = LOADER_VERSION_1_0_0;
  ------------------
  |  |  266|      0|#define LOADER_VERSION_1_0_0 loader_combine_version(1, 0, 0)
  ------------------
  563|  6.58k|    } else {
  564|  6.58k|        ptr_instance->app_api_version = loader_make_version(pCreateInfo->pApplicationInfo->apiVersion);
  565|  6.58k|    }
  566|       |
  567|       |    // Look for one or more VK_EXT_debug_report or VK_EXT_debug_utils create info structures
  568|       |    // and setup a callback(s) for each one found.
  569|       |
  570|       |    // Handle cases of VK_EXT_debug_utils
  571|       |    // Setup the temporary messenger(s) here to catch early issues:
  572|  6.58k|    res = util_CreateDebugUtilsMessengers(ptr_instance, pCreateInfo->pNext, pAllocator);
  573|  6.58k|    if (VK_ERROR_OUT_OF_HOST_MEMORY == res) {
  ------------------
  |  Branch (573:9): [True: 0, False: 6.58k]
  ------------------
  574|       |        // Failure of setting up one or more of the messenger.
  575|      0|        goto out;
  576|      0|    }
  577|       |
  578|       |    // Handle cases of VK_EXT_debug_report
  579|       |    // Setup the temporary callback(s) here to catch early issues:
  580|  6.58k|    res = util_CreateDebugReportCallbacks(ptr_instance, pCreateInfo->pNext, pAllocator);
  581|  6.58k|    if (VK_ERROR_OUT_OF_HOST_MEMORY == res) {
  ------------------
  |  Branch (581:9): [True: 0, False: 6.58k]
  ------------------
  582|       |        // Failure of setting up one or more of the callback.
  583|      0|        goto out;
  584|      0|    }
  585|       |
  586|  6.58k|    loader_log_instance_create_info(ptr_instance, pCreateInfo);
  587|       |
  588|  6.58k|    VkResult settings_file_res = get_loader_settings(ptr_instance, &ptr_instance->settings);
  589|  6.58k|    if (settings_file_res == VK_ERROR_OUT_OF_HOST_MEMORY) {
  ------------------
  |  Branch (589:9): [True: 0, False: 6.58k]
  ------------------
  590|      0|        res = settings_file_res;
  591|      0|        goto out;
  592|      0|    }
  593|  6.58k|    if (ptr_instance->settings.settings_active) {
  ------------------
  |  Branch (593:9): [True: 2.35k, False: 4.23k]
  ------------------
  594|  2.35k|        log_settings(ptr_instance, &ptr_instance->settings);
  595|  2.35k|    }
  596|       |
  597|       |    // Providing an apiVersion less than VK_API_VERSION_1_0 but greater than zero prevents the validation layers from starting
  598|  6.58k|    if (pCreateInfo->pApplicationInfo && pCreateInfo->pApplicationInfo->apiVersion != 0u &&
  ------------------
  |  Branch (598:9): [True: 6.58k, False: 0]
  |  Branch (598:42): [True: 6.58k, False: 0]
  ------------------
  599|  6.58k|        pCreateInfo->pApplicationInfo->apiVersion < VK_API_VERSION_1_0) {
  ------------------
  |  Branch (599:9): [True: 0, False: 6.58k]
  ------------------
  600|      0|        loader_log(ptr_instance, VULKAN_LOADER_FATAL_ERROR_BIT | VULKAN_LOADER_ERROR_BIT, 0,
  601|      0|                   "VkInstanceCreateInfo::pApplicationInfo::apiVersion has value of %u which is not permitted. If apiVersion is "
  602|      0|                   "not 0, then it must be "
  603|      0|                   "greater than or equal to the value of VK_API_VERSION_1_0 [VUID-VkApplicationInfo-apiVersion]",
  604|      0|                   pCreateInfo->pApplicationInfo->apiVersion);
  605|      0|    }
  606|       |
  607|       |    // Check the VkInstanceCreateInfoFlags wether to allow the portability enumeration flag
  608|  6.58k|    if ((pCreateInfo->flags & VK_INSTANCE_CREATE_ENUMERATE_PORTABILITY_BIT_KHR) == 1) {
  ------------------
  |  Branch (608:9): [True: 0, False: 6.58k]
  ------------------
  609|      0|        portability_enumeration_flag_bit_set = true;
  610|      0|    }
  611|       |    // Make sure the portability extension extension has been enabled before enabling portability driver enumeration
  612|  6.58k|    if (pCreateInfo->ppEnabledExtensionNames) {
  ------------------
  |  Branch (612:9): [True: 0, False: 6.58k]
  ------------------
  613|      0|        for (uint32_t i = 0; i < pCreateInfo->enabledExtensionCount; i++) {
  ------------------
  |  Branch (613:30): [True: 0, False: 0]
  ------------------
  614|      0|            if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], VK_KHR_PORTABILITY_ENUMERATION_EXTENSION_NAME) == 0) {
  ------------------
  |  Branch (614:17): [True: 0, False: 0]
  ------------------
  615|      0|                portability_enumeration_extension_enabled = true;
  616|      0|                if (portability_enumeration_flag_bit_set) {
  ------------------
  |  Branch (616:21): [True: 0, False: 0]
  ------------------
  617|      0|                    ptr_instance->portability_enumeration_enabled = true;
  618|      0|                    loader_log(ptr_instance, VULKAN_LOADER_INFO_BIT, 0,
  619|      0|                               "Portability enumeration bit was set, enumerating portability drivers.");
  620|      0|                }
  621|      0|                break;
  622|      0|            }
  623|      0|        }
  624|      0|    }
  625|       |
  626|       |    // Make sure the application provided API version has the correct variant
  627|  6.58k|    if (NULL != pCreateInfo->pApplicationInfo) {
  ------------------
  |  Branch (627:9): [True: 6.58k, False: 0]
  ------------------
  628|  6.58k|        uint32_t variant_version = VK_API_VERSION_VARIANT(pCreateInfo->pApplicationInfo->apiVersion);
  629|  6.58k|        const uint32_t expected_variant = 0;
  630|  6.58k|        if (expected_variant != variant_version) {
  ------------------
  |  Branch (630:13): [True: 0, False: 6.58k]
  ------------------
  631|      0|            loader_log(ptr_instance, VULKAN_LOADER_WARN_BIT, 0,
  632|      0|                       "vkCreateInstance: The API Variant specified in pCreateInfo->pApplicationInfo.apiVersion is %d instead of "
  633|      0|                       "the expected value of %d.",
  634|      0|                       variant_version, expected_variant);
  635|      0|        }
  636|  6.58k|    }
  637|       |
  638|  6.58k|    res = parse_layer_environment_var_filters(ptr_instance, &layer_filters);
  639|  6.58k|    if (VK_SUCCESS != res) {
  ------------------
  |  Branch (639:9): [True: 0, False: 6.58k]
  ------------------
  640|      0|        goto out;
  641|      0|    }
  642|       |
  643|       |    // Due to implicit layers need to get layer list even if
  644|       |    // enabledLayerCount == 0 and VK_INSTANCE_LAYERS is unset. For now always
  645|       |    // get layer list via loader_scan_for_layers().
  646|  6.58k|    memset(&ptr_instance->instance_layer_list, 0, sizeof(ptr_instance->instance_layer_list));
  647|  6.58k|    res = loader_scan_for_layers(ptr_instance, &ptr_instance->instance_layer_list, &layer_filters);
  648|  6.58k|    if (VK_SUCCESS != res) {
  ------------------
  |  Branch (648:9): [True: 0, False: 6.58k]
  ------------------
  649|      0|        goto out;
  650|      0|    }
  651|       |
  652|       |    // Validate the app requested layers to be enabled
  653|  6.58k|    if (pCreateInfo->enabledLayerCount > 0) {
  ------------------
  |  Branch (653:9): [True: 6.58k, False: 0]
  ------------------
  654|  6.58k|        res = loader_validate_layers(ptr_instance, pCreateInfo->enabledLayerCount, pCreateInfo->ppEnabledLayerNames,
  655|  6.58k|                                     &ptr_instance->instance_layer_list);
  656|  6.58k|        if (res != VK_SUCCESS) {
  ------------------
  |  Branch (656:13): [True: 6.58k, False: 2]
  ------------------
  657|  6.58k|            goto out;
  658|  6.58k|        }
  659|  6.58k|    }
  660|       |
  661|       |    // Scan/discover all System and Environment Variable ICD libraries
  662|  6.58k|    bool skipped_portability_drivers = false;
  663|      2|    res = loader_icd_scan(ptr_instance, &ptr_instance->icd_tramp_list, pCreateInfo, &skipped_portability_drivers);
  664|      2|    if (res == VK_ERROR_OUT_OF_HOST_MEMORY) {
  ------------------
  |  Branch (664:9): [True: 0, False: 2]
  ------------------
  665|      0|        goto out;
  666|      0|    }
  667|       |
  668|      2|    if (ptr_instance->icd_tramp_list.count == 0) {
  ------------------
  |  Branch (668:9): [True: 2, False: 0]
  ------------------
  669|       |        // No drivers found
  670|      2|        if (skipped_portability_drivers) {
  ------------------
  |  Branch (670:13): [True: 0, False: 2]
  ------------------
  671|      0|            if (portability_enumeration_extension_enabled && !portability_enumeration_flag_bit_set) {
  ------------------
  |  Branch (671:17): [True: 0, False: 0]
  |  Branch (671:62): [True: 0, False: 0]
  ------------------
  672|      0|                loader_log(ptr_instance, VULKAN_LOADER_ERROR_BIT | VULKAN_LOADER_DRIVER_BIT, 0,
  673|      0|                           "vkCreateInstance: Found drivers that contain devices which support the portability subset, but "
  674|      0|                           "the instance does not enumerate portability drivers! Applications that wish to enumerate portability "
  675|      0|                           "drivers must set the VK_INSTANCE_CREATE_ENUMERATE_PORTABILITY_BIT_KHR bit in the VkInstanceCreateInfo "
  676|      0|                           "flags.");
  677|      0|            } else if (portability_enumeration_flag_bit_set && !portability_enumeration_extension_enabled) {
  ------------------
  |  Branch (677:24): [True: 0, False: 0]
  |  Branch (677:64): [True: 0, False: 0]
  ------------------
  678|      0|                loader_log(ptr_instance, VULKAN_LOADER_ERROR_BIT | VULKAN_LOADER_DRIVER_BIT, 0,
  679|      0|                           "VkInstanceCreateInfo: If flags has the VK_INSTANCE_CREATE_ENUMERATE_PORTABILITY_BIT_KHR bit set, the "
  680|      0|                           "list of enabled extensions in ppEnabledExtensionNames must contain VK_KHR_portability_enumeration "
  681|      0|                           "[VUID-VkInstanceCreateInfo-flags-06559 ]"
  682|      0|                           "Applications that wish to enumerate portability drivers must enable the VK_KHR_portability_enumeration "
  683|      0|                           "instance extension.");
  684|      0|            } else {
  685|      0|                loader_log(ptr_instance, VULKAN_LOADER_ERROR_BIT | VULKAN_LOADER_DRIVER_BIT, 0,
  686|      0|                           "vkCreateInstance: Found drivers that contain devices which support the portability subset, but "
  687|      0|                           "the instance does not enumerate portability drivers! Applications that wish to enumerate portability "
  688|      0|                           "drivers must set the VK_INSTANCE_CREATE_ENUMERATE_PORTABILITY_BIT_KHR bit in the VkInstanceCreateInfo "
  689|      0|                           "flags and enable the VK_KHR_portability_enumeration instance extension.");
  690|      0|            }
  691|      0|        }
  692|      2|        loader_log(ptr_instance, VULKAN_LOADER_ERROR_BIT | VULKAN_LOADER_DRIVER_BIT, 0, "vkCreateInstance: Found no drivers!");
  693|      2|        res = VK_ERROR_INCOMPATIBLE_DRIVER;
  694|      2|        goto out;
  695|      2|    }
  696|       |
  697|       |    // Get extensions from all ICD's, merge so no duplicates, then validate
  698|      0|    res = loader_get_icd_loader_instance_extensions(ptr_instance, &ptr_instance->icd_tramp_list, &ptr_instance->ext_list);
  699|      0|    if (res != VK_SUCCESS) {
  ------------------
  |  Branch (699:9): [True: 0, False: 0]
  ------------------
  700|      0|        goto out;
  701|      0|    }
  702|       |
  703|      0|    ptr_instance->disp = loader_instance_heap_alloc(ptr_instance, sizeof(struct loader_instance_dispatch_table),
  704|      0|                                                    VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE);
  705|      0|    if (ptr_instance->disp == NULL) {
  ------------------
  |  Branch (705:9): [True: 0, False: 0]
  ------------------
  706|      0|        loader_log(ptr_instance, VULKAN_LOADER_ERROR_BIT, 0,
  707|      0|                   "vkCreateInstance:  Failed to allocate Loader's full Instance dispatch table.");
  708|      0|        res = VK_ERROR_OUT_OF_HOST_MEMORY;
  709|      0|        goto out;
  710|      0|    }
  711|      0|    memcpy(&ptr_instance->disp->layer_inst_disp, &instance_disp, sizeof(instance_disp));
  712|       |
  713|      0|    ptr_instance->next = loader.instances;
  714|      0|    loader.instances = ptr_instance;
  715|       |
  716|       |    // Activate any layers on instance chain
  717|      0|    res = loader_enable_instance_layers(ptr_instance, &ici, &layer_filters);
  718|      0|    if (res != VK_SUCCESS) {
  ------------------
  |  Branch (718:9): [True: 0, False: 0]
  ------------------
  719|      0|        goto out;
  720|      0|    }
  721|       |
  722|      0|    res = loader_validate_instance_extensions(ptr_instance, &ptr_instance->ext_list, &ptr_instance->instance_layer_list,
  723|      0|                                              &ptr_instance->expanded_activated_layer_list, &ici);
  724|      0|    if (res != VK_SUCCESS) {
  ------------------
  |  Branch (724:9): [True: 0, False: 0]
  ------------------
  725|      0|        goto out;
  726|      0|    }
  727|       |
  728|      0|    created_instance = (VkInstance)ptr_instance;
  729|      0|    res = loader_create_instance_chain(&ici, pAllocator, ptr_instance, &created_instance);
  730|       |
  731|      0|    if (VK_SUCCESS == res) {
  ------------------
  |  Branch (731:9): [True: 0, False: 0]
  ------------------
  732|       |        // Check for enabled extensions here to setup the loader structures so the loader knows what extensions
  733|       |        // it needs to worry about.
  734|       |        // We do it in the terminator and again above the layers here since we may think different extensions
  735|       |        // are enabled than what's down in the terminator.
  736|       |        // This is why we don't clear inside of these function calls.
  737|       |        // The clearing should actually be handled by the overall memset of the pInstance structure above.
  738|      0|        fill_out_enabled_instance_extensions(ici.enabledExtensionCount, ici.ppEnabledExtensionNames,
  739|      0|                                             &ptr_instance->enabled_extensions);
  740|       |
  741|      0|        *pInstance = (VkInstance)ptr_instance;
  742|       |
  743|       |        // Finally have the layers in place and everyone has seen
  744|       |        // the CreateInstance command go by. This allows the layer's
  745|       |        // GetInstanceProcAddr functions to return valid extension functions
  746|       |        // if enabled.
  747|      0|        loader_activate_instance_layer_extensions(ptr_instance, created_instance);
  748|      0|        ptr_instance->instance_finished_creation = true;
  749|      0|    } else if (VK_ERROR_EXTENSION_NOT_PRESENT == res && !ptr_instance->create_terminator_invalid_extension) {
  ------------------
  |  Branch (749:16): [True: 0, False: 0]
  |  Branch (749:57): [True: 0, False: 0]
  ------------------
  750|      0|        loader_log(ptr_instance, VULKAN_LOADER_WARN_BIT, 0,
  751|      0|                   "vkCreateInstance: Layer returning invalid extension error not triggered by ICD/Loader (Policy #LLP_LAYER_17).");
  752|      0|    }
  753|       |
  754|  6.58k|out:
  755|       |
  756|  6.58k|    if (NULL != ptr_instance) {
  ------------------
  |  Branch (756:9): [True: 6.58k, False: 0]
  ------------------
  757|  6.58k|        if (res != VK_SUCCESS) {
  ------------------
  |  Branch (757:13): [True: 6.58k, False: 0]
  ------------------
  758|       |            // error path, should clean everything up
  759|  6.58k|            if (loader.instances == ptr_instance) {
  ------------------
  |  Branch (759:17): [True: 0, False: 6.58k]
  ------------------
  760|      0|                loader.instances = ptr_instance->next;
  761|      0|            }
  762|       |
  763|  6.58k|            free_loader_settings(ptr_instance, &ptr_instance->settings);
  764|       |
  765|  6.58k|            loader_destroy_generic_list(ptr_instance, (struct loader_generic_list *)&ptr_instance->surfaces_list);
  766|  6.58k|            loader_destroy_generic_list(ptr_instance, (struct loader_generic_list *)&ptr_instance->debug_utils_messengers_list);
  767|  6.58k|            loader_destroy_generic_list(ptr_instance, (struct loader_generic_list *)&ptr_instance->debug_report_callbacks_list);
  768|       |
  769|  6.58k|            loader_instance_heap_free(ptr_instance, ptr_instance->disp);
  770|       |            // Remove any created VK_EXT_debug_report or VK_EXT_debug_utils items
  771|  6.58k|            destroy_debug_callbacks_chain(ptr_instance, pAllocator);
  772|       |
  773|  6.58k|            loader_destroy_pointer_layer_list(ptr_instance, &ptr_instance->expanded_activated_layer_list);
  774|       |
  775|  6.58k|            loader_delete_layer_list_and_properties(ptr_instance, &ptr_instance->instance_layer_list);
  776|  6.58k|            loader_destroy_generic_list(ptr_instance, (struct loader_generic_list *)&ptr_instance->ext_list);
  777|       |
  778|       |            // Free any icd_terms that were created.
  779|       |            // If an OOM occurs from a layer, terminator_CreateInstance won't be reached where this kind of
  780|       |            // cleanup normally occurs
  781|  6.58k|            struct loader_icd_term *icd_term = NULL;
  782|  6.58k|            while (NULL != ptr_instance->icd_terms) {
  ------------------
  |  Branch (782:20): [True: 0, False: 6.58k]
  ------------------
  783|      0|                icd_term = ptr_instance->icd_terms;
  784|       |                // Call destroy Instance on each driver in case we successfully called down the chain but failed on
  785|       |                // our way back out of it.
  786|      0|                if (icd_term->instance) {
  ------------------
  |  Branch (786:21): [True: 0, False: 0]
  ------------------
  787|      0|                    loader_icd_close_objects(ptr_instance, icd_term);
  788|      0|                    icd_term->dispatch.DestroyInstance(icd_term->instance, pAllocator);
  789|      0|                }
  790|      0|                icd_term->instance = VK_NULL_HANDLE;
  791|      0|                ptr_instance->icd_terms = icd_term->next;
  792|      0|                loader_icd_destroy(ptr_instance, icd_term, pAllocator);
  793|      0|            }
  794|       |
  795|  6.58k|            loader_clear_scanned_icd_list(ptr_instance, &ptr_instance->icd_tramp_list);
  796|  6.58k|            free_string_list(ptr_instance, &ptr_instance->enabled_layer_names);
  797|       |
  798|  6.58k|            loader_instance_heap_free(ptr_instance, ptr_instance);
  799|  6.58k|        } else {
  800|       |            // success path, swap out created debug callbacks out so they aren't used until instance destruction
  801|      0|            loader_remove_instance_only_debug_funcs(ptr_instance);
  802|      0|        }
  803|       |        // Only unlock when ptr_instance isn't NULL, as if it is, the above code didn't make it to when loader_lock was locked.
  804|  6.58k|        loader_platform_thread_unlock_mutex(&loader_lock);
  805|  6.58k|    }
  806|       |
  807|  6.58k|    return res;
  808|      0|}
trampoline.c:loader_log_instance_create_info:
  480|  6.58k|static void loader_log_instance_create_info(const struct loader_instance *inst, const VkInstanceCreateInfo *pCreateInfo) {
  481|  6.58k|    const VkApplicationInfo *app_info = pCreateInfo->pApplicationInfo;
  482|  6.58k|    const char *app_name = (app_info && app_info->pApplicationName) ? app_info->pApplicationName : "";
  ------------------
  |  Branch (482:29): [True: 6.58k, False: 0]
  |  Branch (482:41): [True: 6.58k, False: 0]
  ------------------
  483|  6.58k|    const char *engine_name = (app_info && app_info->pEngineName) ? app_info->pEngineName : "";
  ------------------
  |  Branch (483:32): [True: 6.58k, False: 0]
  |  Branch (483:44): [True: 6.58k, False: 0]
  ------------------
  484|  6.58k|    uint32_t app_version = app_info ? app_info->applicationVersion : 0;
  ------------------
  |  Branch (484:28): [True: 6.58k, False: 0]
  ------------------
  485|  6.58k|    uint32_t engine_version = app_info ? app_info->engineVersion : 0;
  ------------------
  |  Branch (485:31): [True: 6.58k, False: 0]
  ------------------
  486|  6.58k|    uint32_t api_version = app_info ? app_info->apiVersion : 0;
  ------------------
  |  Branch (486:28): [True: 6.58k, False: 0]
  ------------------
  487|       |
  488|  6.58k|    loader_log(inst, VULKAN_LOADER_INFO_BIT, 0,
  489|  6.58k|               "vkCreateInstance: applicationName: \"%s\", applicationVersion: %u, engineName: \"%s\", engineVersion: %u, "
  490|  6.58k|               "apiVersion: %u.%u.%u",
  491|  6.58k|               app_name, app_version, engine_name, engine_version, VK_API_VERSION_MAJOR(api_version),
  492|  6.58k|               VK_API_VERSION_MINOR(api_version), VK_API_VERSION_PATCH(api_version));
  493|       |
  494|       |    // Guard the name arrays: this runs before the loader validates pCreateInfo, so the count may be non-zero with a null
  495|       |    // array (see the null-pointer tests).
  496|  6.58k|    loader_log(inst, VULKAN_LOADER_INFO_BIT, 0,
  497|  6.58k|               "vkCreateInstance: Requested %u instance layer(s):", pCreateInfo->enabledLayerCount);
  498|  6.58k|    if (pCreateInfo->ppEnabledLayerNames) {
  ------------------
  |  Branch (498:9): [True: 6.58k, False: 0]
  ------------------
  499|  13.1k|        for (uint32_t i = 0; i < pCreateInfo->enabledLayerCount; ++i) {
  ------------------
  |  Branch (499:30): [True: 6.58k, False: 6.58k]
  ------------------
  500|  6.58k|            if (pCreateInfo->ppEnabledLayerNames[i]) {
  ------------------
  |  Branch (500:17): [True: 6.58k, False: 0]
  ------------------
  501|  6.58k|                loader_log(inst, VULKAN_LOADER_INFO_BIT, 0, "   %s", pCreateInfo->ppEnabledLayerNames[i]);
  502|  6.58k|            } else {
  503|      0|                loader_log(inst, VULKAN_LOADER_INFO_BIT, 0, "   <NULL>");
  504|      0|            }
  505|  6.58k|        }
  506|  6.58k|    }
  507|       |
  508|  6.58k|    loader_log(inst, VULKAN_LOADER_INFO_BIT, 0,
  509|  6.58k|               "vkCreateInstance: Requested %u instance extension(s):", pCreateInfo->enabledExtensionCount);
  510|  6.58k|    if (pCreateInfo->ppEnabledExtensionNames) {
  ------------------
  |  Branch (510:9): [True: 0, False: 6.58k]
  ------------------
  511|      0|        for (uint32_t i = 0; i < pCreateInfo->enabledExtensionCount; ++i) {
  ------------------
  |  Branch (511:30): [True: 0, False: 0]
  ------------------
  512|      0|            if (pCreateInfo->ppEnabledExtensionNames[i]) {
  ------------------
  |  Branch (512:17): [True: 0, False: 0]
  ------------------
  513|      0|                loader_log(inst, VULKAN_LOADER_INFO_BIT, 0, "   %s", pCreateInfo->ppEnabledExtensionNames[i]);
  514|      0|            } else {
  515|      0|                loader_log(inst, VULKAN_LOADER_INFO_BIT, 0, "   <NULL>");
  516|      0|            }
  517|      0|        }
  518|      0|    }
  519|  6.58k|}

trampoline.c:loader_platform_thread_lock_mutex:
  456|  6.58k|static inline void loader_platform_thread_lock_mutex(loader_platform_thread_mutex *pMutex) { pthread_mutex_lock(pMutex); }
trampoline.c:loader_platform_thread_unlock_mutex:
  457|  6.58k|static inline void loader_platform_thread_unlock_mutex(loader_platform_thread_mutex *pMutex) { pthread_mutex_unlock(pMutex); }
debug_utils.c:loader_platform_thread_lock_mutex:
  456|  1.11M|static inline void loader_platform_thread_lock_mutex(loader_platform_thread_mutex *pMutex) { pthread_mutex_lock(pMutex); }
debug_utils.c:loader_platform_thread_unlock_mutex:
  457|  1.11M|static inline void loader_platform_thread_unlock_mutex(loader_platform_thread_mutex *pMutex) { pthread_mutex_unlock(pMutex); }
loader.c:loader_strncpy:
  467|   667k|static inline char *loader_strncpy(char *dest, size_t dest_sz, const char *src, size_t count) {
  468|   667k|    (void)dest_sz;
  469|   667k|    return strncpy(dest, src, count);
  470|   667k|}
loader.c:thread_safe_strtok:
  460|   529k|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|   164k|static inline bool loader_platform_is_path_absolute(const char *path) {
  297|   164k|    if (path[0] == '/') return true;
  ------------------
  |  Branch (297:9): [True: 60.1k, False: 103k]
  ------------------
  298|   103k|    return false;
  299|   164k|}
loader.c:loader_platform_is_path:
  252|  21.2k|static inline bool loader_platform_is_path(const char *path) { return strchr(path, DIRECTORY_SYMBOL) != NULL; }
  ------------------
  |  |  155|  21.2k|#define DIRECTORY_SYMBOL '/'
  ------------------
loader.c:loader_platform_file_exists:
  289|  21.1k|static inline bool loader_platform_file_exists(const char *path) {
  290|  21.1k|    if (access(path, F_OK)) return false;
  ------------------
  |  Branch (290:9): [True: 730, False: 20.4k]
  ------------------
  291|  20.4k|    return true;
  292|  21.1k|}
loader.c:loader_platform_executable_path:
  307|  4.90k|static inline char *loader_platform_executable_path(char *buffer, size_t size) {
  308|  4.90k|    ssize_t count = readlink("/proc/self/exe", buffer, size);
  309|  4.90k|    if (count == -1) return NULL;
  ------------------
  |  Branch (309:9): [True: 0, False: 4.90k]
  ------------------
  310|  4.90k|    if (count == 0) return NULL;
  ------------------
  |  Branch (310:9): [True: 0, False: 4.90k]
  ------------------
  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.90k|    if ((size_t)count >= size) return NULL;
  ------------------
  |  Branch (313:9): [True: 0, False: 4.90k]
  ------------------
  314|  4.90k|    buffer[count] = '\0';
  315|  4.90k|    return buffer;
  316|  4.90k|}
loader_environment.c:thread_safe_strtok:
  460|  13.1k|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|  6.58k|static inline char *loader_strncpy(char *dest, size_t dest_sz, const char *src, size_t count) {
  468|  6.58k|    (void)dest_sz;
  469|  6.58k|    return strncpy(dest, src, count);
  470|  6.58k|}
log.c:loader_strncat:
  463|  71.4k|static inline char *loader_strncat(char *dest, size_t dest_sz, const char *src, size_t count) {
  464|  71.4k|    (void)dest_sz;
  465|  71.4k|    return strncat(dest, src, count);
  466|  71.4k|}
settings.c:loader_strncpy:
  467|  17.6k|static inline char *loader_strncpy(char *dest, size_t dest_sz, const char *src, size_t count) {
  468|  17.6k|    (void)dest_sz;
  469|  17.6k|    return strncpy(dest, src, count);
  470|  17.6k|}
settings.c:loader_strncat:
  463|  16.6k|static inline char *loader_strncat(char *dest, size_t dest_sz, const char *src, size_t count) {
  464|  16.6k|    (void)dest_sz;
  465|  16.6k|    return strncat(dest, src, count);
  466|  16.6k|}
settings.c:loader_platform_file_exists:
  289|  16.6k|static inline bool loader_platform_file_exists(const char *path) {
  290|  16.6k|    if (access(path, F_OK)) return false;
  ------------------
  |  Branch (290:9): [True: 10.7k, False: 5.88k]
  ------------------
  291|  5.88k|    return true;
  292|  16.6k|}
settings.c:loader_platform_executable_path:
  307|  2.83k|static inline char *loader_platform_executable_path(char *buffer, size_t size) {
  308|  2.83k|    ssize_t count = readlink("/proc/self/exe", buffer, size);
  309|  2.83k|    if (count == -1) return NULL;
  ------------------
  |  Branch (309:9): [True: 0, False: 2.83k]
  ------------------
  310|  2.83k|    if (count == 0) return NULL;
  ------------------
  |  Branch (310:9): [True: 0, False: 2.83k]
  ------------------
  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|  2.83k|    if ((size_t)count >= size) return NULL;
  ------------------
  |  Branch (313:9): [True: 0, False: 2.83k]
  ------------------
  314|  2.83k|    buffer[count] = '\0';
  315|  2.83k|    return buffer;
  316|  2.83k|}
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:
  288|  12.6k|bool wsi_unsupported_instance_extension(const VkExtensionProperties *ext_prop) {
  289|       |#if !defined(VK_USE_PLATFORM_WAYLAND_KHR)
  290|       |    if (!strcmp(ext_prop->extensionName, "VK_KHR_wayland_surface")) return true;
  291|       |#endif  // VK_USE_PLATFORM_WAYLAND_KHR
  292|       |#if !defined(VK_USE_PLATFORM_XCB_KHR)
  293|       |    if (!strcmp(ext_prop->extensionName, "VK_KHR_xcb_surface")) return true;
  294|       |#endif  // VK_USE_PLATFORM_XCB_KHR
  295|       |#if !defined(VK_USE_PLATFORM_XLIB_KHR)
  296|       |    if (!strcmp(ext_prop->extensionName, "VK_KHR_xlib_surface")) return true;
  297|       |#endif  // VK_USE_PLATFORM_XLIB_KHR
  298|  12.6k|#if !defined(VK_USE_PLATFORM_DIRECTFB_EXT)
  299|  12.6k|    if (!strcmp(ext_prop->extensionName, "VK_EXT_directfb_surface")) return true;
  ------------------
  |  Branch (299:9): [True: 1.18k, False: 11.4k]
  ------------------
  300|  11.4k|#endif  // VK_USE_PLATFORM_DIRECTFB_EXT
  301|  11.4k|#if !defined(VK_USE_PLATFORM_SCREEN_QNX)
  302|  11.4k|    if (!strcmp(ext_prop->extensionName, "VK_QNX_screen_surface")) return true;
  ------------------
  |  Branch (302:9): [True: 628, False: 10.8k]
  ------------------
  303|  10.8k|#endif  // VK_USE_PLATFORM_SCREEN_QNX
  304|       |
  305|  10.8k|    return false;
  306|  11.4k|}

