[Libreoffice-commits] online.git: Branch 'distro/collabora/collabora-online-cd-3-2' - common/Util.hpp

Jan Holesovsky kendy at collabora.com
Wed Jul 18 14:21:18 UTC 2018


 common/Util.hpp |   16 ++++++++++++++--
 1 file changed, 14 insertions(+), 2 deletions(-)

New commits:
commit 3e121eac09653639ccbe359423a08def29fe9c96
Author: Jan Holesovsky <kendy at 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 <ashnakash at gmail.com>
    Tested-by: Ashod Nakashian <ashnakash at 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.


More information about the Libreoffice-commits mailing list