[Libreoffice-commits] online.git: loolwsd/LOOLProtocol.cpp

Ashod Nakashian ashod.nakashian at collabora.co.uk
Sun Jan 24 13:01:21 PST 2016


 loolwsd/LOOLProtocol.cpp |   11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

New commits:
commit 2bb2e2aec1291468e3e03cff963fffbaad4b0241
Author: Ashod Nakashian <ashod.nakashian at collabora.co.uk>
Date:   Sat Jan 23 17:33:19 2016 -0500

    loolwsd: protect against empty messages
    
    Change-Id: Ic60c1abf85268c9ad629bc1f981e53688fc6267a
    Reviewed-on: https://gerrit.libreoffice.org/21753
    Reviewed-by: Ashod Nakashian <ashnakash at gmail.com>
    Tested-by: Ashod Nakashian <ashnakash at gmail.com>

diff --git a/loolwsd/LOOLProtocol.cpp b/loolwsd/LOOLProtocol.cpp
index 20c5d8e..993ef61 100644
--- a/loolwsd/LOOLProtocol.cpp
+++ b/loolwsd/LOOLProtocol.cpp
@@ -152,6 +152,9 @@ namespace LOOLProtocol
 
     std::string getFirstLine(const char *message, int length)
     {
+        if (message == nullptr || length <= 0)
+            return "";
+
         const char *endOfLine = static_cast<const char *>(std::memchr(message, '\n', length));
         if (endOfLine == nullptr)
             return std::string(message, length);
@@ -161,8 +164,12 @@ namespace LOOLProtocol
 
     std::string getAbbreviatedMessage(const char *message, int length)
     {
-        std::string result = "'" + getFirstLine(message, length) + "'";
-        if (result.size() < static_cast<std::string::size_type>(length))
+        if (message == nullptr || length <= 0)
+            return "";
+
+        const auto firstLine = getFirstLine(message, length);
+        std::string result = "'" + firstLine + "'";
+        if (firstLine.size() < static_cast<std::string::size_type>(length))
             result += "...";
         return result;
     }


More information about the Libreoffice-commits mailing list