loader: Fix skipping all layers if one bad is found

The logic for loaderScanForLayers would jump to out if any issue was found
loading any layer. This prevented any correct layers from being detected.
The other fix is in loader_get_json to return if the length is zero,
which would cause a VK_ERROR_OUT_OF_HOST_MEMORY to be thrown because
cJSON_Parse would fail.

Change-Id: Ie7a5de5d0f38edd9b9012b9cd22fecd9ed86eb5c
diff --git a/loader/loader.c b/loader/loader.c
index b27dea4..444c519 100644
--- a/loader/loader.c
+++ b/loader/loader.c
@@ -2562,6 +2562,11 @@
     }
     json_buf[len] = '\0';
 
+    // Can't be a valid json if the string is of length zero
+    if (len == 0) {
+        res = VK_ERROR_INITIALIZATION_FAILED;
+        goto out;
+    }
     // Parse text from file
     *json = cJSON_Parse(json_buf);
     if (*json == NULL) {
@@ -3381,7 +3386,7 @@
     char *vers_tok;
     cJSON *disable_environment = NULL;
     // Make sure sure the top level json value is an object
-    if(!json || json->type != 6){
+    if (!json || json->type != 6) {
         goto out;
     }
     item = cJSON_GetObjectItem(json, "file_format_version");
@@ -4490,7 +4495,8 @@
             VkResult local_res = loaderAddLayerProperties(inst, instance_layers, json, true, file_str);
             cJSON_Delete(json);
 
-            if (VK_SUCCESS != local_res) {
+            // If the error is anything other than out of memory we still want to try to load the other layers
+            if (VK_ERROR_OUT_OF_HOST_MEMORY == local_res) {
                 goto out;
             }
         }