Add routine for checking out-of-memory on get_surrounding_text 36/68836/2
authorsungwook79.park <sungwook79.park@samsung.com>
Tue, 10 May 2016 05:29:34 +0000 (14:29 +0900)
committersungwook79.park <sungwook79.park@samsung.com>
Tue, 10 May 2016 06:00:54 +0000 (15:00 +0900)
Change-Id: I11a7e0a8f0d18aa53a35b8b57f93abf3a7ea5ede
Signed-off-by: sungwook79.park <sungwook79.park@samsung.com>
src/sclconnection-isf.cpp [changed mode: 0644->0755]
src/sclconnection-isf.h [changed mode: 0644->0755]
src/sclconnection.cpp [changed mode: 0644->0755]
src/sclconnection.h [changed mode: 0644->0755]
src/sclcore.cpp [changed mode: 0644->0755]
src/sclcore.h [changed mode: 0644->0755]
src/sclcoreimpl.cpp [changed mode: 0644->0755]
src/sclcoreimpl.h [changed mode: 0644->0755]

old mode 100644 (file)
new mode 100755 (executable)
index 5bb30a3..ef3f6aa
@@ -949,15 +949,20 @@ void CSCLConnectionISF::get_surrounding_text(const sclchar *ic_uuid, sclint maxl
     }
 }
 
-void CSCLConnectionISF::get_surrounding_text(sclint maxlen_before, sclint maxlen_after, sclchar **text, int &cursor)
+sclint CSCLConnectionISF::get_surrounding_text(sclint maxlen_before, sclint maxlen_after, sclchar **text, int &cursor)
 {
     if (m_initialized) {
         scim::String surrounding_text;
         m_helper_agent.get_surrounding_text(maxlen_before, maxlen_after, surrounding_text, cursor);
 
-        if (text)
+        if (text) {
             *text = strdup(surrounding_text.c_str());
+            if (*text == NULL) {
+                return -1;
+            }
+        }
     }
+    return 0;
 }
 
 void CSCLConnectionISF::delete_surrounding_text(sclint offset, sclint len) const
old mode 100644 (file)
new mode 100755 (executable)
index 0d8bd5b..fc3b976
@@ -83,7 +83,7 @@ public:
     void get_keyboard_ise(const sclchar *uuid);
     void set_selection(sclint start, sclint end);
     void send_private_command(const char *command);
-    void get_surrounding_text(sclint maxlen_before, sclint maxlen_after, sclchar **text, int &cursor);
+    sclint get_surrounding_text(sclint maxlen_before, sclint maxlen_after, sclchar **text, int &cursor);
     void get_selection_text(sclchar **text);
 private:
     sclboolean m_initialized;
old mode 100644 (file)
new mode 100755 (executable)
index 6a7b6e2..0f09588
@@ -273,11 +273,13 @@ void CSCLConnection::get_surrounding_text(const sclchar *ic_uuid, sclint maxlen_
     }
 }
 
-void CSCLConnection::get_surrounding_text(sclint maxlen_before, sclint maxlen_after, sclchar **text, int &cursor)
+sclint CSCLConnection::get_surrounding_text(sclint maxlen_before, sclint maxlen_after, sclchar **text, int &cursor)
 {
+    sclint ret = -1;
     if (m_impl) {
-        m_impl->get_surrounding_text(maxlen_before, maxlen_after, text, cursor);
+        ret = m_impl->get_surrounding_text(maxlen_before, maxlen_after, text, cursor);
     }
+    return ret;
 }
 
 void CSCLConnection::delete_surrounding_text(sclint offset, sclint len) const
old mode 100644 (file)
new mode 100755 (executable)
index 806c4da..6513fa0
@@ -83,7 +83,7 @@ public:
     virtual void get_keyboard_ise(const sclchar *uuid);
     virtual void set_selection(sclint start, sclint end);
     virtual void send_private_command(const sclchar *command);
-    virtual void get_surrounding_text(sclint maxlen_before, sclint maxlen_after, sclchar **text, int &cursor);
+    virtual sclint get_surrounding_text(sclint maxlen_before, sclint maxlen_after, sclchar **text, int &cursor);
     virtual void get_selection_text(sclchar **text);
 protected:
     std::string m_backend_identifier;
old mode 100644 (file)
new mode 100755 (executable)
index 2749ee2..98ed9af
@@ -242,11 +242,13 @@ void CSCLCore::get_surrounding_text(const sclchar *ic_uuid, sclint maxlen_before
     }
 }
 
-void CSCLCore::get_surrounding_text(sclint maxlen_before, sclint maxlen_after, sclchar **text, int &cursor) const
+sclint CSCLCore::get_surrounding_text(sclint maxlen_before, sclint maxlen_after, sclchar **text, int &cursor) const
 {
+    sclint ret = -1;
     if (m_impl) {
-        m_impl->get_surrounding_text(maxlen_before, maxlen_after, text, cursor);
+        ret = m_impl->get_surrounding_text(maxlen_before, maxlen_after, text, cursor);
     }
+    return ret;
 }
 
 void CSCLCore::delete_surrounding_text(sclint offset, sclint len) const
old mode 100644 (file)
new mode 100755 (executable)
index 3a5d909..3ec6270
@@ -350,8 +350,10 @@ public:
      * @param[in] maxlen_after The max length of after.
      * @param[out] text The surrounding text.
      * @param[out] cursor The cursor position.
+     *
+     * @return 0 on success, otherwise a negative error value
      */
-    void get_surrounding_text(sclint maxlen_before, sclint maxlen_after, sclchar **text, int &cursor) const;
+    sclint get_surrounding_text(sclint maxlen_before, sclint maxlen_after, sclchar **text, int &cursor) const;
 
     /**
      * @brief Get the selected text.
old mode 100644 (file)
new mode 100755 (executable)
index f5d5591..d4ecaa8
@@ -232,9 +232,9 @@ void CSCLCoreImpl::get_surrounding_text(const sclchar* ic_uuid, sclint maxlen_be
     m_connection.get_surrounding_text(ic_uuid, maxlen_before, maxlen_after);
 }
 
-void CSCLCoreImpl::get_surrounding_text(sclint maxlen_before, sclint maxlen_after, sclchar **text, int &cursor)
+sclint CSCLCoreImpl::get_surrounding_text(sclint maxlen_before, sclint maxlen_after, sclchar **text, int &cursor)
 {
-    m_connection.get_surrounding_text(maxlen_before, maxlen_after, text, cursor);
+    return m_connection.get_surrounding_text(maxlen_before, maxlen_after, text, cursor);
 }
 
 void CSCLCoreImpl::delete_surrounding_text(sclint offset, sclint len) const
old mode 100644 (file)
new mode 100755 (executable)
index 78c84be..5a20507
@@ -101,7 +101,7 @@ public:
 
     void set_selection(sclint start, sclint end);
     void send_private_command(const sclchar *command);
-    void get_surrounding_text(sclint maxlen_before, sclint maxlen_after, sclchar **text, int &cursor);
+    sclint get_surrounding_text(sclint maxlen_before, sclint maxlen_after, sclchar **text, int &cursor);
     void get_selection_text(sclchar **text);
 
 private: