From 9175eca04bac68fa4be1a6e1ef054ddd7f208e8c Mon Sep 17 00:00:00 2001 From: Peng Wu Date: Wed, 6 Jul 2016 16:34:53 +0800 Subject: add safe guards --- src/pinyin.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/pinyin.cpp b/src/pinyin.cpp index 414cd38..8500311 100644 --- a/src/pinyin.cpp +++ b/src/pinyin.cpp @@ -2335,7 +2335,7 @@ bool pinyin_get_pinyin_offset(pinyin_instance_t * instance, size_t cursor, size_t * poffset) { PhoneticKeyMatrix & matrix = instance->m_matrix; - size_t offset = cursor; + size_t offset = std_lite::min(cursor, instance->m_parsed_len); /* find the first ChewingKey. */ for (; offset > 0; --offset) { @@ -2560,6 +2560,7 @@ bool pinyin_get_full_pinyin_auxiliary_text(pinyin_instance_t * instance, return false; } + cursor = std_lite::min(cursor, instance->m_parsed_len); gchar * prefix = _get_aux_text_prefix (instance, cursor, IS_PINYIN); gchar * postfix = _get_aux_text_postfix @@ -2618,6 +2619,7 @@ bool pinyin_get_double_pinyin_auxiliary_text(pinyin_instance_t * instance, return false; } + cursor = std_lite::min(cursor, instance->m_parsed_len); gchar * prefix = _get_aux_text_prefix (instance, cursor, IS_PINYIN); gchar * postfix = _get_aux_text_postfix @@ -2695,6 +2697,7 @@ bool pinyin_get_chewing_auxiliary_text(pinyin_instance_t * instance, return false; } + cursor = std_lite::min(cursor, instance->m_parsed_len); gchar * prefix = _get_aux_text_prefix (instance, cursor, IS_ZHUYIN); gchar * postfix = _get_aux_text_postfix -- cgit