detect corrupted phrase index log file
authorPeng Wu <alexepico@gmail.com>
Mon, 8 Oct 2012 05:51:37 +0000 (13:51 +0800)
committerPeng Wu <alexepico@gmail.com>
Mon, 8 Oct 2012 05:51:37 +0000 (13:51 +0800)
src/storage/phrase_index.cpp
src/storage/phrase_index_logger.h

index 64eb649..0424b3a 100644 (file)
@@ -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:{
index fe6070f..06f933e 100644 (file)
@@ -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;