[frameworks][native][vulkan] fix -Walloca

Alloca cannot be checked for failure. Replace alloca with dynamic memory
allocations.

Reapply a commit that was previously reverted.  The original commit
removed a call to enumerate_instance_layers() that it should not have.

Prefer std::vector to std::unique_ptr of an array.

Bug: 139945549
Bug: 142475221
Bug: 143156243
Test: mm && adb shell stop && adb sync && adb shell start && atest -it \
  CtsGpuToolsHostTestCases:android.gputools.cts.CtsRootlessGpuDebugHostTest#testDebugLayerLoadExternalVulkan,testMultipleExternalApps,testSystemPropertyIgnoreVulkan,testDebugLayerLoadVulkan,testSystemPropertyEnableVulkan
Signed-off-by: Nick Desaulniers <ndesaulniers@google.com>

Change-Id: Ifdf747fdabc41ee6da8cd83bda5e3f030649030f
diff --git a/vulkan/libvulkan/driver.cpp b/vulkan/libvulkan/driver.cpp
index a544bc5..d92f35a 100644
--- a/vulkan/libvulkan/driver.cpp
+++ b/vulkan/libvulkan/driver.cpp
@@ -151,15 +151,12 @@
 Hal Hal::hal_;
 
 void* LoadLibrary(const android_dlextinfo& dlextinfo,
-                  const char* subname,
-                  int subname_len) {
+                  const std::string_view subname) {
     ATRACE_CALL();
 
-    const char kLibFormat[] = "vulkan.%*s.so";
-    char* name = static_cast<char*>(
-        alloca(sizeof(kLibFormat) + static_cast<size_t>(subname_len)));
-    sprintf(name, kLibFormat, subname_len, subname);
-    return android_dlopen_ext(name, RTLD_LOCAL | RTLD_NOW, &dlextinfo);
+    std::stringstream ss;
+    ss << "vulkan." << subname << ".so";
+    return android_dlopen_ext(ss.str().c_str(), RTLD_LOCAL | RTLD_NOW, &dlextinfo);
 }
 
 const std::array<const char*, 2> HAL_SUBNAME_KEY_PROPERTIES = {{
@@ -179,8 +176,9 @@
     char prop[PROPERTY_VALUE_MAX];
     for (auto key : HAL_SUBNAME_KEY_PROPERTIES) {
         int prop_len = property_get(key, prop, nullptr);
-        if (prop_len > 0) {
-            so = LoadLibrary(dlextinfo, prop, prop_len);
+        if (prop_len > 0 && prop_len <= UINT_MAX) {
+            std::string_view lib_name(prop, static_cast<unsigned int>(prop_len));
+            so = LoadLibrary(dlextinfo, lib_name);
             if (so)
                 break;
         }