} else {
buff[len] = '\0';
if (wsc_ctx->surrounding_text == NULL) {
- /* Add one byte for terminating NULL character and subtract <int> byte for cursor position */
- wsc_ctx->surrounding_text = (char*)malloc (len + 1 - sizeof(int));
- if (wsc_ctx->surrounding_text) {
- memcpy(&(wsc_ctx->surrounding_cursor), buff, sizeof(int));
- memcpy (wsc_ctx->surrounding_text, buff + sizeof(int), len >= sizeof(int) ? (len - sizeof(int)) : 0);
- wsc_ctx->surrounding_text[len - sizeof(int)] = '\0';
- return ECORE_CALLBACK_RENEW;
- } else {
- LOGE ("malloc failed");
+ if (len >= sizeof(int)) {
+ /* Add one byte for terminating NULL character and subtract <int> byte for cursor position */
+ wsc_ctx->surrounding_text = (char*)malloc (len + 1 - sizeof(int));
+ if (wsc_ctx->surrounding_text) {
+ memcpy(&(wsc_ctx->surrounding_cursor), buff, sizeof(int));
+ memcpy (wsc_ctx->surrounding_text, buff + sizeof(int), len - sizeof(int));
+ wsc_ctx->surrounding_text[len - sizeof(int)] = '\0';
+ return ECORE_CALLBACK_RENEW;
+ } else {
+ LOGE ("malloc failed");
+ }
}
} else {
int old_len = strlen (wsc_ctx->surrounding_text);