From c193d01ad652b8da3bcd2b80e5ba271314228771 Mon Sep 17 00:00:00 2001 From: Wonkeun Oh Date: Thu, 19 May 2016 19:19:01 +0900 Subject: [PATCH] Fixed the crash issue when the surrounding text is null Change-Id: I8e2e0cbb7e68192eda28867c8c063854b79b578c --- ism/src/scim_helper.cpp | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/ism/src/scim_helper.cpp b/ism/src/scim_helper.cpp index 5a74a58..0b6a67f 100644 --- a/ism/src/scim_helper.cpp +++ b/ism/src/scim_helper.cpp @@ -1954,6 +1954,12 @@ HelperAgent::get_surrounding_text (int maxlen_before, int maxlen_after, String & { LOGD (""); + if (!m_impl || !m_impl->surrounding_text) { + text = utf8_wcstombs (WideString ()); + cursor = 0; + return; + } + WideString before = utf8_mbstowcs (String (m_impl->surrounding_text)); if (m_impl->cursor_pos > before.length ()) @@ -1983,7 +1989,16 @@ void HelperAgent::delete_surrounding_text (int offset, int len) const { LOGD ("offset = %d, len = %d", offset, len); - WideString ws = utf8_mbstowcs (m_impl->surrounding_text); + + if (!m_impl) + return; + + WideString ws; + + if (!m_impl->surrounding_text) + ws = utf8_mbstowcs (String ("")); + else + ws = utf8_mbstowcs (String (m_impl->surrounding_text)); int _offset = offset + m_impl->cursor_pos; -- 2.7.4