From bee691f0e31f0b661f7c2c16230163dd7d526d4c Mon Sep 17 00:00:00 2001 From: Peng Wu Date: Wed, 1 Sep 2010 17:04:38 +0800 Subject: [PATCH] add safe check for load_text. --- src/storage/phrase_large_table.cpp | 5 ++++- src/storage/pinyin_large_table.cpp | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/storage/phrase_large_table.cpp b/src/storage/phrase_large_table.cpp index d8810d3..b115ceb 100644 --- a/src/storage/phrase_large_table.cpp +++ b/src/storage/phrase_large_table.cpp @@ -318,12 +318,15 @@ bool PhraseLargeTable::load_text(FILE * infile){ phrase_token_t token; size_t freq; - while ( !feof(infile) ){ + while ( !feof(infile) ) { fscanf(infile, "%s", pinyin); fscanf(infile, "%s", phrase); fscanf(infile, "%ld", &token); fscanf(infile, "%ld", &freq); + if ( feof(infile) ) + break; + glong phrase_len = g_utf8_strlen(phrase, -1); utf16_t * new_phrase = g_utf8_to_utf16(phrase, -1, NULL, NULL, NULL); add_index(phrase_len, new_phrase, token); diff --git a/src/storage/pinyin_large_table.cpp b/src/storage/pinyin_large_table.cpp index 07f643e..a5ed998 100644 --- a/src/storage/pinyin_large_table.cpp +++ b/src/storage/pinyin_large_table.cpp @@ -483,11 +483,14 @@ bool PinyinLargeTable::load_text(FILE * infile){ phrase_token_t token; size_t freq; - while ( !feof(infile)){ + while ( !feof(infile) ) { fscanf(infile, "%s", pinyin); fscanf(infile, "%s", phrase); fscanf(infile, "%ld", &token); fscanf(infile, "%ld", &freq); + + if ( feof(infile) ) + break; PinyinDefaultParser parser; NullPinyinValidator validator; -- 2.7.4