Modified to receive both remote_surrounding_text and cursor_position 76/111676/1
authorInHong Han <inhong1.han@samsung.com>
Mon, 23 Jan 2017 10:08:01 +0000 (19:08 +0900)
committerInHong Han <inhong1.han@samsung.com>
Mon, 23 Jan 2017 10:08:01 +0000 (19:08 +0900)
Change-Id: Idb77e9704368bc687c54b1dcfdca0a55cbfbb1c1

ism/modules/panelagent/wayland/wayland_panel_agent_module.cpp

index 4243e49..f6a56f8 100644 (file)
@@ -1769,19 +1769,24 @@ remote_surrounding_text_fd_read_func (void* data, Ecore_Fd_Handler* fd_handler)
 
     if (len == 0) {
         LOGD ("update");
+        LOGD ("remote_surrounding_text : %s, surrounding_cursor : %d\n", wsc_ctx->remote_surrounding_text, wsc_ctx->surrounding_cursor);
         isf_wsc_context_send_surrounding_text (wsc_ctx, wsc_ctx->remote_surrounding_text ? wsc_ctx->remote_surrounding_text : "", wsc_ctx->surrounding_cursor);
     } else if (len < 0) {
         LOGW ("failed");
     } else {
         buff[len] = '\0';
         if (wsc_ctx->remote_surrounding_text == NULL) {
-            wsc_ctx->remote_surrounding_text = (char*)malloc (len + 1);
-            if (wsc_ctx->remote_surrounding_text) {
-                memcpy (wsc_ctx->remote_surrounding_text, buff, len);
-                wsc_ctx->remote_surrounding_text[len] = '\0';
-                return ECORE_CALLBACK_RENEW;
-            } else {
-                LOGE ("malloc failed");
+            if (len >= (int)sizeof(int)) {
+                /* Add one byte for terminating NULL character and subtract <int> byte for cursor position */
+                wsc_ctx->remote_surrounding_text = (char*)malloc (len + 1 - sizeof(int));
+                if (wsc_ctx->remote_surrounding_text) {
+                    memcpy(&(wsc_ctx->surrounding_cursor), buff, sizeof(int));
+                    memcpy (wsc_ctx->remote_surrounding_text, buff + sizeof(int), len - sizeof(int));
+                    wsc_ctx->remote_surrounding_text[len - sizeof(int)] = '\0';
+                    return ECORE_CALLBACK_RENEW;
+                } else {
+                    LOGE ("malloc failed");
+                }
             }
         } else {
             int old_len = strlen (wsc_ctx->remote_surrounding_text);