summaryrefslogtreecommitdiff
path: root/vulkan/libvulkan/driver.cpp
diff options
context:
space:
mode:
author Nick Desaulniers <ndesaulniers@google.com> 2019-10-25 13:34:21 -0700
committer Nick Desaulniers <ndesaulniers@google.com> 2019-10-28 12:55:59 -0700
commit60307ce84d311beef63e1fe770ba49e3fde7133a (patch)
tree4df22a6b113e3f590e57ef35efb87bad2f21c646 /vulkan/libvulkan/driver.cpp
parent30266c647021491da73ba49a9d28f29ac8da4133 (diff)
[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
Diffstat (limited to 'vulkan/libvulkan/driver.cpp')
-rw-r--r--vulkan/libvulkan/driver.cpp16
1 files changed, 7 insertions, 9 deletions
diff --git a/vulkan/libvulkan/driver.cpp b/vulkan/libvulkan/driver.cpp
index a544bc5ff8..d92f35ac23 100644
--- a/vulkan/libvulkan/driver.cpp
+++ b/vulkan/libvulkan/driver.cpp
@@ -151,15 +151,12 @@ class CreateInfoWrapper {
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 @@ int LoadDriver(android_namespace_t* library_namespace,
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;
}