From b72300d3ab1ca7e06bbee6fd1c4bcae2e64cbe9a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-Fran=C3=A7ois=20Verdon?= Date: Tue, 16 Feb 2016 14:54:46 +0100 Subject: [PATCH] Using char* as key for unordered_map can lead to unexpected behavior (the hash used for the key is computed using pointer address, not string content) --- examples/common/entry/input.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/examples/common/entry/input.cpp b/examples/common/entry/input.cpp index c0d2686d2..bb9925990 100644 --- a/examples/common/entry/input.cpp +++ b/examples/common/entry/input.cpp @@ -11,6 +11,7 @@ #include #include +#include #include #include namespace stl = tinystl; @@ -197,12 +198,12 @@ struct Input void addBindings(const char* _name, const InputBinding* _bindings) { - m_inputBindingsMap.insert(stl::make_pair(_name, _bindings) ); + m_inputBindingsMap.insert(stl::make_pair(stl::string(_name), _bindings) ); } void removeBindings(const char* _name) { - InputBindingMap::iterator it = m_inputBindingsMap.find(_name); + InputBindingMap::iterator it = m_inputBindingsMap.find(stl::string(_name)); if (it != m_inputBindingsMap.end() ) { m_inputBindingsMap.erase(it); @@ -275,7 +276,7 @@ struct Input } } - typedef stl::unordered_map InputBindingMap; + typedef stl::unordered_map InputBindingMap; InputBindingMap m_inputBindingsMap; Mouse m_mouse; Keyboard m_keyboard;