Skip to content

Commit

Permalink
Ensure std::string is not accidentally printed to Debug as ResourceKey.
Browse files Browse the repository at this point in the history
  • Loading branch information
mosra committed Jan 26, 2020
1 parent 169378e commit 2ba54b5
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
3 changes: 3 additions & 0 deletions doc/changelog.dox
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
9 changes: 8 additions & 1 deletion src/Magnum/Resource.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion src/Magnum/Test/ResourceManagerTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 2ba54b5

Please sign in to comment.