loader: correct compiler warning
authorCourtney Goeltzenleuchter <courtneygo@google.com>
Thu, 17 Dec 2015 16:51:22 +0000 (09:51 -0700)
committerJon Ashburn <jon@lunarg.com>
Thu, 17 Dec 2015 19:18:53 +0000 (12:18 -0700)
Fixed compiler warning of idx potentially being
undefined. Also added test to check if the code
took that path and return an error if that happens.

loader/loader.c

index 3f71cde..4a83b49 100644 (file)
@@ -2578,7 +2578,7 @@ static void loader_remove_layer_lib(
         struct loader_instance *inst,
         struct loader_layer_properties *layer_prop)
 {
-    uint32_t idx;
+    uint32_t idx = loader.loaded_layer_lib_count;
     struct loader_lib_info *new_layer_lib_list, *my_lib = NULL;
 
     for (uint32_t i = 0; i < loader.loaded_layer_lib_count; i++) {
@@ -2590,6 +2590,12 @@ static void loader_remove_layer_lib(
         }
     }
 
+    if (idx == loader.loaded_layer_lib_count) {
+        loader_log(VK_DEBUG_REPORT_ERROR_BIT, 0,
+                   "Unable to unref library %s", layer_prop->lib_name);
+        return;
+    }
+
     if (my_lib) {
         my_lib->ref_count--;
         if (my_lib->ref_count > 0) {