diff options
author | Jan Holesovsky <kendy@collabora.com> | 2018-07-18 16:18:03 +0200 |
---|---|---|
committer | Ashod Nakashian <ashnakash@gmail.com> | 2018-07-18 16:21:00 +0200 |
commit | 3e121eac09653639ccbe359423a08def29fe9c96 (patch) | |
tree | a3bc61e8e618b6e3d1566c83db74b541afdcea73 | |
parent | c7fd420e0c7e53b7d2aa21640fe81da910d9a7af (diff) |
wsd: safer string splittingcd-3.2.2-7
Change-Id: I88b82a3754c4f5e280f00be8e27614c3fe49eff8
Reviewed-on: https://gerrit.libreoffice.org/57644
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
-rw-r--r-- | common/Util.hpp | 16 |
1 files changed, 14 insertions, 2 deletions
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. |