diff --git a/src/Magnum/Vk/ExtensionProperties.cpp b/src/Magnum/Vk/ExtensionProperties.cpp index 386d8f6c0..f75951be2 100644 --- a/src/Magnum/Vk/ExtensionProperties.cpp +++ b/src/Magnum/Vk/ExtensionProperties.cpp @@ -145,7 +145,7 @@ UnsignedInt ExtensionProperties::revision(const Containers::StringView extension /* Thanks, C++, for forcing me to have a larger bug surface instead of providing a library helper to find the damn thing. */ auto found = std::lower_bound(_names.begin(), _names.end(), extension); - if(*found != extension) return 0; + if(found == _names.end() || *found != extension) return 0; /* The view target is contents of the VkExtensionProperties structure, the revision is stored nearby */ diff --git a/src/Magnum/Vk/Test/ExtensionPropertiesVkTest.cpp b/src/Magnum/Vk/Test/ExtensionPropertiesVkTest.cpp index 25148f7f6..d57deaf11 100644 --- a/src/Magnum/Vk/Test/ExtensionPropertiesVkTest.cpp +++ b/src/Magnum/Vk/Test/ExtensionPropertiesVkTest.cpp @@ -208,6 +208,9 @@ void ExtensionPropertiesVkTest::namedRevision() { /* Unknown extensions return 0 */ CORRADE_COMPARE(properties.revision("VK_this_doesnt_exist"), 0); + /* Verify that we don't dereference garbage when std::lower_bound() returns + `last` */ + CORRADE_COMPARE(properties.revision("ZZZZZ"), 0); /* Verify the overloads that take our extension wrappers work as well */ CORRADE_COMPARE_AS(properties.revision(), 0, diff --git a/src/Magnum/Vk/Test/LayerPropertiesVkTest.cpp b/src/Magnum/Vk/Test/LayerPropertiesVkTest.cpp index c10177589..7bea566c6 100644 --- a/src/Magnum/Vk/Test/LayerPropertiesVkTest.cpp +++ b/src/Magnum/Vk/Test/LayerPropertiesVkTest.cpp @@ -125,6 +125,9 @@ void LayerPropertiesVkTest::isSupported() { LayerProperties properties = enumerateLayerProperties(); CORRADE_VERIFY(!properties.isSupported("this layer doesn't exist")); + /* Verify that we don't dereference garbage when std::lower_bound() returns + `last` */ + CORRADE_VERIFY(!properties.isSupported("ZZZZZ")); if(!properties.count()) CORRADE_SKIP("The driver reported no instance layers, can't fully test.");