Fix issues found by static analysis
authorBen Davis <ben.davis@arm.com>
Wed, 15 Sep 2021 09:08:15 +0000 (10:08 +0100)
committerBen Davis <ben.davis@arm.com>
Mon, 11 Oct 2021 17:31:57 +0000 (17:31 +0000)
Change-Id: I222ec3b352aa220b6c08df3a71de48178b67f06d
Signed-off-by: Ben Davis <ben.davis@arm.com>
util/custom_allocator.hpp
util/extension_list.cpp
wsi/wsi_factory.cpp

index bb6a7a0..486fd18 100644 (file)
@@ -316,7 +316,7 @@ public:
          base::push_back(std::forward<arg_types>(args)...);
          return true;
       }
-      catch (const std::bad_alloc &e)
+      catch (const std::bad_alloc &)
       {
          return false;
       }
@@ -348,11 +348,11 @@ public:
          base::resize(std::forward<arg_types>(args)...);
          return true;
       }
-      catch (const std::bad_alloc &e)
+      catch (const std::bad_alloc &)
       {
          return false;
       }
    }
 };
 
-} /* namespace util */
\ No newline at end of file
+} /* namespace util */
index a3e672b..4194404 100644 (file)
@@ -48,6 +48,11 @@ VkResult extension_list::add(const char *const *extensions, uint32_t count)
    {
       auto &dst = m_ext_props[initial_size + i];
       strncpy(dst.extensionName, extensions[i], sizeof(dst.extensionName));
+
+      if (strlen(extensions[i]) >= sizeof(dst.extensionName))
+      {
+         dst.extensionName[sizeof(dst.extensionName) - 1] = '\0';
+      }
    }
    return VK_SUCCESS;
 }
index 0a85a15..8b8b86a 100644 (file)
@@ -154,6 +154,11 @@ VkResult add_extensions_required_by_layer(VkPhysicalDevice phys_dev, const util:
 
       util::extension_list extensions_required_by_layer{allocator};
       surface_properties *props = get_surface_properties(wsi_ext.platform);
+      if (props == nullptr)
+      {
+         return VK_ERROR_INITIALIZATION_FAILED;
+      }
+
       res = props->get_required_device_extensions(extensions_required_by_layer);
       if (res != VK_SUCCESS)
       {
@@ -197,7 +202,13 @@ PFN_vkVoidFunction get_proc_addr(const char *name)
     */
    for (const auto &wsi_ext : supported_wsi_extensions)
    {
-      PFN_vkVoidFunction func = get_surface_properties(wsi_ext.platform)->get_proc_addr(name);
+      surface_properties *props = get_surface_properties(wsi_ext.platform);
+      if (props == nullptr)
+      {
+         return nullptr;
+      }
+
+      PFN_vkVoidFunction func = props->get_proc_addr(name);
       if (func)
       {
          return func;