common/Util.hpp | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-)
New commits: commit 3e121eac09653639ccbe359423a08def29fe9c96 Author: Jan Holesovsky <ke...@collabora.com> Date: Wed Jul 18 16:18:03 2018 +0200 wsd: safer string splitting Change-Id: I88b82a3754c4f5e280f00be8e27614c3fe49eff8 Reviewed-on: https://gerrit.libreoffice.org/57644 Reviewed-by: Ashod Nakashian <ashnak...@gmail.com> Tested-by: Ashod Nakashian <ashnak...@gmail.com> diff --git a/common/Util.hpp b/common/Util.hpp index 719a1081c..d6e030264 100644 --- a/common/Util.hpp +++ b/common/Util.hpp @@ -278,7 +278,13 @@ namespace Util std::pair<std::string, std::string> split(const char* s, const int length, const char delimeter = ' ', bool removeDelim = true) { const auto size = getDelimiterPosition(s, length, delimeter); - return std::make_pair(std::string(s, size), std::string(s+size+removeDelim)); + + std::string after; + int after_pos = size + (removeDelim? 1: 0); + if (after_pos < length) + after = std::string(s + after_pos, length - after_pos); + + return std::make_pair(std::string(s, size), after); } /// Split a string in two at the delimeter, removing it. @@ -293,7 +299,13 @@ namespace Util std::pair<std::string, std::string> splitLast(const char* s, const int length, const char delimeter = ' ', bool removeDelim = true) { const auto size = getLastDelimiterPosition(s, length, delimeter); - return std::make_pair(std::string(s, size), std::string(s+size+removeDelim)); + + std::string after; + int after_pos = size + (removeDelim? 1: 0); + if (after_pos < length) + after = std::string(s + after_pos, length - after_pos); + + return std::make_pair(std::string(s, size), after); } /// Split a string in two at the delimeter, removing it. _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits