Browse Source

Ensure std::string is not accidentally printed to Debug as ResourceKey.

mousecapture
Vladimír Vondruš 6 years ago
parent
commit
2ba54b542c
  1. 3
      doc/changelog.dox
  2. 9
      src/Magnum/Resource.h
  3. 1
      src/Magnum/Test/ResourceManagerTest.cpp

3
doc/changelog.dox

@ -217,6 +217,9 @@ See also:
to be ignored even though Vsync was in fact not enabled.
- Fixed an otherwise harmless OOB access in @ref MeshTools::tipsify() that
could trigger ASan or debug iterator errors
- With @ref Corrade/Utility/DebugStl.h not being included, @ref std::string
instances could get accidentally printed as @ref ResourceKey instances.
Added and explicit header dependency to avoid such cases.
@subsection changelog-latest-deprecated Deprecated APIs

9
src/Magnum/Resource.h

@ -33,6 +33,13 @@
#include <Corrade/Utility/Assert.h>
#include <Corrade/Utility/MurmurHash2.h>
/* This is needed because ResourceKey is implicitly convertible from a
std::string -- and if DebugStl.h wouldn't be included, an attempt to print a
std::string would choose the ResourceKey printer instead, producing unwanted
results. */
/** @todo remove when we have a StringView and ResourceKey is ported to it */
#include <Corrade/Utility/DebugStl.h>
#include "Magnum/Magnum.h"
#include "Magnum/visibility.h"
@ -91,7 +98,7 @@ class ResourceKey: public Utility::MurmurHash2::Digest {
explicit ResourceKey(std::size_t key): Utility::MurmurHash2::Digest{Utility::MurmurHash2::Digest::fromByteArray(reinterpret_cast<const char*>(&key))} {}
/** @brief Constructor */
ResourceKey(const std::string& key): Utility::MurmurHash2::Digest(Utility::MurmurHash2()(key)) {}
/*implicit*/ ResourceKey(const std::string& key): Utility::MurmurHash2::Digest(Utility::MurmurHash2()(key)) {}
/**
* @brief Constructor

1
src/Magnum/Test/ResourceManagerTest.cpp

@ -26,7 +26,6 @@
#include <sstream>
#include <Corrade/TestSuite/Tester.h>
#include <Corrade/Utility/DebugStl.h>
#include <Corrade/Utility/FormatStl.h>
#include "Magnum/AbstractResourceLoader.h"

Loading…
Cancel
Save