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);