summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric Albright <eric_albright@sil.org>2007-11-28 09:42:23 +0000
committerEric Albright <eric_albright@sil.org>2007-11-28 09:42:23 +0000
commit0907f12f2ddeaae1279a90bd344c9dd2a170f2dd (patch)
tree85936b81dd8a51b292283e8793382519e187f696
parentf99bda15757fb4f86cf668fc16745a024feb6c72 (diff)
downloadenchant-0907f12f2ddeaae1279a90bd344c9dd2a170f2dd.tar.gz
ignore lines that are longer than the read buffer for pwl
git-svn-id: svn+ssh://svn.abisource.com/svnroot/enchant/trunk@22346 bcba8976-2d24-0410-9c9c-aab3bd5fdfd6
-rw-r--r--src/pwl.c13
-rw-r--r--unittests/pwl/enchant_pwl_tests.cpp33
2 files changed, 44 insertions, 2 deletions
diff --git a/src/pwl.c b/src/pwl.c
index dd85a5c..73bfbfc 100644
--- a/src/pwl.c
+++ b/src/pwl.c
@@ -267,7 +267,7 @@ EnchantPWL* enchant_pwl_init_with_file(const char * file)
enchant_lock_file (f);
- while (NULL != (fgets (buffer, sizeof (buffer), f)))
+ for (;NULL != (fgets (buffer, sizeof (buffer), f));++line_number)
{
const gunichar BOM = 0xfeff;
size_t l;
@@ -279,6 +279,16 @@ EnchantPWL* enchant_pwl_init_with_file(const char * file)
l = strlen(line)-1;
if (line[l]=='\n')
line[l] = '\0';
+ else if(!feof(f)) /* ignore lines longer than BUFSIZ. */
+ {
+ g_warning ("Line too long (ignored) in %s at line:%u\n", pwl->filename, line_number);
+ while (NULL != (fgets (buffer, sizeof (buffer), f)))
+ {
+ if (line[strlen(buffer)-1]=='\n')
+ break;
+ }
+ continue;
+ }
if( line[0] != '#')
{
@@ -287,7 +297,6 @@ EnchantPWL* enchant_pwl_init_with_file(const char * file)
else
g_warning ("Bad UTF-8 sequence in %s at line:%u\n", pwl->filename, line_number);
}
- ++line_number;
}
enchant_unlock_file (f);
diff --git a/unittests/pwl/enchant_pwl_tests.cpp b/unittests/pwl/enchant_pwl_tests.cpp
index bf5f55a..202f5d3 100644
--- a/unittests/pwl/enchant_pwl_tests.cpp
+++ b/unittests/pwl/enchant_pwl_tests.cpp
@@ -120,6 +120,39 @@ TEST_FIXTURE(EnchantPwl_TestFixture,
}
/////////////////////////////////////////////////////////////////////////////////////////////////
+// Too long lines ignored
+TEST_FIXTURE(EnchantPwl_TestFixture,
+ IsWordInDictionary_DictionaryHasSuperLongLine_DoesNotReadLine)
+{
+ const size_t lineLen = 2048;
+
+ std::vector<const std::string> sWords;
+ sWords.push_back("cat");
+ sWords.push_back("hat");
+ sWords.push_back("that");
+ sWords.push_back("bat");
+ sWords.push_back("tot");
+
+ std::vector<const std::string>::const_iterator superlong = sWords.insert(sWords.begin()+2, std::string(lineLen, 'c')); //super long line
+ ExternalAddWordsToDictionary(sWords);
+ ReloadTestDictionary();
+
+ for(std::vector<const std::string>::const_iterator itWord = sWords.begin(); itWord != superlong; ++itWord){
+ CHECK( IsWordInDictionary(*itWord) );
+ }
+
+ CHECK(!IsWordInDictionary(*superlong) );
+ for(size_t i=0; i != lineLen; ++i)
+ {
+ CHECK(!IsWordInDictionary(std::string(i, 'c')) );
+ }
+
+ for(std::vector<const std::string>::const_iterator itWord = superlong+1; itWord != sWords.end(); ++itWord){
+ CHECK(IsWordInDictionary(*itWord) );
+ }
+}
+
+/////////////////////////////////////////////////////////////////////////////////////////////////
// Unicode normalization
TEST_FIXTURE(EnchantPwl_TestFixture,
IsWordInDictionary_DictionaryHasComposed_SuccessfulCheckWithComposedAndDecomposed)