diff options
author | Peng Wu <alexepico@gmail.com> | 2012-06-21 13:18:18 +0800 |
---|---|---|
committer | Peng Wu <alexepico@gmail.com> | 2012-06-21 13:18:18 +0800 |
commit | aa31075db890e53bc6cec08d99ba4fb250fcab12 (patch) | |
tree | c5f0f78ff5549610d94f5db73892b53920c29b60 | |
parent | 606b4b110302fad6590eca56cba7108681b8b434 (diff) | |
download | libpinyin-aa31075db890e53bc6cec08d99ba4fb250fcab12.tar.gz libpinyin-aa31075db890e53bc6cec08d99ba4fb250fcab12.tar.xz libpinyin-aa31075db890e53bc6cec08d99ba4fb250fcab12.zip |
refine asserts in large tables
-rw-r--r-- | src/include/novel_types.h | 1 | ||||
-rw-r--r-- | src/storage/chewing_large_table.cpp | 6 | ||||
-rw-r--r-- | src/storage/phrase_large_table.cpp | 8 |
3 files changed, 11 insertions, 4 deletions
diff --git a/src/include/novel_types.h b/src/include/novel_types.h index 014c11a..706afd4 100644 --- a/src/include/novel_types.h +++ b/src/include/novel_types.h @@ -78,6 +78,7 @@ enum ErrorResult{ ERROR_OK = 0, /* operate ok */ ERROR_INSERT_ITEM_EXISTS, /* item already exists */ ERROR_REMOVE_ITEM_DONOT_EXISTS, /* item don't exists */ + ERROR_PHRASE_TOO_LONG, /* the phrase is too long */ ERROR_NO_SUB_PHRASE_INDEX, /* sub phrase index is not loaded */ ERROR_NO_ITEM, /* item has a null slot */ ERROR_OUT_OF_RANGE, /* beyond the end of the sub phrase index */ diff --git a/src/storage/chewing_large_table.cpp b/src/storage/chewing_large_table.cpp index 9185976..ff53b75 100644 --- a/src/storage/chewing_large_table.cpp +++ b/src/storage/chewing_large_table.cpp @@ -490,7 +490,8 @@ int ChewingBitmapIndexLevel::remove_index(int phrase_length, int ChewingLengthIndexLevel::add_index(int phrase_length, /* in */ ChewingKey keys[], /* in */ phrase_token_t token) { - assert(phrase_length + 1 < MAX_PHRASE_LENGTH); + if (!(phrase_length + 1 < MAX_PHRASE_LENGTH)) + return ERROR_PHRASE_TOO_LONG; if (m_chewing_array_indexes->len <= phrase_length) g_array_set_size(m_chewing_array_indexes, phrase_length + 1); @@ -532,7 +533,8 @@ int ChewingLengthIndexLevel::add_index(int phrase_length, int ChewingLengthIndexLevel::remove_index(int phrase_length, /* in */ ChewingKey keys[], /* in */ phrase_token_t token) { - assert(phrase_length + 1 < MAX_PHRASE_LENGTH); + if (!(phrase_length + 1 < MAX_PHRASE_LENGTH)) + return ERROR_PHRASE_TOO_LONG; if (m_chewing_array_indexes->len <= phrase_length) return ERROR_REMOVE_ITEM_DONOT_EXISTS; diff --git a/src/storage/phrase_large_table.cpp b/src/storage/phrase_large_table.cpp index 195024e..1207b17 100644 --- a/src/storage/phrase_large_table.cpp +++ b/src/storage/phrase_large_table.cpp @@ -242,7 +242,9 @@ int PhraseBitmapIndexLevel::remove_index( int phrase_length, /* in */ ucs4_t phr } int PhraseLengthIndexLevel::add_index( int phrase_length, /* in */ ucs4_t phrase[], /* in */ phrase_token_t token){ - assert(phrase_length + 1 < MAX_PHRASE_LENGTH); + if (!(phrase_length + 1 < MAX_PHRASE_LENGTH)) + return ERROR_PHRASE_TOO_LONG; + if ( m_phrase_array_indexes -> len <= phrase_length ) g_array_set_size(m_phrase_array_indexes, phrase_length + 1); @@ -280,7 +282,9 @@ int PhraseLengthIndexLevel::add_index( int phrase_length, /* in */ ucs4_t phrase } int PhraseLengthIndexLevel::remove_index( int phrase_length, /* in */ ucs4_t phrase[], /* out */ phrase_token_t & token){ - assert(phrase_length + 1 < MAX_PHRASE_LENGTH); + if (!(phrase_length + 1 < MAX_PHRASE_LENGTH)) + return ERROR_PHRASE_TOO_LONG; + if ( m_phrase_array_indexes -> len <= phrase_length ) return ERROR_REMOVE_ITEM_DONOT_EXISTS; #define CASE(len) case len: \ |