From 7fa8fe75721e91bcc6449ed35542b520f89800d6 Mon Sep 17 00:00:00 2001 From: Bart van Strien Date: Fri, 28 Jul 2017 14:49:35 +0200 Subject: [PATCH] Fix replacement when using love.joystick.setGamepadMapping (issue #1298) The broken find code would previously cause the (duplicate) key to be appended to the end, now it successfully replaces the previous value --HG-- branch : minor --- src/modules/joystick/sdl/JoystickModule.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/modules/joystick/sdl/JoystickModule.cpp b/src/modules/joystick/sdl/JoystickModule.cpp index ec51ff06c..4ef7587af 100644 --- a/src/modules/joystick/sdl/JoystickModule.cpp +++ b/src/modules/joystick/sdl/JoystickModule.cpp @@ -241,15 +241,15 @@ bool JoystickModule::setGamepadMapping(const std::string &guid, Joystick::Gamepa std::string insertstr = gpinputname + ":" + joyinputstr + ","; // We should replace any existing gamepad bind. - size_t findpos = mapstr.find(std::string(", ") + gpinputname + ":"); + size_t findpos = mapstr.find("," + gpinputname + ":"); if (findpos != std::string::npos) { // The bind string ends at the next comma, or the end of the string. - size_t endpos = mapstr.find_first_of(',', findpos); + size_t endpos = mapstr.find_first_of(',', findpos + 1); if (endpos == std::string::npos) endpos = mapstr.length() - 1; - mapstr.replace(findpos, endpos - findpos + 1, insertstr); + mapstr.replace(findpos + 1, endpos - findpos + 1, insertstr); } else {