Browse Source

Vk: well OF COURSE I made an error when using std::lower_bound()!

Goddammit, C++, why the hell all APIs have to be so error prone. You
didn't learn from C's mistakes at all, did you.
pull/494/head
Vladimír Vondruš 5 years ago
parent
commit
7461a2fe0a
  1. 2
      src/Magnum/Vk/ExtensionProperties.cpp
  2. 3
      src/Magnum/Vk/Test/ExtensionPropertiesVkTest.cpp
  3. 3
      src/Magnum/Vk/Test/LayerPropertiesVkTest.cpp

2
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 /* Thanks, C++, for forcing me to have a larger bug surface instead of
providing a library helper to find the damn thing. */ providing a library helper to find the damn thing. */
auto found = std::lower_bound(_names.begin(), _names.end(), extension); 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 view target is contents of the VkExtensionProperties structure,
the revision is stored nearby */ the revision is stored nearby */

3
src/Magnum/Vk/Test/ExtensionPropertiesVkTest.cpp

@ -208,6 +208,9 @@ void ExtensionPropertiesVkTest::namedRevision() {
/* Unknown extensions return 0 */ /* Unknown extensions return 0 */
CORRADE_COMPARE(properties.revision("VK_this_doesnt_exist"), 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 */ /* Verify the overloads that take our extension wrappers work as well */
CORRADE_COMPARE_AS(properties.revision<Extensions::KHR::get_physical_device_properties2>(), 0, CORRADE_COMPARE_AS(properties.revision<Extensions::KHR::get_physical_device_properties2>(), 0,

3
src/Magnum/Vk/Test/LayerPropertiesVkTest.cpp

@ -125,6 +125,9 @@ void LayerPropertiesVkTest::isSupported() {
LayerProperties properties = enumerateLayerProperties(); LayerProperties properties = enumerateLayerProperties();
CORRADE_VERIFY(!properties.isSupported("this layer doesn't exist")); 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()) if(!properties.count())
CORRADE_SKIP("The driver reported no instance layers, can't fully test."); CORRADE_SKIP("The driver reported no instance layers, can't fully test.");

Loading…
Cancel
Save