summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPeng Wu <alexepico@gmail.com>2012-10-08 13:51:37 +0800
committerPeng Wu <alexepico@gmail.com>2012-10-08 13:51:37 +0800
commitb999e8758ccdc340eeb8204b3cf2a9cdacccfc31 (patch)
tree6c7745ba03a55f6f1e0fd97fb908f26c9767f359
parent4e024b971a013799ddd201011aca30a94870a46e (diff)
downloadlibpinyin-b999e8758ccdc340eeb8204b3cf2a9cdacccfc31.tar.gz
libpinyin-b999e8758ccdc340eeb8204b3cf2a9cdacccfc31.tar.xz
libpinyin-b999e8758ccdc340eeb8204b3cf2a9cdacccfc31.zip
detect corrupted phrase index log file
-rw-r--r--src/storage/phrase_index.cpp6
-rw-r--r--src/storage/phrase_index_logger.h10
2 files changed, 13 insertions, 3 deletions
diff --git a/src/storage/phrase_index.cpp b/src/storage/phrase_index.cpp
index 64eb649..0424b3a 100644
--- a/src/storage/phrase_index.cpp
+++ b/src/storage/phrase_index.cpp
@@ -361,7 +361,11 @@ bool SubPhraseIndex::merge(PhraseIndexLogger * logger){
PhraseItem olditem, newitem, item, * tmpitem;
while(logger->has_next_record()){
- logger->next_record(log_type, token, &oldchunk, &newchunk);
+ bool retval = logger->next_record
+ (log_type, token, &oldchunk, &newchunk);
+
+ if (!retval)
+ break;
switch(log_type){
case LOG_ADD_RECORD:{
diff --git a/src/storage/phrase_index_logger.h b/src/storage/phrase_index_logger.h
index fe6070f..06f933e 100644
--- a/src/storage/phrase_index_logger.h
+++ b/src/storage/phrase_index_logger.h
@@ -59,6 +59,7 @@ class PhraseIndexLogger{
protected:
MemoryChunk * m_chunk;
size_t m_offset;
+ bool m_error;
void reset(){
if ( m_chunk ){
@@ -66,6 +67,7 @@ protected:
m_chunk = NULL;
}
m_offset = 0;
+ m_error = false;
}
public:
/**
@@ -74,7 +76,7 @@ public:
* The constructor of the PhraseIndexLogger.
*
*/
- PhraseIndexLogger():m_offset(0){
+ PhraseIndexLogger():m_offset(0), m_error(false){
m_chunk = new MemoryChunk;
}
@@ -123,6 +125,9 @@ public:
*
*/
bool has_next_record(){
+ if (m_error)
+ return false;
+
return m_offset < m_chunk->size();
}
@@ -204,7 +209,8 @@ public:
break;
}
default:
- assert(false);
+ m_error = true;
+ return false;
}
m_offset = offset;