diff options
author | Eric Albright <eric_albright@sil.org> | 2008-03-02 00:16:49 +0000 |
---|---|---|
committer | Eric Albright <eric_albright@sil.org> | 2008-03-02 00:16:49 +0000 |
commit | 7b8e3a1f27d41887599aaea8d11b83d1875c7595 (patch) | |
tree | 839108e43d94bcbddcd42e350729d5ac665547f6 | |
parent | 9cd2f8ef4485490d97e06fbd35cb14d638350a1e (diff) | |
download | enchant-7b8e3a1f27d41887599aaea8d11b83d1875c7595.tar.gz |
Fix crash when myspell dictionary is missing aff file
git-svn-id: svn+ssh://svn.abisource.com/svnroot/enchant/trunk@22987 bcba8976-2d24-0410-9c9c-aab3bd5fdfd6
-rw-r--r-- | src/myspell/myspell_checker.cpp | 32 |
1 files changed, 26 insertions, 6 deletions
diff --git a/src/myspell/myspell_checker.cpp b/src/myspell/myspell_checker.cpp index fdd9617..031eeea 100644 --- a/src/myspell/myspell_checker.cpp +++ b/src/myspell/myspell_checker.cpp @@ -315,9 +315,15 @@ MySpellChecker::requestDictionary(const char *szLang) aff = g_strdup(dic); int len_dic = strlen(dic); strcpy(aff+len_dic-3, "aff"); - myspell = new Hunspell(aff, dic); + if (g_file_test(aff, G_FILE_TEST_EXISTS)) + { + myspell = new Hunspell(aff, dic); + } g_free(dic); g_free(aff); + if(myspell == NULL){ + return false; + } char *enc = myspell->get_dic_encoding(); m_translate_in = g_iconv_open(enc, "UTF-8"); @@ -369,10 +375,19 @@ myspell_provider_enum_dicts (const char * const directory, int hit = dir_entry.rfind (".dic"); if (hit != -1) { - /* don't include hyphenation dictionaries */ - if(dir_entry.compare (0, 5, "hyph_") != 0){ - out_dicts.push_back (dir_entry.substr (0, hit)); - } + /* don't include hyphenation dictionaries + and require .aff file to be present*/ + if(dir_entry.compare (0, 5, "hyph_") != 0) + { + std::string name(dir_entry.substr (0, hit)); + std::string affFileName(name + ".aff"); + char * aff = g_build_filename(directory, affFileName.c_str(), NULL); + if (g_file_test(aff, G_FILE_TEST_EXISTS)) + { + out_dicts.push_back (dir_entry.substr (0, hit)); + } + g_free(aff); + } } } } @@ -475,7 +490,12 @@ myspell_provider_dictionary_exists (struct str_enchant_provider * me, s_buildHashNames (names, tag); for (size_t i = 0; i < names.size(); i++) { if (g_file_test (names[i].c_str(), G_FILE_TEST_EXISTS)) - return 1; + { + std::string aff(names[i]); + aff.replace(aff.end() - 3, aff.end(), "aff"); + if (g_file_test(aff.c_str(), G_FILE_TEST_EXISTS)) + return 1; + } } return 0; |