From f7a44387af9407d3d9d3224b5eec5077fe141445 Mon Sep 17 00:00:00 2001 From: Peng Wu Date: Wed, 6 Jul 2016 15:37:55 +0800 Subject: fixes empty input --- src/lookup/pinyin_lookup2.cpp | 3 +++ src/pinyin.cpp | 15 +++++++++++++++ src/storage/phonetic_key_matrix.cpp | 10 ++++++++++ 3 files changed, 28 insertions(+) diff --git a/src/lookup/pinyin_lookup2.cpp b/src/lookup/pinyin_lookup2.cpp index 6973ecd..42bbd0e 100644 --- a/src/lookup/pinyin_lookup2.cpp +++ b/src/lookup/pinyin_lookup2.cpp @@ -222,7 +222,10 @@ bool PinyinLookup2::get_best_match(TokenVector prefixes, MatchResults & results){ m_constraints = constraints; m_matrix = matrix; + int nstep = m_matrix->size(); + if (0 == nstep) + return false; clear_steps(m_steps_index, m_steps_content); diff --git a/src/pinyin.cpp b/src/pinyin.cpp index b3ca636..414cd38 100644 --- a/src/pinyin.cpp +++ b/src/pinyin.cpp @@ -2555,6 +2555,11 @@ bool pinyin_get_full_pinyin_auxiliary_text(pinyin_instance_t * instance, size_t cursor, gchar ** aux_text) { PhoneticKeyMatrix & matrix = instance->m_matrix; + if (0 == matrix.size()) { + *aux_text = g_strdup(""); + return false; + } + gchar * prefix = _get_aux_text_prefix (instance, cursor, IS_PINYIN); gchar * postfix = _get_aux_text_postfix @@ -2608,6 +2613,11 @@ bool pinyin_get_double_pinyin_auxiliary_text(pinyin_instance_t * instance, size_t cursor, gchar ** aux_text) { PhoneticKeyMatrix & matrix = instance->m_matrix; + if (0 == matrix.size()) { + *aux_text = g_strdup(""); + return false; + } + gchar * prefix = _get_aux_text_prefix (instance, cursor, IS_PINYIN); gchar * postfix = _get_aux_text_postfix @@ -2680,6 +2690,11 @@ bool pinyin_get_chewing_auxiliary_text(pinyin_instance_t * instance, size_t cursor, gchar ** aux_text) { PhoneticKeyMatrix & matrix = instance->m_matrix; + if (0 == matrix.size()) { + *aux_text = g_strdup(""); + return false; + } + gchar * prefix = _get_aux_text_prefix (instance, cursor, IS_ZHUYIN); gchar * postfix = _get_aux_text_postfix diff --git a/src/storage/phonetic_key_matrix.cpp b/src/storage/phonetic_key_matrix.cpp index 5b6ec5b..856738f 100644 --- a/src/storage/phonetic_key_matrix.cpp +++ b/src/storage/phonetic_key_matrix.cpp @@ -30,7 +30,11 @@ namespace pinyin{ bool fill_matrix(PhoneticKeyMatrix * matrix, ChewingKeyVector keys, ChewingKeyRestVector key_rests) { + matrix->clear_all(); + assert(keys->len == key_rests->len); + if (0 == keys->len) + return false; const ChewingKey * key = NULL; const ChewingKeyRest * key_rest = NULL; @@ -79,6 +83,8 @@ bool resplit_step(pinyin_option_t options, return false; size_t length = matrix->size(); + if (0 == length) + return false; GArray * keys = g_array_new(TRUE, TRUE, sizeof(ChewingKey)); GArray * key_rests = g_array_new(TRUE, TRUE, sizeof(ChewingKeyRest)); @@ -159,6 +165,8 @@ bool inner_split_step(pinyin_option_t options, return false; size_t length = matrix->size(); + if (0 == length) + return false; GArray * keys = g_array_new(TRUE, TRUE, sizeof(ChewingKey)); GArray * key_rests = g_array_new(TRUE, TRUE, sizeof(ChewingKeyRest)); @@ -214,6 +222,8 @@ bool fuzzy_syllable_step(pinyin_option_t options, return false; size_t length = matrix->size(); + if (0 == length) + return false; GArray * keys = g_array_new(TRUE, TRUE, sizeof(ChewingKey)); GArray * key_rests = g_array_new(TRUE, TRUE, sizeof(ChewingKeyRest)); -- cgit