Fix in shadercacheLoad
authorPanagiotis Apostolou <panagiotis.apostolou@arm.com>
Thu, 10 Oct 2019 13:33:32 +0000 (15:33 +0200)
committerAlexander Galazin <Alexander.Galazin@arm.com>
Wed, 16 Oct 2019 11:39:10 +0000 (07:39 -0400)
There is a slim chance that function shadercacheLoad() can pass a null
pointer into the std::string constructor, causing an exception. This can
happen in the case there is a mismatch between the calculated hash and
the one stored in the cache file.

This commit makes the code more robust, handling this case as a miss.

Components: Vulkan

VK-GL-CTS issue: 2052

Change-Id: I84a382dec51f487314304ec9057cefdff22920c3

external/vulkancts/framework/vulkan/vkPrograms.cpp

index f16342b..578623e 100644 (file)
@@ -442,7 +442,7 @@ vk::ProgramBinary* shadercacheLoad (const std::string& shaderstring, const char*
        deUint8*                bin                     = 0;
        char*                   source          = 0;
        deBool                  ok                      = true;
-       deBool                  diff;
+       deBool                  diff            = true;
        cacheFileMutex.lock();
 
        if (cacheFileIndex.count(hash) == 0)
@@ -470,8 +470,8 @@ vk::ProgramBinary* shadercacheLoad (const std::string& shaderstring, const char*
                        source = new char[sourcelength + 1];
                        ok = fread(source, 1, sourcelength, file)                               == (size_t)sourcelength;
                        source[sourcelength] = 0;
+                       diff = shaderstring != std::string(source);
                }
-               diff = shaderstring != std::string(source);
                if (!ok || diff)
                {
                        // Mismatch, but may still exist in cache if there were hash collisions